From 8a2ac6573ff77cfd5426842de656d324ed476c72 Mon Sep 17 00:00:00 2001 From: John Preston Date: Thu, 12 Jun 2014 15:20:14 +0400 Subject: [PATCH] fixed two crashes, fixed elided text display --- Telegram/MetaStyle.vcxproj | 12 ++-- Telegram/Resources/lang.txt | 2 + Telegram/Setup.iss | 6 +- Telegram/SourceFiles/app.cpp | 2 +- Telegram/SourceFiles/art/grid.png | Bin 2083 -> 2083 bytes Telegram/SourceFiles/art/grid_125x.png | Bin 2666 -> 2666 bytes Telegram/SourceFiles/art/grid_150x.png | Bin 3224 -> 3224 bytes Telegram/SourceFiles/art/grid_200x.png | Bin 4505 -> 4505 bytes Telegram/SourceFiles/art/sprite_125x.png | Bin 59262 -> 59262 bytes Telegram/SourceFiles/art/sprite_150x.png | Bin 69851 -> 69851 bytes Telegram/SourceFiles/config.h | 4 +- Telegram/SourceFiles/gui/text.cpp | 21 +++++-- Telegram/SourceFiles/mtproto/mtp.cpp | 2 + Telegram/SourceFiles/types.cpp | 73 +++++++++++++---------- Telegram/SourceFiles/types.h | 1 + Telegram/Telegram.rc | Bin 5558 -> 5558 bytes Telegram/Telegram.vcxproj | 4 +- 17 files changed, 77 insertions(+), 50 deletions(-) diff --git a/Telegram/MetaStyle.vcxproj b/Telegram/MetaStyle.vcxproj index caa8bcc7b..ebf202c78 100644 --- a/Telegram/MetaStyle.vcxproj +++ b/Telegram/MetaStyle.vcxproj @@ -102,16 +102,16 @@ <_ProjectFileVersion>11.0.60610.1 - $(SolutionDir)$(Platform)\$(Configuration)IntermediateMeta\ - $(SolutionDir)$(Platform)\$(Configuration)Meta\ + $(SolutionDir)$(Platform)\$(Configuration)IntermediateStyle\ + $(SolutionDir)$(Platform)\$(Configuration)Style\ - $(SolutionDir)$(Platform)\$(Configuration)Meta\ - $(SolutionDir)$(Platform)\$(Configuration)IntermediateMeta\ + $(SolutionDir)$(Platform)\$(Configuration)Style\ + $(SolutionDir)$(Platform)\$(Configuration)IntermediateStyle\ - $(SolutionDir)$(Platform)\$(Configuration)Meta\ - $(SolutionDir)$(Platform)\$(Configuration)IntermediateMeta\ + $(SolutionDir)$(Platform)\$(Configuration)Style\ + $(SolutionDir)$(Platform)\$(Configuration)IntermediateStyle\ diff --git a/Telegram/Resources/lang.txt b/Telegram/Resources/lang.txt index b14eb0580..e3a010172 100644 --- a/Telegram/Resources/lang.txt +++ b/Telegram/Resources/lang.txt @@ -377,3 +377,5 @@ lng_about_text: "Unofficial free messaging app based on [a href=\"https://core.t This software is licensed under [a href=\"https://github.com/telegramdesktop/tdesktop/blob/master/LICENSE\"]GNU GPL[/a] version 3, source code is available on [a href=\"https://github.com/telegramdesktop/tdesktop\"]GitHub[/a]."; lng_about_done: "Done"; + +// Keys finished diff --git a/Telegram/Setup.iss b/Telegram/Setup.iss index f50e1c3b0..77f48f59f 100644 --- a/Telegram/Setup.iss +++ b/Telegram/Setup.iss @@ -3,9 +3,9 @@ #define MyAppShortName "Telegram" #define MyAppName "Telegram Win (Unofficial)" -#define MyAppVersion "0.5.1" -#define MyAppVersionZero "0.5.1" -#define MyAppFullVersion "0.5.1.0" +#define MyAppVersion "0.5.2" +#define MyAppVersionZero "0.5.2" +#define MyAppFullVersion "0.5.2.0" #define MyAppPublisher "Telegram (Unofficial)" #define MyAppURL "https://tdesktop.com" #define MyAppExeName "Telegram.exe" diff --git a/Telegram/SourceFiles/app.cpp b/Telegram/SourceFiles/app.cpp index 0b9be11de..6cb8f499e 100644 --- a/Telegram/SourceFiles/app.cpp +++ b/Telegram/SourceFiles/app.cpp @@ -587,7 +587,7 @@ namespace App { break; case mtpc_contacts_myLinkEmpty: case mtpc_contacts_myLinkRequested: - if (myLink.c_contacts_myLinkRequested().vcontact.v) { + if (myLink.type() == mtpc_contacts_myLinkRequested && myLink.c_contacts_myLinkRequested().vcontact.v) { user->contact = 1; } else { switch (foreignLink.type()) { diff --git a/Telegram/SourceFiles/art/grid.png b/Telegram/SourceFiles/art/grid.png index de5e3cc653fa57b3ac467067d843faee240b41c7..b886b374d75ca679ee40ce681c8c3966190c8542 100644 GIT binary patch delta 22 ecmZ21uvlP%HaFi91_r((j8nDwq&J$qWd{IC%LbMJ delta 22 dcmZ21uvlP%Hn&g-1A|ZrM46)#j7lXy)-80DRyH2><{9 delta 24 gcmex&j``m?<_X%|LM03gLM4p%(&Q^Pnt4120DI&KV*mgE diff --git a/Telegram/SourceFiles/art/sprite_150x.png b/Telegram/SourceFiles/art/sprite_150x.png index 5f4b4febec2c2b8eef91fc4cf3fd23678e03e3ac..5e9e4ab3a39ff93dfd2ee299c08ff7235d265dc8 100644 GIT binary patch delta 27 jcmcb;kmdG5mI>P2d`B1<_>M46)#j6KG}~&%xKscDhyDny delta 27 jcmcb;kmdG5mI>P2LM03gLM4p%(&Q@|&9<5`E)@U(h!6<} diff --git a/Telegram/SourceFiles/config.h b/Telegram/SourceFiles/config.h index f27476954..845ea10e7 100644 --- a/Telegram/SourceFiles/config.h +++ b/Telegram/SourceFiles/config.h @@ -17,8 +17,8 @@ Copyright (c) 2014 John Preston, https://tdesktop.com */ #pragma once -static const int32 AppVersion = 5001; -static const wchar_t *AppVersionStr = L"0.5.1"; +static const int32 AppVersion = 5002; +static const wchar_t *AppVersionStr = L"0.5.2"; static const wchar_t *AppName = L"Telegram Win (Unofficial)"; static const wchar_t *AppId = L"{53F49750-6209-4FBF-9CA8-7A333C87D1ED}"; diff --git a/Telegram/SourceFiles/gui/text.cpp b/Telegram/SourceFiles/gui/text.cpp index 1571d46c6..0139a11b6 100644 --- a/Telegram/SourceFiles/gui/text.cpp +++ b/Telegram/SourceFiles/gui/text.cpp @@ -1063,8 +1063,11 @@ public: continue; } - bool elidedLine = _elideLast && (_y + _lineHeight >= _yTo); - if (f != j && !elidedLine) { + int32 elidedLineHeight = qMax(_lineHeight, blockHeight); + bool elidedLine = _elideLast && (_y + elidedLineHeight >= _yTo); + if (elidedLine) { + _lineHeight = elidedLineHeight; + } else if (f != j) { j = f; _wLeft = f_wLeft; _lineHeight = f_lineHeight; @@ -1088,7 +1091,11 @@ public: continue; } - bool elidedLine = _elideLast && (_y + _lineHeight >= _yTo); + int32 elidedLineHeight = qMax(_lineHeight, blockHeight); + bool elidedLine = _elideLast && (_y + elidedLineHeight >= _yTo); + if (elidedLine) { + _lineHeight = elidedLineHeight; + } if (!drawLine(elidedLine ? _blockEnd(_t, i, e) : b->from(), i, e)) return; _y += _lineHeight; _lineHeight = qMax(0, blockHeight); @@ -1542,7 +1549,7 @@ public: void elideSaveBlock(int32 blockIndex, ITextBlock *&_endBlock, int32 elideStart, int32 elideWidth) { _elideSavedIndex = blockIndex; _elideSavedBlock = _t->_blocks[blockIndex]; - const_cast(_t)->_blocks[blockIndex] = new SkipBlock(_t->_font, _t->_text, elideStart, elideWidth, _f->height, _elideSavedBlock->lnkIndex()); + const_cast(_t)->_blocks[blockIndex] = new TextBlock(_t->_font, _t->_text, QFIXED_MAX, elideStart, 0, _elideSavedBlock->flags(), _elideSavedBlock->color(), _elideSavedBlock->lnkIndex()); _blocksSize = blockIndex + 1; _endBlock = (blockIndex + 1 < _t->_blocks.size() ? _t->_blocks[blockIndex + 1] : 0); } @@ -1654,9 +1661,11 @@ public: lineLength += _Elide.size(); if (!repeat) { - for (; _t->_blocks[blockIndex] != _endBlock && _t->_blocks[blockIndex]->from() < elideStart; ++blockIndex) { + for (; blockIndex < _blocksSize && _t->_blocks[blockIndex] != _endBlock && _t->_blocks[blockIndex]->from() < elideStart; ++blockIndex) { + } + if (blockIndex < _blocksSize) { + elideSaveBlock(blockIndex, _endBlock, elideStart, elideWidth); } - elideSaveBlock(blockIndex, _endBlock, elideStart, elideWidth); } } diff --git a/Telegram/SourceFiles/mtproto/mtp.cpp b/Telegram/SourceFiles/mtproto/mtp.cpp index 5a5516a96..05dfa57a6 100644 --- a/Telegram/SourceFiles/mtproto/mtp.cpp +++ b/Telegram/SourceFiles/mtproto/mtp.cpp @@ -441,6 +441,8 @@ namespace MTP { } void start() { + unixtimeInit(); + if (!localKey().created()) { LOG(("App Error: trying to start MTP without local key!")); return; diff --git a/Telegram/SourceFiles/types.cpp b/Telegram/SourceFiles/types.cpp index 1ae96b393..c3bafbb6d 100644 --- a/Telegram/SourceFiles/types.cpp +++ b/Telegram/SourceFiles/types.cpp @@ -79,24 +79,54 @@ namespace { QReadWriteLock unixtimeLock; volatile int32 unixtimeDelta = 0; volatile bool unixtimeWasSet = false; - volatile uint64 msgIdStart, msgIdLocal = 0; + volatile uint64 _msgIdStart, _msgIdLocal = 0, _msgIdMsStart; uint32 _reqId = 0; + + void _initMsgIdConstants() { +#ifdef Q_OS_WIN + LARGE_INTEGER li; + QueryPerformanceCounter(&li); + _msgIdMsStart = li.QuadPart; +#elif defined Q_OS_MAC + _msgIdMsStart = mach_absolute_time(); +#else + timespec ts; + clock_gettime(CLOCK_REALTIME, &ts); + _msgIdMsStart = 1000000000 * uint64(ts.tv_sec) + uint64(ts.tv_nsec); +#endif + + uint32 msgIdRand; + memset_rand(&msgIdRand, sizeof(uint32)); + _msgIdStart = (((uint64)((uint32)unixtime()) << 32) | (uint64)msgIdRand); + } } int32 myunixtime() { return (int32)time(NULL); } -void unixtimeSet(int32 serverTime, bool force) { - QWriteLocker locker(&unixtimeLock); - if (force) { - DEBUG_LOG(("MTP Info: forced setting client unixtime to %1").arg(serverTime)); - } else { - if (unixtimeWasSet) return; - DEBUG_LOG(("MTP Info: setting client unixtime to %1").arg(serverTime)); +void unixtimeInit() { + { + QWriteLocker locker(&unixtimeLock); + unixtimeWasSet = false; + unixtimeDelta = 0; } - unixtimeWasSet = true; - unixtimeDelta = serverTime + 1 - myunixtime(); + _initMsgIdConstants(); +} + +void unixtimeSet(int32 serverTime, bool force) { + { + QWriteLocker locker(&unixtimeLock); + if (force) { + DEBUG_LOG(("MTP Info: forced setting client unixtime to %1").arg(serverTime)); + } else { + if (unixtimeWasSet) return; + DEBUG_LOG(("MTP Info: setting client unixtime to %1").arg(serverTime)); + } + unixtimeWasSet = true; + unixtimeDelta = serverTime + 1 - myunixtime(); + } + _initMsgIdConstants(); } int32 unixtime() { @@ -164,23 +194,10 @@ namespace { } }; - class _MsgIdInitializer { - public: - _MsgIdInitializer() { - uint32 msgIdRand; - memset_rand(&msgIdRand, sizeof(uint32)); - msgIdStart = (((uint64)((uint32)time(NULL)) << 32) | (uint64)msgIdRand); - } - }; - void _msInitialize() { static _MsInitializer _msInitializer; } - void _msgIdInitialize() { - static _MsgIdInitializer _msgIdInitializer; - } - class _MsStarter { public: _MsStarter() { @@ -212,16 +229,13 @@ uint64 getms() { } uint64 msgid() { - _msInitialize(); - _msgIdInitialize(); - #ifdef Q_OS_WIN LARGE_INTEGER li; QueryPerformanceCounter(&li); - uint64 result = msgIdStart + (uint64)floor((li.QuadPart - _msStart) * _msgIdCoef); + uint64 result = _msgIdStart + (uint64)floor((li.QuadPart - _msgIdMsStart) * _msgIdCoef); #elif defined Q_OS_MAC uint64 msCount = mach_absolute_time(); - uint64 result = msgIdStart + (uint64)floor((msCount - _msStart) * _msgIdCoef); + uint64 result = _msgIdStart + (uint64)floor((msCount - _msgIdMsStart) * _msgIdCoef); #else uint64 result = 0; //TODO @@ -229,8 +243,7 @@ uint64 msgid() { result &= ~0x03L; - QWriteLocker locker(&unixtimeLock); - return result + ((uint64)unixtimeDelta << 32) + (msgIdLocal += 4); + return result + (_msgIdLocal += 4); } uint32 reqid() { diff --git a/Telegram/SourceFiles/types.h b/Telegram/SourceFiles/types.h index e82f71a18..70fdefedc 100644 --- a/Telegram/SourceFiles/types.h +++ b/Telegram/SourceFiles/types.h @@ -70,6 +70,7 @@ private: class MTPint; int32 myunixtime(); +void unixtimeInit(); void unixtimeSet(int32 servertime, bool force = false); int32 unixtime(); int32 fromServerTime(const MTPint &serverTime); diff --git a/Telegram/Telegram.rc b/Telegram/Telegram.rc index fd45da3121c079d38b9080e308b23eeec9dcd46d..29ecc6916773898dabea194a070c90b9a575ff30 100644 GIT binary patch delta 42 vcmdm{y-jMgG?BT(!uuk_>$exc17{C;cz5dsWb delta 42 vcmdm{y-jMgG?BT(!uuk_>$exc17{C;cz5TOiL diff --git a/Telegram/Telegram.vcxproj b/Telegram/Telegram.vcxproj index 2d830afc7..6110d47d1 100644 --- a/Telegram/Telegram.vcxproj +++ b/Telegram/Telegram.vcxproj @@ -793,11 +793,11 @@ .\GeneratedFiles\style_classes.h - "$(SolutionDir)$(Platform)\$(Configuration)Meta\MetaStyle.exe" -classes_in ".\Resources\style_classes.txt" -classes_out ".\GeneratedFiles\style_classes.h" -styles_in ".\Resources\style.txt" -styles_out ".\GeneratedFiles\style_auto.h" + "$(SolutionDir)$(Platform)\$(Configuration)Style\MetaStyle.exe" -classes_in ".\Resources\style_classes.txt" -classes_out ".\GeneratedFiles\style_classes.h" -styles_in ".\Resources\style.txt" -styles_out ".\GeneratedFiles\style_auto.h" .\GeneratedFiles\style_auto.h - "$(SolutionDir)$(Platform)\$(Configuration)Meta\MetaStyle.exe" -classes_in ".\Resources\style_classes.txt" -classes_out ".\GeneratedFiles\style_classes.h" -styles_in ".\Resources\style.txt" -styles_out ".\GeneratedFiles\style_auto.h" + "$(SolutionDir)$(Platform)\$(Configuration)Style\MetaStyle.exe" -classes_in ".\Resources\style_classes.txt" -classes_out ".\GeneratedFiles\style_classes.h" -styles_in ".\Resources\style.txt" -styles_out ".\GeneratedFiles\style_auto.h" .\GeneratedFiles\lang.h