diff options
-rw-r--r-- | updater/extern.cpp | 67 | ||||
-rw-r--r-- | updater/services.cpp | 4 | ||||
-rw-r--r-- | updater/updater_9.vcproj | 17 | ||||
-rw-r--r-- | updater/utils.cpp | 23 | ||||
-rw-r--r-- | updater/version.h | 2 |
5 files changed, 68 insertions, 45 deletions
diff --git a/updater/extern.cpp b/updater/extern.cpp index f34f24b..7c0feda 100644 --- a/updater/extern.cpp +++ b/updater/extern.cpp @@ -31,8 +31,8 @@ int ExternProcess(bool restart) { char db_name[100], db_path[MAX_PATH];
// Get Miranda exe path and profile
- CallService(MS_DB_GETPROFILENAME, MAX_PATH, (WPARAM)(char*) db_name);
- CallService(MS_DB_GETPROFILEPATH, MAX_PATH, (WPARAM)(char*) db_path);
+ CallService(MS_DB_GETPROFILENAME, SIZEOF(db_name), (WPARAM)(char*) db_name);
+ CallService(MS_DB_GETPROFILEPATH, SIZEOF(db_path), (WPARAM)(char*) db_path);
TCHAR db_pathT[MAX_PATH], *t1, *t2;
mir_sntprintf(db_pathT, SIZEOF(db_pathT), _T("%s\\%s"), (t1=mir_a2t(db_path)), (t2=mir_a2t(db_name)));
@@ -42,10 +42,11 @@ int ExternProcess(bool restart) { REPLACEVARSDATA dat = {0};
dat.cbSize = sizeof(dat);
dat.dwFlags = RVF_TCHAR;
-
- TCHAR* mir_exe = (TCHAR*)CallService(MS_UTILS_REPLACEVARS, (WPARAM)_T("%miranda_path%"), (LPARAM)&dat);
TCHAR* plugins_folder = (TCHAR*)CallService(MS_UTILS_REPLACEVARS, (WPARAM)_T("%miranda_path%\\Plugins"), (LPARAM)&dat);
+ TCHAR mir_exe[MAX_PATH];
+ GetModuleFileName(NULL, mir_exe, SIZEOF(mir_exe));
+
unsigned long bytes_written;
const TCHAR *tnl = _T("\r\n");
@@ -53,31 +54,28 @@ int ExternProcess(bool restart) { WriteFile(hDatFile, tnl, 2 * sizeof(TCHAR), &bytes_written, FALSE);
WriteFile(hDatFile, plugins_folder, (unsigned)_tcslen(plugins_folder) * sizeof(TCHAR), &bytes_written, FALSE);
WriteFile(hDatFile, tnl, 2 * sizeof(TCHAR), &bytes_written, FALSE);
- WriteFile(hDatFile, db_pathT, (unsigned)_tcslen(db_pathT), &bytes_written, FALSE);
- WriteFile(hDatFile, tnl, 2, &bytes_written, FALSE);
+ WriteFile(hDatFile, db_pathT, (unsigned)_tcslen(db_pathT) * sizeof(TCHAR), &bytes_written, FALSE);
+ WriteFile(hDatFile, tnl, 2 * sizeof(TCHAR), &bytes_written, FALSE);
WriteFile(hDatFile, options.temp_folder, (unsigned)_tcslen(options.temp_folder) * sizeof(TCHAR), &bytes_written, FALSE);
WriteFile(hDatFile, tnl, 2 * sizeof(TCHAR), &bytes_written, FALSE);
- if(options.backup) {
+ if(options.backup)
WriteFile(hDatFile, options.backup_folder, (unsigned)_tcslen(options.backup_folder) * sizeof(TCHAR), &bytes_written, FALSE);
- WriteFile(hDatFile, tnl, 2 * sizeof(TCHAR), &bytes_written, FALSE);
- } else {
+ else
WriteFile(hDatFile, _T("no backups"),(unsigned) _tcslen(_T("no backups")) * sizeof(TCHAR), &bytes_written, FALSE);
- WriteFile(hDatFile, tnl, 2 * sizeof(TCHAR), &bytes_written, FALSE);
- }
+ WriteFile(hDatFile, tnl, 2 * sizeof(TCHAR), &bytes_written, FALSE);
TCHAR buf[64];
mir_sntprintf(buf, SIZEOF(buf), _T("%d"), (unsigned int)GetCurrentProcessId());
//MessageBox(0, buf, "Writing process id", MB_OK);
- WriteFile(hDatFile, buf, (unsigned)_tcslen(buf), &bytes_written, FALSE);
- WriteFile(hDatFile, tnl, 2, &bytes_written, FALSE);
+ WriteFile(hDatFile, buf, (unsigned)_tcslen(buf) * sizeof(TCHAR), &bytes_written, FALSE);
+ WriteFile(hDatFile, tnl, 2 * sizeof(TCHAR), &bytes_written, FALSE);
mir_sntprintf(buf, SIZEOF(buf), restart ? _T("restart") : _T("no_restart"));
- WriteFile(hDatFile, buf, (unsigned)_tcslen(buf), &bytes_written, FALSE);
- WriteFile(hDatFile, tnl, 2, &bytes_written, FALSE);
+ WriteFile(hDatFile, buf, (unsigned)_tcslen(buf) * sizeof(TCHAR), &bytes_written, FALSE);
+ WriteFile(hDatFile, tnl, 2 * sizeof(TCHAR), &bytes_written, FALSE);
CloseHandle(hDatFile);
- mir_free(mir_exe);
mir_free(plugins_folder);
/*
@@ -157,9 +155,20 @@ int ExternProcess(bool restart) { #ifdef _UD_LOGGING
void mWriteFile(HANDLE hFile, char *line) {
unsigned long bytes_written;
- char *nl = "\r\n";
+ const char *nl = "\r\n";
- WriteFile(hFile, line, strlen(line), &bytes_written, FALSE);
+ WriteFile(hFile, line, (unsigned)strlen(line), &bytes_written, FALSE);
+ WriteFile(hFile, nl, 2, &bytes_written, FALSE);
+}
+
+void mWriteFile(HANDLE hFile, wchar_t *line) {
+ unsigned long bytes_written;
+ const char *nl = "\r\n";
+
+ char buf[267];
+ WideCharToMultiByte(CP_ACP, 0, line, -1, buf, SIZEOF(buf), NULL, NULL);
+
+ WriteFile(hFile, buf, (unsigned)strlen(buf), &bytes_written, FALSE);
WriteFile(hFile, nl, 2, &bytes_written, FALSE);
}
#endif
@@ -167,7 +176,7 @@ void mWriteFile(HANDLE hFile, char *line) { // move all files in src_folder to dst_folder - put replaced files in backup folder
// if a file in src_folder is a directory, copy it's contents to the same dir in the root folder and
// set that dir as the new root (so that dirs in dirs go in the right place)
-void MoveFiles(HANDLE hLogFile, TCHAR *src_folder, TCHAR *dst_folder, TCHAR *backup_folder, TCHAR *root_folder)\
+void MoveFiles(HANDLE hLogFile, TCHAR *src_folder, TCHAR *dst_folder, TCHAR *backup_folder, TCHAR *root_folder)
{
// move files from src_folder to dst_folder
@@ -181,9 +190,8 @@ void MoveFiles(HANDLE hLogFile, TCHAR *src_folder, TCHAR *dst_folder, TCHAR *bac bool do_backups = backup_folder ? (_tcscmp(backup_folder, _T("no backups")) != 0) : false;
// ensure the destination folder exists
- if(!CreatePath(dst_folder)) {
+ if (!CreatePath(dst_folder))
return;
- }
_sntprintf(szFilesPath, SIZEOF(szFilesPath), _T("%s\\*.*"), src_folder);
szFilesPath[SIZEOF(szFilesPath) - 1] = 0;
@@ -192,7 +200,8 @@ void MoveFiles(HANDLE hLogFile, TCHAR *src_folder, TCHAR *dst_folder, TCHAR *bac WIN32_FIND_DATA findData;
HANDLE hFileSearch = FindFirstFile(szFilesPath, &findData);
- if(hFileSearch != INVALID_HANDLE_VALUE) {
+ if(hFileSearch != INVALID_HANDLE_VALUE)
+ {
do {
if(findData.cFileName[0] != _T('.')) {
@@ -297,8 +306,8 @@ void CALLBACK ExternalUpdate(HWND hwnd, HINSTANCE hInstance, LPSTR lpszCmdLine, *temp_folder = (TCHAR *)malloc(MAX_PATH * sizeof(TCHAR)),
*backup_folder = (TCHAR *)malloc(MAX_PATH * sizeof(TCHAR)),
*root_folder = (TCHAR *)malloc(MAX_PATH * sizeof(TCHAR)),
- *db_path = (TCHAR *)malloc(MAX_PATH),
- *pid = (TCHAR *)malloc(64);
+ *db_path = (TCHAR *)malloc(MAX_PATH * sizeof(TCHAR)),
+ *pid = (TCHAR *)malloc(64 * sizeof(TCHAR));
bool restart = true;
@@ -340,8 +349,7 @@ void CALLBACK ExternalUpdate(HWND hwnd, HINSTANCE hInstance, LPSTR lpszCmdLine, #endif
_tcscpy(root_folder, mir_exe);
- TCHAR *p = _tcsrchr(root_folder, _T('\\'));
- if(p) *p = 0;
+ TCHAR *p = _tcsrchr(root_folder, _T('\\')); if (p) *p = 0;
// ensure miranda has exited
DWORD mpi = (DWORD)_ttol(pid);
@@ -456,11 +464,12 @@ void CALLBACK ExternalUpdate(HWND hwnd, HINSTANCE hInstance, LPSTR lpszCmdLine, else mWriteFile(hDatFile, "Miranda did not exit");
#endif
- free(plugins_folder);
+ free(pid);
free(db_path);
- free(temp_folder);
- free(backup_folder);
free(root_folder);
+ free(backup_folder);
+ free(temp_folder);
+ free(plugins_folder);
free(mir_exe);
#ifdef _UD_LOGGING
diff --git a/updater/services.cpp b/updater/services.cpp index b5c8a88..4e90b15 100644 --- a/updater/services.cpp +++ b/updater/services.cpp @@ -71,7 +71,7 @@ bool DownloadUpdates(UpdateList &todo, FilenameMap *map, bool dlls_only) { }
if(!use_popup) {
- PostMessage(hwndProgress, WMU_SETMESSAGE, (WPARAM)msg, 0);
+ SendMessage(hwndProgress, WMU_SETMESSAGE, (WPARAM)msg, 0);
PostMessage(hwndProgress, WMU_SETPROGRESS, (WPARAM)(int)(index * 100.0 / todo.getCount()), 0);
} //else if(hwndPop) // disabled - just annoying
//ChangePopupText(hwndPop, msg);
@@ -235,7 +235,7 @@ void CheckForUpdatesWorker(void *param) { }
if(!use_popup) {
- PostMessage(hwndProgress, WMU_SETMESSAGE, (WPARAM)msg, 0);
+ SendMessage(hwndProgress, WMU_SETMESSAGE, (WPARAM)msg, 0);
PostMessage(hwndProgress, WMU_SETPROGRESS, (WPARAM)(int)(index * 100.0 / count), 0);
} //else if(hwndPop) // disabled - just annoying
//ChangePopupText(hwndPop, msg);
diff --git a/updater/updater_9.vcproj b/updater/updater_9.vcproj index 47e1190..9e4c520 100644 --- a/updater/updater_9.vcproj +++ b/updater/updater_9.vcproj @@ -87,7 +87,7 @@ MapExports="true"
BaseAddress="0x22000000"
RandomizedBaseAddress="1"
- ImportLibrary=""
+ ImportLibrary="$(IntDir)\$(TargetName).lib"
TargetMachine="1"
/>
<Tool
@@ -156,7 +156,6 @@ SuppressStartupBanner="true"
DebugInformationFormat="3"
CompileAs="0"
- DisableSpecificWarnings="4996"
/>
<Tool
Name="VCManagedResourceCompilerTool"
@@ -183,7 +182,7 @@ MapExports="true"
BaseAddress="0x22000000"
RandomizedBaseAddress="1"
- ImportLibrary="$(IntDir)$(TargetName).lib"
+ ImportLibrary="$(IntDir)\$(TargetName).lib"
TargetMachine="17"
/>
<Tool
@@ -277,7 +276,7 @@ SubSystem="0"
BaseAddress="0x22000000"
RandomizedBaseAddress="1"
- ImportLibrary=""
+ ImportLibrary="$(IntDir)\$(TargetName).lib"
TargetMachine="1"
/>
<Tool
@@ -373,7 +372,7 @@ SubSystem="0"
BaseAddress="0x22000000"
RandomizedBaseAddress="1"
- ImportLibrary="$(IntDir)$(TargetName).lib"
+ ImportLibrary="$(IntDir)\$(TargetName).lib"
TargetMachine="17"
/>
<Tool
@@ -474,7 +473,7 @@ EnableCOMDATFolding="2"
BaseAddress="0x22000000"
RandomizedBaseAddress="1"
- ImportLibrary=""
+ ImportLibrary="$(IntDir)\$(TargetName).lib"
TargetMachine="1"
/>
<Tool
@@ -571,7 +570,7 @@ EnableCOMDATFolding="2"
BaseAddress="0x22000000"
RandomizedBaseAddress="1"
- ImportLibrary="$(IntDir)$(TargetName).lib"
+ ImportLibrary="$(IntDir)\$(TargetName).lib"
TargetMachine="17"
/>
<Tool
@@ -673,7 +672,7 @@ EnableCOMDATFolding="2"
BaseAddress="0x22000000"
RandomizedBaseAddress="1"
- ImportLibrary=""
+ ImportLibrary="$(IntDir)\$(TargetName).lib"
TargetMachine="1"
/>
<Tool
@@ -777,7 +776,7 @@ EnableCOMDATFolding="2"
BaseAddress="0x22000000"
RandomizedBaseAddress="1"
- ImportLibrary="$(IntDir)$(TargetName).lib"
+ ImportLibrary="$(IntDir)\$(TargetName).lib"
TargetMachine="17"
/>
<Tool
diff --git a/updater/utils.cpp b/updater/utils.cpp index 6e1afad..98d57be 100644 --- a/updater/utils.cpp +++ b/updater/utils.cpp @@ -47,11 +47,26 @@ int CheckForFileID(char *update_url, char *version_url, char *name) { return -1;
}
-bool CreatePath(const TCHAR *path)
+bool CreatePath(const TCHAR *szDir)
{
- if (!path) return false;
- CallService(MS_UTILS_CREATEDIRTREET, 0, (LPARAM)path);
- return true;
+ if (!szDir) return false;
+
+ DWORD dwAttributes;
+ TCHAR *pszLastBackslash, szTestDir[ MAX_PATH ];
+
+ lstrcpyn( szTestDir, szDir, SIZEOF( szTestDir ));
+ if (( dwAttributes = GetFileAttributes( szTestDir )) != INVALID_FILE_ATTRIBUTES && ( dwAttributes & FILE_ATTRIBUTE_DIRECTORY ))
+ return true;
+
+ pszLastBackslash = _tcsrchr( szTestDir, '\\' );
+ if ( pszLastBackslash == NULL )
+ return true;
+
+ *pszLastBackslash = '\0';
+ CreatePath( szTestDir );
+ *pszLastBackslash = '\\';
+
+ return CreateDirectory( szTestDir, NULL ) != 0;
}
// must 'mir_free' return val
diff --git a/updater/version.h b/updater/version.h index d6022f9..1fdc1af 100644 --- a/updater/version.h +++ b/updater/version.h @@ -5,7 +5,7 @@ #define __MAJOR_VERSION 0
#define __MINOR_VERSION 6
#define __RELEASE_NUM 0
-#define __BUILD_NUM 1
+#define __BUILD_NUM 2
#define __FILEVERSION_STRING __MAJOR_VERSION,__MINOR_VERSION,__RELEASE_NUM,__BUILD_NUM
#define __FILEVERSION_STRING_DOTS __MAJOR_VERSION.__MINOR_VERSION.__RELEASE_NUM.__BUILD_NUM
|