Skip to content

Commit 5f0449a

Browse files
author
cspangler
committed
Minor settings class refactor
1 parent 0b59238 commit 5f0449a

File tree

5 files changed

+20
-10
lines changed

5 files changed

+20
-10
lines changed

cfg-switcher/Settings.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@
77
#include "game.h"
88
#include "Settings.h"
99

10-
void Settings::deleteSettingsFile() {
11-
remove("settings.xml");
10+
Settings::Settings() {
11+
path = GetCurrentWorkingDir();
12+
cfgPath = path + "\\configs";
1213
}
1314

1415
bool Settings::initSettings() {
@@ -69,7 +70,7 @@ bool Settings::createSettingsFile() {
6970
element->SetText(0.1f);
7071
rootNode->InsertEndChild(element);
7172
element = settings.NewElement("path");
72-
element->SetText("D:\\cfg-switcher\\cfg-switcher");
73+
element->SetText(path.c_str());
7374
rootNode->InsertEndChild(element);
7475
rootNode->InsertEndChild(settings.NewElement("games"));
7576
tinyxml2::XMLError saved = settings.SaveFile("settings.xml");

cfg-switcher/Settings.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,12 @@ class Settings {
99
std::vector<game> games;
1010
std::string path;
1111
std::string cfgPath;
12-
public:
13-
void deleteSettingsFile();
14-
bool initSettings();
1512
bool createSettingsFile();
1613
bool createFileStruct();
17-
bool removeFileStruct(game remGame);
1814
bool updateFileStruct();
15+
public:
16+
Settings();
17+
bool initSettings();
1918
bool addGame(std::string gameID, std::string gamePath);
2019
bool removeGame(game remGame, powerState keep);
2120
bool gameExists(std::string gameID);

cfg-switcher/WinUtils.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
#include <iostream>
88
#include <fstream>
99
#include <conio.h>
10+
#include <stdio.h>
11+
#include <direct.h>
1012

1113
//Returns the last Win32 error, in string format. Returns an empty string if there is no error.
1214
std::string GetLastErrorAsString() {
@@ -180,4 +182,11 @@ int DeleteDirectory(const std::string &refcstrRootDirectory, bool bDeleteSubdire
180182
}
181183

182184
return 0;
185+
}
186+
187+
std::string GetCurrentWorkingDir() {
188+
char buff[FILENAME_MAX];
189+
_getcwd(buff, FILENAME_MAX);
190+
std::string current_working_dir(buff);
191+
return current_working_dir;
183192
}

cfg-switcher/WinUtils.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@ std::string BrowseFile(std::string prompt);
99
std::string FileFromPath(std::string filePath);
1010
bool copyFile(const char *SRC, const char* DEST);
1111
int DeleteDirectory(const std::string &refcstrRootDirectory, bool bDeleteSubdirectories = true);
12+
std::string GetCurrentWorkingDir();

cfg-switcher/main.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -220,15 +220,15 @@ int main() {
220220
}
221221
else {
222222
std::cout << "Set configs for MAIN or BATTERY power?" << std::endl;
223-
std::cout << "1: BATTERY\n2: MAIN" << std::endl;
223+
std::cout << "1: BATTERY\n2: MAIN\n3: CANCEL" << std::endl;
224224
opt = 0;
225-
while (opt < 1 || opt > 2) {
225+
while (opt < 1 || opt > 3) {
226226
while (!(std::cin >> opt)) {
227227
std::cerr << "Error: Invalid input; expecting option number" << std::endl;
228228
std::cin.clear();
229229
std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
230230
}
231-
if (opt < 1 || opt > 2)
231+
if (opt < 1 || opt > 3)
232232
std::cerr << "Error: Invalid option" << std::endl;
233233
}
234234
bool result;

0 commit comments

Comments
 (0)