Launcher, based on PickleLauncher
[mupen64plus-pandora.git] / source / mupen64launcher / src / cprofile.h
... / ...
CommitLineData
1/**
2 * @section LICENSE
3 *
4 * PickleLauncher
5 * Copyright (C) 2010-2011 Scott Smith
6 *
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 *
20 * @section LOCATION
21 */
22
23#ifndef CPROFILE_H
24#define CPROFILE_H
25
26#include "cbase.h"
27#include "czip.h"
28
29using namespace std;
30
31#define ZIP_EXT ".zip" /** The zip extension. */
32
33#define PROFILE_TARGETAPP "targetapp=" /** Prefix for the profile file to identify the path the target application. */
34#define PROFILE_FILEPATH "filepath=" /** Prefix for the profile file to identify the initial path for files. */
35#define PROFILE_BLACKLIST "blacklist=" /** Prefix for the profile file to identify items not to be displayed. */
36#define PROFILE_CMDPATH "cmdpath=" /** Prefix for the profile file to identify a command path and binary. */
37#define PROFILE_CMDARG "cmdarg=" /** Prefix for the profile file to identify a command argument. */
38#define PROFILE_EXEPATH "exepath=" /** Prefix for the profile file to identify the executable path. */
39#define PROFILE_EXEFORCE "exeforce=" /** Prefix for the profile file to identify the forced executable path for certain files. */
40#define PROFILE_EXTARG "extarg=" /** Prefix for the profile file to identify the executable path. */
41#define PROFILE_ARGFORCE "argforce=" /** Prefix for the profile file to identify the executable argument force. */
42#define PROFILE_ENTRY_ARGS "entryargs=" /** Prefix for the profile file to identify an entry custom argument values. */
43#define PROFILE_ENTRY_CMDS "entrycmds=" /** Prefix for the profile file to identify an entry custom command values. */
44
45#define EXT_DIRS "dirs" /** Special extension identifier for directories. */
46#define VALUE_FILENAME "%filename%" /** Profile keyword that is replaced by the path to selected file. */
47#define VALUE_NOVALUE "%na%" /** Profile keyword that identifies a empty option. */
48#define VALUE_FLAGONLY "%flagonly%" /** Profile keyword that identifies a empty option. */
49
50#define MAX_PATH 1024 /** Maximum path length. */
51#define ARG_MIN_COUNT 4 /** Minumum options for an argument. */
52#define ARGFORCE_COUNT 3 /** Minumum options for an argument force. */
53#define EXEFORCE_COUNT 2 /** Minumum options for an exe force. */
54#define TOTAL_LETTERS 27 /** 26 alpha chars plus 1 for anything else */
55
56//SEB
57#define PROFILE_PLUGIN "plugin" /** Plugin name in profile */
58#define PROFILE_PLUGINTXT "plugintxt" /** Plugin .txt file */
59#define PROFILE_PLUGINNAME "pluginname" /** Plugin clear name */
60
61/** @brief Type of items that can be displayed in selection mode
62 */
63enum ITEMTYPES_T {
64 TYPE_DIR=0, /** @brief Directory */
65 TYPE_FILE, /** @brief File */
66 TYPE_ZIP /** @brief Zipfile */
67};
68
69/** @brief Data structure for of items that can be displayed in selection mode
70 */
71struct listitem_t {
72 listitem_t() : Type(0), Entry(-1), Name("") {};
73 uint8_t Type; /** @brief The type of item, file/dir/etc. */
74 int16_t Entry; /** @brief The entry index assoicated with this item. */
75 string Name; /** @brief The name of the list item. */
76};
77
78/** @brief Data structure for of options that can be displayed in selection mode
79 */
80struct listoption_t {
81 listoption_t() : Extension(-1), Command(-1), Argument(-1), Name("") {};
82 int16_t Extension; /** @brief Index to the extension for the option */
83 int16_t Command; /** @brief Index to the command for the option (-1 if not a command) */
84 int16_t Argument; /** @brief Index to the argument for the option */
85 string Name; /** @brief Display name for the option */
86};
87
88/** @brief Data structure for an argument
89 */
90struct argument_t {
91 argument_t() : Default(0), Flag(""), Names(), Values() {};
92 int8_t Default; /** @brief Index to the default value for the argument */
93 string Flag; /** @brief Flag that is used in the command line string which is followed by the value */
94 vector<string> Names; /** @brief Names for the possible values */
95 vector<string> Values; /** @brief Values for the argument */
96};
97
98/** @brief Data structure for overriding argument values that reside in the path
99 */
100struct argforce_t {
101 argforce_t() : Argument(0), Path(""), Value("") {};
102 uint8_t Argument; /** @brief The index of the agrument to override */
103 string Path; /** @brief The location of target files to override */
104 string Value; /** @brief Value to overide the argument with */
105};
106
107/** @brief Data structure for overriding the exe path for listed files.
108 */
109struct exeforce_t {
110 exeforce_t() : exeName(""), exePath(""), Files() {};
111 string exeName; /** @brief The executable name to pass the detected files to. */
112 string exePath; /** @brief The path to the executable. */
113 vector<string> Files; /** @brief Value to overide the argument with */
114};
115
116/** @brief Data structure for an command that is run before the application
117 */
118struct command_t {
119 command_t() : Name(""), Command(""), Path(""), Arguments() {};
120 string Name; /** @brief Display name for the command. */
121 string Command; /** @brief Executable name for the command. */
122 string Path; /** @brief Path to the executable. */
123 vector<argument_t> Arguments; /** @brief Arguments to apply to the command. */
124};
125
126/** @brief Data structure for an file extension type
127 */
128struct extension_t {
129 extension_t() : exeName(""), exePath(""), extName(), Blacklist(), Arguments(), ArgForces(), ExeForces() {};
130 string exeName; /** @brief The executable name to pass the detected files to. */
131 string exePath; /** @brief The path to the executable. */
132 vector<string> extName; /** @brief The extenion (usually 3 letters). */
133 vector<string> Blacklist; /** @brief List of filenames that will be filtered from the selection output. */
134 vector<argument_t> Arguments; /** @brief Arguments to apply to the appliction. */
135 vector<argforce_t> ArgForces; /** @brief Overide arguments based on path. */
136 vector<exeforce_t> ExeForces; /** @brief Overide the exe path based on file names. */
137};
138
139/** @brief Data structure for a detected entry that has been set with custom arg/cmd values
140 */
141struct entry_t {
142 entry_t() : Custom(false), Name(""), Path(""), Alias(""), CmdValues(), ArgValues() {};
143 bool Custom; /** @brief Does the entry have values that are different than the defaults */
144 string Name; /** @brief Name of the entry */
145 string Path; /** @brief Path to the file */
146 string Alias; /** @brief Overides the actual filename for display */
147 vector<uint16_t> CmdValues; /** @brief The current selected values for the commands */
148 vector<uint16_t> ArgValues; /** @brief The current selected values for the arguments */
149};
150
151//SEB
152/** @brief Data structure for a plugin that has been set in profile
153 */
154struct oneplugin_t {
155 oneplugin_t() : So(""), Name(""), Desc("") {};
156 string So; /** @brief So Name of the entry */
157 string Name; /** @brief Clear Name to the file */
158 string Desc; /** @brief Description of plugin */
159};
160
161/** @brief Data structure for a plugin that has been set in profile
162 */
163struct plugin_t {
164 plugin_t() : Name(""), TextFile(""), Alias(""), Which(0), Rom(-1), Plugins() {};
165 string Name; /** @brief Name of the entry */
166 string TextFile; /** @brief Path to the file */
167 string Alias; /** @brief Overides the actual filename for display */
168 uint16_t Which; /** @brief Current selected plugin */
169 int16_t Rom; /** @brief Current plugin for selected Rom */
170 vector<oneplugin_t> Plugins; /** @brief The current plugins */
171};
172
173/** @brief This class controls loading, processing, and saving of profile data
174 */
175class CProfile : public CBase
176{
177 public:
178 /** Constructor. */
179 CProfile();
180 /** Destructor. */
181 virtual ~CProfile();
182
183 /** @brief Load the profile data from file and store in memory.
184 * @param location : path to the profile file.
185 * @param delimiter : the delimiter used between options.
186 * @return 0 if passed 1 if failed.
187 */
188 int8_t Load ( const string& location, const string& delimiter );
189
190 /** @brief Save the profile data to file from memory.
191 * @param location : path to the profile file.
192 * @param delimiter : the delimiter used between options.
193 * @return 0 if passed 1 if failed.
194 */
195 int8_t Save ( const string& location, const string& delimiter );
196
197 /** @brief Load a command from a line from the profile.
198 * @param fin : file input.
199 * @param line : current read line.
200 * @param delimiter : the delimiter used between options.
201 * @return 0 if passed 1 if failed.
202 */
203 int8_t LoadCmd ( ifstream& fin, string& line, const string& delimiter );
204
205 /** @brief Load plugins from the profile.
206 * @return 0 if passed 1 if failed.
207 */
208 int8_t LoadPlugins ( );
209
210 /** @brief Load a extension from a line from the profile.
211 * @param fin : file input.
212 * @param line : current read line.
213 * @param delimiter : the delimiter used between options.
214 * @return 0 if passed 1 if failed.
215 */
216 int8_t LoadExt ( ifstream& fin, string& line, const string& delimiter );
217
218 /** @brief Load a entry from a line from the profile.
219 * @param fin : file input.
220 * @param line : current read line.
221 * @param delimiter : the delimiter used between options.
222 * @return 0 if passed 1 if failed.
223 */
224 int8_t LoadEntry ( ifstream& fin, string& line, const string& delimiter );
225
226 /** @brief Scan an entry for command and arguments and load them into a list.
227 * @param item : the selected item from the list.
228 * @param items : list to load into.
229 * @return 0 if passed 1 if failed.
230 */
231 int8_t ScanEntry ( listitem_t& item, vector<listoption_t>& items );
232
233 /** @brief Add an entry that will contain custom values.
234 * @param argument : argument with the custom value.
235 * @param name : name for the new entry.
236 * @return -1 if failed, else the new size of the entry list.
237 */
238 int16_t AddEntry ( listoption_t& argument, const string& name );
239
240 /** @brief Scan an entry for values and load them into a list.
241 * @param item : argument with the custom value.
242 * @param values : values for the argument.
243 */
244 void ScanArgument ( listoption_t& item, vector<string>& values );
245
246 /** @brief Scan an the current path for dirs and runable files.
247 * @param location : path the scan.
248 * @param showhidden : if true include hidden items in output list, else ignore.
249 * @param showzip : if true include zip items in output list, else put through filters.
250 * @param items : entries det.
251 * @return 0 if passed 1 if failed.
252 */
253 int8_t ScanDir ( string location, bool showhidden, bool showzip, vector<listitem_t>& items );
254
255 /** @brief Find the extension a file belongs to.
256 * @param ext : extension to search for.
257 * @return -1 if failed, else the index of the ext structure.
258 */
259 int16_t FindExtension ( const string& ext );
260
261 /** @brief Scan def. plugins and load them into a list.
262 * @param values : values for the argument.
263 */
264 void ScanDefPlugins ( vector<listoption_t>& items );
265
266 /** @brief Scan rom plugins and load them into a list.
267 * @param values : values for the argument.
268 */
269 void ScanRomPlugins ( const string& name, vector<listoption_t>& items );
270
271 /** @brief Scan def. one plugin type and load them into a list.
272 * @param which : which of the default plugins
273 * @param values : values for the argument.
274 */
275 void ScanDef1Plugins ( int8_t which, vector<listitem_t>& items );
276
277 void ScanRom1Plugins ( int8_t which, vector<listitem_t>& items );
278
279 /** @brief Save 1 type of default plugin
280 */
281 void SaveDef1Plugin ( int8_t which, int8_t index );
282
283 /** @brief Save plugin for curent Rom
284 */
285 void SaveRom1Plugin ( int8_t which, int8_t index );
286
287 /** @brief Get CRC of Rom file
288 */
289 string RomCRC (const string& name);
290
291 int8_t FindPlugin(const string& name);
292 int8_t Find1Plugin(int8_t which, const string& name);
293
294 bool LaunchableDirs; /**< If true directories are considered as launchable, if false browsing is on. */
295 string LauncherPath; /**< Path where the launcher was executed from. */
296 string LauncherName; /**< Name of the launcher when executed. */
297 string FilePath; /**< Current path for searching for runable files. */
298 string TargetApp; /**< Label for the target appliction the launcher is executing. */
299 string ZipFile; /**< If not empty then the currently loaded zip file. */
300 string EntryFilter;
301 vector<command_t> Commands; /**< Commands to be run before executing the target application. */
302 vector<extension_t> Extensions; /**< File extensions runable by the target application. */
303 vector<entry_t> Entries; /**< Entries with custom values. */
304 vector<int16_t> AlphabeticIndices; /**< Set to cause the current directory to be rescaned. */
305 string Rom; /**< CRC of the current rom */
306 //SEB
307 vector<plugin_t> Plugins; /**< All plugins */
308 CZip Minizip; /**< Handles examing and extracting zip files. */
309};
310
311bool CompareItems( listitem_t a, listitem_t b ); /**< Compare two listitems, which sort by type and then by name. */
312
313#endif // CPROFILE_H