Skip to content

Commit

Permalink
[added] wine env variable setting
Browse files Browse the repository at this point in the history
  • Loading branch information
TheAnswer committed Dec 3, 2013
1 parent e384eed commit 41aa046
Show file tree
Hide file tree
Showing 9 changed files with 115 additions and 9 deletions.
6 changes: 4 additions & 2 deletions SWGEmuLaunchpad.pro
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ SOURCES += main.cpp\
configparser.cpp \
gameprocess.cpp \
selfupdater.cpp \
installfromswg.cpp
installfromswg.cpp \
utils.cpp

HEADERS += mainwindow.h \
settings.h \
Expand All @@ -33,7 +34,8 @@ HEADERS += mainwindow.h \
gameprocess.h \
selfupdater.h \
singleinstance.h \
installfromswg.h
installfromswg.h \
utils.h

FORMS += mainwindow.ui \
settings.ui \
Expand Down
15 changes: 13 additions & 2 deletions gameprocess.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
#include <QDateTime>
#include <QFileDialog>

#include "utils.h"

#ifdef Q_OS_WIN32
WinDebugMonitor* GameProcess::debugMonitor = NULL;
#endif
Expand Down Expand Up @@ -108,12 +110,21 @@ bool GameProcess::start(const QString& folder, const QString& executable, const

QStringList argsList;
if (!args.isEmpty())
argsList = args.split(" ");
argsList = Utils::getArgumentList(args);

argsList.append(folder + "\\" + executable);
argsList.append(folder + "/" + executable);

qDebug() << argsList;

QString envs = settings.value("wine_env").toString();
if (!envs.isEmpty()) {
env.append(Utils::getArgumentList(envs));

qDebug() << env;

process->setEnvironment(env);
}

if (!QProcess::startDetached(wineBinary, argsList, folder)) {
QMessageBox::warning(this, "ERROR", "Could not launch game settings!");
}
Expand Down
3 changes: 3 additions & 0 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "singleinstance.h"
#endif
#include <QMessageBox>
#include "utils.h"

int main(int argc, char *argv[]) {
QApplication a(argc, argv);
Expand All @@ -18,6 +19,8 @@ int main(int argc, char *argv[]) {

//HANDLE instanceMutex = CreateMutex()



#ifdef Q_OS_WIN32
SingleInstance instance(TEXT("DCB15209-9E02-489D-9FD6-03689735BD49"));

Expand Down
11 changes: 8 additions & 3 deletions mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include "selfupdater.h"
#include <QCloseEvent>
#include "installfromswg.h"
#include "utils.h"

#if QT_VERSION >= 0x050000
#include <QtConcurrent/QtConcurrentRun>
Expand Down Expand Up @@ -245,7 +246,11 @@ void MainWindow::deleteProfiles() {
QSettings settings;
QString folder = settings.value("swg_folder").toString();

#ifdef Q_OS_WIN32
QDir dir(folder + "\\profiles");
#else
QDir dir(folder + "/profiles");
#endif

if (!dir.exists()) {
QMessageBox::warning(this, "Warning", "No profiles folder found");
Expand Down Expand Up @@ -962,7 +967,7 @@ void MainWindow::startKodanCalculator() {

QStringList argsList;
if (!args.isEmpty())
argsList = args.split(" ");
argsList = Utils::getArgumentList(args);

argsList.append("KSWGProfCalcEditor.exe");

Expand Down Expand Up @@ -999,9 +1004,9 @@ void MainWindow::startSWGSetup() {

QStringList argsList;
if (!args.isEmpty())
argsList = args.split(" ");
argsList = Utils::getArgumentList(args);

argsList.append(folder + "\\" + "SWGEmu_Setup.exe");
argsList.append(folder + "/" + "SWGEmu_Setup.exe");

qDebug() << argsList;

Expand Down
16 changes: 16 additions & 0 deletions settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ Settings::Settings(QWidget *parent) :
ui->checkBox_minimize->setChecked(settings.value("minimize_after_start", false).toBool());
ui->checkBox_debug->setChecked(settings.value("capture_debug_output", false).toBool());
ui->checkBox_multithreaded->setChecked(settings.value("multi_threaded_full_scan", false).toBool());
ui->lineEdit_wine_env->setText(settings.value("wine_env").toString());
QString wineBinary = settings.value("wine_binary").toString();

if (!wineBinary.isEmpty())
Expand Down Expand Up @@ -64,6 +65,7 @@ void Settings::updateAllOptions() {
updateMultiThreadedFullScan();
updateWineBinary();
updateWineArguments();
updateWineEnvironment();
}

void Settings::updateMultiThreadedFullScan() {
Expand Down Expand Up @@ -117,6 +119,13 @@ void Settings::updateWineArguments() {
settings.setValue("wine_args", arguments);
}

void Settings::updateWineEnvironment() {
QString env = ui->lineEdit_wine_env->text();

QSettings settings;
settings.setValue("wine_env", env);
}

void Settings::restoreOptions() {
restoreFolder();
restoreCloseAfterStart();
Expand All @@ -125,6 +134,13 @@ void Settings::restoreOptions() {
restoreMultiThreadedFullScan();
restoreWineArgs();
restoreWineBinary();
restoreWineEnvironment();
}

void Settings::restoreWineEnvironment() {
QSettings settings;

ui->lineEdit_wine_env->setText(settings.value("wine_env").toString());
}

void Settings::restoreWineBinary() {
Expand Down
2 changes: 2 additions & 0 deletions settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public slots:
void updateMultiThreadedFullScan();
void updateWineBinary();
void updateWineArguments();
void updateWineEnvironment();

void restoreCloseAfterStart();
void restoreMimizeAfterStart();
Expand All @@ -33,6 +34,7 @@ public slots:
void restoreFolder();
void restoreWineBinary();
void restoreWineArgs();
void restoreWineEnvironment();

void closeAfterStartChanged(bool state);
void minimizeToTrayAfterStartChanged(bool state);
Expand Down
18 changes: 16 additions & 2 deletions settings.ui
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>422</width>
<height>234</height>
<width>347</width>
<height>239</height>
</rect>
</property>
<property name="windowTitle">
Expand Down Expand Up @@ -115,6 +115,20 @@
</item>
</layout>
</item>
<item row="2" column="0">
<layout class="QHBoxLayout" name="horizontalLayout_5">
<item>
<widget class="QLabel" name="label_4">
<property name="text">
<string>Wine Env. Vars</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="lineEdit_wine_env"/>
</item>
</layout>
</item>
</layout>
</widget>
</item>
Expand Down
40 changes: 40 additions & 0 deletions utils.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#include "utils.h"
#include <QDebug>

Utils::Utils() {
}

QStringList Utils::getArgumentList(const QString& args) {
bool str = false;
QStringList argumentList;
QString currentArg;

for (int i = 0; i < args.length(); ++i) {
currentArg.append(args.at(i));

if (args.at(i) == '"' || args.at(i) == '\'') {
if (str) {
argumentList.append(currentArg);
currentArg = "";
}

str = !str;
} else if (args.at(i) == ' ') {
if (str)
continue;
else {
currentArg.remove(currentArg.length() - 1, 1);

if (!currentArg.isEmpty())
argumentList.append(currentArg);

currentArg = "";
}
}
}

if (!currentArg.isEmpty())
argumentList.append(currentArg);

return argumentList;
}
13 changes: 13 additions & 0 deletions utils.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#ifndef UTILS_H
#define UTILS_H

#include <QStringList>

class Utils {
public:
Utils();

static QStringList getArgumentList(const QString& args);
};

#endif // UTILS_H

0 comments on commit 41aa046

Please sign in to comment.