From ae3b5c4c1a221efb690506ff0b1192f8424cc484 Mon Sep 17 00:00:00 2001 From: Steve Date: Wed, 24 Feb 2016 07:17:53 +0000 Subject: [PATCH] Create tbfss save folder in Windows with current username. --- src/plat/win32/win32Init.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/plat/win32/win32Init.c b/src/plat/win32/win32Init.c index 742dce4..0a8e281 100644 --- a/src/plat/win32/win32Init.c +++ b/src/plat/win32/win32Init.c @@ -22,4 +22,25 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. void createSaveFolder(void) { + char *userHome; + char dir[MAX_FILENAME_LENGTH]; + + userHome = getenv("USERNAME"); + + if (!userHome) + { + SDL_LogMessage(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_WARN, "Unable to determine user save folder. Will save to current dir."); + return; + } + + SDL_LogMessage(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO, "User home = %s", userHome); + + sprintf(dir, "%s/tbftss", userHome); + if (mkdir(dir, S_IRWXU|S_IRWXG|S_IROTH|S_IXOTH) != 0 && errno != EEXIST) + { + SDL_LogMessage(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_WARN, "Failed to create save dir '%s'. Will save to current dir.", dir); + return; + } + + STRNCPY(app.saveDir, dir, MAX_FILENAME_LENGTH); }