mirror of https://github.com/procxx/kepka.git
Use TelegramForcePortable for alpha versions.
This commit is contained in:
parent
631e51a493
commit
e8a390c251
|
@ -371,11 +371,11 @@ uint64 SandboxUserTag = 0;
|
||||||
|
|
||||||
namespace Sandbox {
|
namespace Sandbox {
|
||||||
|
|
||||||
bool MoveLegacyAlphaFolder() {
|
bool MoveLegacyAlphaFolder(const QString &folder, const QString &file) {
|
||||||
const auto was = cExeDir() + qsl("TelegramBeta_data");
|
const auto was = cExeDir() + folder;
|
||||||
const auto now = cExeDir() + qsl("TelegramAlpha_data");
|
const auto now = cExeDir() + qsl("TelegramForcePortable");
|
||||||
if (QDir(was).exists() && !QDir(now).exists()) {
|
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";
|
const auto newFile = was + "/tdata/alpha";
|
||||||
if (QFile(oldFile).exists() && !QFile(newFile).exists()) {
|
if (QFile(oldFile).exists() && !QFile(newFile).exists()) {
|
||||||
if (!QFile(oldFile).copy(newFile)) {
|
if (!QFile(oldFile).copy(newFile)) {
|
||||||
|
@ -395,59 +395,67 @@ bool MoveLegacyAlphaFolder() {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CheckAlphaVersionDir() {
|
bool MoveLegacyAlphaFolder() {
|
||||||
if (!MoveLegacyAlphaFolder()) {
|
if (!MoveLegacyAlphaFolder(qsl("TelegramAlpha_data"), qsl("alpha"))
|
||||||
|
|| !MoveLegacyAlphaFolder(qsl("TelegramBeta_data"), qsl("beta"))) {
|
||||||
return false;
|
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;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CheckPortableVersionDir() {
|
bool CheckPortableVersionDir() {
|
||||||
if (CheckAlphaVersionDir()) {
|
if (!MoveLegacyAlphaFolder()) {
|
||||||
return true;
|
return false;
|
||||||
} else if (QDir(cExeDir() + qsl("TelegramForcePortable")).exists()) {
|
}
|
||||||
cForceWorkingDir(cExeDir() + qsl("TelegramForcePortable/"));
|
|
||||||
|
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 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() {
|
QString InstallBetaVersionsSettingPath() {
|
||||||
|
|
|
@ -332,18 +332,20 @@ void start(not_null<Core::Launcher*> launcher) {
|
||||||
|
|
||||||
if (cAlphaVersion()) {
|
if (cAlphaVersion()) {
|
||||||
workingDirChosen = true;
|
workingDirChosen = true;
|
||||||
|
|
||||||
#if defined Q_OS_MAC || defined Q_OS_LINUX
|
#if defined Q_OS_MAC || defined Q_OS_LINUX
|
||||||
} else {
|
} else {
|
||||||
#ifdef _DEBUG
|
|
||||||
cForceWorkingDir(cExeDir());
|
|
||||||
#else // _DEBUG
|
|
||||||
if (!cWorkingDir().isEmpty()) {
|
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());
|
cForceWorkingDir(cWorkingDir());
|
||||||
} else {
|
} else {
|
||||||
|
#ifdef _DEBUG
|
||||||
|
cForceWorkingDir(cExeDir());
|
||||||
|
#else // _DEBUG
|
||||||
cForceWorkingDir(psAppDataPath());
|
cForceWorkingDir(psAppDataPath());
|
||||||
}
|
|
||||||
#endif // !_DEBUG
|
#endif // !_DEBUG
|
||||||
|
}
|
||||||
workingDirChosen = true;
|
workingDirChosen = true;
|
||||||
|
|
||||||
#if defined Q_OS_LINUX && !defined _DEBUG // fix first version
|
#if defined Q_OS_LINUX && !defined _DEBUG // fix first version
|
||||||
|
@ -354,6 +356,7 @@ void start(not_null<Core::Launcher*> launcher) {
|
||||||
} else {
|
} else {
|
||||||
cForceWorkingDir(psAppDataPath());
|
cForceWorkingDir(psAppDataPath());
|
||||||
workingDirChosen = true;
|
workingDirChosen = true;
|
||||||
|
|
||||||
#elif defined OS_WIN_STORE // Q_OS_MAC || Q_OS_LINUX || Q_OS_WINRT
|
#elif defined OS_WIN_STORE // Q_OS_MAC || Q_OS_LINUX || Q_OS_WINRT
|
||||||
#ifdef _DEBUG
|
#ifdef _DEBUG
|
||||||
cForceWorkingDir(cExeDir());
|
cForceWorkingDir(cExeDir());
|
||||||
|
@ -361,13 +364,16 @@ void start(not_null<Core::Launcher*> launcher) {
|
||||||
cForceWorkingDir(psAppDataPath());
|
cForceWorkingDir(psAppDataPath());
|
||||||
#endif // !_DEBUG
|
#endif // !_DEBUG
|
||||||
workingDirChosen = true;
|
workingDirChosen = true;
|
||||||
|
|
||||||
#elif defined Q_OS_WIN
|
#elif defined Q_OS_WIN
|
||||||
} else {
|
} else {
|
||||||
if (!cWorkingDir().isEmpty()) {
|
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());
|
cForceWorkingDir(cWorkingDir());
|
||||||
workingDirChosen = true;
|
workingDirChosen = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // Q_OS_MAC || Q_OS_LINUX || Q_OS_WINRT || OS_WIN_STORE
|
#endif // Q_OS_MAC || Q_OS_LINUX || Q_OS_WINRT || OS_WIN_STORE
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue