OpenTTD Source: ScriptScanner Class Reference

OpenTTD Source 15.0-beta1

Public Member Functions | Protected Member Functions | Protected Attributes
ScriptScanner Class Referenceabstract

Scanner to help finding scripts. More...

`#include <script_scanner.hpp>`

Inheritance diagram for ScriptScanner:

## Public Member Functions
virtual void | Initialize ()=0
class Squirrel * | GetEngine ()
| 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 ScriptInfoList * | GetInfoList ()
| Get the list of all registered scripts.
const ScriptInfoList * | GetUniqueInfoList ()
| Get the list of the latest version of all registered scripts.
void | RegisterScript (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.
const char * | 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 (const char *name)
| Initialize the scanner.
virtual std::string | GetScriptName (ScriptInfo *info)=0
| Get the script name how to store the script in memory.
virtual const char * | 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 const char * | 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
class Squirrel * | engine
| 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.
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 | ( |  | ) |

Definition at line 47 of file script_scanner.cpp.

## ◆ ~ScriptScanner()

ScriptScanner::~ScriptScanner | ( |  | ) |
| virtual

Definition at line 68 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

  filename | the full path to the file to read
  basepath_length | amount of characters to chop of before to get a filename relative to the search path.
  tar_filename | the 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(), Squirrel::LoadScript(), main_script, ResetEngine(), FileScanner::subdir, and tar_file.

## ◆ FindMainScript()

const char * ScriptScanner::FindMainScript | ( | const ContentInfo * | ci,
|  | bool | md5sum
| ) |  |

Find a script of a ContentInfo.

Parameters

  ci | The information to compare to.
  md5sum | Whether to check the MD5 checksum.

Returns
  A filename of a file of the content, else `nullptr`.

Definition at line 243 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_iterator | The iterator to write the output to.
  newest_only | Whether to only show the newest scripts.

Definition at line 141 of file script_scanner.cpp.

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

Referenced by AI::GetConsoleLibraryList(), Game::GetConsoleLibraryList(), AI::GetConsoleList(), and Game::GetConsoleList().

## ◆ GetDirectory()

virtual Subdirectory ScriptScanner::GetDirectory | ( |  | ) | const
| protectedpure virtual

Get the directory to scan 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).

Definition at line 29 of file script_scanner.hpp.

References engine.

Referenced by ScriptInfo::Constructor().

## ◆ GetFileName()

virtual const char * ScriptScanner::GetFileName | ( |  | ) | const
| protectedpure virtual

Get the filename to scan for this type of script.

Implemented in AIScannerInfo, AIScannerLibrary, GameScannerInfo, and GameScannerLibrary.

Referenced by RescanDir().

## ◆ GetInfoList()

const ScriptInfoList * ScriptScanner::GetInfoList | ( |  | ) |
| inline

Get the list of all registered scripts.

Definition at line 44 of file script_scanner.hpp.

References info_list.

Referenced by AI::GetInfoList(), and Game::GetInfoList().

## ◆ GetMainScript()

std::string ScriptScanner::GetMainScript | ( |  | ) |
| inline

Get the current main script the ScanDir is currently tracking.

Definition at line 34 of file script_scanner.hpp.

References main_script.

Referenced by ScriptInfo::Constructor(), and RegisterScript().

## ◆ GetScannerName()

virtual const char * ScriptScanner::GetScannerName | ( |  | ) | const
| protectedpure virtual

Get the type of the script, in plural.

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.

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.

Definition at line 39 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.

Definition at line 49 of file script_scanner.hpp.

References info_single_list.

Referenced by AI::GetUniqueInfoList(), and Game::GetUniqueInfoList().

## ◆ HasScript()

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

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

Parameters

  ci | The characteristics to search on (shortname and md5sum).
  md5sum | Whether to check the MD5 checksum.

Returns
  True iff we have a script matching.

Definition at line 235 of file script_scanner.cpp.

References info_list, and IsSameScript().

Referenced by AI::HasAI(), and Game::HasGame().

## ◆ Initialize()

void ScriptScanner::Initialize | ( | const char * | name | ) |
| protected

Initialize the scanner.

Parameters

  name | The name of the scanner ("AIScanner", "GSScanner", ..).

Definition at line 59 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.

Implemented in AIScannerInfo, AIScannerLibrary, GameScannerInfo, and GameScannerLibrary.

Referenced by ResetEngine().

## ◆ RegisterScript()

void ScriptScanner::RegisterScript | ( | class ScriptInfo * | info | ) |

Register a ScriptInfo to the scanner.

Definition at line 94 of file script_scanner.cpp.

References _settings_client, GUISettings::ai_developer_tools, Debug, GetMainScript(), ScriptInfo::GetMainScript(), ScriptInfo::GetName(), GetScriptName(), ScriptInfo::GetShortName(), ScriptInfo::GetVersion(), ClientSettings::gui, info_list, info_single_list, ScriptInfo::IsDeveloperOnly(), and StrEqualsIgnoreCase().

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

## ◆ RescanDir()

void ScriptScanner::RescanDir | ( |  | ) |

Rescan the script dir.

Definition at line 75 of file script_scanner.cpp.

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

Referenced by Initialize(), and AI::Rescan().

## ◆ Reset()

void ScriptScanner::Reset | ( |  | ) |
| protected

Reset all allocated lists.

Definition at line 84 of file script_scanner.cpp.

References info_list, and info_single_list.

Referenced by RescanDir().

## ◆ ResetEngine()

void ScriptScanner::ResetEngine | ( |  | ) |
| protected

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

Definition at line 52 of file script_scanner.cpp.

References engine, RegisterAPI(), Squirrel::Reset(), and Squirrel::SetGlobalPointer().

Referenced by AddFile(), and Initialize().

## Field Documentation

## ◆ engine

class Squirrel* ScriptScanner::engine
| protected

The engine we're scanning with.

Definition at line 87 of file script_scanner.hpp.

Referenced by AddFile(), GetEngine(), Initialize(), AIScannerInfo::RegisterAPI(), AIScannerLibrary::RegisterAPI(), GameScannerInfo::RegisterAPI(), GameScannerLibrary::RegisterAPI(), and ResetEngine().

## ◆ info_list

ScriptInfoList ScriptScanner::info_list
| protected

The list of all script.

Definition at line 91 of file script_scanner.hpp.

Referenced by AIScannerInfo::FindInfo(), GameScannerInfo::FindInfo(), AIScannerLibrary::FindLibrary(), GameScannerLibrary::FindLibrary(), FindMainScript(), GetConsoleList(), GetInfoList(), HasScript(), RegisterScript(), and Reset().

## ◆ 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 92 of file script_scanner.hpp.

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

## ◆ main_script

std::string ScriptScanner::main_script
| protected

The full path of the script.

Definition at line 88 of file script_scanner.hpp.

Referenced by AddFile(), GetMainScript(), and IsSameScript().

## ◆ tar_file

std::string ScriptScanner::tar_file
| protected

If, which tar file the script was in.

Definition at line 89 of file script_scanner.hpp.

Referenced by AddFile(), and GetTarFile().

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

- src/script/script_scanner.hpp
- src/script/script_scanner.cpp