GTA V Folder now over Environment value
This commit is contained in:
parent
25184e13b3
commit
b1155cb2a7
7 changed files with 159 additions and 46 deletions
95
AppEnv.cpp
Executable file
95
AppEnv.cpp
Executable file
|
@ -0,0 +1,95 @@
|
||||||
|
/*****************************************************************************
|
||||||
|
* gta5sync GRAND THEFT AUTO V SYNC
|
||||||
|
* Copyright (C) 2016 Syping
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*****************************************************************************/
|
||||||
|
|
||||||
|
#define _CRT_SECURE_NO_WARNINGS
|
||||||
|
#include "AppEnv.h"
|
||||||
|
#include "StandardPaths.h"
|
||||||
|
#include <QDir>
|
||||||
|
#include <QSettings>
|
||||||
|
#include <iostream>
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
AppEnv::AppEnv()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
QString AppEnv::getGameFolder(bool *ok)
|
||||||
|
{
|
||||||
|
Q_UNUSED(ok)
|
||||||
|
QDir dir;
|
||||||
|
bool retok;
|
||||||
|
QString GTAV_FOLDER(getenv("GTAV_FOLDER"));
|
||||||
|
if (GTAV_FOLDER != "")
|
||||||
|
{
|
||||||
|
dir.setPath(GTAV_FOLDER);
|
||||||
|
if (dir.exists())
|
||||||
|
{
|
||||||
|
retok = true;
|
||||||
|
ok = &retok;
|
||||||
|
#ifdef GTA5SYNC_WIN
|
||||||
|
_putenv(QString("GTAV_FOLDER=" + dir.absolutePath()).toStdString().c_str());
|
||||||
|
#else
|
||||||
|
putenv(QString("GTAV_FOLDER=" + dir.absolutePath()).toStdString().c_str());
|
||||||
|
#endif
|
||||||
|
return dir.absolutePath();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
QString GTAV_defaultFolder = StandardPaths::documentsLocation() + QDir::separator() + "Rockstar Games" + QDir::separator() + "GTA V";
|
||||||
|
QString GTAV_returnFolder = GTAV_defaultFolder;
|
||||||
|
|
||||||
|
QSettings SyncSettings("Syping", "gta5sync");
|
||||||
|
SyncSettings.beginGroup("dir");
|
||||||
|
bool forceDir = SyncSettings.value("force", false).toBool();
|
||||||
|
if (forceDir)
|
||||||
|
{
|
||||||
|
GTAV_returnFolder = SyncSettings.value("dir", GTAV_defaultFolder).toString();
|
||||||
|
}
|
||||||
|
SyncSettings.endGroup();
|
||||||
|
|
||||||
|
dir.setPath(GTAV_returnFolder);
|
||||||
|
if (dir.exists())
|
||||||
|
{
|
||||||
|
retok = true;
|
||||||
|
ok = &retok;
|
||||||
|
#ifdef GTA5SYNC_WIN
|
||||||
|
_putenv(QString("GTAV_FOLDER=" + dir.absolutePath()).toStdString().c_str());
|
||||||
|
#else
|
||||||
|
putenv(QString("GTAV_FOLDER=" + dir.absolutePath()).toStdString().c_str());
|
||||||
|
#endif
|
||||||
|
return dir.absolutePath();
|
||||||
|
}
|
||||||
|
|
||||||
|
dir.setPath(GTAV_defaultFolder);
|
||||||
|
if (dir.exists())
|
||||||
|
{
|
||||||
|
retok = true;
|
||||||
|
ok = &retok;
|
||||||
|
#ifdef GTA5SYNC_WIN
|
||||||
|
_putenv(QString("GTAV_FOLDER=" + dir.absolutePath()).toStdString().c_str());
|
||||||
|
#else
|
||||||
|
putenv(QString("GTAV_FOLDER=" + dir.absolutePath()).toStdString().c_str());
|
||||||
|
#endif
|
||||||
|
return dir.absolutePath();
|
||||||
|
}
|
||||||
|
|
||||||
|
retok = false;
|
||||||
|
ok = &retok;
|
||||||
|
return "";
|
||||||
|
}
|
31
AppEnv.h
Executable file
31
AppEnv.h
Executable file
|
@ -0,0 +1,31 @@
|
||||||
|
/*****************************************************************************
|
||||||
|
* gta5sync GRAND THEFT AUTO V SYNC
|
||||||
|
* Copyright (C) 2016 Syping
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*****************************************************************************/
|
||||||
|
|
||||||
|
#ifndef APPENV_H
|
||||||
|
#define APPENV_H
|
||||||
|
|
||||||
|
#include <QString>
|
||||||
|
|
||||||
|
class AppEnv
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
AppEnv();
|
||||||
|
static QString getGameFolder(bool *ok = 0);
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // APPENV_H
|
|
@ -384,9 +384,9 @@ bool ProfileInterface::importSnapmaticPicture(SnapmaticPicture *picture, QString
|
||||||
QMessageBox::warning(this, tr("Import"), tr("Failed to import the Snapmatic picture, file not begin with PGTA"));
|
QMessageBox::warning(this, tr("Import"), tr("Failed to import the Snapmatic picture, file not begin with PGTA"));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
else if (QFile::copy(picPath, profileFolder + "/" + picFileName))
|
else if (QFile::copy(picPath, profileFolder + QDir::separator() + picFileName))
|
||||||
{
|
{
|
||||||
pictureLoaded_f(picture, profileFolder + "/" + picFileName, true);
|
pictureLoaded_f(picture, profileFolder + QDir::separator() + picFileName, true);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -411,7 +411,7 @@ bool ProfileInterface::importSavegameData(SavegameData *savegame, QString sgdPat
|
||||||
}
|
}
|
||||||
sgdFileName = "SGTA500" + sgdNumber;
|
sgdFileName = "SGTA500" + sgdNumber;
|
||||||
|
|
||||||
if (!QFile::exists(profileFolder + "/" + sgdFileName))
|
if (!QFile::exists(profileFolder + QDir::separator() + sgdFileName))
|
||||||
{
|
{
|
||||||
foundFree = true;
|
foundFree = true;
|
||||||
}
|
}
|
||||||
|
@ -420,9 +420,9 @@ bool ProfileInterface::importSavegameData(SavegameData *savegame, QString sgdPat
|
||||||
|
|
||||||
if (foundFree)
|
if (foundFree)
|
||||||
{
|
{
|
||||||
if (QFile::copy(sgdPath, profileFolder + "/" + sgdFileName))
|
if (QFile::copy(sgdPath, profileFolder + QDir::separator() + sgdFileName))
|
||||||
{
|
{
|
||||||
savegameLoaded_f(savegame, profileFolder + "/" + sgdFileName, true);
|
savegameLoaded_f(savegame, profileFolder + QDir::separator() + sgdFileName, true);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|
|
@ -58,7 +58,7 @@ void ProfileLoader::run()
|
||||||
foreach(const QString &SavegameFile, SavegameFiles)
|
foreach(const QString &SavegameFile, SavegameFiles)
|
||||||
{
|
{
|
||||||
emit loadingProgress(curFile, maximumV);
|
emit loadingProgress(curFile, maximumV);
|
||||||
QString sgdPath = profileFolder + "/" + SavegameFile;
|
QString sgdPath = profileFolder + QDir::separator() + SavegameFile;
|
||||||
SavegameData *savegame = new SavegameData(sgdPath);
|
SavegameData *savegame = new SavegameData(sgdPath);
|
||||||
if (savegame->readingSavegame())
|
if (savegame->readingSavegame())
|
||||||
{
|
{
|
||||||
|
@ -69,7 +69,7 @@ void ProfileLoader::run()
|
||||||
foreach(const QString &SnapmaticPic, SnapmaticPics)
|
foreach(const QString &SnapmaticPic, SnapmaticPics)
|
||||||
{
|
{
|
||||||
emit loadingProgress(curFile, maximumV);
|
emit loadingProgress(curFile, maximumV);
|
||||||
QString picturePath = profileFolder + "/" + SnapmaticPic;
|
QString picturePath = profileFolder + QDir::separator() + SnapmaticPic;
|
||||||
SnapmaticPicture *picture = new SnapmaticPicture(picturePath);
|
SnapmaticPicture *picture = new SnapmaticPicture(picturePath);
|
||||||
if (picture->readingPicture())
|
if (picture->readingPicture())
|
||||||
{
|
{
|
||||||
|
|
|
@ -21,6 +21,7 @@
|
||||||
#include "ProfileInterface.h"
|
#include "ProfileInterface.h"
|
||||||
#include "StandardPaths.h"
|
#include "StandardPaths.h"
|
||||||
#include "AboutDialog.h"
|
#include "AboutDialog.h"
|
||||||
|
#include "AppEnv.h"
|
||||||
#include <QHBoxLayout>
|
#include <QHBoxLayout>
|
||||||
#include <QSpacerItem>
|
#include <QSpacerItem>
|
||||||
#include <QPushButton>
|
#include <QPushButton>
|
||||||
|
@ -45,24 +46,9 @@ UserInterface::UserInterface(ProfileDatabase *profileDB, CrewDatabase *crewDB, D
|
||||||
|
|
||||||
this->setWindowTitle(defaultWindowTitle.arg(tr("Select Profile")));
|
this->setWindowTitle(defaultWindowTitle.arg(tr("Select Profile")));
|
||||||
|
|
||||||
// init settings
|
bool folderExists;
|
||||||
QSettings SyncSettings("Syping", "gta5sync");
|
GTAV_Folder = AppEnv::getGameFolder(&folderExists);
|
||||||
SyncSettings.beginGroup("dir");
|
if (folderExists)
|
||||||
bool forceDir = SyncSettings.value("force", false).toBool();
|
|
||||||
|
|
||||||
// init folder
|
|
||||||
QString GTAV_defaultFolder = StandardPaths::documentsLocation() + "/Rockstar Games/GTA V";
|
|
||||||
QDir GTAV_Dir;
|
|
||||||
if (forceDir)
|
|
||||||
{
|
|
||||||
GTAV_Folder = SyncSettings.value("dir", GTAV_defaultFolder).toString();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
GTAV_Folder = GTAV_defaultFolder;
|
|
||||||
}
|
|
||||||
GTAV_Dir.setPath(GTAV_Folder);
|
|
||||||
if (GTAV_Dir.exists())
|
|
||||||
{
|
{
|
||||||
QDir::setCurrent(GTAV_Folder);
|
QDir::setCurrent(GTAV_Folder);
|
||||||
}
|
}
|
||||||
|
@ -70,13 +56,13 @@ UserInterface::UserInterface(ProfileDatabase *profileDB, CrewDatabase *crewDB, D
|
||||||
{
|
{
|
||||||
QMessageBox::warning(this, tr("gta5sync"), tr("Grand Theft Auto V Folder not found!"));
|
QMessageBox::warning(this, tr("gta5sync"), tr("Grand Theft Auto V Folder not found!"));
|
||||||
}
|
}
|
||||||
SyncSettings.endGroup();
|
|
||||||
|
|
||||||
// profiles init
|
// profiles init
|
||||||
|
QSettings SyncSettings("Syping", "gta5sync");
|
||||||
SyncSettings.beginGroup("Profile");
|
SyncSettings.beginGroup("Profile");
|
||||||
QString defaultProfile = SyncSettings.value("Default", "").toString();
|
QString defaultProfile = SyncSettings.value("Default", "").toString();
|
||||||
QDir GTAV_ProfilesDir;
|
QDir GTAV_ProfilesDir;
|
||||||
GTAV_ProfilesFolder = GTAV_Folder + "/Profiles";
|
GTAV_ProfilesFolder = GTAV_Folder + QDir::separator() + "Profiles";
|
||||||
GTAV_ProfilesDir.setPath(GTAV_ProfilesFolder);
|
GTAV_ProfilesDir.setPath(GTAV_ProfilesFolder);
|
||||||
|
|
||||||
QStringList GTAV_Profiles = GTAV_ProfilesDir.entryList(QDir::Dirs | QDir::NoDotAndDotDot, QDir::NoSort);
|
QStringList GTAV_Profiles = GTAV_ProfilesDir.entryList(QDir::Dirs | QDir::NoDotAndDotDot, QDir::NoSort);
|
||||||
|
@ -90,7 +76,6 @@ UserInterface::UserInterface(ProfileDatabase *profileDB, CrewDatabase *crewDB, D
|
||||||
{
|
{
|
||||||
openProfile(defaultProfile);
|
openProfile(defaultProfile);
|
||||||
}
|
}
|
||||||
SyncSettings.endGroup();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void UserInterface::setupProfileUi(QStringList GTAV_Profiles)
|
void UserInterface::setupProfileUi(QStringList GTAV_Profiles)
|
||||||
|
|
|
@ -25,6 +25,7 @@ TEMPLATE = app
|
||||||
|
|
||||||
SOURCES += main.cpp \
|
SOURCES += main.cpp \
|
||||||
AboutDialog.cpp \
|
AboutDialog.cpp \
|
||||||
|
AppEnv.cpp \
|
||||||
CrewDatabase.cpp \
|
CrewDatabase.cpp \
|
||||||
DatabaseThread.cpp \
|
DatabaseThread.cpp \
|
||||||
ExportThread.cpp \
|
ExportThread.cpp \
|
||||||
|
@ -51,6 +52,7 @@ SOURCES += main.cpp \
|
||||||
|
|
||||||
HEADERS += \
|
HEADERS += \
|
||||||
AboutDialog.h \
|
AboutDialog.h \
|
||||||
|
AppEnv.h \
|
||||||
CrewDatabase.h \
|
CrewDatabase.h \
|
||||||
DatabaseThread.h \
|
DatabaseThread.h \
|
||||||
ExportThread.h \
|
ExportThread.h \
|
||||||
|
|
36
main.cpp
36
main.cpp
|
@ -92,9 +92,9 @@ int main(int argc, char *argv[])
|
||||||
QStringList langList = languageName.split("_");
|
QStringList langList = languageName.split("_");
|
||||||
if (langList.length() >= 1)
|
if (langList.length() >= 1)
|
||||||
{
|
{
|
||||||
if (QFile::exists(langpath + "/gta5sync_" + langList.at(0) + ".qm"))
|
if (QFile::exists(langpath + QDir::separator() + "gta5sync_" + langList.at(0) + ".qm"))
|
||||||
{
|
{
|
||||||
EappTranslator.load(langpath + "/gta5sync_" + langList.at(0) + ".qm");
|
EappTranslator.load(langpath + QDir::separator() + "/gta5sync_" + langList.at(0) + ".qm");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -104,9 +104,9 @@ int main(int argc, char *argv[])
|
||||||
QStringList langList = languageName.split("_");
|
QStringList langList = languageName.split("_");
|
||||||
if (langList.length() >= 1)
|
if (langList.length() >= 1)
|
||||||
{
|
{
|
||||||
if (QFile::exists(langpath + "/gta5sync_" + langList.at(0) + ".qm"))
|
if (QFile::exists(langpath + QDir::separator() + "gta5sync_" + langList.at(0) + ".qm"))
|
||||||
{
|
{
|
||||||
if (!EappTranslator.load(langpath + "/gta5sync_" + langList.at(0) + ".qm"))
|
if (!EappTranslator.load(langpath + QDir::separator() + "gta5sync_" + langList.at(0) + ".qm"))
|
||||||
{
|
{
|
||||||
if (langList.at(0) != "en")
|
if (langList.at(0) != "en")
|
||||||
{
|
{
|
||||||
|
@ -133,9 +133,9 @@ int main(int argc, char *argv[])
|
||||||
QStringList langList = languageName.split("_");
|
QStringList langList = languageName.split("_");
|
||||||
if (langList.length() >= 1)
|
if (langList.length() >= 1)
|
||||||
{
|
{
|
||||||
if (QFile::exists(langpath + "/gta5sync_" + langList.at(0) + ".qm"))
|
if (QFile::exists(langpath + QDir::separator() + "gta5sync_" + langList.at(0) + ".qm"))
|
||||||
{
|
{
|
||||||
EappTranslator.load(langpath + "/gta5sync_" + langList.at(0) + ".qm");
|
EappTranslator.load(langpath + QDir::separator() + "gta5sync_" + langList.at(0) + ".qm");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -148,9 +148,9 @@ int main(int argc, char *argv[])
|
||||||
QStringList langList = languageName.split("_");
|
QStringList langList = languageName.split("_");
|
||||||
if (langList.length() >= 1)
|
if (langList.length() >= 1)
|
||||||
{
|
{
|
||||||
if (QFile::exists(langpath + "/qtbase_" + langList.at(0) + ".qm"))
|
if (QFile::exists(langpath + QDir::separator() + "qtbase_" + langList.at(0) + ".qm"))
|
||||||
{
|
{
|
||||||
EqtTranslator1.load(langpath + "/qtbase_" + langList.at(0) + ".qm");
|
EqtTranslator1.load(langpath + QDir::separator() + "qtbase_" + langList.at(0) + ".qm");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -160,9 +160,9 @@ int main(int argc, char *argv[])
|
||||||
QStringList langList = languageName.split("_");
|
QStringList langList = languageName.split("_");
|
||||||
if (langList.length() >= 1)
|
if (langList.length() >= 1)
|
||||||
{
|
{
|
||||||
if (QFile::exists(langpath + "/qtbase_" + langList.at(0) + ".qm"))
|
if (QFile::exists(langpath + QDir::separator() + "qtbase_" + langList.at(0) + ".qm"))
|
||||||
{
|
{
|
||||||
EqtTranslator1.load(langpath + "/qtbase_" + langList.at(0) + ".qm");
|
EqtTranslator1.load(langpath + QDir::separator() + "qtbase_" + langList.at(0) + ".qm");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -172,9 +172,9 @@ int main(int argc, char *argv[])
|
||||||
QStringList langList = languageName.split("_");
|
QStringList langList = languageName.split("_");
|
||||||
if (langList.length() >= 1)
|
if (langList.length() >= 1)
|
||||||
{
|
{
|
||||||
if (QFile::exists(langpath + "/qtbase_" + langList.at(0) + ".qm"))
|
if (QFile::exists(langpath + QDir::separator() + "qtbase_" + langList.at(0) + ".qm"))
|
||||||
{
|
{
|
||||||
EqtTranslator1.load(langpath + "/qtbase_" + langList.at(0) + ".qm");
|
EqtTranslator1.load(langpath + QDir::separator() + "qtbase_" + langList.at(0) + ".qm");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -187,9 +187,9 @@ int main(int argc, char *argv[])
|
||||||
QStringList langList = languageName.split("_");
|
QStringList langList = languageName.split("_");
|
||||||
if (langList.length() >= 1)
|
if (langList.length() >= 1)
|
||||||
{
|
{
|
||||||
if (QFile::exists(langpath + "/qt_" + langList.at(0) + ".qm"))
|
if (QFile::exists(langpath + QDir::separator() + "qt_" + langList.at(0) + ".qm"))
|
||||||
{
|
{
|
||||||
EqtTranslator.load(langpath + "/qt_" + langList.at(0) + ".qm");
|
EqtTranslator.load(langpath + QDir::separator() + "qt_" + langList.at(0) + ".qm");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -199,9 +199,9 @@ int main(int argc, char *argv[])
|
||||||
QStringList langList = languageName.split("_");
|
QStringList langList = languageName.split("_");
|
||||||
if (langList.length() >= 1)
|
if (langList.length() >= 1)
|
||||||
{
|
{
|
||||||
if (QFile::exists(langpath + "/qt_" + langList.at(0) + ".qm"))
|
if (QFile::exists(langpath + QDir::separator() + "qt_" + langList.at(0) + ".qm"))
|
||||||
{
|
{
|
||||||
EqtTranslator.load(langpath + "/qt_" + langList.at(0) + ".qm");
|
EqtTranslator.load(langpath + QDir::separator() + "qt_" + langList.at(0) + ".qm");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -211,9 +211,9 @@ int main(int argc, char *argv[])
|
||||||
QStringList langList = languageName.split("_");
|
QStringList langList = languageName.split("_");
|
||||||
if (langList.length() >= 1)
|
if (langList.length() >= 1)
|
||||||
{
|
{
|
||||||
if (QFile::exists(langpath + "/qt_" + langList.at(0) + ".qm"))
|
if (QFile::exists(langpath + QDir::separator() + "qt_" + langList.at(0) + ".qm"))
|
||||||
{
|
{
|
||||||
EqtTranslator.load(langpath + "/qt_" + langList.at(0) + ".qm");
|
EqtTranslator.load(langpath + QDir::separator() + "qt_" + langList.at(0) + ".qm");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue