diff options
author | George Hazan <ghazan@miranda.im> | 2022-04-16 16:48:24 +0300 |
---|---|---|
committer | George Hazan <ghazan@miranda.im> | 2022-04-16 16:48:24 +0300 |
commit | 86e467dcc11f7f5accd6f123e8bfbaf4ef5d1208 (patch) | |
tree | d7234a92eca3838223da73c38f632173af8e304d /plugins | |
parent | 86b82de0ec0aa933bf8101cef55597e19d78d6a8 (diff) |
fixes #3065 (PluginUpdater настойчиво хочет переименовать языковой пакет) + code cleaning
Diffstat (limited to 'plugins')
-rw-r--r-- | plugins/PluginUpdater/src/DlgListNew.cpp | 10 | ||||
-rw-r--r-- | plugins/PluginUpdater/src/DlgUpdate.cpp | 101 | ||||
-rw-r--r-- | plugins/PluginUpdater/src/Events.cpp | 2 | ||||
-rw-r--r-- | plugins/PluginUpdater/src/Options.cpp | 16 | ||||
-rw-r--r-- | plugins/PluginUpdater/src/PluginUpdater.cpp | 1 | ||||
-rw-r--r-- | plugins/PluginUpdater/src/Utils.cpp | 9 | ||||
-rw-r--r-- | plugins/PluginUpdater/src/stdafx.h | 3 |
7 files changed, 66 insertions, 76 deletions
diff --git a/plugins/PluginUpdater/src/DlgListNew.cpp b/plugins/PluginUpdater/src/DlgListNew.cpp index bcc050163f..78b29e7e05 100644 --- a/plugins/PluginUpdater/src/DlgListNew.cpp +++ b/plugins/PluginUpdater/src/DlgListNew.cpp @@ -285,8 +285,6 @@ public: TFileName wszTempFolder, wszBackupFolder;
CreateWorkFolders(wszTempFolder, wszBackupFolder);
- VARSW wszMirandaPath(L"%miranda_path%");
-
HNETLIBCONN nlc = nullptr;
int i = 0;
for (auto &p : *todo) {
@@ -300,7 +298,7 @@ public: if (DownloadFile(&p->File, nlc) == ERROR_SUCCESS) {
m_list.SetItemText(i, 1, TranslateT("Succeeded."));
- if (!unzip(p->File.wszDiskPath, wszMirandaPath, wszBackupFolder, false))
+ if (!unzip(p->File.wszDiskPath, g_mirandaPath, wszBackupFolder, false))
PU::SafeDeleteFile(p->File.wszDiskPath); // remove .zip after successful update
db_unset(0, DB_MODULE_NEW_FILES, _T2A(p->wszOldName));
}
@@ -392,11 +390,10 @@ static void GetList(void *) }
FILELIST *UpdateFiles = new FILELIST(20);
- VARSW dirname(L"%miranda_path%");
for (auto &it : hashes) {
TFileName pwszPath;
- mir_snwprintf(pwszPath, L"%s\\%s", dirname.get(), it->m_name);
+ mir_snwprintf(pwszPath, L"%s\\%s", g_mirandaPath.get(), it->m_name);
if (GetFileAttributes(pwszPath) == INVALID_FILE_ATTRIBUTES) {
FILEINFO *FileInfo = ServerEntryToFileInfo(*it, baseUrl, pwszPath);
@@ -469,9 +466,8 @@ static INT_PTR ParseUriService(WPARAM, LPARAM lParam) if (hash == nullptr)
return 0;
- VARSW dirName(L"%miranda_path%");
TFileName pwszPath;
- mir_snwprintf(pwszPath, L"%s\\%s", dirName.get(), hash->m_name);
+ mir_snwprintf(pwszPath, L"%s\\%s", g_mirandaPath.get(), hash->m_name);
FILEINFO *fileInfo = ServerEntryToFileInfo(*hash, baseUrl, pwszPath);
FILELIST *fileList = new FILELIST(1);
diff --git a/plugins/PluginUpdater/src/DlgUpdate.cpp b/plugins/PluginUpdater/src/DlgUpdate.cpp index 8f626876fa..3681b992a7 100644 --- a/plugins/PluginUpdater/src/DlgUpdate.cpp +++ b/plugins/PluginUpdater/src/DlgUpdate.cpp @@ -44,7 +44,6 @@ class CUpdateDLg : public CDlgBase return;
}
- VARSW wszMirandaPath(L"%miranda_path%");
{
ThreadWatch threadId(pDlg->dwThreadId);
@@ -88,7 +87,7 @@ class CUpdateDLg : public CDlgBase if (it->bDeleteOnly) {
// we need only to backup the old file
TFileName wszBackFile;
- mir_snwprintf(wszBackFile, L"%s\\%s", wszBackupFolder, it->wszNewName + wcslen(wszMirandaPath) + 1);
+ mir_snwprintf(wszBackFile, L"%s\\%s", wszBackupFolder, it->wszNewName + wcslen(g_mirandaPath) + 1);
if (dwErrorCode = BackupFile(it->wszNewName, wszBackFile)) {
LBL_Error:
RollbackChanges(wszBackupFolder);
@@ -104,13 +103,13 @@ LBL_Error: // otherwise it would be replaced by unzip
if (_wcsicmp(it->wszOldName, it->wszNewName)) {
TFileName wszSrcPath, wszBackFile;
- mir_snwprintf(wszSrcPath, L"%s\\%s", wszMirandaPath.get(), it->wszOldName);
+ mir_snwprintf(wszSrcPath, L"%s\\%s", g_mirandaPath.get(), it->wszOldName);
mir_snwprintf(wszBackFile, L"%s\\%s", wszBackupFolder, it->wszOldName);
if (dwErrorCode = BackupFile(wszSrcPath, wszBackFile))
goto LBL_Error;
}
- if (dwErrorCode = unzip(it->File.wszDiskPath, wszMirandaPath, wszBackupFolder, true))
+ if (dwErrorCode = unzip(it->File.wszDiskPath, g_mirandaPath, wszBackupFolder, true))
goto LBL_Error;
PU::SafeDeleteFile(it->File.wszDiskPath); // remove .zip after successful update
@@ -408,13 +407,12 @@ static void DlgUpdateSilent(void *param) // 3) Unpack all zips
uint32_t dwErrorCode;
- VARSW wszMirandaPath(L"%miranda_path%");
for (auto &it : UpdateFiles) {
if (it->bEnabled) {
if (it->bDeleteOnly) {
// we need only to backup the old file
TFileName wszBackFile;
- mir_snwprintf(wszBackFile, L"%s\\%s", wszBackupFolder, it->wszNewName + wcslen(wszMirandaPath) + 1);
+ mir_snwprintf(wszBackFile, L"%s\\%s", wszBackupFolder, it->wszNewName + wcslen(g_mirandaPath) + 1);
if (dwErrorCode = BackupFile(it->wszNewName, wszBackFile)) {
LBL_Error:
RollbackChanges(wszBackupFolder);
@@ -428,14 +426,14 @@ LBL_Error: // otherwise it would be replaced by unzip
if (_wcsicmp(it->wszOldName, it->wszNewName)) {
TFileName wszSrcPath, wszBackFile;
- mir_snwprintf(wszSrcPath, L"%s\\%s", wszMirandaPath.get(), it->wszOldName);
+ mir_snwprintf(wszSrcPath, L"%s\\%s", g_mirandaPath.get(), it->wszOldName);
mir_snwprintf(wszBackFile, L"%s\\%s", wszBackupFolder, it->wszOldName);
if (dwErrorCode = BackupFile(wszSrcPath, wszBackFile))
goto LBL_Error;
}
// remove .zip after successful update
- if (dwErrorCode = unzip(it->File.wszDiskPath, wszMirandaPath, wszBackupFolder, true))
+ if (dwErrorCode = unzip(it->File.wszDiskPath, g_mirandaPath, wszBackupFolder, true))
goto LBL_Error;
PU::SafeDeleteFile(it->File.wszDiskPath);
}
@@ -580,18 +578,26 @@ static renameTable[] = // Checks if file needs to be renamed and copies it in pNewName
// Returns true if smth. was copied
-static bool CheckFileRename(const wchar_t *pwszOldName, wchar_t *pNewName)
+static bool CheckFileRename(const wchar_t *pwszFolder, const wchar_t *pwszOldName, wchar_t *pNewName)
{
+ MFilePath fullOldPath;
+ fullOldPath.Format(L"%s\\%s", pwszFolder, pwszOldName);
+
for (auto &it : renameTable) {
if (wildcmpiw(pwszOldName, it.oldName)) {
- wchar_t *pwszDest = it.newName;
- if (pwszDest == nullptr)
+ if (it.newName == nullptr)
*pNewName = 0;
else {
- wcsncpy_s(pNewName, MAX_PATH, pwszDest, _TRUNCATE);
- size_t cbLen = wcslen(pwszDest) - 1;
+ wcsncpy_s(pNewName, MAX_PATH, it.newName, _TRUNCATE);
+ size_t cbLen = wcslen(it.newName) - 1;
if (pNewName[cbLen] == '*')
wcsncpy_s(pNewName + cbLen, MAX_PATH - cbLen, pwszOldName, _TRUNCATE);
+
+ // don't try to rename a file to itself
+ MFilePath fullNewPath;
+ fullNewPath.Format(L"%s\\%s", g_mirandaPath.get(), pNewName);
+ if (fullNewPath == fullOldPath)
+ return false;
}
return true;
}
@@ -623,51 +629,46 @@ static bool isValidDirectory(const wchar_t *pwszDirName) static int ScanFolder(const wchar_t *pwszFolder, size_t cbBaseLen, const wchar_t *pwszBaseUrl, SERVLIST &hashes, OBJLIST<FILEINFO> *UpdateFiles, int level = 0)
{
- TFileName wszBuf;
- mir_snwprintf(wszBuf, L"%s\\*", pwszFolder);
-
- WIN32_FIND_DATA ffd;
- HANDLE hFind = FindFirstFile(wszBuf, &ffd);
- if (hFind == INVALID_HANDLE_VALUE)
- return 0;
-
Netlib_LogfW(g_hNetlibUser, L"Scanning folder %s", pwszFolder);
int count = 0;
- do {
+
+ MFilePath wszBuf;
+ wszBuf.Format(L"%s\\*", pwszFolder);
+ for (auto &ff: wszBuf.search()) {
TFileName wszNewName;
- if (ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
+ if (ff.isDir()) {
// Scan recursively all subfolders
- if (isValidDirectory(ffd.cFileName)) {
- mir_snwprintf(wszBuf, L"%s\\%s", pwszFolder, ffd.cFileName);
+ if (isValidDirectory(ff.getPath())) {
+ wszBuf.Format(L"%s\\%s", pwszFolder, ff.getPath());
count += ScanFolder(wszBuf, cbBaseLen, pwszBaseUrl, hashes, UpdateFiles, level + 1);
}
continue;
}
// create full name of the current file
- mir_snwprintf(wszBuf, L"%s\\%s", pwszFolder, ffd.cFileName);
+ wszBuf.Format(L"%s\\%s", pwszFolder, ff.getPath());
- if (isValidExtension(ffd.cFileName)) {
+ if (isValidExtension(ff.getPath())) {
// calculate the current file's relative name and store it into wszNewName
- if (CheckFileRename(ffd.cFileName, wszNewName)) {
+ if (CheckFileRename(pwszFolder, ff.getPath(), wszNewName)) {
if (wszNewName[0])
- Netlib_LogfW(g_hNetlibUser, L"File <%s> will be renamed to <%s>", wszBuf, wszNewName);
+ Netlib_LogfW(g_hNetlibUser, L"File <%s> will be renamed to <%s>", wszBuf.c_str(), wszNewName);
else
- Netlib_LogfW(g_hNetlibUser, L"File <%s> will be deleted", wszBuf);
+ Netlib_LogfW(g_hNetlibUser, L"File <%s> will be deleted", wszBuf.c_str());
}
else {
if (level == 0) {
// Rename Miranda*.exe
- wcsncpy_s(wszNewName, g_plugin.bChangePlatform && !mir_wstrcmpi(ffd.cFileName, OLD_FILENAME) ? NEW_FILENAME : ffd.cFileName, _TRUNCATE);
- mir_snwprintf(wszBuf, L"%s\\%s", pwszFolder, wszNewName);
+ wcsncpy_s(wszNewName, g_plugin.bChangePlatform && !mir_wstrcmpi(ff.getPath(), OLD_FILENAME) ? NEW_FILENAME : ff.getPath(), _TRUNCATE);
+ wszBuf.Format(L"%s\\%s", pwszFolder, wszNewName);
}
- else mir_snwprintf(wszNewName, L"%s\\%s", pwszFolder + cbBaseLen, ffd.cFileName);
+ else mir_snwprintf(wszNewName, L"%s\\%s", pwszFolder + cbBaseLen, ff.getPath());
}
}
else {
- if (!wcsicmp(ffd.cFileName, L"libeay32.mir") || !wcsicmp(ffd.cFileName, L"ssleay32.mir")) // remove old OpenSSL modules
+ if (!wcsicmp(ff.getPath(), L"libeay32.mir") || !wcsicmp(ff.getPath(), L"ssleay32.mir")) // remove old OpenSSL modules
wszNewName[0] = 0;
else
continue; // skip all another files
@@ -685,7 +686,7 @@ static int ScanFolder(const wchar_t *pwszFolder, size_t cbBaseLen, const wchar_t if (item == nullptr) {
wchar_t *p = wcsrchr(wszNewName, '.');
if (p[-1] != 'w' && p[-1] != 'W') {
- Netlib_LogfW(g_hNetlibUser, L"File %s: Not found on server, skipping", ffd.cFileName);
+ Netlib_LogfW(g_hNetlibUser, L"File %s: Not found on server, skipping", ff.getPath());
continue;
}
@@ -693,7 +694,7 @@ static int ScanFolder(const wchar_t *pwszFolder, size_t cbBaseLen, const wchar_t int iPos = int(p - wszNewName) - 1;
strdelw(p - 1, 1);
if ((item = hashes.find((ServListEntry*)&pName)) == nullptr) {
- Netlib_LogfW(g_hNetlibUser, L"File %s: Not found on server, skipping", ffd.cFileName);
+ Netlib_LogfW(g_hNetlibUser, L"File %s: Not found on server, skipping", ff.getPath());
continue;
}
@@ -708,29 +709,29 @@ static int ScanFolder(const wchar_t *pwszFolder, size_t cbBaseLen, const wchar_t CalculateModuleHash(wszBuf, szMyHash);
// hashes are the same, skipping
if (strcmp(szMyHash, item->m_szHash) == 0) {
- Netlib_LogfW(g_hNetlibUser, L"File %s: Already up-to-date, skipping", ffd.cFileName);
+ Netlib_LogfW(g_hNetlibUser, L"File %s: Already up-to-date, skipping", ff.getPath());
continue;
}
- else Netlib_LogfW(g_hNetlibUser, L"File %s: Update available", ffd.cFileName);
+ else Netlib_LogfW(g_hNetlibUser, L"File %s: Update available", ff.getPath());
}
__except (EXCEPTION_EXECUTE_HANDLER)
{
// smth went wrong, reload a file from scratch
}
}
- else Netlib_LogfW(g_hNetlibUser, L"File %s: Forcing redownload", ffd.cFileName);
+ else Netlib_LogfW(g_hNetlibUser, L"File %s: Forcing redownload", ff.getPath());
pwszUrl = item->m_name;
MyCRC = item->m_crc;
}
else {
// file was marked for deletion, add it to the list anyway
- Netlib_LogfW(g_hNetlibUser, L"File %s: Marked for deletion", ffd.cFileName);
+ Netlib_LogfW(g_hNetlibUser, L"File %s: Marked for deletion", ff.getPath());
pwszUrl = L"";
MyCRC = 0;
}
- CMStringA szSetting(wszBuf + cbBaseLen);
+ CMStringA szSetting(wszBuf.c_str() + cbBaseLen);
int bEnabled = db_get_b(0, DB_MODULE_FILES, StrToLower(szSetting.GetBuffer()), 1);
if (bEnabled == 2) // hidden database setting to exclude a plugin from list
continue;
@@ -738,22 +739,23 @@ static int ScanFolder(const wchar_t *pwszFolder, size_t cbBaseLen, const wchar_t // Yeah, we've got new version.
FILEINFO *FileInfo = new FILEINFO;
// copy the relative old name
- wcsncpy_s(FileInfo->wszOldName, wszBuf + cbBaseLen, _TRUNCATE);
+ wcsncpy_s(FileInfo->wszOldName, wszBuf.c_str() + cbBaseLen, _TRUNCATE);
FileInfo->bDeleteOnly = bDeleteOnly;
if (FileInfo->bDeleteOnly) // save the full old name for deletion
wcsncpy_s(FileInfo->wszNewName, wszBuf, _TRUNCATE);
else
wcsncpy_s(FileInfo->wszNewName, pwszUrl, _TRUNCATE);
- wcsncpy_s(wszBuf, pwszUrl, _TRUNCATE);
- wchar_t *p = wcsrchr(wszBuf, '.');
+ wchar_t buf[MAX_PATH];
+ wcsncpy_s(buf, pwszUrl, _TRUNCATE);
+ wchar_t *p = wcsrchr(buf, '.');
if (p) *p = 0;
- p = wcsrchr(wszBuf, '\\');
- p = (p) ? p + 1 : wszBuf;
+ p = wcsrchr(buf, '\\');
+ p = (p) ? p + 1 : buf;
_wcslwr(p);
mir_snwprintf(FileInfo->File.wszDiskPath, L"%s\\Temp\\%s.zip", g_wszRoot, p);
- mir_snwprintf(FileInfo->File.wszDownloadURL, L"%s/%s.zip", pwszBaseUrl, wszBuf);
+ mir_snwprintf(FileInfo->File.wszDownloadURL, L"%s/%s.zip", pwszBaseUrl, buf);
for (p = wcschr(FileInfo->File.wszDownloadURL, '\\'); p != nullptr; p = wcschr(p, '\\'))
*p++ = '/';
@@ -767,9 +769,7 @@ static int ScanFolder(const wchar_t *pwszFolder, size_t cbBaseLen, const wchar_t if (!g_plugin.bSilent || FileInfo->bEnabled)
count++;
}
- while (FindNextFile(hFind, &ffd) != 0);
- FindClose(hFind);
return count;
}
@@ -793,8 +793,7 @@ static void CheckUpdates(void *) bool success = ParseHashes(updateUrl, baseUrl, hashes);
if (success) {
FILELIST *UpdateFiles = new FILELIST(20);
- VARSW dirname(L"%miranda_path%");
- int count = ScanFolder(dirname, mir_wstrlen(dirname) + 1, baseUrl, hashes, UpdateFiles);
+ int count = ScanFolder(g_mirandaPath, mir_wstrlen(g_mirandaPath) + 1, baseUrl, hashes, UpdateFiles);
if (count == 0) {
if (!g_plugin.bSilent)
ShowPopup(TranslateT("Plugin Updater"), TranslateT("No updates found."), POPUP_TYPE_INFO);
diff --git a/plugins/PluginUpdater/src/Events.cpp b/plugins/PluginUpdater/src/Events.cpp index 7f2abf8d6c..a823bc7f17 100644 --- a/plugins/PluginUpdater/src/Events.cpp +++ b/plugins/PluginUpdater/src/Events.cpp @@ -38,7 +38,7 @@ static int ModulesLoaded(WPARAM, LPARAM) HookEvent(ME_FOLDERS_PATH_CHANGED, OnFoldersChanged);
OnFoldersChanged(0, 0);
}
- else lstrcpyn(g_wszRoot, VARSW(L"%miranda_path%\\" DEFAULT_UPDATES_FOLDER), _countof(g_wszRoot));
+ else mir_snwprintf(g_wszRoot, L"%s\\%s", g_mirandaPath.get(), DEFAULT_UPDATES_FOLDER);
if (ServiceExists(MS_ASSOCMGR_ADDNEWURLTYPE))
AssocMgr_AddNewUrlTypeW("mirpu:", TranslateT("Plugin updater URI scheme"), g_plugin.getInst(), IDI_PLGLIST, MODULENAME "/ParseUri", 0);
diff --git a/plugins/PluginUpdater/src/Options.cpp b/plugins/PluginUpdater/src/Options.cpp index da0291c4be..c5d0b52def 100644 --- a/plugins/PluginUpdater/src/Options.cpp +++ b/plugins/PluginUpdater/src/Options.cpp @@ -260,17 +260,13 @@ public: // if user selected update channel without symbols, remove PDBs
if (bNoSymbols) {
- CMStringW wszPath(VARSW(L"%miranda_path%"));
- wszPath.AppendChar('\\');
-
- WIN32_FIND_DATA ffd;
- HANDLE hFind = FindFirstFile(wszPath + L"*.pdb", &ffd);
- if (hFind != INVALID_HANDLE_VALUE) {
- do {
- DeleteFileW(wszPath + ffd.cFileName);
- } while (FindNextFile(hFind, &ffd) != 0);
+ MFilePath wszPath;
+ wszPath.Format(L"%s\\*.pdb", g_mirandaPath.get());
+
+ for (auto &it : wszPath.search()) {
+ wszPath.Format(L"%s\\%s", g_mirandaPath.get(), it.getPath());
+ DeleteFileW(wszPath);
}
- FindClose(hFind);
}
if (PU::PrepareEscalation())
diff --git a/plugins/PluginUpdater/src/PluginUpdater.cpp b/plugins/PluginUpdater/src/PluginUpdater.cpp index ff19aff47c..81b793e43e 100644 --- a/plugins/PluginUpdater/src/PluginUpdater.cpp +++ b/plugins/PluginUpdater/src/PluginUpdater.cpp @@ -22,6 +22,7 @@ Boston, MA 02111-1307, USA. CMPlugin g_plugin;
TFileName g_wszRoot = {0}, g_wszTempPath;
+VARSW g_mirandaPath(L"%miranda_path%");
/////////////////////////////////////////////////////////////////////////////////////////
diff --git a/plugins/PluginUpdater/src/Utils.cpp b/plugins/PluginUpdater/src/Utils.cpp index f1636511d8..b39f3c7acf 100644 --- a/plugins/PluginUpdater/src/Utils.cpp +++ b/plugins/PluginUpdater/src/Utils.cpp @@ -297,8 +297,7 @@ static void SafeMoveFolder(const wchar_t *wszSrc, const wchar_t *wszDest) void RollbackChanges(TFileName &pwszBackupFolder)
{
- VARSW dirname(L"%miranda_path%");
- SafeMoveFolder(pwszBackupFolder, dirname);
+ SafeMoveFolder(pwszBackupFolder, g_mirandaPath);
PU::SafeDeleteDirectory(pwszBackupFolder);
}
@@ -329,13 +328,11 @@ void DoRestart() {
BOOL bRestartCurrentProfile = g_plugin.getBool("RestartCurrentProfile", true);
if (g_plugin.bChangePlatform) {
- VARSW wszMirandaPath(L"%miranda_path%");
-
MFilePath mirstartpath;
#ifdef _WIN64
- mirstartpath.Format(L"%s\\miranda32.exe", wszMirandaPath.get());
+ mirstartpath.Format(L"%s\\miranda32.exe", g_mirandaPath.get());
#else
- mirstartpath.Format(L"%s\\miranda64.exe", wszMirandaPath.get());
+ mirstartpath.Format(L"%s\\miranda64.exe", g_mirandaPath.get());
#endif
CallServiceSync(MS_SYSTEM_RESTART, bRestartCurrentProfile, (LPARAM)mirstartpath.c_str());
}
diff --git a/plugins/PluginUpdater/src/stdafx.h b/plugins/PluginUpdater/src/stdafx.h index c12ec6e08a..9aaeef3415 100644 --- a/plugins/PluginUpdater/src/stdafx.h +++ b/plugins/PluginUpdater/src/stdafx.h @@ -150,7 +150,8 @@ enum using namespace std;
extern uint32_t g_mirandaVersion;
-extern wchar_t g_wszRoot[MAX_PATH], g_wszTempPath[MAX_PATH];
+extern TFileName g_wszRoot, g_wszTempPath;
+extern VARSW g_mirandaPath;
extern HNETLIBUSER g_hNetlibUser;
struct CMPlugin : public PLUGIN<CMPlugin>
|