1 /* $Id: script_scanner.hpp 24487 2012-08-20 21:01:40Z yexo $ */
4 * This file is part of OpenTTD.
5 * 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.
6 * 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.
7 * 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/>.
10 /** @file script_scanner.hpp Declarations of the class for the script scanner. */
12 #ifndef SCRIPT_SCANNER_HPP
13 #define SCRIPT_SCANNER_HPP
16 #include "../fileio_func.h"
17 #include "../core/string_compare_type.hpp"
19 typedef std::map
<const char *, class ScriptInfo
*, StringCompare
> ScriptInfoList
; ///< Type for the list of scripts.
21 /** Scanner to help finding scripts. */
22 class ScriptScanner
: public FileScanner
{
25 virtual ~ScriptScanner();
27 virtual void Initialize() = 0;
30 * Get the engine of the main squirrel handler (it indexes all available scripts).
32 class Squirrel
*GetEngine() { return this->engine
; }
35 * Get the current main script the ScanDir is currently tracking.
37 const char *GetMainScript() { return this->main_script
; }
40 * Get the current tar file the ScanDir is currently tracking.
42 const char *GetTarFile() { return this->tar_file
; }
45 * Get the list of all registered scripts.
47 const ScriptInfoList
*GetInfoList() { return &this->info_list
; }
50 * Get the list of the latest version of all registered scripts.
52 const ScriptInfoList
*GetUniqueInfoList() { return &this->info_single_list
; }
55 * Register a ScriptInfo to the scanner.
57 void RegisterScript(class ScriptInfo
*info
);
60 * Get the list of registered scripts to print on the console.
62 char *GetConsoleList(char *p
, const char *last
, bool newest_only
) const;
65 * Check whether we have a script with the exact characteristics as ci.
66 * @param ci The characteristics to search on (shortname and md5sum).
67 * @param md5sum Whether to check the MD5 checksum.
68 * @return True iff we have a script matching.
70 bool HasScript(const struct ContentInfo
*ci
, bool md5sum
);
73 * Find a script of a #ContentInfo
74 * @param ci The information to compare to.
75 * @param md5sum Whether to check the MD5 checksum.
76 * @return A filename of a file of the content, else \c NULL.
78 const char *FindMainScript(const ContentInfo
*ci
, bool md5sum
);
80 /* virtual */ bool AddFile(const char *filename
, size_t basepath_length
, const char *tar_filename
);
83 * Rescan the script dir.
88 class Squirrel
*engine
; ///< The engine we're scanning with.
89 char *main_script
; ///< The full path of the script.
90 char *tar_file
; ///< If, which tar file the script was in.
92 ScriptInfoList info_list
; ///< The list of all script.
93 ScriptInfoList info_single_list
; ///< The list of all unique script. The best script (highest version) is shown.
96 * Initialize the scanner.
97 * @param name The name of the scanner ("AIScanner", "GSScanner", ..).
99 void Initialize(const char *name
);
102 * Get the script name how to store the script in memory.
104 virtual void GetScriptName(ScriptInfo
*info
, char *name
, const char *last
) = 0;
107 * Get the filename to scan for this type of script.
109 virtual const char *GetFileName() const = 0;
112 * Get the directory to scan in.
114 virtual Subdirectory
GetDirectory() const = 0;
117 * Register the API for this ScriptInfo.
119 virtual void RegisterAPI(class Squirrel
*engine
) = 0;
122 * Get the type of the script, in plural.
124 virtual const char *GetScannerName() const = 0;
127 * Reset all allocated lists.
132 * Reset the engine to ensure a clean environment for further steps.
137 #endif /* SCRIPT_SCANNER_HPP */