OpenTTD Source 20260218-master-g2123fca5ea
ScriptScanner Class Referenceabstract

Scanner to help finding scripts. More...

#include <script_scanner.hpp>

Inheritance diagram for ScriptScanner:
FileScanner AIScannerInfo AIScannerLibrary GameScannerInfo GameScannerLibrary

Public Member Functions

virtual void Initialize ()=0
 Initialize the scanner by scanning for scripts and creating dummies if needed.
class SquirrelGetEngine ()
 Get the engine of the main squirrel handler (it indexes all available scripts).
std::string GetMainScript ()
 Get the current main script the ScanDir is currently tracking.
std::string GetTarFile ()
 Get the current tar file the ScanDir is currently tracking.
const ScriptInfoListGetInfoList ()
 Get the list of all registered scripts.
const ScriptInfoListGetUniqueInfoList ()
 Get the list of the latest version of all registered scripts.
void RegisterScript (std::unique_ptr< class ScriptInfo > &&info)
 Register a ScriptInfo to the scanner.
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.
bool HasScript (const struct ContentInfo &ci, bool md5sum)
 Check whether we have a script with the exact characteristics as ci.
std::optional< std::string_view > FindMainScript (const ContentInfo &ci, bool md5sum)
 Find a script of a ContentInfo.
bool AddFile (const std::string &filename, size_t basepath_length, const std::string &tar_filename) override
 Add a file with the given filename.
void RescanDir ()
 Rescan the script dir.
Public Member Functions inherited from FileScanner
virtual ~FileScanner ()=default
 Destruct the proper one...
uint Scan (std::string_view extension, Subdirectory sd, bool tars=true, bool recursive=true)
 Scan for files with the given extension in the given search path.
uint Scan (std::string_view extension, const std::string &directory, bool recursive=true)
 Scan for files with the given extension in the given search path.

Protected Member Functions

void Initialize (std::string_view name)
 Initialize the scanner.
virtual std::string GetScriptName (ScriptInfo &info)=0
 Get the script name how to store the script in memory.
virtual std::string_view GetFileName () const =0
 Get the filename to scan for this type of script.
virtual Subdirectory GetDirectory () const =0
 Get the directory to scan in.
virtual void RegisterAPI (class Squirrel &engine)=0
 Register the API for this ScriptInfo.
virtual std::string_view GetScannerName () const =0
 Get the type of the script, in plural.
void Reset ()
 Reset all allocated lists.
void ResetEngine ()
 Reset the engine to ensure a clean environment for further steps.

Protected Attributes

std::unique_ptr< class Squirrelengine
 The engine we're scanning with.
std::string main_script
 The full path of the script.
std::string tar_file
 If, which tar file the script was in.
std::vector< std::unique_ptr< ScriptInfo > > info_vector
 The known ScriptInfo objects.
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.
Protected Attributes inherited from FileScanner
Subdirectory subdir {}
 The current sub directory we are searching through.

Detailed Description

Scanner to help finding scripts.

Definition at line 19 of file script_scanner.hpp.

Constructor & Destructor Documentation

◆ ~ScriptScanner()

ScriptScanner::~ScriptScanner ( )
override

Definition at line 65 of file script_scanner.cpp.

Member Function Documentation

◆ AddFile()

bool ScriptScanner::AddFile ( const std::string & filename,
size_t basepath_length,
const std::string & tar_filename )
overridevirtual

Add a file with the given filename.

Parameters
filenamethe full path to the file to read
basepath_lengthamount of characters to chop of before to get a filename relative to the search path.
tar_filenamethe name of the tar file the file is read from.
Returns
true if the file is added.

Implements FileScanner.

Definition at line 26 of file script_scanner.cpp.

References Debug, engine, FioCheckFileExists(), Script_FatalError::GetErrorMessage(), main_script, ResetEngine(), FileScanner::subdir, and tar_file.

◆ FindMainScript()

