MCPcopy Create free account
hub / github.com/dhewm/dhewm3 / OSPathToRelativePath

Method OSPathToRelativePath

neo/framework/FileSystem.cpp:842–920  ·  view source on GitHub ↗

================ idFileSystemLocal::OSPathToRelativePath takes a full OS path, as might be found in data from a media creation program, and converts it to a relativePath by stripping off directories Returns false if the osPath tree doesn't match any of the existing search paths. ================ */

Source from the content-addressed store, hash-verified

840================
841*/
842const char *idFileSystemLocal::OSPathToRelativePath( const char *OSPath ) {
843 static char relativePath[MAX_STRING_CHARS];
844 const char *s, *base;
845
846 // skip a drive letter?
847
848 // search for anything with "base" in it
849 // Ase files from max may have the form of:
850 // "//Purgatory/purgatory/doom/base/models/mapobjects/bitch/hologirl.tga"
851 // which won't match any of our drive letter based search paths
852 // look for the first complete directory name
853 base = strstr( OSPath, BASE_GAMEDIR );
854 while ( base ) {
855 char c1 = '\0', c2;
856 if ( base > OSPath ) {
857 c1 = *(base - 1);
858 }
859 c2 = *( base + strlen( BASE_GAMEDIR ) );
860 if ( ( c1 == '/' || c1 == '\\' ) && ( c2 == '/' || c2 == '\\' ) ) {
861 break;
862 }
863 base = strstr( base + 1, BASE_GAMEDIR );
864 }
865
866 // fs_game and fs_game_base support - look for first complete name with a mod path
867 // ( fs_game searched before fs_game_base )
868 const char *fsgame = NULL;
869 int igame = 0;
870 for ( igame = 0; igame < 2; igame++ ) {
871 if ( igame == 0 ) {
872 fsgame = fs_game.GetString();
873 } else if ( igame == 1 ) {
874 fsgame = fs_game_base.GetString();
875 }
876 if ( base == NULL && fsgame && strlen( fsgame ) ) {
877 base = strstr( OSPath, fsgame );
878 while ( base ) {
879 char c1 = '\0', c2;
880 if ( base > OSPath ) {
881 c1 = *(base - 1);
882 }
883 c2 = *( base + strlen( fsgame ) );
884 if ( ( c1 == '/' || c1 == '\\' ) && ( c2 == '/' || c2 == '\\' ) ) {
885 break;
886 }
887 base = strstr( base + 1, fsgame );
888 }
889 }
890 }
891
892 if ( base ) {
893 // DG: on Windows base might look like "base\\pak008.pk4/script/doom_util.script"
894 // while on Linux it'll be more like "base/pak008.pk4/script/doom_util.script"
895 // I /think/ we want to get rid of the bla.pk4 part, at least that's what happens implicitly on Windows
896 // (I hope these problems don't exist if the file is not from a .pk4, so that case is handled like before)
897 s = strstr( base, ".pk4/" );
898 if ( s != NULL ) {
899 s += 4; // skip ".pk4", but *not* the following '/', that'll be skipped below

Callers 11

GetFilenumMethod · 0.45
CompileFileMethod · 0.45
Com_LocalizeMaps_fFunction · 0.45
Com_LocalizeMapsTest_fFunction · 0.45
MA_AddMaterialFunction · 0.45
ASE_KeyMAP_DIFFUSEFunction · 0.45
GetFilenumMethod · 0.45
CompileFileMethod · 0.45

Calls 4

GetIntegerMethod · 0.80
GetStringMethod · 0.45
PrintfMethod · 0.45
WarningMethod · 0.45

Tested by

no test coverage detected