diff --git a/AppEnv.cpp b/AppEnv.cpp new file mode 100755 index 0000000..b137b21 --- /dev/null +++ b/AppEnv.cpp @@ -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 . +*****************************************************************************/ + +#define _CRT_SECURE_NO_WARNINGS +#include "AppEnv.h" +#include "StandardPaths.h" +#include +#include +#include +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 ""; +} diff --git a/AppEnv.h b/AppEnv.h new file mode 100755 index 0000000..96f93fc --- /dev/null +++ b/AppEnv.h @@ -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 . +*****************************************************************************/ + +#ifndef APPENV_H +#define APPENV_H + +#include + +class AppEnv +{ +public: + AppEnv(); + static QString getGameFolder(bool *ok = 0); +}; + +#endif // APPENV_H diff --git a/ProfileInterface.cpp b/ProfileInterface.cpp index 3b60208..bcf1ded 100755 --- a/ProfileInterface.cpp +++ b/ProfileInterface.cpp @@ -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")); 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; } else @@ -411,7 +411,7 @@ bool ProfileInterface::importSavegameData(SavegameData *savegame, QString sgdPat } sgdFileName = "SGTA500" + sgdNumber; - if (!QFile::exists(profileFolder + "/" + sgdFileName)) + if (!QFile::exists(profileFolder + QDir::separator() + sgdFileName)) { foundFree = true; } @@ -420,9 +420,9 @@ bool ProfileInterface::importSavegameData(SavegameData *savegame, QString sgdPat 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; } else diff --git a/ProfileLoader.cpp b/ProfileLoader.cpp index a9ce157..c635360 100755 --- a/ProfileLoader.cpp +++ b/ProfileLoader.cpp @@ -58,7 +58,7 @@ void ProfileLoader::run() foreach(const QString &SavegameFile, SavegameFiles) { emit loadingProgress(curFile, maximumV); - QString sgdPath = profileFolder + "/" + SavegameFile; + QString sgdPath = profileFolder + QDir::separator() + SavegameFile; SavegameData *savegame = new SavegameData(sgdPath); if (savegame->readingSavegame()) { @@ -69,7 +69,7 @@ void ProfileLoader::run() foreach(const QString &SnapmaticPic, SnapmaticPics) { emit loadingProgress(curFile, maximumV); - QString picturePath = profileFolder + "/" + SnapmaticPic; + QString picturePath = profileFolder + QDir::separator() + SnapmaticPic; SnapmaticPicture *picture = new SnapmaticPicture(picturePath); if (picture->readingPicture()) { diff --git a/UserInterface.cpp b/UserInterface.cpp index f57271e..6375cab 100755 --- a/UserInterface.cpp +++ b/UserInterface.cpp @@ -21,6 +21,7 @@ #include "ProfileInterface.h" #include "StandardPaths.h" #include "AboutDialog.h" +#include "AppEnv.h" #include #include #include @@ -45,24 +46,9 @@ UserInterface::UserInterface(ProfileDatabase *profileDB, CrewDatabase *crewDB, D this->setWindowTitle(defaultWindowTitle.arg(tr("Select Profile"))); - // init settings - QSettings SyncSettings("Syping", "gta5sync"); - SyncSettings.beginGroup("dir"); - 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()) + bool folderExists; + GTAV_Folder = AppEnv::getGameFolder(&folderExists); + if (folderExists) { 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!")); } - SyncSettings.endGroup(); // profiles init + QSettings SyncSettings("Syping", "gta5sync"); SyncSettings.beginGroup("Profile"); QString defaultProfile = SyncSettings.value("Default", "").toString(); QDir GTAV_ProfilesDir; - GTAV_ProfilesFolder = GTAV_Folder + "/Profiles"; + GTAV_ProfilesFolder = GTAV_Folder + QDir::separator() + "Profiles"; GTAV_ProfilesDir.setPath(GTAV_ProfilesFolder); 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); } - SyncSettings.endGroup(); } void UserInterface::setupProfileUi(QStringList GTAV_Profiles) diff --git a/gta5sync.pro b/gta5sync.pro index abd26ba..c94c22e 100755 --- a/gta5sync.pro +++ b/gta5sync.pro @@ -25,6 +25,7 @@ TEMPLATE = app SOURCES += main.cpp \ AboutDialog.cpp \ + AppEnv.cpp \ CrewDatabase.cpp \ DatabaseThread.cpp \ ExportThread.cpp \ @@ -51,6 +52,7 @@ SOURCES += main.cpp \ HEADERS += \ AboutDialog.h \ + AppEnv.h \ CrewDatabase.h \ DatabaseThread.h \ ExportThread.h \ diff --git a/main.cpp b/main.cpp index 20660ab..5ac4596 100755 --- a/main.cpp +++ b/main.cpp @@ -92,9 +92,9 @@ int main(int argc, char *argv[]) QStringList langList = languageName.split("_"); 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("_"); 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") { @@ -133,9 +133,9 @@ int main(int argc, char *argv[]) QStringList langList = languageName.split("_"); 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("_"); 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("_"); 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("_"); 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("_"); 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("_"); 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("_"); 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"); } } }