std::optional< std::string_view > ScriptScanner::FindMainScript ( const ContentInfo & ci,
bool md5sum )

Find a script of a ContentInfo.

Parameters
ciThe information to compare to.
md5sumWhether to check the MD5 checksum.
Returns
A filename of a file of the content, else nullptr.

Definition at line 234 of file script_scanner.cpp.

References info_list, and IsSameScript().

Referenced by ContentInfo::GetTextfile().

◆ GetConsoleList()

void ScriptScanner::GetConsoleList ( std::back_insert_iterator< std::string > & output_iterator,
bool newest_only ) const

Get the list of registered scripts to print on the console.

Parameters
output_iteratorThe iterator to write the output to.
newest_onlyWhether to only show the newest scripts.

Definition at line 131 of file script_scanner.cpp.

References ScriptInfo::GetDescription(), ScriptInfo::GetName(), GetScannerName(), ScriptInfo::GetVersion(), info_list, and info_single_list.

◆ GetDirectory()

virtual Subdirectory ScriptScanner::GetDirectory ( ) const
protectedpure virtual

Get the directory to scan in.

Returns
The sub directory to search in.

Implemented in AIScannerInfo, AIScannerLibrary, GameScannerInfo, and GameScannerLibrary.

Referenced by RescanDir().

◆ GetEngine()

class Squirrel * ScriptScanner::GetEngine ( )
inline

Get the engine of the main squirrel handler (it indexes all available scripts).

Returns
The engine.

Definition at line 33 of file script_scanner.hpp.

References engine.

Referenced by ScriptInfo::Constructor().

◆ GetFileName()

virtual std::string_view ScriptScanner::GetFileName ( ) const
protectedpure virtual

Get the filename to scan for this type of script.

Returns
The file name of the main file of the script/library.

Implemented in AIScannerInfo, AIScannerLibrary, GameScannerInfo, and GameScannerLibrary.

Referenced by RescanDir().

◆ GetInfoList()

const ScriptInfoList * ScriptScanner::GetInfoList ( )
inline

Get the list of all registered scripts.

Returns
The list of ScriptInfo elements.

Definition at line 51 of file script_scanner.hpp.

References info_list.

◆ GetMainScript()

std::string ScriptScanner::GetMainScript ( )
inline

Get the current main script the ScanDir is currently tracking.

Returns
The path to the main script.

Definition at line 39 of file script_scanner.hpp.

References main_script.

Referenced by ScriptInfo::Constructor().

◆ GetScannerName()

virtual std::string_view ScriptScanner::GetScannerName ( ) const
protectedpure virtual

Get the type of the script, in plural.

Returns
Type of script to show on the console.

Implemented in AIScannerInfo, AIScannerLibrary, GameScannerInfo, and GameScannerLibrary.

Referenced by GetConsoleList().

◆ GetScriptName()

virtual std::string ScriptScanner::GetScriptName ( ScriptInfo & info)
protectedpure virtual

Get the script name how to store the script in memory.

Parameters
infoThe information to get name for.
Returns
The script's name.

Implemented in AIScannerInfo, AIScannerLibrary, GameScannerInfo, and GameScannerLibrary.

Referenced by RegisterScript().

◆ GetTarFile()

std::string ScriptScanner::GetTarFile ( )
inline

Get the current tar file the ScanDir is currently tracking.

Returns
The tar file the script is in, or an empty string.

Definition at line 45 of file script_scanner.hpp.

References tar_file.

Referenced by ScriptInfo::Constructor().

◆ GetUniqueInfoList()

const ScriptInfoList * ScriptScanner::GetUniqueInfoList ( )
inline

Get the list of the latest version of all registered scripts.

Returns
The list of ScriptInfo elements.

Definition at line 57 of file script_scanner.hpp.

References info_single_list.

◆ HasScript()

bool ScriptScanner::HasScript ( const struct ContentInfo & ci,
bool md5sum )

Check whether we have a script with the exact characteristics as ci.

