OpenTTD Source: src/script/script_scanner.hpp Source File

OpenTTD Source 1.11.0-RC1

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 <map>
14 #include "../fileio_func.h"
15 #include "../core/string_compare_type.hpp"
16
17 typedef std::map<const char *, class ScriptInfo *, StringCompare> ScriptInfoList;
18
20 class ScriptScanner : public FileScanner {
21 public:
22 ScriptScanner();
23 virtual ~ScriptScanner();
24
25 virtual void Initialize() = 0;
26
30 class Squirrel *GetEngine() { return this->engine; }
31
35 std::string GetMainScript() { return this->main_script; }
36
40 std::string GetTarFile() { return this->tar_file; }
41
45 const ScriptInfoList *GetInfoList() { return &this->info_list; }
46
50 const ScriptInfoList *GetUniqueInfoList() { return &this->info_single_list; }
51
55 void RegisterScript(class ScriptInfo *info);
56
60 char *GetConsoleList(char *p, const char *last, bool newest_only) const;
61
68 bool HasScript(const struct ContentInfo *ci, bool md5sum);
69
76 const char *FindMainScript(const ContentInfo *ci, bool md5sum);
77
78 bool AddFile(const std::string &filename, size_t basepath_length, const std::string &tar_filename) override;
79
83 void RescanDir();
84
85 protected:
86 class Squirrel *engine;
87 std::string main_script;
88 std::string tar_file;
89
90 ScriptInfoList info_list;
91 ScriptInfoList info_single_list;
92
97 void Initialize(const char *name);
98
102 virtual void GetScriptName(ScriptInfo *info, char *name, const char *last) = 0;
103
107 virtual const char *GetFileName() const = 0;
108
112 virtual Subdirectory GetDirectory() const = 0;
113
117 virtual void RegisterAPI(class Squirrel *engine) = 0;
118
122 virtual const char *GetScannerName() const = 0;
123
127 void Reset();
128
132 void ResetEngine();
133 };
134
135 #endif /* SCRIPT_SCANNER_HPP */
ScriptScanner::GetScriptName
virtual void GetScriptName(ScriptInfo *info, char *name, const char *last)=0
Get the script name how to store the script in memory.
ScriptScanner::engine
class Squirrel * engine
The engine we're scanning with.
Definition: script_scanner.hpp:86
ScriptScanner::GetMainScript
std::string GetMainScript()
Get the current main script the ScanDir is currently tracking.
Definition: script_scanner.hpp:35
ScriptScanner::RegisterAPI
virtual void RegisterAPI(class Squirrel *engine)=0
Register the API for this ScriptInfo.
ScriptScanner::tar_file
std::string tar_file
If, which tar file the script was in.
Definition: script_scanner.hpp:88
ScriptScanner::GetConsoleList
char * GetConsoleList(char *p, const char *last, bool newest_only) const
Get the list of registered scripts to print on the console.
Definition: script_scanner.cpp:148
ScriptScanner::RescanDir
void RescanDir()
Rescan the script dir.
Definition: script_scanner.cpp:75
ScriptScanner::ResetEngine
void ResetEngine()
Reset the engine to ensure a clean environment for further steps.
Definition: script_scanner.cpp:52
ScriptScanner::GetUniqueInfoList
const ScriptInfoList * GetUniqueInfoList()
Get the list of the latest version of all registered scripts.
Definition: script_scanner.hpp:50
Squirrel::Initialize
void Initialize()
Perform all initialization steps to create the engine.
Definition: squirrel.cpp:469
Squirrel
Definition: squirrel.hpp:23
ScriptInfoList
std::map< const char *, class ScriptInfo *, StringCompare > ScriptInfoList
A list that maps AI names to their AIInfo object.
Definition: ai.hpp:19
ScriptScanner::GetFileName
virtual const char * GetFileName() const =0
Get the filename to scan for this type of script.
ContentInfo
Container for all important information about a piece of content.
Definition: tcp_content.h:54
ScriptScanner::AddFile
bool AddFile(const std::string &filename, size_t basepath_length, const std::string &tar_filename) override
Add a file with the given filename.
Definition: script_scanner.cpp:26
ScriptScanner
Scanner to help finding scripts.
Definition: script_scanner.hpp:20
ScriptInfoList
std::map< const char *, class ScriptInfo *, StringCompare > ScriptInfoList
Type for the list of scripts.
Definition: script_scanner.hpp:17
ScriptScanner::GetEngine
class Squirrel * GetEngine()
Get the engine of the main squirrel handler (it indexes all available scripts).
Definition: script_scanner.hpp:30
ScriptScanner::main_script
std::string main_script
The full path of the script.
Definition: script_scanner.hpp:87
ScriptScanner::HasScript
bool HasScript(const struct ContentInfo *ci, bool md5sum)
Check whether we have a script with the exact characteristics as ci.
Definition: script_scanner.cpp:251
ScriptScanner::info_list
ScriptInfoList info_list
The list of all script.
Definition: script_scanner.hpp:90
ScriptScanner::GetInfoList
const ScriptInfoList * GetInfoList()
Get the list of all registered scripts.
Definition: script_scanner.hpp:45
ScriptScanner::GetScannerName
virtual const char * GetScannerName() const =0
Get the type of the script, in plural.
ScriptScanner::RegisterScript
void RegisterScript(class ScriptInfo *info)
Register a ScriptInfo to the scanner.
Definition: script_scanner.cpp:98
ScriptScanner::Reset
void Reset()
Reset all allocated lists.
Definition: script_scanner.cpp:84
ScriptScanner::GetDirectory
virtual Subdirectory GetDirectory() const =0
Get the directory to scan in.
Subdirectory
Subdirectory
The different kinds of subdirectories OpenTTD uses.
Definition: fileio_type.h:108
FileScanner
Helper for scanning for files with a given name.
Definition: fileio_func.h:59
ScriptScanner::FindMainScript
const char * FindMainScript(const ContentInfo *ci, bool md5sum)
Find a script of a ContentInfo.
Definition: script_scanner.cpp:259
ScriptScanner::GetTarFile
std::string GetTarFile()
Get the current tar file the ScanDir is currently tracking.
Definition: script_scanner.hpp:40
ScriptInfo
All static information from an Script like name, version, etc.
Definition: script_info.hpp:30
ScriptScanner::info_single_list
ScriptInfoList info_single_list
The list of all unique script. The best script (highest version) is shown.
Definition: script_scanner.hpp:91