Skip to content

Commit fb77779

Browse files
authored
refactor(ini): Simplify some INI code (#2541)
1 parent 2f427b1 commit fb77779

File tree

1 file changed

+23
-48
lines changed
  • Core/GameEngine/Source/Common/INI

1 file changed

+23
-48
lines changed

Core/GameEngine/Source/Common/INI/INI.cpp

Lines changed: 23 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -162,21 +162,7 @@ Bool INI::isValidINIFilename( const char *filename )
162162
if( filename == nullptr )
163163
return FALSE;
164164

165-
Int len = strlen( filename );
166-
if( len < 3 )
167-
return FALSE;
168-
169-
if( filename[ len - 1 ] != 'I' && filename[ len - 1 ] != 'i' )
170-
return FALSE;
171-
172-
if( filename[ len - 2 ] != 'N' && filename[ len - 2 ] != 'n' )
173-
return FALSE;
174-
175-
if( filename[ len - 3 ] != 'I' && filename[ len - 3 ] != 'i' )
176-
return FALSE;
177-
178-
return TRUE;
179-
165+
return endsWithNoCase(filename, ".ini");
180166
}
181167

182168
///////////////////////////////////////////////////////////////////////////////////////////////////
@@ -264,42 +250,34 @@ UnsignedInt INI::loadDirectory( AsciiString dirName, INILoadType loadType, Xfer
264250
if( dirName.isEmpty() )
265251
throw INI_INVALID_DIRECTORY;
266252

267-
try
253+
FilenameList filenameList;
254+
dirName.concat('\\');
255+
TheFileSystem->getFileListInDirectory(dirName, "*.ini", filenameList, subdirs);
256+
// Load the INI files in the dir now, in a sorted order. This keeps things the same between machines
257+
// in a network game.
258+
FilenameList::const_iterator it = filenameList.begin();
259+
while (it != filenameList.end())
268260
{
269-
FilenameList filenameList;
270-
dirName.concat('\\');
271-
TheFileSystem->getFileListInDirectory(dirName, "*.ini", filenameList, subdirs);
272-
// Load the INI files in the dir now, in a sorted order. This keeps things the same between machines
273-
// in a network game.
274-
FilenameList::const_iterator it = filenameList.begin();
275-
while (it != filenameList.end())
276-
{
277-
AsciiString tempname;
278-
tempname = (*it).str() + dirName.getLength();
261+
AsciiString tempname;
262+
tempname = (*it).str() + dirName.getLength();
279263

280-
if ((tempname.find('\\') == nullptr) && (tempname.find('/') == nullptr)) {
281-
// this file doesn't reside in a subdirectory, load it first.
282-
filesRead += load( *it, loadType, pXfer );
283-
}
284-
++it;
264+
if ((tempname.find('\\') == nullptr) && (tempname.find('/') == nullptr)) {
265+
// this file doesn't reside in a subdirectory, load it first.
266+
filesRead += load( *it, loadType, pXfer );
285267
}
268+
++it;
269+
}
286270

287-
it = filenameList.begin();
288-
while (it != filenameList.end())
289-
{
290-
AsciiString tempname;
291-
tempname = (*it).str() + dirName.getLength();
271+
it = filenameList.begin();
272+
while (it != filenameList.end())
273+
{
274+
AsciiString tempname;
275+
tempname = (*it).str() + dirName.getLength();
292276

293-
if ((tempname.find('\\') != nullptr) || (tempname.find('/') != nullptr)) {
294-
filesRead += load( *it, loadType, pXfer );
295-
}
296-
++it;
277+
if ((tempname.find('\\') != nullptr) || (tempname.find('/') != nullptr)) {
278+
filesRead += load( *it, loadType, pXfer );
297279
}
298-
}
299-
catch (...)
300-
{
301-
// propagate the exception
302-
throw;
280+
++it;
303281
}
304282

305283
return filesRead;
@@ -1753,14 +1731,11 @@ Type scanType(std::string_view token)
17531731
}
17541732

17551733
// search for matching name
1756-
Bool found = false;
17571734
for( const LookupListRec* lookup = &lookupList[0]; lookup->name; lookup++ )
17581735
{
17591736
if( stricmp( lookup->name, token ) == 0 )
17601737
{
17611738
return lookup->value;
1762-
found = true;
1763-
break;
17641739
}
17651740
}
17661741

0 commit comments

Comments
 (0)