improve ips and filename generation system

This commit is contained in:
zeromus 2008-08-12 05:31:06 +00:00
parent 17df29de0f
commit 89641c1b92
3 changed files with 52 additions and 43 deletions

View File

@ -336,7 +336,6 @@ FCEUGI *FCEUI_LoadGameVirtual(const char *name, int OverwriteVidMode)
//---------- //----------
//attempt to open the files //attempt to open the files
FCEUFILE *fp; FCEUFILE *fp;
char *ipsfn;
FCEU_printf("Loading %s...\n\n",name); FCEU_printf("Loading %s...\n\n",name);

View File

@ -175,51 +175,56 @@ FileBaseInfo CurrentFileBase() {
} }
FileBaseInfo DetermineFileBase(const char *f) { FileBaseInfo DetermineFileBase(const char *f) {
const char *tp1,*tp3; //const char *tp1,*tp3;
char FileBase[2048]; //char FileBase[2048];
char FileBaseDirectory[2048]; //char FileBaseDirectory[2048];
char FileExt[2048]; //char FileExt[2048];
#if PSS_STYLE==4 //#if PSS_STYLE==4
tp1=((char *)strrchr(f,':')); // tp1=((char *)strrchr(f,':'));
#elif PSS_STYLE==1 //#elif PSS_STYLE==1
tp1=((char *)strrchr(f,'/')); // tp1=((char *)strrchr(f,'/'));
#else //#else
tp1=((char *)strrchr(f,'\\')); // tp1=((char *)strrchr(f,'\\'));
#if PSS_STYLE!=3 //#if PSS_STYLE!=3
tp3=((char *)strrchr(f,'/')); // tp3=((char *)strrchr(f,'/'));
if(tp1<tp3) tp1=tp3; // if(tp1<tp3) tp1=tp3;
#endif //#endif
#endif //#endif
if(!tp1) //if(!tp1)
{ //{
tp1=f; // tp1=f;
strcpy(FileBaseDirectory,"."); // strcpy(FileBaseDirectory,".");
} //}
else //else
{ //{
memcpy(FileBaseDirectory,f,tp1-f); // memcpy(FileBaseDirectory,f,tp1-f);
FileBaseDirectory[tp1-f]=0; // FileBaseDirectory[tp1-f]=0;
tp1++; // tp1++;
} //}
if(((tp3=strrchr(f,'.'))!=NULL) && (tp3>tp1)) //if(((tp3=strrchr(f,'.'))!=NULL) && (tp3>tp1))
{ //{
memcpy(FileBase,tp1,tp3-tp1); // memcpy(FileBase,tp1,tp3-tp1);
FileBase[tp3-tp1]=0; // FileBase[tp3-tp1]=0;
strcpy(FileExt,tp3); // strcpy(FileExt,tp3);
} //}
else //else
{ //{
strcpy(FileBase,tp1); // strcpy(FileBase,tp1);
FileExt[0]=0; // FileExt[0]=0;
} //}
return FileBaseInfo(FileBaseDirectory,FileBase,FileExt); char drv[1000], dir[1000], name[1000], ext[1000];
splitpath(f,drv,dir,name,ext);
return FileBaseInfo((std::string)drv + dir,name,ext);
} }
inline FileBaseInfo DetermineFileBase(const std::string& str) { return DetermineFileBase(str.c_str()); }
FCEUFILE * FCEU_fopen(const char *path, const char *ipsfn, char *mode, char *ext, int index) FCEUFILE * FCEU_fopen(const char *path, const char *ipsfn, char *mode, char *ext, int index)
{ {
FILE *ipsfile=0; FILE *ipsfile=0;
@ -236,8 +241,6 @@ FCEUFILE * FCEU_fopen(const char *path, const char *ipsfn, char *mode, char *ext
std::string archive,fname,fileToOpen; std::string archive,fname,fileToOpen;
FCEU_SplitArchiveFilename(path,archive,fname,fileToOpen); FCEU_SplitArchiveFilename(path,archive,fname,fileToOpen);
if(!ipsfn) {
}
//try to setup the ips file //try to setup the ips file
if(ipsfn && read) if(ipsfn && read)
@ -256,6 +259,7 @@ FCEUFILE * FCEU_fopen(const char *path, const char *ipsfn, char *mode, char *ext
} }
fceufp = new FCEUFILE(); fceufp = new FCEUFILE();
fceufp->filename = fileToOpen; fceufp->filename = fileToOpen;
fceufp->logicalPath = fileToOpen;
fceufp->fullFilename = fileToOpen; fceufp->fullFilename = fileToOpen;
fceufp->archiveIndex = -1; fceufp->archiveIndex = -1;
fceufp->stream = (std::iostream*)fp; fceufp->stream = (std::iostream*)fp;
@ -274,13 +278,16 @@ FCEUFILE * FCEU_fopen(const char *path, const char *ipsfn, char *mode, char *ext
fceufp = FCEUD_OpenArchive(asr, fileToOpen, 0); fceufp = FCEUD_OpenArchive(asr, fileToOpen, 0);
else else
fceufp = FCEUD_OpenArchive(asr, archive, &fname); fceufp = FCEUD_OpenArchive(asr, archive, &fname);
FileBaseInfo fbi = DetermineFileBase(fileToOpen);
fceufp->logicalPath = fbi.filebasedirectory + fceufp->filename;
goto applyips; goto applyips;
} }
applyips: applyips:
//try to open the ips file //try to open the ips file
if(!ipsfile && !ipsfn) if(!ipsfile && !ipsfn)
ipsfile=FCEUD_UTF8fopen(FCEU_MakeIpsFilename(DetermineFileBase(fceufp->filename.c_str())),"rb"); ipsfile=FCEUD_UTF8fopen(FCEU_MakeIpsFilename(DetermineFileBase(fceufp->logicalPath.c_str())),"rb");
ApplyIPS(ipsfile,fceufp); ApplyIPS(ipsfile,fceufp);
return fceufp; return fceufp;
} }

View File

@ -13,6 +13,9 @@ struct FCEUFILE {
//the name of the file, or the logical name of the file within the archive //the name of the file, or the logical name of the file within the archive
std::string filename; std::string filename;
//a weirdly derived value.. maybe a path to a file, or maybe a path to a file which doesnt exist but which is in an archive in the same directory
std::string logicalPath;
//the filename of the archive (maybe "" if it is not in an archive) //the filename of the archive (maybe "" if it is not in an archive)
std::string archiveFilename; std::string archiveFilename;