summaryrefslogtreecommitdiff
path: root/src/strife/m_saves.c
diff options
context:
space:
mode:
authorJames Haley2011-02-11 03:02:45 +0000
committerJames Haley2011-02-11 03:02:45 +0000
commit9c4484196a6a5daa1b8c7426a67f6158659027c3 (patch)
tree5583b41bbc117224decf81d3936f63d144b495b6 /src/strife/m_saves.c
parent0e7e7ba3b64e6bccfcca85d4120f2f60f1fe05c3 (diff)
downloadchocolate-doom-9c4484196a6a5daa1b8c7426a67f6158659027c3.tar.gz
chocolate-doom-9c4484196a6a5daa1b8c7426a67f6158659027c3.tar.bz2
chocolate-doom-9c4484196a6a5daa1b8c7426a67f6158659027c3.zip
Finished routines in m_saves.c. Added M_CreateSaveDirs to make
directories under the standard choco savegamedir for each Strife saveslot. Subversion-branch: /branches/strife-branch Subversion-revision: 2253
Diffstat (limited to 'src/strife/m_saves.c')
-rw-r--r--src/strife/m_saves.c98
1 files changed, 89 insertions, 9 deletions
diff --git a/src/strife/m_saves.c b/src/strife/m_saves.c
index 6b99a7a8..a49302c8 100644
--- a/src/strife/m_saves.c
+++ b/src/strife/m_saves.c
@@ -2,7 +2,6 @@
//-----------------------------------------------------------------------------
//
// Copyright(C) 1993-1996 Id Software, Inc.
-// Copyright(C) 1996 Rogue Entertainment / Velocity, Inc.
// Copyright(C) 2010 James Haley, Samuel Villareal
//
// This program is free software; you can redistribute it and/or
@@ -55,9 +54,9 @@
//
// Strife maintains multiple file paths related to savegames.
//
-char *savepath;
-char *savepath2;
-char *loadpath;
+char *savepath; // The actual path of the saveslot?
+char *savepath2; // The path of the temporary saveslot?
+char *loadpath; // Path used while loading the game
//
// ClearTmp
@@ -101,10 +100,30 @@ void ClearTmp(void)
//
void ClearSlot(void)
{
+ DIR *spdir = NULL;
+ struct dirent *f = NULL;
+
if(savepath == NULL)
I_Error("userdir is fucked up man!");
- // STRIFE-TODO
+ if(!(spdir = opendir(savepath)))
+ I_Error("ClearSlot: Couldn't open dir %s", savepath);
+
+ while((f = readdir(spdir)))
+ {
+ char *filepath = NULL;
+
+ if(!strcmp(f->d_name, ".") || !strcmp(f->d_name, ".."))
+ continue;
+
+ // haleyjd: use M_SafeFilePath, not sprintf
+ filepath = M_SafeFilePath(savepath, f->d_name);
+ remove(filepath);
+
+ Z_Free(filepath);
+ }
+
+ closedir(spdir);
}
//
@@ -148,13 +167,45 @@ void FromCurr(void)
}
//
-// ?????
+// ToCurr
//
-// More file moving; don't even know what to call it yet.
+// Copying files from savepath to savepath2
//
-void sub_1B2F4(void)
+void ToCurr(void)
{
- // STRIFE-TODO
+ DIR *spdir = NULL;
+ struct dirent *f = NULL;
+
+ ClearTmp();
+
+ // BUG: Rogue copypasta'd this error message, which is why we don't know
+ // the real original name of this function.
+ if(!(spdir = opendir(savepath)))
+ I_Error("ClearSlot: Couldn't open dir %s", savepath);
+
+ while((f = readdir(spdir)))
+ {
+ byte *filebuffer = NULL;
+ int filelen = 0;
+ char *srcfilename = NULL;
+ char *dstfilename = NULL;
+
+ if(!strcmp(f->d_name, ".") || !strcmp(f->d_name, ".."))
+ continue;
+
+ // haleyjd: use M_SafeFilePath, NOT sprintf.
+ srcfilename = M_SafeFilePath(savepath, f->d_name);
+ dstfilename = M_SafeFilePath(savepath2, f->d_name);
+
+ filelen = M_ReadFile(srcfilename, &filebuffer);
+ M_WriteFile(dstfilename, filebuffer, filelen);
+
+ Z_Free(filebuffer);
+ Z_Free(srcfilename);
+ Z_Free(dstfilename);
+ }
+
+ closedir(spdir);
}
//
@@ -387,6 +438,35 @@ char *M_SafeFilePath(const char *basepath, const char *newcomponent)
return newstr;
}
+//
+// M_CreateSaveDirs
+//
+// haleyjd 20110210: Vanilla Strife went tits-up if it didn't have the full set
+// of save folders which were created externally by the installer. fraggle says
+// that's no good for Choco purposes, and I agree, so this routine will create
+// the full set of folders under the configured savegamedir.
+//
+void M_CreateSaveDirs(const char *savedir)
+{
+ int i;
+
+ for(i = 0; i < 7; i++)
+ {
+ char dirname[16];
+ char *compositedir;
+
+ memset(dirname, 0, sizeof(dirname));
+ sprintf(dirname, "STRFSAV%d.SSG", i);
+
+ // compose the full path by concatenating with savedir
+ compositedir = M_SafeFilePath(savedir, dirname);
+
+ M_MakeDirectory(compositedir);
+
+ Z_Free(compositedir);
+ }
+}
+
//
// M_GetFilePath
//