diff --git a/Telegram/SourceFiles/facades.cpp b/Telegram/SourceFiles/facades.cpp index 4f057446b..a9de1ea83 100644 --- a/Telegram/SourceFiles/facades.cpp +++ b/Telegram/SourceFiles/facades.cpp @@ -371,11 +371,11 @@ uint64 SandboxUserTag = 0; namespace Sandbox { -bool MoveLegacyAlphaFolder() { - const auto was = cExeDir() + qsl("TelegramBeta_data"); - const auto now = cExeDir() + qsl("TelegramAlpha_data"); +bool MoveLegacyAlphaFolder(const QString &folder, const QString &file) { + const auto was = cExeDir() + folder; + const auto now = cExeDir() + qsl("TelegramForcePortable"); if (QDir(was).exists() && !QDir(now).exists()) { - const auto oldFile = was + "/tdata/beta"; + const auto oldFile = was + "/tdata/" + file; const auto newFile = was + "/tdata/alpha"; if (QFile(oldFile).exists() && !QFile(newFile).exists()) { if (!QFile(oldFile).copy(newFile)) { @@ -395,59 +395,67 @@ bool MoveLegacyAlphaFolder() { return true; } -bool CheckAlphaVersionDir() { - if (!MoveLegacyAlphaFolder()) { +bool MoveLegacyAlphaFolder() { + if (!MoveLegacyAlphaFolder(qsl("TelegramAlpha_data"), qsl("alpha")) + || !MoveLegacyAlphaFolder(qsl("TelegramBeta_data"), qsl("beta"))) { return false; } - QFile key(cExeDir() + qsl("TelegramAlpha_data/tdata/alpha")); - if (cAlphaVersion()) { - cForceWorkingDir(cExeDir() + qsl("TelegramAlpha_data/")); - QDir().mkpath(cWorkingDir() + qstr("tdata")); - if (*AlphaPrivateKey) { - cSetAlphaPrivateKey(QByteArray(AlphaPrivateKey)); - } - if (key.open(QIODevice::WriteOnly)) { - QDataStream dataStream(&key); - dataStream.setVersion(QDataStream::Qt_5_3); - dataStream << quint64(cRealAlphaVersion()) << cAlphaPrivateKey(); - } else { - LOG(("FATAL: Could not open '%1' for writing private key!" - ).arg(key.fileName())); - return false; - } - } else if (key.exists()) { - cForceWorkingDir(cExeDir() + qsl("TelegramAlpha_data/")); - if (key.open(QIODevice::ReadOnly)) { - QDataStream dataStream(&key); - dataStream.setVersion(QDataStream::Qt_5_3); - - quint64 v; - QByteArray k; - dataStream >> v >> k; - if (dataStream.status() == QDataStream::Ok && !k.isEmpty()) { - cSetAlphaVersion(AppVersion * 1000ULL); - cSetAlphaPrivateKey(k); - cSetRealAlphaVersion(v); - } else { - LOG(("FATAL: '%1' is corrupted, reinstall private alpha!").arg(key.fileName())); - return false; - } - } else { - LOG(("FATAL: could not open '%1' for reading private key!").arg(key.fileName())); - return false; - } - } return true; } bool CheckPortableVersionDir() { - if (CheckAlphaVersionDir()) { - return true; - } else if (QDir(cExeDir() + qsl("TelegramForcePortable")).exists()) { - cForceWorkingDir(cExeDir() + qsl("TelegramForcePortable/")); + if (!MoveLegacyAlphaFolder()) { + return false; + } + + const auto portable = cExeDir() + qsl("TelegramForcePortable"); + QFile key(portable + qsl("/tdata/alpha")); + if (cAlphaVersion()) { + cForceWorkingDir(portable + '/'); + QDir().mkpath(cWorkingDir() + qstr("tdata")); + if (*AlphaPrivateKey) { + cSetAlphaPrivateKey(QByteArray(AlphaPrivateKey)); + } + if (!key.open(QIODevice::WriteOnly)) { + LOG(("FATAL: Could not open '%1' for writing private key!" + ).arg(key.fileName())); + return false; + } + QDataStream dataStream(&key); + dataStream.setVersion(QDataStream::Qt_5_3); + dataStream << quint64(cRealAlphaVersion()) << cAlphaPrivateKey(); return true; } - return false; + if (!QDir(portable).exists()) { + return true; + } + cForceWorkingDir(portable + '/'); + if (!key.exists()) { + return true; + } + + if (!key.open(QIODevice::ReadOnly)) { + LOG(("FATAL: could not open '%1' for reading private key. " + "Delete it or reinstall private alpha version." + ).arg(key.fileName())); + return false; + } + QDataStream dataStream(&key); + dataStream.setVersion(QDataStream::Qt_5_3); + + quint64 v; + QByteArray k; + dataStream >> v >> k; + if (dataStream.status() != QDataStream::Ok || k.isEmpty()) { + LOG(("FATAL: '%1' is corrupted. " + "Delete it or reinstall private alpha version." + ).arg(key.fileName())); + return false; + } + cSetAlphaVersion(AppVersion * 1000ULL); + cSetAlphaPrivateKey(k); + cSetRealAlphaVersion(v); + return true; } QString InstallBetaVersionsSettingPath() { diff --git a/Telegram/SourceFiles/logs.cpp b/Telegram/SourceFiles/logs.cpp index 96204e6b1..ed2c7ce76 100644 --- a/Telegram/SourceFiles/logs.cpp +++ b/Telegram/SourceFiles/logs.cpp @@ -332,18 +332,20 @@ void start(not_null launcher) { if (cAlphaVersion()) { workingDirChosen = true; + #if defined Q_OS_MAC || defined Q_OS_LINUX } else { -#ifdef _DEBUG - cForceWorkingDir(cExeDir()); -#else // _DEBUG if (!cWorkingDir().isEmpty()) { - // This value must come only from the "-workdir" argument. + // This value must come from TelegramForcePortable + // or from the "-workdir" command line argument. cForceWorkingDir(cWorkingDir()); } else { +#ifdef _DEBUG + cForceWorkingDir(cExeDir()); +#else // _DEBUG cForceWorkingDir(psAppDataPath()); - } #endif // !_DEBUG + } workingDirChosen = true; #if defined Q_OS_LINUX && !defined _DEBUG // fix first version @@ -354,6 +356,7 @@ void start(not_null launcher) { } else { cForceWorkingDir(psAppDataPath()); workingDirChosen = true; + #elif defined OS_WIN_STORE // Q_OS_MAC || Q_OS_LINUX || Q_OS_WINRT #ifdef _DEBUG cForceWorkingDir(cExeDir()); @@ -361,13 +364,16 @@ void start(not_null launcher) { cForceWorkingDir(psAppDataPath()); #endif // !_DEBUG workingDirChosen = true; + #elif defined Q_OS_WIN } else { if (!cWorkingDir().isEmpty()) { - // This value must come only from the "-workdir" argument. + // This value must come from TelegramForcePortable + // or from the "-workdir" command line argument. cForceWorkingDir(cWorkingDir()); workingDirChosen = true; } + #endif // Q_OS_MAC || Q_OS_LINUX || Q_OS_WINRT || OS_WIN_STORE }