]> de.git.xonotic.org Git - xonotic/netradiant.git/blobdiff - plugins/vfspk3/vfs.cpp
radiant: replace StringBuffer with std::string
[xonotic/netradiant.git] / plugins / vfspk3 / vfs.cpp
index ded3d048f817a5278b0dec1f05762c96339965f2..703a956e15246afa5854a276fb5f692eef52f658 100644 (file)
@@ -129,8 +129,8 @@ static void FixDOSName( char *src ){
 }
 
 const _QERArchiveTable* GetArchiveTable( ArchiveModules& archiveModules, const char* ext ){
-       StringOutputStream tmp( 16 );
-       tmp << LowerCase( ext );
+       std::string tmp = ext;
+       transform(tmp.begin(), tmp.end(), tmp.begin(), ::tolower);
        return archiveModules.findModule( tmp.c_str() );
 }
 
@@ -347,6 +347,9 @@ static const char* GetLatestDpkPakVersion( const char* name ){
 }
 
 // release string after using
+// Note: it also contains the version string,
+// for …/src/map-castle_src.dpkdir/maps/castle.map
+// it will return map-castle_src
 static char* GetCurrentMapDpkPakName(){
        char* mapdir;
        char* mapname;
@@ -356,21 +359,27 @@ static char* GetCurrentMapDpkPakName(){
        mapname = string_clone( GlobalRadiant().getMapName() );
        mapnamelen = string_length( mapname );
 
-       mapdir = strrchr( mapname, '/' );
-       if ( mapdir ) {
-               mapdir -= 12;
-               if ( strncmp( mapdir, ".dpkdir/maps/", 13 ) == 0 ) {
-                       *mapdir = '\0';
-                       mapdir = strrchr( mapname, '/' );
-                       if ( mapdir ) mapdir++;
-                       else mapdir = mapname;
-                       result = string_clone( mapdir );
+       char pattern[] = ".dpkdir/";
+       char* end = strstr( mapname, ".dpkdir/" );
+       if ( end )
+       {
+               end[ 0 ] = '\0';
+
+               mapdir = strrchr( mapname, '/' );
+               if ( mapdir )
+               {
+                       mapdir++;
+               }
+               else
+               {
+                       mapdir = mapname;
                }
+
+               result = string_clone( mapdir );
        }
 
        string_release( mapname, mapnamelen );
        return result;
-
 }
 
 // prevent loading duplicates or circular references
@@ -384,9 +393,9 @@ static void LoadDpkPakWithDeps( const char* pakname ){
 
        if (pakname == NULL) {
                // load DEPS from game pack
-               StringOutputStream baseDirectory( 256 );
-               const char* basegame = GlobalRadiant().getRequiredGameDescriptionKeyValue( "basegame" );
-               baseDirectory << GlobalRadiant().getGameToolsPath() << basegame << '/';
+               std::string baseDirectory( GlobalRadiant().getGameToolsPath() );
+               baseDirectory += GlobalRadiant().getRequiredGameDescriptionKeyValue( "basegame" );
+               baseDirectory += '/';
                arc = AddDpkDir( baseDirectory.c_str() );
                depsFile = arc->openTextFile( "DEPS" );
        } else {
@@ -562,7 +571,7 @@ void InitDirectory( const char* directory, ArchiveModules& archiveModules ){
                                }
 
                                const char *ext = strrchr( name, '.' );
-                               char tmppath[PATH_MAX];
+                               char tmppath[PATH_MAX + 1];
 
                                if ( ext != nullptr ) {
                                        if ( is_dpk_vfs && !string_compare_nocase_upper( ext, ".dpkdir" ) ) {