2009-08-21 20:21:05 +00:00
|
|
|
/*
|
|
|
|
* This file is part of OpenTTD.
|
|
|
|
* 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.
|
|
|
|
* 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.
|
|
|
|
* 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/>.
|
|
|
|
*/
|
|
|
|
|
2009-03-15 22:41:57 +00:00
|
|
|
/** @file script_scanner.hpp Declarations of the class for the script scanner. */
|
|
|
|
|
|
|
|
#ifndef SCRIPT_SCANNER_HPP
|
|
|
|
#define SCRIPT_SCANNER_HPP
|
|
|
|
|
2011-11-29 23:21:52 +00:00
|
|
|
#include <map>
|
2011-08-25 10:37:28 +00:00
|
|
|
#include "../fileio_func.h"
|
2011-11-29 23:21:52 +00:00
|
|
|
#include "../core/string_compare_type.hpp"
|
|
|
|
|
|
|
|
typedef std::map<const char *, class ScriptInfo *, StringCompare> ScriptInfoList; ///< Type for the list of scripts.
|
2009-03-15 22:41:57 +00:00
|
|
|
|
2011-05-01 19:51:52 +00:00
|
|
|
/** Scanner to help finding scripts. */
|
2011-08-25 10:37:28 +00:00
|
|
|
class ScriptScanner : public FileScanner {
|
2009-03-15 22:41:57 +00:00
|
|
|
public:
|
|
|
|
ScriptScanner();
|
2011-11-29 23:21:52 +00:00
|
|
|
virtual ~ScriptScanner();
|
|
|
|
|
2012-02-12 17:29:58 +00:00
|
|
|
virtual void Initialize() = 0;
|
2009-03-15 22:41:57 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the engine of the main squirrel handler (it indexes all available scripts).
|
|
|
|
*/
|
|
|
|
class Squirrel *GetEngine() { return this->engine; }
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the current main script the ScanDir is currently tracking.
|
|
|
|
*/
|
2020-12-06 20:11:50 +00:00
|
|
|
std::string GetMainScript() { return this->main_script; }
|
2009-03-15 22:41:57 +00:00
|
|
|
|
2011-09-08 09:48:52 +00:00
|
|
|
/**
|
|
|
|
* Get the current tar file the ScanDir is currently tracking.
|
|
|
|
*/
|
2020-12-06 20:11:50 +00:00
|
|
|
std::string GetTarFile() { return this->tar_file; }
|
2011-09-08 09:48:52 +00:00
|
|
|
|
2011-11-29 23:21:52 +00:00
|
|
|
/**
|
|
|
|
* Get the list of all registered scripts.
|
|
|
|
*/
|
|
|
|
const ScriptInfoList *GetInfoList() { return &this->info_list; }
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the list of the latest version of all registered scripts.
|
|
|
|
*/
|
|
|
|
const ScriptInfoList *GetUniqueInfoList() { return &this->info_single_list; }
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Register a ScriptInfo to the scanner.
|
|
|
|
*/
|
|
|
|
void RegisterScript(class ScriptInfo *info);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the list of registered scripts to print on the console.
|
|
|
|
*/
|
|
|
|
char *GetConsoleList(char *p, const char *last, bool newest_only) const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check whether we have a script with the exact characteristics as ci.
|
|
|
|
* @param ci The characteristics to search on (shortname and md5sum).
|
|
|
|
* @param md5sum Whether to check the MD5 checksum.
|
|
|
|
* @return True iff we have a script matching.
|
|
|
|
*/
|
|
|
|
bool HasScript(const struct ContentInfo *ci, bool md5sum);
|
|
|
|
|
2012-08-20 21:01:40 +00:00
|
|
|
/**
|
|
|
|
* Find a script of a #ContentInfo
|
|
|
|
* @param ci The information to compare to.
|
|
|
|
* @param md5sum Whether to check the MD5 checksum.
|
2019-04-10 21:07:06 +00:00
|
|
|
* @return A filename of a file of the content, else \c nullptr.
|
2012-08-20 21:01:40 +00:00
|
|
|
*/
|
|
|
|
const char *FindMainScript(const ContentInfo *ci, bool md5sum);
|
|
|
|
|
2020-12-06 20:11:50 +00:00
|
|
|
bool AddFile(const std::string &filename, size_t basepath_length, const std::string &tar_filename) override;
|
2009-03-15 22:41:57 +00:00
|
|
|
|
2011-11-29 23:21:52 +00:00
|
|
|
/**
|
|
|
|
* Rescan the script dir.
|
|
|
|
*/
|
|
|
|
void RescanDir();
|
|
|
|
|
2009-03-15 22:41:57 +00:00
|
|
|
protected:
|
2020-12-06 20:11:50 +00:00
|
|
|
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.
|
2011-11-29 23:21:52 +00:00
|
|
|
|
|
|
|
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.
|
|
|
|
|
2012-02-12 17:29:58 +00:00
|
|
|
/**
|
|
|
|
* Initialize the scanner.
|
|
|
|
* @param name The name of the scanner ("AIScanner", "GSScanner", ..).
|
|
|
|
*/
|
|
|
|
void Initialize(const char *name);
|
|
|
|
|
2011-11-29 23:21:52 +00:00
|
|
|
/**
|
|
|
|
* Get the script name how to store the script in memory.
|
|
|
|
*/
|
2014-04-23 21:16:58 +00:00
|
|
|
virtual void GetScriptName(ScriptInfo *info, char *name, const char *last) = 0;
|
2011-11-29 23:21:52 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the filename to scan for this type of script.
|
|
|
|
*/
|
|
|
|
virtual const char *GetFileName() const = 0;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the directory to scan in.
|
|
|
|
*/
|
|
|
|
virtual Subdirectory GetDirectory() const = 0;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Register the API for this ScriptInfo.
|
|
|
|
*/
|
|
|
|
virtual void RegisterAPI(class Squirrel *engine) = 0;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the type of the script, in plural.
|
|
|
|
*/
|
|
|
|
virtual const char *GetScannerName() const = 0;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Reset all allocated lists.
|
|
|
|
*/
|
|
|
|
void Reset();
|
|
|
|
|
2014-05-25 19:53:46 +00:00
|
|
|
/**
|
|
|
|
* Reset the engine to ensure a clean environment for further steps.
|
|
|
|
*/
|
|
|
|
void ResetEngine();
|
2009-03-15 22:41:57 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif /* SCRIPT_SCANNER_HPP */
|