GameList: Slight optimization to scanning

This commit is contained in:
Connor McLaughlin
2021-02-18 18:07:09 +10:00
parent 3ab7e140ee
commit 1b544ae350
4 changed files with 37 additions and 17 deletions

View File

@ -7,6 +7,7 @@
#include "common/file_system.h"
#include "common/iso_reader.h"
#include "common/log.h"
#include "common/make_array.h"
#include "common/state_wrapper.h"
#include "common/string_util.h"
#include "common/timestamp.h"
@ -279,6 +280,26 @@ bool IsM3UFileName(const char* path)
return (extension && StringUtil::Strcasecmp(extension, ".m3u") == 0);
}
bool IsLoadableFilename(const char* path)
{
static constexpr auto extensions = make_array(".bin", ".cue", ".img", ".iso", ".chd", // discs
".exe", ".psexe", // exes
".psf", ".minipsf", // psf
".m3u" // playlists
);
const char* extension = std::strrchr(path, '.');
if (!extension)
return false;
for (const char* test_extension : extensions)
{
if (StringUtil::Strcasecmp(extension, test_extension) == 0)
return true;
}
return false;
}
std::vector<std::string> ParseM3UFile(const char* path)
{
std::ifstream ifs(path);

View File

@ -66,6 +66,9 @@ bool IsPsfFileName(const char* path);
/// Returns true if the filename is a M3U Playlist we can handle.
bool IsM3UFileName(const char* path);
/// Returns true if the filename is one we can load.
bool IsLoadableFilename(const char* path);
/// Parses an M3U playlist, returning the entries.
std::vector<std::string> ParseM3UFile(const char* path);