Consolidate MoveOldDataFiles path determinition

This commit is contained in:
Ilya Fedin 2023-08-14 10:56:09 +04:00 committed by John Preston
parent b35fff01b0
commit 330dfaa4d9
1 changed files with 6 additions and 9 deletions

View File

@ -280,6 +280,9 @@ namespace {
bool DebugModeEnabled = false; bool DebugModeEnabled = false;
void MoveOldDataFiles(const QString &wasDir) { void MoveOldDataFiles(const QString &wasDir) {
if (wasDir.isEmpty()) {
return;
}
QFile data(wasDir + "data"), dataConfig(wasDir + "data_config"), tdataConfig(wasDir + "tdata/config"); QFile data(wasDir + "data"), dataConfig(wasDir + "data_config"), tdataConfig(wasDir + "tdata/config");
if (data.exists() && dataConfig.exists() && !QFileInfo::exists(cWorkingDir() + "data") && !QFileInfo::exists(cWorkingDir() + "data_config")) { // move to home dir if (data.exists() && dataConfig.exists() && !QFileInfo::exists(cWorkingDir() + "data") && !QFileInfo::exists(cWorkingDir() + "data_config")) { // move to home dir
LOG(("Copying data to home dir '%1' from '%2'").arg(cWorkingDir(), wasDir)); LOG(("Copying data to home dir '%1' from '%2'").arg(cWorkingDir(), wasDir));
@ -351,7 +354,6 @@ void start() {
return; return;
} }
auto moveOldDataFrom = QString();
auto workingDirChosen = false; auto workingDirChosen = false;
if (cAlphaVersion()) { if (cAlphaVersion()) {
@ -371,10 +373,6 @@ void start() {
#endif // !_DEBUG || OS_MAC_STORE #endif // !_DEBUG || OS_MAC_STORE
} }
#if !defined Q_OS_MAC && !defined _DEBUG // fix first version
moveOldDataFrom = launcher.initialWorkingDir();
#endif // !Q_OS_MAC && !_DEBUG
#elif defined Q_OS_WINRT // Q_OS_UNIX #elif defined Q_OS_WINRT // Q_OS_UNIX
cForceWorkingDir(psAppDataPath()); cForceWorkingDir(psAppDataPath());
@ -443,12 +441,11 @@ void start() {
#ifdef Q_OS_WIN #ifdef Q_OS_WIN
if (cWorkingDir() == psAppDataPath()) { // fix old "Telegram Win (Unofficial)" version if (cWorkingDir() == psAppDataPath()) { // fix old "Telegram Win (Unofficial)" version
moveOldDataFrom = psAppDataPathOld(); MoveOldDataFiles(psAppDataPathOld());
} }
#elif !defined Q_OS_MAC && !defined _DEBUG // fix first version
MoveOldDataFiles(launcher.initialWorkingDir());
#endif #endif
if (!moveOldDataFrom.isEmpty()) {
MoveOldDataFiles(moveOldDataFrom);
}
if (LogsInMemory) { if (LogsInMemory) {
Assert(LogsInMemory != DeletedLogsInMemory); Assert(LogsInMemory != DeletedLogsInMemory);