summaryrefslogtreecommitdiff
path: root/src/fios.cpp
diff options
context:
space:
mode:
authoryexo <yexo@openttd.org>2012-08-20 21:01:40 +0000
committeryexo <yexo@openttd.org>2012-08-20 21:01:40 +0000
commitfe31aa28c422f1fab32ab3b72d8369d539c8496e (patch)
tree78d7776bd3eaf5c9fb62ca7f3b7ea4e26824260b /src/fios.cpp
parent2a89d0d13d9b7afb6a56b31715ba1b022070eef8 (diff)
downloadopenttd-fe31aa28c422f1fab32ab3b72d8369d539c8496e.tar.xz
(svn r24487) -Codechange [FS#5236]: make several DoesContentExist return the path instead of a boolean (LordAro)
Diffstat (limited to 'src/fios.cpp')
-rw-r--r--src/fios.cpp36
1 files changed, 24 insertions, 12 deletions
diff --git a/src/fios.cpp b/src/fios.cpp
index ffbe57375..e948b5680 100644
--- a/src/fios.cpp
+++ b/src/fios.cpp
@@ -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);
}
/**