From 657f59f84e0210062c651910d3fed2879437bdd4 Mon Sep 17 00:00:00 2001 From: Chris Taylor Date: Sun, 5 Mar 2006 11:10:46 +0000 Subject: [PATCH] create write directory if it doesn't exist (didn't work before) --- ChangeLog | 5 +++++ main/inferno.c | 31 ++++++++++++++++++++++++++----- 2 files changed, 31 insertions(+), 5 deletions(-) diff --git a/ChangeLog b/ChangeLog index 4875e187..5182c4c9 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2006-03-05 Chris Taylor + + * main/inferno.c: create write directory if it doesn't exist + (didn't work before) + 2006-02-26 Chris Taylor * include/strutil.h, main/bm.c, main/gamepal.c, main/gamesave.c, diff --git a/main/inferno.c b/main/inferno.c index 615fbbe0..5f6a0077 100644 --- a/main/inferno.c +++ b/main/inferno.c @@ -1,4 +1,4 @@ -/* $Id: inferno.c,v 1.105 2005-08-06 13:50:13 chris Exp $ */ +/* $Id: inferno.c,v 1.106 2006-03-05 11:10:27 chris Exp $ */ /* THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX SOFTWARE CORPORATION ("PARALLAX"). PARALLAX, IN DISTRIBUTING THE CODE TO @@ -512,12 +512,33 @@ int main(int argc, char *argv[]) strncpy(fullPath, path, PATH_MAX + 5); PHYSFS_setWriteDir(fullPath); - if (!PHYSFS_getWriteDir()) // need to make it - { - PHYSFS_mkdir(fullPath); + if (!PHYSFS_getWriteDir()) + { // need to make it + char *p; + char ancestor[PATH_MAX + 5]; // the directory which actually exists + char child[PATH_MAX + 5]; // the directory relative to the above we're trying to make + + strcpy(ancestor, fullPath); + while (!PHYSFS_getWriteDir() && ((p = strrchr(ancestor, *PHYSFS_getDirSeparator())))) + { + if (p[1] == 0) + { // separator at the end (intended here, for safety) + *p = 0; // kill this separator + if (!((p = strrchr(ancestor, *PHYSFS_getDirSeparator())))) + break; // give up, this is (usually) the root directory + } + + p[1] = 0; // go to parent + PHYSFS_setWriteDir(ancestor); + } + + strcpy(child, fullPath + strlen(ancestor)); + for (p = child; (p = strchr(p, *PHYSFS_getDirSeparator())); p++) + *p = '/'; + PHYSFS_mkdir(child); PHYSFS_setWriteDir(fullPath); } - + PHYSFS_addToSearchPath(PHYSFS_getWriteDir(), 1); AppendArgs(); } -- 2.39.2