From aeb2ec68efeb1a66782fc90fd3a05518b82b9de8 Mon Sep 17 00:00:00 2001 From: John Preston Date: Fri, 24 Apr 2015 19:02:45 +0300 Subject: [PATCH] added some debug info in autoupdate, version 0.8.7 stable prepared --- Telegram/PrepareWin.bat | 10 +- Telegram/SourceFiles/application.cpp | 4 +- Telegram/SourceFiles/config.h | 6 +- Telegram/SourceFiles/pspecific_wnd.cpp | 117 ++++++++++++-------- Telegram/Telegram.plist | 2 +- Telegram/Telegram.rc | Bin 5532 -> 5532 bytes Telegram/Telegram.xcodeproj/project.pbxproj | 12 +- Telegram/Version.sh | 2 +- 8 files changed, 86 insertions(+), 67 deletions(-) diff --git a/Telegram/PrepareWin.bat b/Telegram/PrepareWin.bat index bfa070b85..65198f6d8 100644 --- a/Telegram/PrepareWin.bat +++ b/Telegram/PrepareWin.bat @@ -1,10 +1,10 @@ @echo OFF -set "AppVersion=8006" -set "AppVersionStrSmall=0.8.6" -set "AppVersionStr=0.8.6" -set "AppVersionStrFull=0.8.6.0" -set "DevChannel=1" +set "AppVersion=8007" +set "AppVersionStrSmall=0.8.7" +set "AppVersionStr=0.8.7" +set "AppVersionStrFull=0.8.7.0" +set "DevChannel=0" if %DevChannel% neq 0 goto preparedev diff --git a/Telegram/SourceFiles/application.cpp b/Telegram/SourceFiles/application.cpp index da8f7ae46..5cd003dba 100644 --- a/Telegram/SourceFiles/application.cpp +++ b/Telegram/SourceFiles/application.cpp @@ -664,8 +664,8 @@ void Application::checkMapVersion() { QString versionFeatures; if (DevChannel && Local::oldMapVersion() < 8006) { versionFeatures = QString::fromUtf8("\xe2\x80\x94 Old default chat background image placed first in background Gallery\n\xe2\x80\x94 Forwarded files, videos, audios and contacts original sender name is displayed\n\xe2\x80\x94 Grouped notifications when several messages are forwarded").replace('@', qsl("@") + QChar(0x200D)); - } else if (!DevChannel && Local::oldMapVersion() < 8004) { - versionFeatures = lang(lng_new_version_minor).trimmed(); + } else if (!DevChannel && Local::oldMapVersion() < 8007) { + versionFeatures = lang(lng_new_version_text).trimmed(); } if (!versionFeatures.isEmpty()) { versionFeatures = lng_new_version_wrap(lt_version, QString::fromStdWString(AppVersionStr), lt_changes, versionFeatures, lt_link, qsl("https://desktop.telegram.org/#changelog")); diff --git a/Telegram/SourceFiles/config.h b/Telegram/SourceFiles/config.h index e4f695d07..81738044f 100644 --- a/Telegram/SourceFiles/config.h +++ b/Telegram/SourceFiles/config.h @@ -17,9 +17,9 @@ Copyright (c) 2014 John Preston, https://desktop.telegram.org */ #pragma once -static const int32 AppVersion = 8006; -static const wchar_t *AppVersionStr = L"0.8.6"; -static const bool DevChannel = true; +static const int32 AppVersion = 8007; +static const wchar_t *AppVersionStr = L"0.8.7"; +static const bool DevChannel = false; static const wchar_t *AppNameOld = L"Telegram Win (Unofficial)"; static const wchar_t *AppName = L"Telegram Desktop"; diff --git a/Telegram/SourceFiles/pspecific_wnd.cpp b/Telegram/SourceFiles/pspecific_wnd.cpp index 62cc470ef..9efc1b4f0 100644 --- a/Telegram/SourceFiles/pspecific_wnd.cpp +++ b/Telegram/SourceFiles/pspecific_wnd.cpp @@ -1595,6 +1595,21 @@ void PsUpdateDownloader::clearAll() { deleteDir(cWorkingDir() + qsl("tupdates")); } +QString winapiErrorWrap() { + WCHAR errMsg[2048]; + DWORD errorCode = GetLastError(); + 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); + if (!errorText) { + errorText = errorTextDefault; + } + StringCbPrintf(errMsg, sizeof(errMsg), L"Error code: %d, error message: %s", errorCode, errorText); + if (errorText != errorTextDefault) { + LocalFree(errorText); + } + return QString::fromWCharArray(errMsg); +} + void PsUpdateDownloader::unpackUpdate() { QByteArray packed; if (!outputFile.open(QIODevice::ReadOnly)) { @@ -1616,49 +1631,53 @@ void PsUpdateDownloader::unpackUpdate() { deleteDir(tempDirPath); deleteDir(readyDirPath); - QDir tempDir(tempDirPath), readyDir(readyDirPath); - if (tempDir.exists() || readyDir.exists()) { - LOG(("Update Error: cant clear tupdates/temp or tupdates/ready dir!")); - return fatalFail(); - } - - uchar sha1Buffer[20]; - bool goodSha1 = !memcmp(compressed.constData() + hSigLen, hashSha1(compressed.constData() + hSigLen + hShaLen, compressedLen + hPropsLen + hOriginalSizeLen, sha1Buffer), hShaLen); - if (!goodSha1) { - LOG(("Update Error: bad SHA1 hash of update file!")); - return fatalFail(); - } - - RSA *pbKey = PEM_read_bio_RSAPublicKey(BIO_new_mem_buf(const_cast(DevChannel ? UpdatesPublicDevKey : UpdatesPublicKey), -1), 0, 0, 0); - if (!pbKey) { - LOG(("Update Error: cant read public rsa key!")); - return fatalFail(); - } - if (RSA_verify(NID_sha1, (const uchar*)(compressed.constData() + hSigLen), hShaLen, (const uchar*)(compressed.constData()), hSigLen, pbKey) != 1) { // verify signature - RSA_free(pbKey); - LOG(("Update Error: bad RSA signature of update file!")); - return fatalFail(); - } - RSA_free(pbKey); - - QByteArray uncompressed; - - int32 uncompressedLen; - memcpy(&uncompressedLen, compressed.constData() + hSigLen + hShaLen + hPropsLen, hOriginalSizeLen); - uncompressed.resize(uncompressedLen); - - size_t resultLen = uncompressed.size(); - SizeT srcLen = compressedLen; - int uncompressRes = LzmaUncompress((uchar*)uncompressed.data(), &resultLen, (const uchar*)(compressed.constData() + hSize), &srcLen, (const uchar*)(compressed.constData() + hSigLen + hShaLen), LZMA_PROPS_SIZE); - if (uncompressRes != SZ_OK) { - LOG(("Update Error: could not uncompress lzma, code: %1").arg(uncompressRes)); - return fatalFail(); - } - - tempDir.mkdir(tempDir.absolutePath()); - - quint32 version; { + QDir tempDir(tempDirPath), readyDir(readyDirPath); + if (tempDir.exists() || readyDir.exists()) { + LOG(("Update Error: cant clear tupdates/temp or tupdates/ready dir!")); + return fatalFail(); + } + + tempDirPath = tempDir.absolutePath(); + readyDirPath = readyDir.absolutePath(); + + uchar sha1Buffer[20]; + bool goodSha1 = !memcmp(compressed.constData() + hSigLen, hashSha1(compressed.constData() + hSigLen + hShaLen, compressedLen + hPropsLen + hOriginalSizeLen, sha1Buffer), hShaLen); + if (!goodSha1) { + LOG(("Update Error: bad SHA1 hash of update file!")); + return fatalFail(); + } + + RSA *pbKey = PEM_read_bio_RSAPublicKey(BIO_new_mem_buf(const_cast(DevChannel ? UpdatesPublicDevKey : UpdatesPublicKey), -1), 0, 0, 0); + if (!pbKey) { + LOG(("Update Error: cant read public rsa key!")); + return fatalFail(); + } + if (RSA_verify(NID_sha1, (const uchar*)(compressed.constData() + hSigLen), hShaLen, (const uchar*)(compressed.constData()), hSigLen, pbKey) != 1) { // verify signature + RSA_free(pbKey); + LOG(("Update Error: bad RSA signature of update file!")); + return fatalFail(); + } + RSA_free(pbKey); + + QByteArray uncompressed; + + int32 uncompressedLen; + memcpy(&uncompressedLen, compressed.constData() + hSigLen + hShaLen + hPropsLen, hOriginalSizeLen); + uncompressed.resize(uncompressedLen); + + size_t resultLen = uncompressed.size(); + SizeT srcLen = compressedLen; + int uncompressRes = LzmaUncompress((uchar*)uncompressed.data(), &resultLen, (const uchar*)(compressed.constData() + hSize), &srcLen, (const uchar*)(compressed.constData() + hSigLen + hShaLen), LZMA_PROPS_SIZE); + if (uncompressRes != SZ_OK) { + LOG(("Update Error: could not uncompress lzma, code: %1").arg(uncompressRes)); + return fatalFail(); + } + + QDir().mkdir(tempDirPath); + + quint32 version; + QBuffer buffer(&uncompressed); buffer.open(QIODevice::ReadOnly); QDataStream stream(&buffer); @@ -1713,15 +1732,15 @@ void PsUpdateDownloader::unpackUpdate() { } // create tdata/version file - tempDir.mkdir(QDir(tempDirPath + qsl("/tdata")).absolutePath()); + QDir().mkdir(tempDirPath + qsl("/tdata")); std::wstring versionString = ((version % 1000) ? QString("%1.%2.%3").arg(int(version / 1000000)).arg(int((version % 1000000) / 1000)).arg(int(version % 1000)) : QString("%1.%2").arg(int(version / 1000000)).arg(int((version % 1000000) / 1000))).toStdWString(); DWORD versionNum = DWORD(version), versionLen = DWORD(versionString.size() * sizeof(WCHAR)); WCHAR versionStr[32]; memcpy(versionStr, versionString.c_str(), versionLen); - QFile fVersion(tempDirPath + qsl("/tdata/version")); + QFile fVersion(tempDirPath + qsl("/tdata/version")); if (!fVersion.open(QIODevice::WriteOnly)) { - LOG(("Update Error: cant write version file '%1'").arg(tempDirPath + qsl("/version"))); + LOG(("Update Error: cant write version file '%1'").arg(tempDirPath + qsl("/tdata/version"))); return fatalFail(); } fVersion.write((const char*)&versionNum, sizeof(DWORD)); @@ -1729,10 +1748,10 @@ void PsUpdateDownloader::unpackUpdate() { fVersion.write((const char*)&versionStr[0], versionLen); fVersion.close(); } - - QFile tempDirFile(tempDir.absolutePath()); - if (!tempDirFile.rename(readyDir.absolutePath())) { - LOG(("Update Error: cant rename temp dir '%1' to ready dir '%2', error %3: %4").arg(tempDir.absolutePath()).arg(readyDir.absolutePath()).arg(tempDirFile.error()).arg(tempDirFile.errorString())); + + std::wstring tempDirNative = QDir::toNativeSeparators(tempDirPath).toStdWString(), readyDirNative = QDir::toNativeSeparators(readyDirPath).toStdWString(); + if (!MoveFile(tempDirNative.c_str(), readyDirNative.c_str())) { + LOG(("Update Error: cant rename temp dir '%1' to ready dir '%2'. %3").arg(QString::fromStdWString(tempDirNative)).arg(QString::fromStdWString(readyDirNative)).arg(winapiErrorWrap())); return fatalFail(); } deleteDir(tempDirPath); diff --git a/Telegram/Telegram.plist b/Telegram/Telegram.plist index 5f9ce7c81..3589dc1dc 100644 --- a/Telegram/Telegram.plist +++ b/Telegram/Telegram.plist @@ -11,7 +11,7 @@ CFBundlePackageType APPL CFBundleShortVersionString - 0.8.6 + 0.8.7 CFBundleSignature ???? CFBundleURLTypes diff --git a/Telegram/Telegram.rc b/Telegram/Telegram.rc index 431bca1854fe90b216d90eb6ebfa1acca723c174..1bd38866b0b6e0d6ceb6c2e378a20c7eddef7d41 100644 GIT binary patch delta 50 zcmbQEJx6;(0WYKZ