-
Notifications
You must be signed in to change notification settings - Fork 177
EFF subdirectories #449
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
EFF subdirectories #449
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -88,6 +88,7 @@ cf_pathtype Pathtypes[CF_MAX_PATH_TYPES] = { | |
| { CF_TYPE_INTEL_ANIMS, "data" DIR_SEPARATOR_STR "intelanims", ".pcx .ani .eff .tga .jpg .png .dds", CF_TYPE_DATA }, | ||
| { CF_TYPE_SCRIPTS, "data" DIR_SEPARATOR_STR "scripts", ".lua .lc", CF_TYPE_DATA }, | ||
| { CF_TYPE_FICTION, "data" DIR_SEPARATOR_STR "fiction", ".txt", CF_TYPE_DATA }, | ||
| { CF_TYPE_TEMP_SUBDIR_LOOKUP, NULL, ".pcx .tga .jpg .png .dds", CF_TYPE_DATA }, | ||
| }; | ||
|
|
||
|
|
||
|
|
@@ -135,6 +136,8 @@ void cfile_close() | |
|
|
||
| cf_free_secondary_filelist(); | ||
|
|
||
| vm_free(Pathtypes[CF_TYPE_TEMP_SUBDIR_LOOKUP].path); | ||
|
|
||
| cfile_inited = 0; | ||
| } | ||
|
|
||
|
|
@@ -235,6 +238,9 @@ int cfile_init(const char *exe_dir, const char *cdrom_dir) | |
| Cfile_block_list[i].type = CFILE_BLOCK_UNUSED; | ||
| } | ||
|
|
||
| // Init to an empty string to avoid having to test for NULL everywhere | ||
| Pathtypes[CF_TYPE_TEMP_SUBDIR_LOOKUP].path = vm_strdup(""); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This memory is leaked. This can be seen in the valgrind results of the unit tests. |
||
|
|
||
| // 32 bit CRC table init | ||
| cf_chksum_long_init(); | ||
|
|
||
|
|
@@ -1120,6 +1126,43 @@ int cf_get_dir_type(CFILE *cfile) | |
| return Cfile_block_list[cfile->id].dir_type; | ||
| } | ||
|
|
||
| /** | ||
| * Stuffs Pathtypes with an additional path leading to a subdir of the same name as the given file (minus file extension). | ||
| * Currently used for allowing frames of .eff animations to be found in their own subdirectories. | ||
| * | ||
| * Example: if called with "debris.eff" and that file is in data/maps, then Pathtypes[CF_TYPE_TEMP_SUBDIR_LOOKUP].path | ||
| * will be stuffed with data/maps/debris, allowing data/maps/debris/debris_0000.dds (etc) to be found | ||
| */ | ||
| bool cf_set_temp_subdir_pathtype(const char *filename) { | ||
| mprintf(("CFILE: Setting temporary pathtype for %s... ", filename)); | ||
|
|
||
| // Finds the relative path of where the file exists and appends the filename | ||
| // (without extension) to it, giving us a relative path that can be temporarily | ||
| // stuffed into Pathtypes | ||
| for (size_t i=CF_TYPE_ROOT; i<CF_MAX_PATH_TYPES; i++) { | ||
| if (cf_find_file_location(filename, i, 0, NULL, NULL, NULL)) { | ||
| SCP_string subdir, finalpath; | ||
|
|
||
| subdir = SCP_string(filename); | ||
| subdir = subdir.substr(0, subdir.find_last_of(".")); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If filename doesn't contain an extension then will
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I didn't specifically test it, but according to documentation it'll return string::npos meaning that substr will just return the complete string.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh, well that's convenient. |
||
|
|
||
| finalpath = SCP_string(Pathtypes[i].path); | ||
| finalpath += DIR_SEPARATOR_STR + subdir; | ||
|
|
||
| vm_free(Pathtypes[CF_TYPE_TEMP_SUBDIR_LOOKUP].path); | ||
|
|
||
| Pathtypes[CF_TYPE_TEMP_SUBDIR_LOOKUP].path = vm_strdup(finalpath.c_str()); | ||
|
|
||
| mprintf(("OK. Temporary pathtype is now %s\n", Pathtypes[CF_TYPE_TEMP_SUBDIR_LOOKUP].path)); | ||
|
|
||
| return true; | ||
| } | ||
| } | ||
|
|
||
| mprintf(("Failed! File %s not found!\n", filename)); | ||
| return false; | ||
| } | ||
|
|
||
| // cf_returndata() returns the data pointer for a memory-mapped file that is associated | ||
| // with the CFILE structure passed as a parameter | ||
| // | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This macro is getting a bit too big, how about converting it to a static function?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IIRC I didn't because it was the more complicated route and I didn't want to bundle potentially error-prone refactoring like that with the feature. It could certainly be done separately.