Skip to content

Commit

Permalink
fixed two crashes, fixed elided text display
Browse files Browse the repository at this point in the history
  • Loading branch information
john-preston committed Jun 12, 2014
1 parent 30a07de commit 8a2ac65
Show file tree
Hide file tree
Showing 17 changed files with 76 additions and 49 deletions.
12 changes: 6 additions & 6 deletions Telegram/MetaStyle.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -102,16 +102,16 @@
<_ProjectFileVersion>11.0.60610.1</_ProjectFileVersion>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<IntDir>$(SolutionDir)$(Platform)\$(Configuration)IntermediateMeta\</IntDir>
<OutDir>$(SolutionDir)$(Platform)\$(Configuration)Meta\</OutDir>
<IntDir>$(SolutionDir)$(Platform)\$(Configuration)IntermediateStyle\</IntDir>
<OutDir>$(SolutionDir)$(Platform)\$(Configuration)Style\</OutDir>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<OutDir>$(SolutionDir)$(Platform)\$(Configuration)Meta\</OutDir>
<IntDir>$(SolutionDir)$(Platform)\$(Configuration)IntermediateMeta\</IntDir>
<OutDir>$(SolutionDir)$(Platform)\$(Configuration)Style\</OutDir>
<IntDir>$(SolutionDir)$(Platform)\$(Configuration)IntermediateStyle\</IntDir>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Deploy|Win32'">
<OutDir>$(SolutionDir)$(Platform)\$(Configuration)Meta\</OutDir>
<IntDir>$(SolutionDir)$(Platform)\$(Configuration)IntermediateMeta\</IntDir>
<OutDir>$(SolutionDir)$(Platform)\$(Configuration)Style\</OutDir>
<IntDir>$(SolutionDir)$(Platform)\$(Configuration)IntermediateStyle\</IntDir>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
Expand Down
2 changes: 2 additions & 0 deletions Telegram/Resources/lang.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
6 changes: 3 additions & 3 deletions Telegram/Setup.iss
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion Telegram/SourceFiles/app.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand Down
Binary file modified Telegram/SourceFiles/art/grid.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Telegram/SourceFiles/art/grid_125x.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Telegram/SourceFiles/art/grid_150x.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Telegram/SourceFiles/art/grid_200x.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Telegram/SourceFiles/art/sprite_125x.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Telegram/SourceFiles/art/sprite_150x.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions Telegram/SourceFiles/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -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}";

Expand Down
21 changes: 15 additions & 6 deletions Telegram/SourceFiles/gui/text.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1063,8 +1063,11 @@ class TextPainter {
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;
Expand All @@ -1088,7 +1091,11 @@ class TextPainter {
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);
Expand Down Expand Up @@ -1542,7 +1549,7 @@ class TextPainter {
void elideSaveBlock(int32 blockIndex, ITextBlock *&_endBlock, int32 elideStart, int32 elideWidth) {
_elideSavedIndex = blockIndex;
_elideSavedBlock = _t->_blocks[blockIndex];
const_cast<Text*>(_t)->_blocks[blockIndex] = new SkipBlock(_t->_font, _t->_text, elideStart, elideWidth, _f->height, _elideSavedBlock->lnkIndex());
const_cast<Text*>(_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);
}
Expand Down Expand Up @@ -1654,9 +1661,11 @@ class TextPainter {
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);
}
}

Expand Down
2 changes: 2 additions & 0 deletions Telegram/SourceFiles/mtproto/mtp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,8 @@ namespace MTP {
}

void start() {
unixtimeInit();

if (!localKey().created()) {
LOG(("App Error: trying to start MTP without local key!"));
return;
Expand Down
71 changes: 42 additions & 29 deletions Telegram/SourceFiles/types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 unixtimeInit() {
{
QWriteLocker locker(&unixtimeLock);
unixtimeWasSet = false;
unixtimeDelta = 0;
}
_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));
{
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();
}
unixtimeWasSet = true;
unixtimeDelta = serverTime + 1 - myunixtime();
_initMsgIdConstants();
}

int32 unixtime() {
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -212,25 +229,21 @@ 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
#endif

result &= ~0x03L;

QWriteLocker locker(&unixtimeLock);
return result + ((uint64)unixtimeDelta << 32) + (msgIdLocal += 4);
return result + (_msgIdLocal += 4);
}

uint32 reqid() {
Expand Down
1 change: 1 addition & 0 deletions Telegram/SourceFiles/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ class Exception : public exception {
class MTPint;

int32 myunixtime();
void unixtimeInit();
void unixtimeSet(int32 servertime, bool force = false);
int32 unixtime();
int32 fromServerTime(const MTPint &serverTime);
Expand Down
Binary file modified Telegram/Telegram.rc
Binary file not shown.
4 changes: 2 additions & 2 deletions Telegram/Telegram.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -793,11 +793,11 @@
</CustomBuild>
<CustomBuild Include="Resources\style_classes.txt">
<Outputs>.\GeneratedFiles\style_classes.h</Outputs>
<Command>"$(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"</Command>
<Command>"$(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"</Command>
</CustomBuild>
<CustomBuild Include="Resources\style.txt">
<Outputs>.\GeneratedFiles\style_auto.h</Outputs>
<Command>"$(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"</Command>
<Command>"$(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"</Command>
</CustomBuild>
<CustomBuild Include="Resources\lang.txt">
<Outputs>.\GeneratedFiles\lang.h</Outputs>
Expand Down

0 comments on commit 8a2ac65

Please sign in to comment.