Stop using current working directory on Windows.

Links generated by system sometimes have weird working directories,
like C:\Windows\system32. Stop trying to use current working folder
as a place for program data. Instead always try to use current exe
folder and if we were unable use app data folder.
This commit is contained in:
John Preston 2017-12-06 19:07:01 +04:00
parent 727f8aec13
commit ff84962148

View file

@ -307,20 +307,21 @@ namespace Logs {
if (!Sandbox::CheckBetaVersionDir()) { if (!Sandbox::CheckBetaVersionDir()) {
return; return;
} }
bool workingDirChosen = cBetaVersion();
QString initialWorkingDir = QDir(cWorkingDir()).absolutePath() + '/', moveOldDataFrom; auto initialWorkingDir = QDir(cWorkingDir()).absolutePath() + '/';
auto moveOldDataFrom = QString();
auto workingDirChosen = false;
if (cBetaVersion()) { if (cBetaVersion()) {
cSetDebug(true); cSetDebug(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 #ifdef _DEBUG
cForceWorkingDir(cExeDir()); cForceWorkingDir(cExeDir());
#else // _DEBUG #else // _DEBUG
if (cWorkingDir().isEmpty()) { cForceWorkingDir(psAppDataPath());
cForceWorkingDir(psAppDataPath()); #endif // !_DEBUG
}
#endif // else for _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
@ -331,31 +332,31 @@ namespace Logs {
} else { } else {
cForceWorkingDir(psAppDataPath()); cForceWorkingDir(psAppDataPath());
workingDirChosen = true; workingDirChosen = true;
#elif defined OS_WIN_STORE #elif defined OS_WIN_STORE // Q_OS_MAC || Q_OS_LINUX || Q_OS_WINRT
#ifdef _DEBUG #ifdef _DEBUG
cForceWorkingDir(cExeDir()); cForceWorkingDir(cExeDir());
#else // _DEBUG #else // _DEBUG
cForceWorkingDir(psAppDataPath()); cForceWorkingDir(psAppDataPath());
#endif // else for _DEBUG #endif // !_DEBUG
#endif // OS_WIN_STORE workingDirChosen = true;
#endif // Q_OS_MAC || Q_OS_LINUX || Q_OS_WINRT || OS_WIN_STORE
} }
LogsData = new LogsDataFields(); LogsData = new LogsDataFields();
if (!workingDirChosen) { if (!workingDirChosen) {
cForceWorkingDir(cWorkingDir()); cForceWorkingDir(cExeDir());
if (!LogsData->openMain()) { if (!LogsData->openMain()) {
cForceWorkingDir(cExeDir()); cForceWorkingDir(psAppDataPath());
if (!LogsData->openMain()) {
cForceWorkingDir(psAppDataPath());
}
} }
} }
cForceWorkingDir(QDir(cWorkingDir()).absolutePath() + '/'); cForceWorkingDir(QDir(cWorkingDir()).absolutePath() + '/');
// WinRT build requires the working dir to stay the same for plugin loading. // WinRT build requires the working dir to stay the same for plugin loading.
#ifndef Q_OS_WINRT #ifndef Q_OS_WINRT
QDir().setCurrent(cWorkingDir()); QDir().setCurrent(cWorkingDir());
#endif // !Q_OS_WINRT #endif // !Q_OS_WINRT
QDir().mkpath(cWorkingDir() + qstr("tdata")); QDir().mkpath(cWorkingDir() + qstr("tdata"));
Sandbox::WorkingDirReady(); Sandbox::WorkingDirReady();