Merge pull request #1154 from QtRoS/updater_unicode_improvements

Improvements in Updater
This commit is contained in:
telegramdesktop 2015-10-04 11:54:53 +03:00
commit 001864baab
2 changed files with 10 additions and 10 deletions

View File

@ -30,8 +30,8 @@ bool equal(const wstring &a, const wstring &b) {
void updateError(const WCHAR *msg, DWORD errorCode) {
WCHAR errMsg[2048];
LPTSTR errorText = NULL, errorTextDefault = L"(Unknown error)";
FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_IGNORE_INSERTS, NULL, errorCode, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPTSTR)&errorText, 0, 0);
LPWSTR errorText = NULL, errorTextDefault = L"(Unknown error)";
FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_IGNORE_INSERTS, NULL, errorCode, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPWSTR)&errorText, 0, 0);
if (!errorText) {
errorText = errorTextDefault;
}
@ -146,11 +146,11 @@ bool update() {
HANDLE versionFile = CreateFile((tdataDir + L"\\version").c_str(), GENERIC_READ, FILE_SHARE_READ, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
if (versionFile != INVALID_HANDLE_VALUE) {
if (ReadFile(versionFile, &versionNum, sizeof(DWORD), &readLen, NULL) != TRUE || readLen != sizeof(DWORD)) {
if (!ReadFile(versionFile, &versionNum, sizeof(DWORD), &readLen, NULL) || readLen != sizeof(DWORD)) {
versionNum = 0;
} else if (ReadFile(versionFile, &versionLen, sizeof(DWORD), &readLen, NULL) != TRUE || readLen != sizeof(DWORD) || versionLen > 63) {
} else if (!ReadFile(versionFile, &versionLen, sizeof(DWORD), &readLen, NULL) || readLen != sizeof(DWORD) || versionLen > 63) {
versionNum = 0;
} else if (ReadFile(versionFile, versionStr, versionLen, &readLen, NULL) != TRUE || readLen != versionLen) {
} else if (!ReadFile(versionFile, versionStr, versionLen, &readLen, NULL) || readLen != versionLen) {
versionNum = 0;
}
CloseHandle(versionFile);
@ -245,14 +245,14 @@ bool update() {
int copyTries = 0;
do {
copyResult = CopyFile(fname.c_str(), tofname.c_str(), FALSE);
if (copyResult == FALSE) {
if (!copyResult) {
++copyTries;
Sleep(100);
} else {
break;
}
} while (copyTries < 30);
if (copyResult == FALSE) {
if (!copyResult) {
writeLog(L"Error: failed to copy, asking to retry..");
WCHAR errMsg[2048];
wsprintf(errMsg, L"Failed to update Telegram :(\n%s is not accessible.", tofname.c_str());
@ -261,7 +261,7 @@ bool update() {
return false;
}
}
} while (copyResult == FALSE);
} while (!copyResult);
}
writeLog(L"Update succeed! Clearing folder..");
@ -292,7 +292,7 @@ void updateRegistry() {
}
}
if (locationType == REG_EXPAND_SZ || locationType == REG_SZ) {
if (PathCanonicalize(exp, locationStr) == TRUE) {
if (PathCanonicalize(exp, locationStr)) {
memcpy(locationStr, exp, bufSize * sizeof(WCHAR));
if (GetFullPathName(L".", bufSize, exp, 0) < bufSize) {
wstring installpath = locationStr, mypath = exp;
@ -326,7 +326,7 @@ void updateRegistry() {
#include <ShlObj.h>
int APIENTRY WinMain(HINSTANCE instance, HINSTANCE prevInstance, LPSTR cmdParamarg, int cmdShow) {
int APIENTRY wWinMain(HINSTANCE instance, HINSTANCE prevInstance, LPWSTR cmdParamarg, int cmdShow) {
openLog();
#ifdef _NEED_WIN_GENERATE_DUMP

Binary file not shown.