reman3/Rayman_X/cpa/tempgrp/GAM/TTrouble/P5/GamSave.c

830 lines
26 KiB
C
Raw Blame History

/*=========================================================================
* GamSave.c : Game save
* This is a part of the Game project.
*
* Version 1.0
* Creation date 03/07/97
* Revision date
*
* That file needs to be compatible for all platforms.
*
* (c) Ubi Studios 1997
*=======================================================================*/
#define SCR_DM_OptCFiles
#define D_FIL_StructureDefine
#include "ToolsCPA.h"
#include "Options/Options.h"
#include "Macros.h"
#include "Actions/AllActs.h"
#include "Structur/3DOSLktb.h"
#include "Structur/EngMode.h"
#include "Structur/StdObjSt.h"
#include "Structur/Objects.h"
#include "Structur/GameScpt.h"
#include "Structur/ErrGame.h"
#include "Structur/MemGame.h"
#include "gamopt.h"
#include "PlayAnim/PlayAnim.h"
#include "Always.h"
#include "Basic.h"
#include "DspFix.h"
#include "GameEng.h"
#include "GamSave.h"
#include "LoadLvl.h"
#include "ObjInit.h"
#include "ObjType.h"
#include "Zemem.h"
#include "CMP.h"
extern unsigned char FIL_fn_bIsValidPath(char *_szFileName);
const char *g_c_szSlotNames[] = /*extern declared in GamSave.h*/
{
"HiddenSlot",
"Slot1",
"Slot2",
"Slot3"
};
#ifndef U64
/************ FabPerez ***************/
#include <time.h>
#define _MAX_PATH_DIR 128
unsigned char g_ucNbSaveGameSlots = 0;
BOOL g_bIsGameAlreadyExist = FALSE;
//extern StructRecupPosSlot * g_p_LastStructRecupPosSlot;
StructRecupPosSlot * g_p_LastStructRecupPosSlot = NULL;
char g_a_szSlotNames[4] = "\\";
char * fn_bGetStringSlotDate(unsigned long _ulSlotId);
ACP_tdxBool fn_bActualizeSlotList( char *szDstPath, unsigned long _ulSlotId);
ACP_tdxBool fn_bActualizeSlotPos(void);
ACP_tdxBool fn_bCreateSlotDir( char *szDstPath, unsigned long _ulSlotId);
int fn_iCompareSlotDate(unsigned char * CurrentSlotDir, unsigned char * NextSlotDir);
BOOL fn_bGetSlotDate( unsigned char * SlotDate, unsigned long _ulSlotId);
extern int fn_iVersionN64_PC(void);
extern long fn_bRecupSlotNum(long lSlotPosId);
/*************** EndFabPerez **************/
#endif
unsigned char GAM_g_ucSaveGameBeforeChangeLevel = 1;
/**************************************************************************/
unsigned char fn_bPlayerSaveGameAll(void)
{
unsigned char bReturn = TRUE;
char szFileNameGeneral[_MAX_PATH]/*,szFileNameLevel[_MAX_PATH]*/;
sprintf(szFileNameGeneral,"%s\\%s\\General.sav",fn_szGetSaveGameDataPath(),g_c_szSlotNames[0]); /* save in hidden slot*/
bReturn = fn_bPlayerSaveGameGeneral(szFileNameGeneral);
return(bReturn);
}
/**************************************************************************/
unsigned char fn_bLevelSaveGameAll(void)
{
unsigned char bReturn = TRUE;
char szFileName[_MAX_PATH];
sprintf(szFileName,"%s\\%s\\%s_%d.sav",fn_szGetSaveGameDataPath(),g_c_szSlotNames[0],fn_p_szGetLevelName(), GAM_M_GetSubMap(fn_lGetSubMapNumber()));
bReturn = fn_bLevelSaveGameItSelf(szFileName);
return(bReturn);
}
/**************************************************************************/
unsigned char fn_bPlayerSaveGameGeneral(char *_szFileName)
{
return(SAI_fn_ucPlayerSaveValues(_szFileName));
}
/**************************************************************************/
unsigned char fn_bLevelSaveGameItSelf(char *_szFileName)
{
return(SAI_fn_ucLevelSaveValues(_szFileName));
}
/**************************************************************************/
unsigned char fn_bLoadPlayerSaveGameAfterLoadLevel(void)
{
unsigned char bReturn = FALSE;
char szFileName[_MAX_PATH];
sprintf(szFileName,"%s\\%s\\General.sav",fn_szGetSaveGameDataPath(),g_c_szSlotNames[0]); /* save in hidden slot*/
if (SCR_fn_c_RdL0_IsSectionExists(szFileName))
{
/*SAI_fn_ucLoadValues(szFileName);*/
SAI_fn_ucLoadPlayerValues( szFileName );
/* fn_vGameTestMemory();*/
bReturn = TRUE;
}
return(bReturn);
}
/**************************************************************************/
unsigned char fn_bLoadLevelSaveGameAfterLoadLevel(void)
{
unsigned char bReturn = FALSE;
char szFileName[_MAX_PATH];
sprintf(szFileName,"%s\\%s\\%s_%d.sav",fn_szGetSaveGameDataPath(),g_c_szSlotNames[0],fn_p_szGetLevelName(), GAM_M_GetSubMap(fn_lGetSubMapNumber()));
if (SCR_fn_c_RdL0_IsSectionExists(szFileName))
{
/*SAI_fn_ucLoadValues(szFileName);*/
SAI_fn_ucLoadLevelValues( szFileName );
/* fn_vGameTestMemory();*/
bReturn = TRUE;
}
return(bReturn);
}
/**************************************************************************/
ACP_tdxBool fn_bRenameSaveGameSlot(char *_szOldName, char *_szNewName)
{
ACP_tdxBool bReturn = FALSE;
char szOldFileName[_MAX_PATH], szNewFileName[_MAX_PATH];
sprintf(szOldFileName,"%s\\%s",fn_szGetSaveGameDataPath(), _szOldName);
if ( FIL_fn_bIsValidPath(szOldFileName) )
{
sprintf(szNewFileName,"%s\\%s",fn_szGetSaveGameDataPath(), _szNewName);
bReturn = (unsigned char)MoveFile(szOldFileName, szNewFileName);
}
return bReturn;
}
/**************************************************************************/
unsigned char fn_bDestroySavedGame(unsigned long _ulSlotId)
{
unsigned char bReturn = FALSE;
char szFileName[_MAX_PATH];
int Version;
#ifdef U64
if ( !((_ulSlotId >= 1) && (_ulSlotId <= C_ucNbSaveGameSlots)) ) return bReturn;
sprintf(szFileName,"%s\\%s",fn_szGetSaveGameDataPath(),g_c_szSlotNames[_ulSlotId]);
#else // PC
#ifdef ACTIVE_EDITOR
Version = fn_iVersionN64_PC();
if ( Version == 1 /* U64 */)
{
if ( !((_ulSlotId >= 1) && (_ulSlotId <= C_ucNbSaveGameSlots)) ) return bReturn;
sprintf(szFileName,"%s\\%s",fn_szGetSaveGameDataPath(),g_c_szSlotNames[_ulSlotId]);
}
else if( Version == 2 /* PC */)
{
if( _ulSlotId == 0) sprintf(szFileName,"%s\\%s",fn_szGetSaveGameDataPath(),g_c_szSlotNames[_ulSlotId]);
else
{
if ( !((_ulSlotId >= 1) && (_ulSlotId <= g_ucNbSaveGameSlots)) ) return bReturn;;
if( !fn_bCreateSlotDir(szFileName, _ulSlotId) ) return FALSE; // Fct PC
}
}
#else // PC sans editeur
if( _ulSlotId == 0) sprintf(szFileName,"%s\\%s",fn_szGetSaveGameDataPath(),g_c_szSlotNames[_ulSlotId]);
else
{
if ( !((_ulSlotId >= 1) && (_ulSlotId <= g_ucNbSaveGameSlots)) ) return bReturn;;
if( !fn_bCreateSlotDir(szFileName, _ulSlotId) ) return FALSE; // Fct PC
}
#endif // EDITOR
#endif // U64
bReturn = FIL_fn_bDestroyFileOrDirectory(szFileName);
return(bReturn);
}
/**************************************************************************/
/*
----------------------------------------------------------------------------------------
Description : copy directory
Returns (BOOL ) true if success
----------------------------------------------------------------------------------------
*/
BOOL fn_bCopyDirectory(char * _szSrcDir, char * _szDestDir)
{
WIN32_FIND_DATA stFindData;
HANDLE hFind;
char szSrcDir[255];
char szDestDir[255];
char *p_szEndSource;
char *p_szEndTarget;
strcpy(szSrcDir,_szSrcDir);
strcpy(szDestDir,_szDestDir);
p_szEndSource = szSrcDir + strlen( szSrcDir );
p_szEndTarget = szDestDir + strlen( szDestDir );
strcpy( p_szEndSource, "\\*.*" );
if( (hFind = FindFirstFile(szSrcDir, &stFindData )) == INVALID_HANDLE_VALUE)
return FALSE;
do
{
*p_szEndTarget = *p_szEndSource = '\\';
if ( !(stFindData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) )
{
strcpy( p_szEndSource + 1, stFindData.cFileName );
strcpy( p_szEndTarget + 1, stFindData.cFileName );
if ( !CopyFile( szSrcDir, szDestDir, FALSE ) )
return FALSE;
}
*p_szEndSource = *p_szEndTarget = 0;
} while(FindNextFile( hFind, &stFindData ));
FindClose( hFind );
return TRUE;
}
/**************************************************************************/
/* Delete all files and sub dirs in a directory but not the dir itself (recursive).*/
/* Return TRUE on success or FALSE on error.*/
BOOL fn_bDeleteDirectoryContent( char * _szDir )
{
WIN32_FIND_DATA stFindData;
HANDLE hFind;
char szDir[255];
char *p_szEndString;
strcpy(szDir,_szDir);
p_szEndString = szDir + strlen( szDir );
if( *(p_szEndString-1) == '\\' )
*(p_szEndString-1) = 0;
strcpy( p_szEndString, "\\*.*" );
if( (hFind = FindFirstFile(szDir, &stFindData )) == INVALID_HANDLE_VALUE)
/* Dir does not exist or is empty, return TRUE.*/
return TRUE;
do
{
if ( !(stFindData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) )
{
strcpy( p_szEndString + 1, stFindData.cFileName );
if ( !DeleteFile( szDir ) )
/* Error deleting file, return FALSE*/
return FALSE;
}
else
if( strcmp(stFindData.cFileName,".") && strcmp(stFindData.cFileName,"..") )
{
strcpy( p_szEndString + 1, stFindData.cFileName );
if( !fn_bDeleteDirectoryContent( szDir ) )
/* Error deleting files in subdir, return FALSE*/
return FALSE;
RemoveDirectory( szDir );
}
} while(FindNextFile( hFind, &stFindData ));
FindClose( hFind );
return TRUE;
}
BOOL fn_bDeleteDirectory( char * _szDir )
{
WIN32_FIND_DATA stFindData;
HANDLE hFind;
char szDir[255];
char *p_szEndString;
strcpy(szDir,_szDir);
/*
p_szEndString = szDir + strlen( szDir );
if( *(p_szEndString-1) == '\\' )
*(p_szEndString-1) = 0;
strcpy( p_szEndString, "\\*.*" );
*/
if( (hFind = FindFirstFile(szDir, &stFindData )) == INVALID_HANDLE_VALUE)
// Dir does not exist or is empty, return TRUE.
return TRUE;
if ( !(stFindData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) )
{
strcpy( p_szEndString + 1, stFindData.cFileName );
if ( !DeleteFile( szDir ) )
/* Error deleting file, return FALSE*/
return FALSE;
}
FindClose( hFind );
return TRUE;
}
/**************************************************************************/
ACP_tdxBool fn_bSaveGameInSlot(unsigned long _ulSlotId)
{
unsigned char bReturn = FALSE;
char szSrcPath[_MAX_PATH], szDstPath[_MAX_PATH];
int Version;
#ifndef U64
StructRecupPosSlot *p_CurrentStructRecupPosSlot;
int iNum = 1;
#endif // U64
/* if the slot name is valid*/
#ifdef U64
if ( !( ((_ulSlotId >= 1) && (_ulSlotId <= C_ucNbSaveGameSlots)) && GAM_fn_bIsSlotNameValid(g_c_szSlotNames[_ulSlotId]) ) ) return bReturn;
#else // PC
#ifdef ACTIVE_EDITOR
Version = fn_iVersionN64_PC();
if( Version == 1 /* N64 */)
{
if ( !( ((_ulSlotId >= 1) && (_ulSlotId <= C_ucNbSaveGameSlots)) && GAM_fn_bIsSlotNameValid(g_c_szSlotNames[_ulSlotId]) ) ) return bReturn;
}
else if( Version == 2 /* PC */)
{
//if( _ulSlotId > g_ucNbSaveGameSlots ) _ulSlotId = g_ucNbSaveGameSlots;
if ( !((_ulSlotId >= 1) && (_ulSlotId <= g_ucNbSaveGameSlots)) ) return bReturn;
}
#else // PC sans editeur
//if( _ulSlotId > g_ucNbSaveGameSlots ) _ulSlotId = g_ucNbSaveGameSlots;
if ( !((_ulSlotId >= 1) && (_ulSlotId <= g_ucNbSaveGameSlots)) ) return bReturn;
#endif // EDITOR
#endif // U64
sprintf(szSrcPath,"%s\\%s",fn_szGetSaveGameDataPath(),g_c_szSlotNames[0]);
/*make sure the source (the hidden slot) exists*/
if ( FIL_fn_bIsValidPath(szSrcPath) )
{
#ifndef U64
#ifdef ACTIVE_EDITOR
Version = fn_iVersionN64_PC();
if( Version == 1 /* N64 */)
{
sprintf(szDstPath,"%s\\%s",fn_szGetSaveGameDataPath(),g_c_szSlotNames[_ulSlotId]);
}
else if( Version == 2 /* PC */)
{
p_CurrentStructRecupPosSlot = g_p_LastStructRecupPosSlot;
while( iNum != _ulSlotId && g_bIsGameAlreadyExist)
{
p_CurrentStructRecupPosSlot = p_CurrentStructRecupPosSlot->pt_NextStructRecupPosSlot;
iNum++;
}
_ulSlotId = p_CurrentStructRecupPosSlot->pos;
if( !fn_bCreateSlotDir(szDstPath, _ulSlotId) ) return FALSE; // Fct PC
}
#else // PC sans editeur
p_CurrentStructRecupPosSlot = g_p_LastStructRecupPosSlot;
while( iNum != _ulSlotId && g_bIsGameAlreadyExist)
{
p_CurrentStructRecupPosSlot = p_CurrentStructRecupPosSlot->pt_NextStructRecupPosSlot;
iNum++;
}
_ulSlotId = p_CurrentStructRecupPosSlot->pos;
if( !fn_bCreateSlotDir(szDstPath, _ulSlotId) ) return FALSE; // Fct PC
#endif // EDITOR
#else // N64
sprintf(szDstPath,"%s\\%s",fn_szGetSaveGameDataPath(),g_c_szSlotNames[_ulSlotId]);
#endif // U64
/*make sure the destination is cleaned*/
/* if ( FIL_fn_bDestroyFileOrDirectory(szDstPath) )*/
if ( fn_bDeleteDirectoryContent(szDstPath) )
{
/* create the path to the destination if */
FIL_fn_bValidatePath(szDstPath, "");
/* now copy the contents of the source in the destination, replacing existing files*/
bReturn = fn_bCopyDirectory(szSrcPath, szDstPath);
#ifndef U64
#ifdef ACTIVE_EDITOR
Version = fn_iVersionN64_PC();
if( Version == 2 /* PC */) bReturn = fn_bActualizeSlotList(szDstPath, _ulSlotId);
#else // PC sans editeur
bReturn = fn_bActualizeSlotList(szDstPath, _ulSlotId);
#endif // EDITOR
#endif N64
}
#ifndef U64
#ifdef ACTIVE_EDITOR
Version = fn_iVersionN64_PC();
if( Version == 2 /* PC */) fn_bSaveCurrentGameOptions();
#else // PC sans editeur
fn_bSaveCurrentGameOptions();
#endif // EDITOR
#endif // U64
}
return(bReturn);
}
/********************************** FabPerez *********************************/
ACP_tdxBool fn_bCreateSlotDir(char *szDstPath, unsigned long _ulSlotId)
{
unsigned char a_cSlotNameDir[_MAX_PATH_DIR] ;
sprintf(a_cSlotNameDir,"%s\\%s%i", fn_szGetSaveGameDataPath(), "Slot", _ulSlotId);
if( strlen(a_cSlotNameDir) > _MAX_PATH_DIR) return FALSE;
else strcpy(szDstPath, a_cSlotNameDir);
return TRUE;
}
ACP_tdxBool fn_bActualizeSlotList( char *szDstPath, unsigned long _ulSlotId)
{
unsigned char a_cSlotNameDir[_MAX_PATH_DIR] ;
unsigned char a_cSlotNameNb[5] = "Slot";
struct StructRecupPosSlot *p_StructRecupPosSlot;
//SAF_M_AssertWithMsg((_ulSlotId >= 1 && _ulSlotId <= g_ucNbSaveGameSlots ),"Slot inexistant");
if( _ulSlotId >=1 && _ulSlotId <= g_ucNbSaveGameSlots) // Slot existe deja
{
fn_bActualizeSlotPos();
}
else // Nouveau Slot
{
if(g_p_LastStructRecupPosSlot != NULL)
{
p_StructRecupPosSlot = g_p_LastStructRecupPosSlot;
g_p_LastStructRecupPosSlot = TMP_M_p_Malloc( sizeof(StructRecupPosSlot) );
g_p_LastStructRecupPosSlot->pt_NextStructRecupPosSlot = p_StructRecupPosSlot;
g_p_LastStructRecupPosSlot->pos = ++g_ucNbSaveGameSlots;
}
}
strncpy( g_p_LastStructRecupPosSlot->a_szSlotNames, g_a_szSlotNames, 3);
strcpy( g_p_LastStructRecupPosSlot->a_szOldSlotNames, "\\");
return TRUE;
}
ACP_tdxBool fn_bActualizeSlotPos(void)
{
int i, j;
BOOL INVERT;
StructRecupPosSlot * p_CurrentStructRecupPosSlot;
StructRecupPosSlot * p_NextStructRecupPosSlot;
unsigned char a128_cCurrentSlotDir[128];
unsigned char a128_cNextSlotDir[128];
char a_c4TmpName[C_ucSaveGameSlotNameLength + 1];
char a_c4TmpOldName[C_ucSaveGameSlotNameLength + 1];
long TmpPos;
i = 0;
INVERT =TRUE;
while( i < g_ucNbSaveGameSlots && INVERT )
{
INVERT = FALSE;
for( j = g_ucNbSaveGameSlots-1 ; j > i ; j--)
{
if( j == g_ucNbSaveGameSlots-1) // Debut en haut de pile
{
p_CurrentStructRecupPosSlot= g_p_LastStructRecupPosSlot->pt_NextStructRecupPosSlot;
p_NextStructRecupPosSlot = g_p_LastStructRecupPosSlot;
}
else // Suite de la liste
{
p_NextStructRecupPosSlot = p_CurrentStructRecupPosSlot;
p_CurrentStructRecupPosSlot = p_NextStructRecupPosSlot->pt_NextStructRecupPosSlot;
}
sprintf( a128_cCurrentSlotDir, "%s\\%s%i", fn_szGetSaveGameDataPath(),"Slot", p_CurrentStructRecupPosSlot->pos);
sprintf( a128_cNextSlotDir, "%s\\%s%i", fn_szGetSaveGameDataPath(),"Slot", p_NextStructRecupPosSlot->pos);
if( fn_iCompareSlotDate(a128_cCurrentSlotDir, a128_cNextSlotDir) )
{
INVERT =TRUE;
TmpPos = p_CurrentStructRecupPosSlot->pos;
strcpy( a_c4TmpName, p_CurrentStructRecupPosSlot->a_szSlotNames);
strcpy( a_c4TmpOldName, p_CurrentStructRecupPosSlot->a_szOldSlotNames);
p_CurrentStructRecupPosSlot->pos = p_NextStructRecupPosSlot->pos;
strcpy(p_CurrentStructRecupPosSlot->a_szSlotNames, p_NextStructRecupPosSlot->a_szSlotNames);
p_NextStructRecupPosSlot->pos = TmpPos;
strcpy( p_NextStructRecupPosSlot->a_szSlotNames, a_c4TmpName);
strcpy( p_NextStructRecupPosSlot->a_szOldSlotNames, a_c4TmpOldName);
} // If
} // For
i++;
} // While
return 1;
}
int fn_iCompareSlotDate(unsigned char * CurrentSlotDir, unsigned char * NextSlotDir)
{
struct _finddata_t c_file_currentslot, c_file_nextslot;
long hFileCurrentSlot, hFileNextSlot;
unsigned char a128_cTextTmp[128];
double fDiffSeconde;
if( (hFileCurrentSlot = _findfirst( CurrentSlotDir, &c_file_currentslot)) == -1L)
{
sprintf(a128_cTextTmp, "Erreur : impossible de lire la date de creation du repertoire : %s", CurrentSlotDir);
if(MessageBox(NULL, a128_cTextTmp, NULL, MB_RETRYCANCEL) != IDRETRY) return -1;
else fn_iCompareSlotDate(CurrentSlotDir, NextSlotDir);
}
else
{
if( (c_file_currentslot.attrib & _A_RDONLY) == _A_RDONLY) _chmod( CurrentSlotDir, _S_IREAD | _S_IWRITE );
if( (hFileNextSlot = _findfirst( NextSlotDir, &c_file_nextslot)) == -1L)
{
sprintf(a128_cTextTmp, "Erreur : impossible de lire la date de creation du repertoire : %s", NextSlotDir);
if(MessageBox(NULL, a128_cTextTmp, NULL, MB_RETRYCANCEL) != IDRETRY) return -1;
else fn_iCompareSlotDate(CurrentSlotDir, NextSlotDir);
}
else
{
fDiffSeconde = difftime( c_file_currentslot.time_write, c_file_nextslot.time_write);
if( fDiffSeconde <= 0) return 0;
}
}
_findclose( hFileCurrentSlot );
_findclose( hFileNextSlot );
return 1;
}
BOOL fn_bGetSlotDate( unsigned char * SlotDate, unsigned long _ulSlotId)
{
struct _finddata_t c_file_slot;
struct tm *Date;
long hFileSlot;
unsigned char a128_cSlotDir[128];
unsigned char a128_cTextTmp[128];
BOOL bReturn = TRUE;
if( !fn_bCreateSlotDir( a128_cSlotDir, _ulSlotId) ) return FALSE;
sprintf(a128_cSlotDir, "%s\\%s", a128_cSlotDir, "general.sav");
if( (hFileSlot = _findfirst( a128_cSlotDir, &c_file_slot)) == -1L)
{
sprintf(a128_cTextTmp, "Erreur : impossible de lire la date de creation du repertoire : %s", a128_cSlotDir);
if(MessageBox(NULL, a128_cTextTmp, NULL, MB_RETRYCANCEL) != IDRETRY) return FALSE;
else fn_bGetSlotDate(a128_cSlotDir, _ulSlotId);
}
else
{
if( (c_file_slot.attrib & _A_RDONLY) == _A_RDONLY) _chmod( a128_cSlotDir, _S_IREAD | _S_IWRITE );
Date = localtime( &c_file_slot.time_write );
sprintf(SlotDate, "%i/%i %i:%i", Date->tm_mday, Date->tm_mon, Date->tm_hour, Date->tm_min);
}
_findclose( hFileSlot );
return(bReturn);
}
char * fn_bGetStringSlotDate(unsigned long _ulSlotId)
{
struct _finddata_t c_file_slot;
struct tm *Date;
long hFileSlot;
unsigned char a128_cSlotDir[128];
unsigned char a128_cTextTmp[128];
char * tmp = NULL;
if( !fn_bCreateSlotDir( a128_cSlotDir, _ulSlotId) ) return tmp;
sprintf(a128_cSlotDir, "%s\\%s", a128_cSlotDir, "general.sav");
if( (hFileSlot = _findfirst( a128_cSlotDir, &c_file_slot)) == -1L)
{
sprintf(a128_cTextTmp, "Erreur : impossible de lire la date de creation du repertoire : %s", a128_cSlotDir);
if(MessageBox(NULL, a128_cTextTmp, NULL, MB_RETRYCANCEL) != IDRETRY) return tmp;
else fn_bGetSlotDate(a128_cSlotDir, _ulSlotId);
}
else
{
if( (c_file_slot.attrib & _A_RDONLY) == _A_RDONLY) _chmod( a128_cSlotDir, _S_IREAD | _S_IWRITE );
Date = localtime( &c_file_slot.time_write );
sprintf(a128_cSlotDir, "%i.%i %i.%i", Date->tm_mday, Date->tm_mon+1, Date->tm_hour, Date->tm_min);
}
_findclose( hFileSlot );
return(tmp = a128_cSlotDir);
}
/******************************* Fin FabPerez *********************************/
/**************************************************************************/
ACP_tdxBool fn_bIsSlotOccupied(unsigned long _ulSlotId)
{
unsigned char bReturn = FALSE;
char szSrcPath[_MAX_PATH];
int Version;
/* Also test for slot 0 (AI can delete hidden slot) */
#ifdef U64
if ( !((_ulSlotId >= 1) && (_ulSlotId <= C_ucNbSaveGameSlots)) ) return bReturn;
sprintf(szSrcPath,"%s\\%s",fn_szGetSaveGameDataPath(),g_c_szSlotNames[_ulSlotId]);
#else // PC
#ifdef ACTIVE_EDITOR
Version = fn_iVersionN64_PC();
if( Version == 1 /* N64 */)
{
if ( !((_ulSlotId >= 1) && (_ulSlotId <= C_ucNbSaveGameSlots)) ) return bReturn;
sprintf(szSrcPath,"%s\\%s",fn_szGetSaveGameDataPath(),g_c_szSlotNames[_ulSlotId]);
}
else if( Version == 2 /* PC */)
{
if ( !((_ulSlotId >= 1) && (_ulSlotId <= g_ucNbSaveGameSlots)) ) return bReturn;
sprintf(szSrcPath,"%s\\Slot%i",fn_szGetSaveGameDataPath(), fn_bRecupSlotNum(_ulSlotId) );
}
#else // PC sans editeur
if ( !((_ulSlotId >= 1) && (_ulSlotId <= g_ucNbSaveGameSlots)) ) return bReturn;
sprintf(szSrcPath,"%s\\Slot%i",fn_szGetSaveGameDataPath(), fn_bRecupSlotNum(_ulSlotId) );
#endif // EDITOR
#endif // U64
bReturn = (unsigned char) FIL_fn_bIsValidPath(szSrcPath);
return bReturn;
}
/**************************************************************************/
/* move the contents of a registered slot to the hidden slot (where the data will be read when the engine initializes)*/
ACP_tdxBool fn_bLoadGameFromSlot(unsigned long _ulSlotId)
{
unsigned char bReturn = FALSE;
int Version;
if ( fn_bIsSlotOccupied (_ulSlotId) )
{
char szSrcPath[_MAX_PATH], szDstPath[_MAX_PATH];
#ifdef U64
sprintf(szSrcPath,"%s\\%s",fn_szGetSaveGameDataPath(),g_c_szSlotNames[_ulSlotId]);
#else // PC
#ifdef ACTIVE_EDITOR
Version = fn_iVersionN64_PC();
if ( Version == 1 /* U64 */)
{
sprintf(szSrcPath,"%s\\%s",fn_szGetSaveGameDataPath(),g_c_szSlotNames[_ulSlotId]);
}
else if( Version == 2 /* PC */)
{
sprintf(szSrcPath,"%s\\Slot%i",fn_szGetSaveGameDataPath(), fn_bRecupSlotNum( _ulSlotId) );
}
#else // PC sans editeur
sprintf(szSrcPath,"%s\\Slot%i",fn_szGetSaveGameDataPath(), fn_bRecupSlotNum( _ulSlotId) );
#endif // EDITOR
#endif // U64
/*make sure the source exists*/
sprintf(szDstPath,"%s\\%s",fn_szGetSaveGameDataPath(),g_c_szSlotNames[0]);
/*make sure the destination is cleaned*/
/* if ( FIL_fn_bDestroyFileOrDirectory(szDstPath) )*/
if ( fn_bDeleteDirectoryContent(szDstPath) )
{
/* create the path to the destination if necessary*/
FIL_fn_bValidatePath(szDstPath, "");
/* now copy the contents of the source in the destination, replacing existing files*/
bReturn = fn_bCopyDirectory(szSrcPath, szDstPath);
}
}
/* Next time we change level, don't save the current game.*/
GAM_g_ucSaveGameBeforeChangeLevel = 0;
return bReturn;
}
/**************************************************************************/
/*erase the contents of the specified slot*/
ACP_tdxBool fn_bEraseGameInSlot(unsigned long _ulSlotId)
{
unsigned char bReturn = TRUE; /*if the slot is already empty, the function is successful*/
int Version;
if ( fn_bIsSlotOccupied(_ulSlotId) )
{
char szPath[_MAX_PATH];
#ifdef U64
sprintf(szPath,"%s\\%s",fn_szGetSaveGameDataPath(),g_c_szSlotNames[_ulSlotId]);
bReturn = FIL_fn_bDestroyFileOrDirectory(szPath);
#else /* PC*/
#ifdef ACTIVE_EDITOR
Version = fn_iVersionN64_PC();
if ( Version == 1 /* U64 */)
{
sprintf(szPath,"%s\\%s",fn_szGetSaveGameDataPath(),g_c_szSlotNames[_ulSlotId]);
bReturn = FIL_fn_bDestroyFileOrDirectory(szPath);
}
else if( Version == 2 /* PC */)
{
char szSrcPath[_MAX_PATH], szDstPath[_MAX_PATH];
StructRecupPosSlot *p_CurrentStructRecupPosSlot;
sprintf(szSrcPath,"%s\\Slot%i",fn_szGetSaveGameDataPath(), g_ucNbSaveGameSlots );
if(g_ucNbSaveGameSlots != fn_bRecupSlotNum(_ulSlotId) )
{
sprintf(szDstPath,"%s\\Slot%i",fn_szGetSaveGameDataPath(), fn_bRecupSlotNum(_ulSlotId) );
if ( (bReturn = FIL_fn_bValidatePath(szDstPath, "")) != 0 )
{
bReturn = fn_bCopyDirectory(szSrcPath, szDstPath);
}
p_CurrentStructRecupPosSlot = g_p_LastStructRecupPosSlot;
while( p_CurrentStructRecupPosSlot->pt_NextStructRecupPosSlot != NULL && p_CurrentStructRecupPosSlot->pos != g_ucNbSaveGameSlots)
{
p_CurrentStructRecupPosSlot = p_CurrentStructRecupPosSlot->pt_NextStructRecupPosSlot;
}
p_CurrentStructRecupPosSlot->pos = fn_bRecupSlotNum(_ulSlotId);
}
bReturn = FIL_fn_bDestroyFileOrDirectory(szSrcPath);
}
#else // Pc sans editor
char szSrcPath[_MAX_PATH], szDstPath[_MAX_PATH];
StructRecupPosSlot *p_CurrentStructRecupPosSlot;
// Copie du repertoire du dernier slot de la list dans le repertoire du slot qui va etre effac<61>
// => pas de trou dans les repertoire rep 1, rep 2 et rep 4 impossible mais bien rep 1 2 et 3
//fn_bCopyGameInSlotFromSlot( fn_bRecupSlotNum(_ulSlotId), fn_bRecupSlotNum( g_ucNbSaveGameSlots));
sprintf(szSrcPath,"%s\\Slot%i",fn_szGetSaveGameDataPath(), g_ucNbSaveGameSlots );
if(g_ucNbSaveGameSlots != fn_bRecupSlotNum(_ulSlotId) )
{
sprintf(szDstPath,"%s\\Slot%i",fn_szGetSaveGameDataPath(), fn_bRecupSlotNum(_ulSlotId) );
// Verif et creation si necessaire de la destination
if ( (bReturn = FIL_fn_bValidatePath(szDstPath, "")) != 0 )
{
bReturn = fn_bCopyDirectory(szSrcPath, szDstPath);
}
// actualise le num du repertoire du dernier slot de la liste
p_CurrentStructRecupPosSlot = g_p_LastStructRecupPosSlot;
while( p_CurrentStructRecupPosSlot->pt_NextStructRecupPosSlot != NULL && p_CurrentStructRecupPosSlot->pos != g_ucNbSaveGameSlots)
{
p_CurrentStructRecupPosSlot = p_CurrentStructRecupPosSlot->pt_NextStructRecupPosSlot;
}
p_CurrentStructRecupPosSlot->pos = fn_bRecupSlotNum(_ulSlotId);
}
// efface le repertoire du dernier slot de la liste
bReturn = FIL_fn_bDestroyFileOrDirectory(szSrcPath);
#endif // EDITOR
#endif // U64
}
return bReturn;
}
/**************************************************************************/
/*duplicate the contents of the specified slots*/
ACP_tdxBool fn_bCopyGameInSlotFromSlot(unsigned long _ulDstSlotId, unsigned long _ulSrcSlotId)
{
unsigned char bReturn = FALSE;
if
(
fn_bIsSlotOccupied(_ulSrcSlotId) /*we must copy from a non-empty slot*/
&& fn_bEraseGameInSlot(_ulDstSlotId) /*in a cleaned slot*/
)
{
char szSrcPath[_MAX_PATH], szDstPath[_MAX_PATH];
sprintf(szSrcPath,"%s\\%s",fn_szGetSaveGameDataPath(),g_c_szSlotNames[_ulSrcSlotId]);
/*make sure the source exists*/
sprintf(szDstPath,"%s\\%s",fn_szGetSaveGameDataPath(),g_c_szSlotNames[_ulDstSlotId]);
/* create the path to the destination if necessary*/
if ( (bReturn = FIL_fn_bValidatePath(szDstPath, "")) != 0 )
{
/* now copy the contents of the source in the destination, replacing existing files*/
bReturn = fn_bCopyDirectory(szSrcPath, szDstPath);
}
}
return bReturn;
}