OpenTTD Source  20241109-master-g5e4f8db7d6
script_scanner.hpp
Go to the documentation of this file.
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  */
7 
10 #ifndef SCRIPT_SCANNER_HPP
11 #define SCRIPT_SCANNER_HPP
12 
13 #include "../fileio_func.h"
14 #include "../string_func.h"
15 
16 typedef std::map<std::string, class ScriptInfo *, CaseInsensitiveComparator> ScriptInfoList;
17 
19 class ScriptScanner : public FileScanner {
20 public:
21  ScriptScanner();
22  virtual ~ScriptScanner();
23 
24  virtual void Initialize() = 0;
25 
29  class Squirrel *GetEngine() { return this->engine; }
30 
34  std::string GetMainScript() { return this->main_script; }
35 
39  std::string GetTarFile() { return this->tar_file; }
40 
44  const ScriptInfoList *GetInfoList() { return &this->info_list; }
45 
50 
54  void RegisterScript(class ScriptInfo *info);
55 
61  void GetConsoleList(std::back_insert_iterator<std::string> &output_iterator, bool newest_only) const;
62 
69  bool HasScript(const struct ContentInfo *ci, bool md5sum);
70 
77  const char *FindMainScript(const ContentInfo *ci, bool md5sum);
78 
79  bool AddFile(const std::string &filename, size_t basepath_length, const std::string &tar_filename) override;
80 
84  void RescanDir();
85 
86 protected:
87  class Squirrel *engine;
88  std::string main_script;
89  std::string tar_file;
90 
93 
98  void Initialize(const char *name);
99 
103  virtual std::string GetScriptName(ScriptInfo *info) = 0;
104 
108  virtual const char *GetFileName() const = 0;
109 
113  virtual Subdirectory GetDirectory() const = 0;
114 
118  virtual void RegisterAPI(class Squirrel *engine) = 0;
119 
123  virtual const char *GetScannerName() const = 0;
124 
128  void Reset();
129 
133  void ResetEngine();
134 };
135 
136 #endif /* SCRIPT_SCANNER_HPP */
Helper for scanning for files with a given name.
Definition: fileio_func.h:37
All static information from an Script like name, version, etc.
Definition: script_info.hpp:30
Scanner to help finding scripts.
bool HasScript(const struct ContentInfo *ci, bool md5sum)
Check whether we have a script with the exact characteristics as ci.
const ScriptInfoList * GetUniqueInfoList()
Get the list of the latest version of all registered scripts.
bool AddFile(const std::string &filename, size_t basepath_length, const std::string &tar_filename) override
Add a file with the given filename.
virtual const char * GetFileName() const =0
Get the filename to scan for this type of script.
const char * FindMainScript(const ContentInfo *ci, bool md5sum)
Find a script of a ContentInfo.
const ScriptInfoList * GetInfoList()
Get the list of all registered scripts.
virtual const char * GetScannerName() const =0
Get the type of the script, in plural.
class Squirrel * engine
The engine we're scanning with.
std::string GetTarFile()
Get the current tar file the ScanDir is currently tracking.
std::string tar_file
If, which tar file the script was in.
class Squirrel * GetEngine()
Get the engine of the main squirrel handler (it indexes all available scripts).
void Reset()
Reset all allocated lists.
void RescanDir()
Rescan the script dir.
virtual Subdirectory GetDirectory() const =0
Get the directory to scan in.
std::string main_script
The full path of the script.
virtual void RegisterAPI(class Squirrel *engine)=0
Register the API for this ScriptInfo.
void GetConsoleList(std::back_insert_iterator< std::string > &output_iterator, bool newest_only) const
Get the list of registered scripts to print on the console.
virtual std::string GetScriptName(ScriptInfo *info)=0
Get the script name how to store the script in memory.
std::string GetMainScript()
Get the current main script the ScanDir is currently tracking.
ScriptInfoList info_list
The list of all script.
ScriptInfoList info_single_list
The list of all unique script. The best script (highest version) is shown.
void RegisterScript(class ScriptInfo *info)
Register a ScriptInfo to the scanner.
void ResetEngine()
Reset the engine to ensure a clean environment for further steps.
void Initialize()
Perform all initialization steps to create the engine.
Definition: squirrel.cpp:519
Subdirectory
The different kinds of subdirectories OpenTTD uses.
Definition: fileio_type.h:115
std::map< std::string, class ScriptInfo *, CaseInsensitiveComparator > ScriptInfoList
Type for the list of scripts.
Container for all important information about a piece of content.