summaryrefslogtreecommitdiff
path: root/src
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
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')
-rw-r--r--src/strife/d_main.c1
-rw-r--r--src/strife/m_saves.c98
-rw-r--r--src/strife/m_saves.h14
3 files changed, 103 insertions, 10 deletions
diff --git a/src/strife/d_main.c b/src/strife/d_main.c
index 8ffcc2ad..2d9d14a0 100644
--- a/src/strife/d_main.c
+++ b/src/strife/d_main.c
@@ -933,6 +933,7 @@ static void SetSaveGameDir(char *iwad_filename)
M_MakeDirectory(savegamedir);
// haleyjd 20110210: Create Strife hub save folders
+ M_CreateSaveDirs(savegamedir);
}
// Check if the IWAD file is the Chex Quest IWAD.
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
//
diff --git a/src/strife/m_saves.h b/src/strife/m_saves.h
index b55ffa12..8942f237 100644
--- a/src/strife/m_saves.h
+++ b/src/strife/m_saves.h
@@ -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
@@ -31,8 +30,20 @@
#ifndef M_SAVES_H__
#define M_SAVES_H__
+extern char *savepath;
+extern char *savepath2;
+extern char *loadpath;
+
// Strife Savegame Functions
+void ClearTmp(void);
+void ClearSlot(void);
+void FromCurr(void);
+void ToCurr(void);
+void M_SaveMoveMapToHere(void);
+void M_SaveMoveHereToMap(void);
+
boolean M_SaveMisObj(const char *path);
+void M_ReadMisObj(void);
// Custom Utilities for Filepath Handling
void *M_Calloc(size_t n1, size_t n2);
@@ -40,6 +51,7 @@ void M_NormalizeSlashes(char *str);
int M_StringAlloc(char **str, int numstrs, size_t extra, const char *str1, ...);
char *M_SafeFilePath(const char *basepath, const char *newcomponent);
char M_GetFilePath(const char *fn, char *dest, size_t len);
+void M_CreateSaveDirs(const char *savedir);
#endif