git repos / blockattack-game

commit f634c96f

sago007 · 2019-05-05 15:50
f634c96f1af1e7baf1948c0fb6f456f0f3c2c0fe patch · browse files
parent 8b477c41b39ebf4de2b71249daab031113bcefce

Place screenshots under "My Pictures" instead of some deep hidden folder

Changed files

M source/code/main.cpp before
M source/code/os.cpp before
M source/code/os.hpp before
diff --git a/source/code/main.cpp b/source/code/main.cpp index 8cbfb6d..473a2f7 100644 --- a/source/code/main.cpp +++ b/source/code/main.cpp
@@ -106,7 +106,7 @@ static void PhysFsSetSearchPath(const vector<string>& paths, const string& savep
static void PhysFsCreateFolders() {
- PHYSFS_mkdir("screenshots");
+ //PHYSFS_mkdir("screenshots");
PHYSFS_mkdir("replays");
PHYSFS_mkdir("puzzles");
}
@@ -323,7 +323,11 @@ static ExplosionManager theExplosionManager;
#include "BlockGameSdl.inc"
#include "sago/SagoMisc.hpp"
#include "ReplayPlayer.hpp"
+#include "sago/platform_folders.h"
+std::string pathToScreenShots() {
+ return sago::getPicturesFolder() + "/blockattack";
+}
//writeScreenShot saves the screen as a bmp file, it uses the time to get a unique filename
void writeScreenShot() {
@@ -331,7 +335,6 @@ void writeScreenShot() {
cout << "Saving screenshot" << "\n";
}
int rightNow = (int)time(nullptr);
- string buf = getPathToSaveFiles() + "/screenshots/screenshot"+std::to_string(rightNow)+".bmp";
SDL_Surface* infoSurface = SDL_GetWindowSurface(sdlWindow);
if (!infoSurface) {
std::cerr << "Could not get infoSurface. No screenshot written. Be aware that the screenshot feature only works with software render\n";
@@ -350,6 +353,8 @@ void writeScreenShot() {
std::cerr << "Could not get sreenshotSurface. No screenshot written\n";
return;
}
+ OsCreateFolder(pathToScreenShots());
+ std::string buf = pathToScreenShots() + "/screenshot"+std::to_string(rightNow)+".bmp";
SDL_SaveBMP(sreenshotSurface, buf.c_str());
SDL_FreeSurface(sreenshotSurface);
if (!globalData.NoSound) {
diff --git a/source/code/os.cpp b/source/code/os.cpp index a55a518..8e65df5 100644 --- a/source/code/os.cpp +++ b/source/code/os.cpp
@@ -101,7 +101,15 @@ std::string defaultPlayerName() {
return ret;
}
-static void OsCreateFolder(const std::string& path) {
+static bool OsPathIsRelative(const std::string& path) {
+#if defined(_WIN32)
+ return PathIsRelativeW(win32_utf8_to_utf16(path.c_str()));
+#else
+ return path[0] != '/';
+#endif
+}
+
+void OsCreateFolder(const std::string& path) {
#if defined(__unix__)
std::string cmd = "mkdir -p '"+path+"/'";
int retcode = system(cmd.c_str());
@@ -113,6 +121,8 @@ static void OsCreateFolder(const std::string& path) {
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 3277fa3..94339d3 100644 --- a/source/code/os.hpp +++ b/source/code/os.hpp
@@ -37,3 +37,5 @@ std::string defaultPlayerName();
void setPathToSaveFiles(const std::string& path);
void OsCreateSaveFolder();
+
+void OsCreateFolder(const std::string& path);