File diff r24528:a7298f737f00 → r24529:3dec691db49a
src/script/script_scanner.hpp
Show inline comments
 
@@ -11,102 +11,102 @@
 
#define SCRIPT_SCANNER_HPP
 

	
 
#include <map>
 
#include "../fileio_func.h"
 
#include "../core/string_compare_type.hpp"
 

	
 
typedef std::map<const char *, class ScriptInfo *, StringCompare> ScriptInfoList; ///< Type for the list of scripts.
 

	
 
/** Scanner to help finding scripts. */
 
class ScriptScanner : public FileScanner {
 
public:
 
	ScriptScanner();
 
	virtual ~ScriptScanner();
 

	
 
	virtual void Initialize() = 0;
 

	
 
	/**
 
	 * 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.
 
	 */
 
	const char *GetMainScript() { return this->main_script; }
 
	std::string GetMainScript() { return this->main_script; }
 

	
 
	/**
 
	 * Get the current tar file the ScanDir is currently tracking.
 
	 */
 
	const char *GetTarFile() { return this->tar_file; }
 
	std::string GetTarFile() { return this->tar_file; }
 

	
 
	/**
 
	 * 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);
 

	
 
	/**
 
	 * Find a script of a #ContentInfo
 
	 * @param ci The information to compare to.
 
	 * @param md5sum Whether to check the MD5 checksum.
 
	 * @return A filename of a file of the content, else \c nullptr.
 
	 */
 
	const char *FindMainScript(const ContentInfo *ci, bool md5sum);
 

	
 
	bool AddFile(const char *filename, size_t basepath_length, const char *tar_filename) override;
 
	bool AddFile(const std::string &filename, size_t basepath_length, const std::string &tar_filename) override;
 

	
 
	/**
 
	 * Rescan the script dir.
 
	 */
 
	void RescanDir();
 

	
 
protected:
 
	class Squirrel *engine; ///< The engine we're scanning with.
 
	char *main_script;      ///< The full path of the script.
 
	char *tar_file;         ///< If, which tar file the script was in.
 
	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.
 

	
 
	/**
 
	 * Initialize the scanner.
 
	 * @param name The name of the scanner ("AIScanner", "GSScanner", ..).
 
	 */
 
	void Initialize(const char *name);
 

	
 
	/**
 
	 * Get the script name how to store the script in memory.
 
	 */
 
	virtual void GetScriptName(ScriptInfo *info, char *name, const char *last) = 0;
 

	
 
	/**
 
	 * 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;