commit 877e52e0
Start writing information about executable location to a state file. Can be picked up by other programs to see where the game is installed.
Changed files
| M | source/code/HelpAboutState.cpp before |
| M | source/code/main.cpp before |
| M | source/code/os.cpp before |
| M | source/code/os.hpp before |
diff --git a/source/code/HelpAboutState.cpp b/source/code/HelpAboutState.cpp
index 24d0666..7f4a98f 100644
--- a/source/code/HelpAboutState.cpp
+++ b/source/code/HelpAboutState.cpp
@@ -62,7 +62,7 @@ HelpAboutState::HelpAboutState() {
infoStream << _("SDL compiled version:") << " " << sdl_verison_as_string(compiled) << "\n";
infoStream << _("SDL linked version:") << " " << sdl_verison_as_string(linked) << "\n";
SDL_IMAGE_VERSION(&compiled);
- const SDL_version *sdl_link_version=IMG_Linked_Version();
+ const SDL_version* sdl_link_version=IMG_Linked_Version();
infoStream << _("SDL_image compiled version:") << " " << sdl_verison_as_string(compiled) << "\n";
infoStream << _("SDL_image linked version:") << " " << sdl_verison_as_string(*sdl_link_version) << "\n";
SDL_MIXER_VERSION(&compiled);
diff --git a/source/code/main.cpp b/source/code/main.cpp
index f588f8c..096c48a 100644
--- a/source/code/main.cpp
+++ b/source/code/main.cpp
@@ -955,6 +955,18 @@ static void ParseArguments(int argc, char* argv[], globalConfig& conf) {
#define PHYSFS_unmount PHYSFS_removeFromSearchPath
#endif
+static void writeStateFile(const char* executable, const char* basedir) {
+ std::string path = getPathToStateFiles();
+ OsCreateFolder(path);
+ std::ofstream stateFile;
+ stateFile.open (path+"/game.txt");
+ if (executable) {
+ stateFile << "executable " << executable << "\n";
+ }
+ stateFile << "basedir " << basedir << "\n";
+ stateFile << "SHAREDIR " << SHAREDIR << "\n";
+}
+
//Warning: the arguments to main must be "int argc, char* argv[]" NO CONST! or SDL_main will fail to find it
int main(int argc, char* argv[]) {
try {
@@ -973,6 +985,7 @@ int main(int argc, char* argv[]) {
textdomain (PACKAGE);
ParseArguments(argc, argv, config);
OsCreateSaveFolder();
+ writeStateFile(argv[0], PHYSFS_getBaseDir());
PhysFsSetSearchPath(config.search_paths, config.savepath);
/*if (globalData.modList.empty() && sago::FileExists(MODLIST_TXT)) {
std::string modString = sago::GetFileContent(MODLIST_TXT);
diff --git a/source/code/os.cpp b/source/code/os.cpp
index 47fdc6b..4adf8e0 100644
--- a/source/code/os.cpp
+++ b/source/code/os.cpp
@@ -52,6 +52,10 @@ std::string getPathToSaveFiles() {
return pf.getSaveGamesFolder1()+"/"+GAMENAME;
}
+std::string getPathToStateFiles() {
+ return sago::getStateDir()+"/"+GAMENAME+"/state";
+}
+
void setPathToSaveFiles(const std::string& path) {
overrideSavePath = path;
}
@@ -114,19 +118,19 @@ bool OsPathIsRelative(const std::string& path) {
}
void OsCreateFolder(const std::string& path) {
-#if defined(__unix__)
+ //Once all supported systems works with C++17 then we can use "std::filesystem::create_directories" instead
+#if defined(_WIN32)
+ //Now for Windows Vista+
+ int retcode = SHCreateDirectoryExW(NULL, win32_utf8_to_utf16(path.c_str()).c_str(), NULL);
+ if (retcode != ERROR_SUCCESS) {
+ std::cerr << "Failed to create: " << path+"/" << "\n";
+ }
+#else
std::string cmd = "mkdir -p '"+path+"/'";
int retcode = system(cmd.c_str());
if (retcode != 0) {
std::cerr << "Failed to create: " << path+"/" << "\n";
}
-#elif defined(_WIN32)
- //Now for Windows NT/2k/xp/2k3 etc.
- CreateDirectoryW(win32_utf8_to_utf16(pf.getSaveGamesFolder1().c_str()).c_str(), nullptr);
- std::string tempA = path;
- CreateDirectoryW(win32_utf8_to_utf16(tempA.c_str()).c_str(), nullptr);
-#else
- std::cerr << "Failed to create: \"" << path << "\"\n";
#endif
}
diff --git a/source/code/os.hpp b/source/code/os.hpp
index d0f60df..05c124f 100644
--- a/source/code/os.hpp
+++ b/source/code/os.hpp
@@ -33,6 +33,8 @@ https://blockattack.net
std::string getPathToSaveFiles();
+std::string getPathToStateFiles();
+
std::string defaultPlayerName();
void setPathToSaveFiles(const std::string& path);