Update: Translations from eints
[openttd-github.git] / src / script / script_scanner.hpp
blob1f5dca048571196e00979466624b75da118eedc1
1 /*
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/>.
6 */
8 /** @file script_scanner.hpp Declarations of the class for the script scanner. */
10 #ifndef SCRIPT_SCANNER_HPP
11 #define SCRIPT_SCANNER_HPP
13 #include "../fileio_func.h"
14 #include "../string_func.h"
16 typedef std::map<std::string, class ScriptInfo *, CaseInsensitiveComparator> ScriptInfoList; ///< Type for the list of scripts.
18 /** Scanner to help finding scripts. */
19 class ScriptScanner : public FileScanner {
20 public:
21 ScriptScanner();
22 virtual ~ScriptScanner();
24 virtual void Initialize() = 0;
26 /**
27 * Get the engine of the main squirrel handler (it indexes all available scripts).
29 class Squirrel *GetEngine() { return this->engine; }
31 /**
32 * Get the current main script the ScanDir is currently tracking.
34 std::string GetMainScript() { return this->main_script; }
36 /**
37 * Get the current tar file the ScanDir is currently tracking.
39 std::string GetTarFile() { return this->tar_file; }
41 /**
42 * Get the list of all registered scripts.
44 const ScriptInfoList *GetInfoList() { return &this->info_list; }
46 /**
47 * Get the list of the latest version of all registered scripts.
49 const ScriptInfoList *GetUniqueInfoList() { return &this->info_single_list; }
51 /**
52 * Register a ScriptInfo to the scanner.
54 void RegisterScript(class ScriptInfo *info);
56 /**
57 * Get the list of registered scripts to print on the console.
58 * @param output_iterator The iterator to write the output to.
59 * @param newest_only Whether to only show the newest scripts.
61 void GetConsoleList(std::back_insert_iterator<std::string> &output_iterator, bool newest_only) const;
63 /**
64 * Check whether we have a script with the exact characteristics as ci.
65 * @param ci The characteristics to search on (shortname and md5sum).
66 * @param md5sum Whether to check the MD5 checksum.
67 * @return True iff we have a script matching.
69 bool HasScript(const struct ContentInfo *ci, bool md5sum);
71 /**
72 * Find a script of a #ContentInfo
73 * @param ci The information to compare to.
74 * @param md5sum Whether to check the MD5 checksum.
75 * @return A filename of a file of the content, else \c nullptr.
77 const char *FindMainScript(const ContentInfo *ci, bool md5sum);
79 bool AddFile(const std::string &filename, size_t basepath_length, const std::string &tar_filename) override;
81 /**
82 * Rescan the script dir.
84 void RescanDir();
86 protected:
87 class Squirrel *engine; ///< The engine we're scanning with.
88 std::string main_script; ///< The full path of the script.
89 std::string tar_file; ///< If, which tar file the script was in.
91 ScriptInfoList info_list; ///< The list of all script.
92 ScriptInfoList info_single_list; ///< The list of all unique script. The best script (highest version) is shown.
94 /**
95 * Initialize the scanner.
96 * @param name The name of the scanner ("AIScanner", "GSScanner", ..).
98 void Initialize(const char *name);
101 * Get the script name how to store the script in memory.
103 virtual std::string GetScriptName(ScriptInfo *info) = 0;
106 * Get the filename to scan for this type of script.
108 virtual const char *GetFileName() const = 0;
111 * Get the directory to scan in.
113 virtual Subdirectory GetDirectory() const = 0;
116 * Register the API for this ScriptInfo.
118 virtual void RegisterAPI(class Squirrel *engine) = 0;
121 * Get the type of the script, in plural.
123 virtual const char *GetScannerName() const = 0;
126 * Reset all allocated lists.
128 void Reset();
131 * Reset the engine to ensure a clean environment for further steps.
133 void ResetEngine();
136 #endif /* SCRIPT_SCANNER_HPP */