Create save directories recursively.
This commit is contained in:
parent
e1992b8ce4
commit
15043e7776
|
@ -19,6 +19,8 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "unixInit.h"
|
#include "unixInit.h"
|
||||||
|
|
||||||
|
static void mkpath(const char *path);
|
||||||
|
|
||||||
void createSaveFolder(void)
|
void createSaveFolder(void)
|
||||||
{
|
{
|
||||||
|
@ -39,16 +41,49 @@ void createSaveFolder(void)
|
||||||
for (i = 0 ; i < MAX_SAVE_SLOTS ; i++)
|
for (i = 0 ; i < MAX_SAVE_SLOTS ; i++)
|
||||||
{
|
{
|
||||||
sprintf(dir, "%s/.local/share/blobwarsAttrition/%d", userHome, i);
|
sprintf(dir, "%s/.local/share/blobwarsAttrition/%d", userHome, i);
|
||||||
if (mkdir(dir, S_IRWXU|S_IRWXG|S_IROTH|S_IXOTH) != 0 && errno != EEXIST)
|
|
||||||
{
|
mkpath(dir);
|
||||||
SDL_LogMessage(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_ERROR, "Failed to create save dir '%s'.", dir);
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
sprintf(app.saveDir, "%s/.local/share/blobwarsAttrition", userHome);
|
sprintf(app.saveDir, "%s/.local/share/blobwarsAttrition", userHome);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void mkpath(const char *path)
|
||||||
|
{
|
||||||
|
char dir[MAX_FILENAME_LENGTH];
|
||||||
|
int i, rootPath;
|
||||||
|
|
||||||
|
strcpy(dir, "");
|
||||||
|
|
||||||
|
rootPath = 1;
|
||||||
|
|
||||||
|
for (i = 0 ; i < strlen(path) ; i++)
|
||||||
|
{
|
||||||
|
if (path[i] == '/')
|
||||||
|
{
|
||||||
|
if (!rootPath)
|
||||||
|
{
|
||||||
|
if (mkdir(dir, S_IRWXU|S_IRWXG|S_IROTH|S_IXOTH) != 0 && errno != EEXIST)
|
||||||
|
{
|
||||||
|
SDL_LogMessage(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_ERROR, "Failed to create save dir '%s'.", dir);
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
rootPath = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
dir[i] = path[i];
|
||||||
|
dir[i + 1] = '\0';
|
||||||
|
}
|
||||||
|
|
||||||
|
if (mkdir(dir, S_IRWXU|S_IRWXG|S_IROTH|S_IXOTH) != 0 && errno != EEXIST)
|
||||||
|
{
|
||||||
|
SDL_LogMessage(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_ERROR, "Failed to create save dir '%s'.", dir);
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void createScreenshotFolder(void)
|
void createScreenshotFolder(void)
|
||||||
{
|
{
|
||||||
mkdir("/tmp/blobwarsAttrition", S_IRWXU|S_IRWXG|S_IROTH|S_IXOTH);
|
mkdir("/tmp/blobwarsAttrition", S_IRWXU|S_IRWXG|S_IROTH|S_IXOTH);
|
||||||
|
|
|
@ -20,6 +20,8 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||||
|
|
||||||
#include "win32Init.h"
|
#include "win32Init.h"
|
||||||
|
|
||||||
|
static void mkpath(const char *path);
|
||||||
|
|
||||||
void createSaveFolder(void)
|
void createSaveFolder(void)
|
||||||
{
|
{
|
||||||
char *userHome;
|
char *userHome;
|
||||||
|
@ -39,16 +41,49 @@ void createSaveFolder(void)
|
||||||
for (i = 0 ; i < MAX_SAVE_SLOTS ; i++)
|
for (i = 0 ; i < MAX_SAVE_SLOTS ; i++)
|
||||||
{
|
{
|
||||||
sprintf(dir, "%s\\blobwarsAttrition\\%d", userHome, i);
|
sprintf(dir, "%s\\blobwarsAttrition\\%d", userHome, i);
|
||||||
if (mkdir(dir) != 0 && errno != EEXIST)
|
|
||||||
{
|
mkpath(dir);
|
||||||
SDL_LogMessage(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_ERROR, "Failed to create save dir '%s'.", dir);
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
sprintf(app.saveDir, "%s\\blobwarsAttrition", userHome);
|
sprintf(app.saveDir, "%s\\blobwarsAttrition", userHome);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void mkpath(const char *path)
|
||||||
|
{
|
||||||
|
char dir[MAX_FILENAME_LENGTH];
|
||||||
|
int i, rootPath;
|
||||||
|
|
||||||
|
strcpy(dir, "");
|
||||||
|
|
||||||
|
rootPath = 1;
|
||||||
|
|
||||||
|
for (i = 0 ; i < strlen(path) ; i++)
|
||||||
|
{
|
||||||
|
if (path[i] == '\\' || i == strlen(path) - 1)
|
||||||
|
{
|
||||||
|
if (!rootPath)
|
||||||
|
{
|
||||||
|
if (mkdir(dir) != 0 && errno != EEXIST)
|
||||||
|
{
|
||||||
|
SDL_LogMessage(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_ERROR, "Failed to create save dir '%s'.", dir);
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
rootPath = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
dir[i] = path[i];
|
||||||
|
dir[i + 1] = '\0';
|
||||||
|
}
|
||||||
|
|
||||||
|
if (mkdir(dir) != 0 && errno != EEXIST)
|
||||||
|
{
|
||||||
|
SDL_LogMessage(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_ERROR, "Failed to create save dir '%s'.", dir);
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void createScreenshotFolder(void)
|
void createScreenshotFolder(void)
|
||||||
{
|
{
|
||||||
dev.screenshotFolder = "./";
|
dev.screenshotFolder = "./";
|
||||||
|
|
Loading…
Reference in New Issue