Skip to content

Commit d19bf31

Browse files
author
stgatilov
committed
Fixed bug which caused tdm_installer to reanalyze installation after TDM run.
The analysis was run because TDM repacked tdm_base01.pk4. The reason it repacked tdm_base01.pk4 is: it thought "strings/all.lang" had "png" extension =) It turns out that idStr::CheckExtension assumes that extension starts with dot, while in this case it was not. It does not compare the first character at all =( Here is the list of changes: 1) idStr::CheckExtension now asserts that first character of extension is "." 2) Function DoNotCompressFile now prepends "." to extension name before calling CheckExtension (that's the main bugfix). 3) stdext::iends_with now calls new idStr::IendsWith instead of idStr::CheckExtension. As far as I see, DoNotCompressFile and stdext::iends_with were the only calls to CheckExtension without dot. Also stdext::iends_with is only called in MissionManager for l10n packs, so even if I break it, it won't be a big problem =) git-svn-id: http://svn.thedarkmod.com/svn/darkmod_src/trunk@9817 49c82d7f-2e2a-0410-a16f-ae8f201b507f
1 parent 530e605 commit d19bf31

File tree

4 files changed

+30
-3
lines changed

4 files changed

+30
-3
lines changed

framework/FileSystem.cpp

+5-2
Original file line numberDiff line numberDiff line change
@@ -1151,9 +1151,12 @@ That's why if we detect that such a file is compressed in pk4, we recompress the
11511151
*/
11521152
#include "CompressionParameters.h"
11531153
bool DoNotCompressFile(const char *filename) {
1154-
for (int i = 0; i < PK4_UNCOMPRESSED_EXTENSIONS_COUNT; i++)
1155-
if (idStr::CheckExtension(filename, PK4_UNCOMPRESSED_EXTENSIONS[i]))
1154+
char ext[16] = ".";
1155+
for (int i = 0; i < PK4_UNCOMPRESSED_EXTENSIONS_COUNT; i++) {
1156+
strcpy(ext + 1, PK4_UNCOMPRESSED_EXTENSIONS[i]);
1157+
if (idStr::CheckExtension(filename, ext))
11561158
return true;
1159+
}
11571160
return false;
11581161
}
11591162

idlib/StdString.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,6 @@ namespace stdext {
6161
}
6262

6363
bool iends_with(const std::string &text, const std::string &suffix) {
64-
return idStr::CheckExtension(text.c_str(), suffix.c_str());
64+
return idStr::IendsWith(text.c_str(), suffix.c_str());
6565
}
6666
}

idlib/Str.cpp

+23
Original file line numberDiff line numberDiff line change
@@ -443,12 +443,35 @@ void idStr::StripMediaName( const char *name, idStr &mediaName ) {
443443
}
444444
}
445445

446+
/*
447+
=============
448+
idStr::IendsWith
449+
=============
450+
*/
451+
bool idStr::IendsWith( const char *text, const char *suffix ) {
452+
int textLen = Length( text );
453+
int suffLen = Length( suffix );
454+
if ( suffLen > textLen )
455+
return false;
456+
int offset = textLen - suffLen;
457+
458+
for ( int i = 0; i < suffLen; i++ ) {
459+
char c1 = text[offset + i];
460+
char c2 = suffix[i];
461+
if ( ToLower(c1) != ToLower(c2) )
462+
return false;
463+
}
464+
465+
return true;
466+
}
467+
446468
/*
447469
=============
448470
idStr::CheckExtension
449471
=============
450472
*/
451473
bool idStr::CheckExtension( const char *name, const char *ext ) {
474+
assert( ext && ext[0] == '.' );
452475
const char *s1 = name + Length( name ) - 1;
453476
const char *s2 = ext + Length( ext ) - 1;
454477
int c1, c2, d;

idlib/Str.h

+1
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,7 @@ class idStr {
260260
static int FindText( const char *str, const char *text, bool casesensitive = true, int start = 0, int end = -1 );
261261
static bool Filter( const char *filter, const char *name, bool casesensitive );
262262
static void StripMediaName( const char *name, idStr &mediaName );
263+
static bool IendsWith( const char *text, const char *suffix );
263264
static bool CheckExtension( const char *name, const char *ext );
264265
static const char * FloatArrayToString( const float *array, const int length, const int precision );
265266

0 commit comments

Comments
 (0)