Posted By: Uhrwerk
Small snippet: Open files in any of your paths - 04/01/08 16:21
When working with file_open_game I found it rather annoying that files in one of the paths were never found by the instruction. The only workaround was to give absolute filenames like c:\myfile.txt. Now this small code snippet works the same way file_open_game does, but additionally finds files that are placed in any one of the games folders:
Just be carefull, this function is even slower than file_open_game. Use it only for loading things, not during the actual game phase.
Code:
fixed fileOpenGame(char* fileName)
{
fixed fh = file_open_game(fileName);
if (!fh)
{
char** c;
STRING* s = str_create("");
for (c = pPaths; (*c != NULL) && (!fh); c++)
{
str_cpy(s,work_dir);
str_cat(s,*c);
str_cat(s,fileName);
fileHandle = file_open_game(s);
}
ptr_remove(s);
}
return(fh);
}Just be carefull, this function is even slower than file_open_game. Use it only for loading things, not during the actual game phase.