From 92be070586e97f44892da28a592aa1c0925a40d1 Mon Sep 17 00:00:00 2001 From: "(no author)" <(no author)@4f64403b-2f21-0410-a795-97e2b3489a10> Date: Wed, 7 Apr 2010 00:07:56 +0000 Subject: Fixed updating issues git-svn-id: https://server.scottellis.com.au/svn/mim_plugs@502 4f64403b-2f21-0410-a795-97e2b3489a10 --- updater/extern.cpp | 67 +++++++++++++++++++++++++++++++----------------------- 1 file changed, 38 insertions(+), 29 deletions(-) (limited to 'updater/extern.cpp') 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 -- cgit v1.2.3