From b6325ec9d4c5a3da10cfb58b840f7eb440c95be0 Mon Sep 17 00:00:00 2001 From: John Preston Date: Thu, 4 Jun 2015 14:59:30 +0300 Subject: [PATCH] 0.8.24.dev test (not production!) version ready, updaters improved (no tdata copying while updating) --- Telegram/PrepareWin.bat | 8 +- Telegram/SourceFiles/_other/updater.cpp | 131 +++++++++--------- Telegram/SourceFiles/_other/updater_linux.cpp | 2 - Telegram/SourceFiles/_other/updater_osx.m | 2 +- Telegram/SourceFiles/config.h | 4 +- Telegram/Telegram.plist | 2 +- Telegram/Telegram.rc | Bin 5540 -> 5540 bytes Telegram/Telegram.xcodeproj/project.pbxproj | 12 +- Telegram/Version.sh | 2 +- 9 files changed, 83 insertions(+), 80 deletions(-) diff --git a/Telegram/PrepareWin.bat b/Telegram/PrepareWin.bat index a291fa2f2..c55dad70a 100644 --- a/Telegram/PrepareWin.bat +++ b/Telegram/PrepareWin.bat @@ -1,9 +1,9 @@ @echo OFF -set "AppVersion=8023" -set "AppVersionStrSmall=0.8.23" -set "AppVersionStr=0.8.23" -set "AppVersionStrFull=0.8.23.0" +set "AppVersion=8024" +set "AppVersionStrSmall=0.8.24" +set "AppVersionStr=0.8.24" +set "AppVersionStrFull=0.8.24.0" set "DevChannel=1" if %DevChannel% neq 0 goto preparedev diff --git a/Telegram/SourceFiles/_other/updater.cpp b/Telegram/SourceFiles/_other/updater.cpp index b9b7a2587..81afbde5c 100644 --- a/Telegram/SourceFiles/_other/updater.cpp +++ b/Telegram/SourceFiles/_other/updater.cpp @@ -124,19 +124,38 @@ void delFolder() { RemoveDirectory(delFolder.c_str()); } +DWORD versionNum = 0, versionLen = 0, readLen = 0; +WCHAR versionStr[32] = { 0 }; + bool update() { writeLog(L"Update started.."); - wstring updDir = L"tupdates\\temp", readyFilePath = L"tupdates\\temp\\ready"; + wstring updDir = L"tupdates\\temp", readyFilePath = L"tupdates\\temp\\ready", tdataDir = L"tupdates\\temp\\tdata"; { HANDLE readyFile = CreateFile(readyFilePath.c_str(), GENERIC_READ, FILE_SHARE_READ, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0); if (readyFile != INVALID_HANDLE_VALUE) { CloseHandle(readyFile); } else { updDir = L"tupdates\\ready"; // old + tdataDir = L"tupdates\\ready\\tdata"; } } + 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)) { + versionNum = 0; + } else if (ReadFile(versionFile, &versionLen, sizeof(DWORD), &readLen, NULL) != TRUE || readLen != sizeof(DWORD) || versionLen > 63) { + versionNum = 0; + } else if (ReadFile(versionFile, versionStr, versionLen, &readLen, NULL) != TRUE || readLen != versionLen) { + versionNum = 0; + } + CloseHandle(versionFile); + writeLog(L"Version file read."); + } else { + writeLog(L"Could not open version file to update registry :("); + } + deque dirs; dirs.push_back(updDir); @@ -167,13 +186,15 @@ bool update() { } do { - if (findData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) { + wstring fname = dir + L"\\" + findData.cFileName; + if (fname.substr(0, tdataDir.size()) == tdataDir && (fname.size() <= tdataDir.size() || fname.at(tdataDir.size()) == '/')) { + writeLog(L"Skipped 'tdata' path '" + fname + L"'"); + } else if (findData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) { if (findData.cFileName != wstring(L".") && findData.cFileName != wstring(L"..")) { - dirs.push_back(dir + L"\\" + findData.cFileName); - writeLog(L"Added dir '" + dir + L"\\" + findData.cFileName + L"' in update tree.."); + dirs.push_back(fname); + writeLog(L"Added dir '" + fname + L"' in update tree.."); } } else { - wstring fname = dir + L"\\" + findData.cFileName; wstring tofname = updateTo + fname.substr(updDir.size() + 1); if (equal(tofname, exeName)) { // bad update - has Updater.exe - delete all dir writeLog(L"Error: bad update, has Updater.exe! '" + tofname + L"' equal '" + exeName + L"'"); @@ -246,73 +267,57 @@ bool update() { } void updateRegistry() { - HANDLE versionFile = CreateFile((updateTo + L"tdata\\version").c_str(), GENERIC_READ, FILE_SHARE_READ, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0); - if (versionFile != INVALID_HANDLE_VALUE) { + if (versionNum) { writeLog(L"Updating registry.."); - DWORD versionNum = 0, versionLen = 0, readLen = 0; - WCHAR versionStr[32]; - if (ReadFile(versionFile, &versionNum, sizeof(DWORD), &readLen, NULL) != TRUE || readLen != sizeof(DWORD)) { - versionNum = 0; - } else if (ReadFile(versionFile, &versionLen, sizeof(DWORD), &readLen, NULL) != TRUE || readLen != sizeof(DWORD) || versionLen > 63) { - versionNum = 0; - } else if (ReadFile(versionFile, versionStr, versionLen, &readLen, NULL) != TRUE || readLen != versionLen) { - versionNum = 0; - } - CloseHandle(versionFile); - writeLog(L"Version file read."); - if (versionNum) { - versionStr[versionLen / 2] = 0; - HKEY rkey; - LSTATUS status = RegOpenKeyEx(HKEY_CURRENT_USER, L"Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\{53F49750-6209-4FBF-9CA8-7A333C87D1ED}_is1", 0, KEY_QUERY_VALUE | KEY_SET_VALUE, &rkey); - if (status == ERROR_SUCCESS) { - writeLog(L"Checking registry install location.."); - static const int bufSize = 4096; - DWORD locationType, locationSize = bufSize * 2; - WCHAR locationStr[bufSize], exp[bufSize]; - if (RegQueryValueEx(rkey, L"InstallLocation", 0, &locationType, (BYTE*)locationStr, &locationSize) == ERROR_SUCCESS) { - locationSize /= 2; - if (locationStr[locationSize - 1]) { - locationStr[locationSize++] = 0; + versionStr[versionLen / 2] = 0; + HKEY rkey; + LSTATUS status = RegOpenKeyEx(HKEY_CURRENT_USER, L"Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\{53F49750-6209-4FBF-9CA8-7A333C87D1ED}_is1", 0, KEY_QUERY_VALUE | KEY_SET_VALUE, &rkey); + if (status == ERROR_SUCCESS) { + writeLog(L"Checking registry install location.."); + static const int bufSize = 4096; + DWORD locationType, locationSize = bufSize * 2; + WCHAR locationStr[bufSize], exp[bufSize]; + if (RegQueryValueEx(rkey, L"InstallLocation", 0, &locationType, (BYTE*)locationStr, &locationSize) == ERROR_SUCCESS) { + locationSize /= 2; + if (locationStr[locationSize - 1]) { + locationStr[locationSize++] = 0; + } + if (locationType == REG_EXPAND_SZ) { + DWORD copy = ExpandEnvironmentStrings(locationStr, exp, bufSize); + if (copy <= bufSize) { + memcpy(locationStr, exp, copy * sizeof(WCHAR)); } - if (locationType == REG_EXPAND_SZ) { - DWORD copy = ExpandEnvironmentStrings(locationStr, exp, bufSize); - if (copy <= bufSize) { - memcpy(locationStr, exp, copy * sizeof(WCHAR)); - } - } - if (locationType == REG_EXPAND_SZ || locationType == REG_SZ) { - if (PathCanonicalize(exp, locationStr) == TRUE) { - memcpy(locationStr, exp, bufSize * sizeof(WCHAR)); - if (GetFullPathName(L".", bufSize, exp, 0) < bufSize) { - wstring installpath = locationStr, mypath = exp; - if (installpath == mypath + L"\\" || true) { // always update reg info, if we found it - WCHAR nameStr[bufSize], dateStr[bufSize], publisherStr[bufSize], icongroupStr[bufSize]; - SYSTEMTIME stLocalTime; - GetLocalTime(&stLocalTime); - RegSetValueEx(rkey, L"DisplayVersion", 0, REG_SZ, (BYTE*)versionStr, ((versionLen / 2) + 1) * sizeof(WCHAR)); - wsprintf(nameStr, L"Telegram Desktop version %s", versionStr); - RegSetValueEx(rkey, L"DisplayName", 0, REG_SZ, (BYTE*)nameStr, (wcslen(nameStr) + 1) * sizeof(WCHAR)); - wsprintf(publisherStr, L"Telegram Messenger LLP"); - RegSetValueEx(rkey, L"Publisher", 0, REG_SZ, (BYTE*)publisherStr, (wcslen(publisherStr) + 1) * sizeof(WCHAR)); - wsprintf(icongroupStr, L"Telegram Desktop"); - RegSetValueEx(rkey, L"Inno Setup: Icon Group", 0, REG_SZ, (BYTE*)icongroupStr, (wcslen(icongroupStr) + 1) * sizeof(WCHAR)); - wsprintf(dateStr, L"%04d%02d%02d", stLocalTime.wYear, stLocalTime.wMonth, stLocalTime.wDay); - RegSetValueEx(rkey, L"InstallDate", 0, REG_SZ, (BYTE*)dateStr, (wcslen(dateStr) + 1) * sizeof(WCHAR)); + } + if (locationType == REG_EXPAND_SZ || locationType == REG_SZ) { + if (PathCanonicalize(exp, locationStr) == TRUE) { + memcpy(locationStr, exp, bufSize * sizeof(WCHAR)); + if (GetFullPathName(L".", bufSize, exp, 0) < bufSize) { + wstring installpath = locationStr, mypath = exp; + if (installpath == mypath + L"\\" || true) { // always update reg info, if we found it + WCHAR nameStr[bufSize], dateStr[bufSize], publisherStr[bufSize], icongroupStr[bufSize]; + SYSTEMTIME stLocalTime; + GetLocalTime(&stLocalTime); + RegSetValueEx(rkey, L"DisplayVersion", 0, REG_SZ, (BYTE*)versionStr, ((versionLen / 2) + 1) * sizeof(WCHAR)); + wsprintf(nameStr, L"Telegram Desktop version %s", versionStr); + RegSetValueEx(rkey, L"DisplayName", 0, REG_SZ, (BYTE*)nameStr, (wcslen(nameStr) + 1) * sizeof(WCHAR)); + wsprintf(publisherStr, L"Telegram Messenger LLP"); + RegSetValueEx(rkey, L"Publisher", 0, REG_SZ, (BYTE*)publisherStr, (wcslen(publisherStr) + 1) * sizeof(WCHAR)); + wsprintf(icongroupStr, L"Telegram Desktop"); + RegSetValueEx(rkey, L"Inno Setup: Icon Group", 0, REG_SZ, (BYTE*)icongroupStr, (wcslen(icongroupStr) + 1) * sizeof(WCHAR)); + wsprintf(dateStr, L"%04d%02d%02d", stLocalTime.wYear, stLocalTime.wMonth, stLocalTime.wDay); + RegSetValueEx(rkey, L"InstallDate", 0, REG_SZ, (BYTE*)dateStr, (wcslen(dateStr) + 1) * sizeof(WCHAR)); - WCHAR *appURL = L"https://desktop.telegram.org"; - RegSetValueEx(rkey, L"HelpLink", 0, REG_SZ, (BYTE*)appURL, (wcslen(appURL) + 1) * sizeof(WCHAR)); - RegSetValueEx(rkey, L"URLInfoAbout", 0, REG_SZ, (BYTE*)appURL, (wcslen(appURL) + 1) * sizeof(WCHAR)); - RegSetValueEx(rkey, L"URLUpdateInfo", 0, REG_SZ, (BYTE*)appURL, (wcslen(appURL) + 1) * sizeof(WCHAR)); - } + WCHAR *appURL = L"https://desktop.telegram.org"; + RegSetValueEx(rkey, L"HelpLink", 0, REG_SZ, (BYTE*)appURL, (wcslen(appURL) + 1) * sizeof(WCHAR)); + RegSetValueEx(rkey, L"URLInfoAbout", 0, REG_SZ, (BYTE*)appURL, (wcslen(appURL) + 1) * sizeof(WCHAR)); + RegSetValueEx(rkey, L"URLUpdateInfo", 0, REG_SZ, (BYTE*)appURL, (wcslen(appURL) + 1) * sizeof(WCHAR)); } } } } - RegCloseKey(rkey); } + RegCloseKey(rkey); } - } else { - writeLog(L"Could not open version file to update registry :("); } } diff --git a/Telegram/SourceFiles/_other/updater_linux.cpp b/Telegram/SourceFiles/_other/updater_linux.cpp index 30fff3b36..c616c727d 100644 --- a/Telegram/SourceFiles/_other/updater_linux.cpp +++ b/Telegram/SourceFiles/_other/updater_linux.cpp @@ -271,8 +271,6 @@ bool update() { } if (fname == readyFilePath) { writeLog("Skipped ready file '%s'", fname.c_str()); - } else if (fname == versionFilePath) { - writeLog("Skipped version file '%s'", fname.c_str()); } else { from.push_back(fname); to.push_back(tofname); diff --git a/Telegram/SourceFiles/_other/updater_osx.m b/Telegram/SourceFiles/_other/updater_osx.m index 649452306..b27329095 100644 --- a/Telegram/SourceFiles/_other/updater_osx.m +++ b/Telegram/SourceFiles/_other/updater_osx.m @@ -35,7 +35,7 @@ void openLog() { return; } - NSDateFormatter *fmt = [[NSDateFormatter alloc] initWithDateFormat:@"DebugLogs/%Y%m%d %H%M%S_upd.txt" allowNaturalLanguage:NO]; + NSDateFormatter *fmt = [[NSDateFormatter alloc] initWithDateFormat:@"DebugLogs/%Y%m%d_%H%M%S_upd.txt" allowNaturalLanguage:NO]; NSString *logPath = [workDir stringByAppendingString:[fmt stringFromDate:[NSDate date]]]; [[NSFileManager defaultManager] createFileAtPath:logPath contents:nil attributes:nil]; _logFile = [NSFileHandle fileHandleForWritingAtPath:logPath]; diff --git a/Telegram/SourceFiles/config.h b/Telegram/SourceFiles/config.h index 1da5bd352..a14a5c58d 100644 --- a/Telegram/SourceFiles/config.h +++ b/Telegram/SourceFiles/config.h @@ -17,8 +17,8 @@ Copyright (c) 2014 John Preston, https://desktop.telegram.org */ #pragma once -static const int32 AppVersion = 8023; -static const wchar_t *AppVersionStr = L"0.8.23"; +static const int32 AppVersion = 8024; +static const wchar_t *AppVersionStr = L"0.8.24"; static const bool DevChannel = true; static const wchar_t *AppNameOld = L"Telegram Win (Unofficial)"; diff --git a/Telegram/Telegram.plist b/Telegram/Telegram.plist index b0a2b66e0..0ba654895 100644 --- a/Telegram/Telegram.plist +++ b/Telegram/Telegram.plist @@ -11,7 +11,7 @@ CFBundlePackageType APPL CFBundleShortVersionString - 0.8.23 + 0.8.24 LSMinimumSystemVersion $(MACOSX_DEPLOYMENT_TARGET) CFBundleSignature diff --git a/Telegram/Telegram.rc b/Telegram/Telegram.rc index 30e84033c84ffc9174d2fed5d2b22525daf73927..234db8af4dc6efa6145055bb17b4e506a5e3be1b 100644 GIT binary patch delta 53 zcmZ3Yy+nIM5ig_3