2 * This file is part of OpenTTD.
3 * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
4 * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
5 * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
8 /** @file script_scanner.hpp Declarations of the class for the script scanner. */
10 #ifndef SCRIPT_SCANNER_HPP
11 #define SCRIPT_SCANNER_HPP
14 #include "../fileio_func.h"
15 #include "../core/string_compare_type.hpp"
17 typedef std::map
<const char *, class ScriptInfo
*, StringCompare
> ScriptInfoList
; ///< Type for the list of scripts.
19 /** Scanner to help finding scripts. */
20 class ScriptScanner
: public FileScanner
{
23 virtual ~ScriptScanner();
25 virtual void Initialize() = 0;
28 * Get the engine of the main squirrel handler (it indexes all available scripts).
30 class Squirrel
*GetEngine() { return this->engine
; }
33 * Get the current main script the ScanDir is currently tracking.
35 std::string
GetMainScript() { return this->main_script
; }
38 * Get the current tar file the ScanDir is currently tracking.
40 std::string
GetTarFile() { return this->tar_file
; }
43 * Get the list of all registered scripts.
45 const ScriptInfoList
*GetInfoList() { return &this->info_list
; }
48 * Get the list of the latest version of all registered scripts.
50 const ScriptInfoList
*GetUniqueInfoList() { return &this->info_single_list
; }
53 * Register a ScriptInfo to the scanner.
55 void RegisterScript(class ScriptInfo
*info
);
58 * Get the list of registered scripts to print on the console.
60 char *GetConsoleList(char *p
, const char *last
, bool newest_only
) const;
63 * Check whether we have a script with the exact characteristics as ci.
64 * @param ci The characteristics to search on (shortname and md5sum).
65 * @param md5sum Whether to check the MD5 checksum.
66 * @return True iff we have a script matching.
68 bool HasScript(const struct ContentInfo
*ci
, bool md5sum
);
71 * Find a script of a #ContentInfo
72 * @param ci The information to compare to.
73 * @param md5sum Whether to check the MD5 checksum.
74 * @return A filename of a file of the content, else \c nullptr.
76 const char *FindMainScript(const ContentInfo
*ci
, bool md5sum
);
78 bool AddFile(const std::string
&filename
, size_t basepath_length
, const std::string
&tar_filename
) override
;
81 * Rescan the script dir.
86 class Squirrel
*engine
; ///< The engine we're scanning with.
87 std::string main_script
; ///< The full path of the script.
88 std::string tar_file
; ///< If, which tar file the script was in.
90 ScriptInfoList info_list
; ///< The list of all script.
91 ScriptInfoList info_single_list
; ///< The list of all unique script. The best script (highest version) is shown.
94 * Initialize the scanner.
95 * @param name The name of the scanner ("AIScanner", "GSScanner", ..).
97 void Initialize(const char *name
);
100 * Get the script name how to store the script in memory.
102 virtual void GetScriptName(ScriptInfo
*info
, char *name
, const char *last
) = 0;
105 * Get the filename to scan for this type of script.
107 virtual const char *GetFileName() const = 0;
110 * Get the directory to scan in.
112 virtual Subdirectory
GetDirectory() const = 0;
115 * Register the API for this ScriptInfo.
117 virtual void RegisterAPI(class Squirrel
*engine
) = 0;
120 * Get the type of the script, in plural.
122 virtual const char *GetScannerName() const = 0;
125 * Reset all allocated lists.
130 * Reset the engine to ensure a clean environment for further steps.
135 #endif /* SCRIPT_SCANNER_HPP */