2
0
mirror of https://github.com/telegramdesktop/tdesktop synced 2025-08-31 06:26:18 +00:00

Use TelegramForcePortable for alpha versions.

This commit is contained in:
John Preston
2018-10-09 19:21:20 +03:00
parent 631e51a493
commit e8a390c251
2 changed files with 69 additions and 55 deletions

View File

@@ -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() {