(svn r24487) -Codechange [FS#5236]: make several DoesContentExist return the path instead of a boolean (LordAro)

This commit is contained in:
yexo
2012-08-20 21:01:40 +00:00
parent 3132b9a9ab
commit 4d1d6332fb
10 changed files with 114 additions and 27 deletions

View File

@@ -561,8 +561,9 @@ void FiosGetHeightmapList(SaveLoadDialogMode mode)
/** Basic data to distinguish a scenario. Used in the server list window */
struct ScenarioIdentifier {
uint32 scenid; ///< ID for the scenario (generated by content)
uint8 md5sum[16]; ///< MD5 checksum of file
uint32 scenid; ///< ID for the scenario (generated by content).
uint8 md5sum[16]; ///< MD5 checksum of file.
char filename[MAX_PATH]; ///< filename of the file.
bool operator == (const ScenarioIdentifier &other) const
{
@@ -606,6 +607,7 @@ public:
int fret = fscanf(f, "%i", &id.scenid);
FioFCloseFile(f);
if (fret != 1) return false;
strecpy(id.filename, filename, lastof(id.filename));
Md5 checksum;
uint8 buffer[1024];
@@ -638,24 +640,34 @@ public:
static ScenarioScanner _scanner;
/**
* Check whether we've got a given scenario based on its unique ID.
* @param ci the content info to compare it to
* @param md5sum whether to look at the md5sum or the id
* @return true if we've got the scenario
* Find a given scenario based on its unique ID.
* @param ci The content info to compare it to.
* @param md5sum Whether to look at the md5sum or the id.
* @return The filename of the file, else \c NULL.
*/
bool HasScenario(const ContentInfo *ci, bool md5sum)
const char *FindScenario(const ContentInfo *ci, bool md5sum)
{
_scanner.Scan(false);
for (ScenarioIdentifier *id = _scanner.Begin(); id != _scanner.End(); id++) {
if (md5sum ?
(memcmp(id->md5sum, ci->md5sum, sizeof(id->md5sum)) == 0) :
(id->scenid == ci->unique_id)) {
return true;
if (md5sum ? (memcmp(id->md5sum, ci->md5sum, sizeof(id->md5sum)) == 0)
: (id->scenid == ci->unique_id)) {
return id->filename;
}
}
return false;
return NULL;
}
/**
* Check whether we've got a given scenario based on its unique ID.
* @param ci The content info to compare it to.
* @param md5sum Whether to look at the md5sum or the id.
* @return True iff we've got the scenario.
*/
bool HasScenario(const ContentInfo *ci, bool md5sum)
{
return (FindScenario(ci, md5sum) != NULL);
}
/**