Parameters
ciThe characteristics to search on (shortname and md5sum).
md5sumWhether to check the MD5 checksum.
Returns
True iff we have a script matching.

Definition at line 226 of file script_scanner.cpp.

References info_list, and IsSameScript().

◆ Initialize() [1/2]

virtual void ScriptScanner::Initialize ( )
pure virtual

Initialize the scanner by scanning for scripts and creating dummies if needed.

Implemented in AIScannerInfo, AIScannerLibrary, GameScannerInfo, and GameScannerLibrary.

Referenced by AIScannerInfo::Initialize(), AIScannerLibrary::Initialize(), GameScannerInfo::Initialize(), and GameScannerLibrary::Initialize().

◆ Initialize() [2/2]

void ScriptScanner::Initialize ( std::string_view name)
protected

Initialize the scanner.

Parameters
nameThe name of the scanner ("AIScanner", "GSScanner", ..).

Definition at line 56 of file script_scanner.cpp.

References engine, RescanDir(), and ResetEngine().

◆ RegisterAPI()

virtual void ScriptScanner::RegisterAPI ( class Squirrel & engine)
protectedpure virtual

Register the API for this ScriptInfo.

Parameters
engineThe engine to register to.

Implemented in AIScannerInfo, AIScannerLibrary, GameScannerInfo, and GameScannerLibrary.

References engine.

Referenced by ResetEngine().

◆ RegisterScript()

void ScriptScanner::RegisterScript ( std::unique_ptr< class ScriptInfo > && info)

Register a ScriptInfo to the scanner.

Parameters
infoThe script to register.

Definition at line 86 of file script_scanner.cpp.

References _settings_client, Debug, GetScriptName(), ScriptInfo::GetVersion(), info_list, info_single_list, info_vector, ScriptInfo::IsDeveloperOnly(), and StrEqualsIgnoreCase().

Referenced by AIInfo::Constructor(), and GameInfo::Constructor().

◆ RescanDir()

void ScriptScanner::RescanDir ( )

Rescan the script dir.

Definition at line 70 of file script_scanner.cpp.

References GetDirectory(), GetFileName(), Reset(), and FileScanner::Scan().

Referenced by Initialize().

◆ Reset()

void ScriptScanner::Reset ( )
protected

Reset all allocated lists.

Definition at line 79 of file script_scanner.cpp.

References info_list, info_single_list, and info_vector.

Referenced by RescanDir().

◆ ResetEngine()

void ScriptScanner::ResetEngine ( )
protected

Reset the engine to ensure a clean environment for further steps.

Definition at line 49 of file script_scanner.cpp.

References engine, and RegisterAPI().

Referenced by AddFile(), and Initialize().

Field Documentation

◆ engine

std::unique_ptr<class Squirrel> ScriptScanner::engine
protected

◆ info_list

◆ info_single_list

ScriptInfoList ScriptScanner::info_single_list
protected

The list of all unique script. The best script (highest version) is shown.

Definition at line 103 of file script_scanner.hpp.

Referenced by AIScannerInfo::FindInfo(), GameScannerInfo::FindInfo(), GetConsoleList(), GetUniqueInfoList(), RegisterScript(), Reset(), and AIScannerInfo::SelectRandomAI().

◆ info_vector

std::vector<std::unique_ptr<ScriptInfo> > ScriptScanner::info_vector
protected

The known ScriptInfo objects.

Definition at line 100 of file script_scanner.hpp.

Referenced by RegisterScript(), and Reset().

◆ main_script

std::string ScriptScanner::main_script
protected

The full path of the script.

Definition at line 97 of file script_scanner.hpp.

Referenced by AddFile(), GetMainScript(), AIScannerInfo::Initialize(), and IsSameScript().

◆ tar_file

std::string ScriptScanner::tar_file
protected

If, which tar file the script was in.

Definition at line 98 of file script_scanner.hpp.

Referenced by AddFile(), and GetTarFile().


The documentation for this class was generated from the following files: