1 |
cycrow |
1 |
/*
|
|
|
2 |
SPKTool V1.00 Created by Cycrow (Matthew Gravestock)
|
|
|
3 |
*/
|
|
|
4 |
|
|
|
5 |
// Main Spk File Library Include
|
|
|
6 |
#ifdef _WIN32
|
|
|
7 |
#include <spk.h>
|
|
|
8 |
#include <MultiSpkFile.h>
|
|
|
9 |
#include <spkcmdprogress.h>
|
|
|
10 |
#else
|
|
|
11 |
#include "../spk/spk.h"
|
|
|
12 |
#include "../spk/MultiSpkFile.h"
|
|
|
13 |
#include "../spk/spkcmdprogress.h"
|
|
|
14 |
#endif
|
|
|
15 |
// Multi Spk File format, required if using Multi Spk files
|
|
|
16 |
// Displays 7Zip compression progress to the command line
|
|
|
17 |
#include <time.h>
|
|
|
18 |
#ifdef _WIN32
|
|
|
19 |
#include <windows.h>
|
|
|
20 |
#include <direct.h>
|
|
|
21 |
#include <shlobj.h>
|
|
|
22 |
#endif
|
|
|
23 |
|
|
|
24 |
CyString g_dir;
|
|
|
25 |
bool g_read;
|
|
|
26 |
|
134 |
cycrow |
27 |
class CFileProgress : public CProgressInfo
|
|
|
28 |
{
|
|
|
29 |
private:
|
|
|
30 |
Utils::String _display;
|
|
|
31 |
CBaseFile *_package;
|
|
|
32 |
CPackages *_packages;
|
|
|
33 |
|
|
|
34 |
public:
|
|
|
35 |
CFileProgress(CPackages *packages, CBaseFile *package, const Utils::String &display) :
|
|
|
36 |
_display(display),
|
|
|
37 |
_packages(packages),
|
|
|
38 |
_package(package)
|
|
|
39 |
{
|
|
|
40 |
|
|
|
41 |
}
|
|
|
42 |
|
|
|
43 |
protected:
|
|
|
44 |
void ProgressUpdated(const long cur, const long max)
|
|
|
45 |
{
|
|
|
46 |
}
|
|
|
47 |
void DoingFile(C_File *file)
|
|
|
48 |
{
|
|
|
49 |
Utils::String game;
|
|
|
50 |
|
|
|
51 |
if (!file->game() || file->game() == GAME_ALLNEW)
|
|
|
52 |
game = "All Games";
|
|
|
53 |
else if (_packages)
|
|
|
54 |
{
|
|
|
55 |
for (unsigned int i = 0; i < 31; ++i)
|
|
|
56 |
{
|
|
|
57 |
if (file->game() & (1 << i))
|
|
|
58 |
{
|
|
|
59 |
Utils::String g = _packages->GetGameExe()->GetGameNameFromType(i - 1);
|
|
|
60 |
if (!g.empty())
|
|
|
61 |
{
|
|
|
62 |
if (game.empty())
|
|
|
63 |
game = g;
|
|
|
64 |
else
|
|
|
65 |
game = game + ", " + g;
|
|
|
66 |
}
|
|
|
67 |
}
|
|
|
68 |
}
|
|
|
69 |
}
|
|
|
70 |
|
|
|
71 |
if(game.empty())
|
|
|
72 |
printf("%s: %s\n", _display.c_str(), file->getNameDirectory(_package).c_str());
|
|
|
73 |
else
|
|
|
74 |
printf("%s: %s [%s]\n", _display.c_str(), file->getNameDirectory(_package).c_str(), game.c_str());
|
|
|
75 |
}
|
|
|
76 |
|
|
|
77 |
};
|
|
|
78 |
|
1 |
cycrow |
79 |
/*
|
|
|
80 |
Func: GetInput
|
|
|
81 |
Desc: Gets an input from the user, ie, any settings required to be typed in
|
|
|
82 |
*/
|
127 |
cycrow |
83 |
Utils::String GetInput ()
|
1 |
cycrow |
84 |
{
|
|
|
85 |
g_read = true;
|
|
|
86 |
|
127 |
cycrow |
87 |
Utils::String line;
|
1 |
cycrow |
88 |
char c = getchar();
|
|
|
89 |
|
|
|
90 |
while ( (c != '\n') && (c != '\0') )
|
|
|
91 |
{
|
|
|
92 |
line += c;
|
|
|
93 |
c = getchar();
|
|
|
94 |
}
|
|
|
95 |
|
|
|
96 |
return line;
|
|
|
97 |
}
|
|
|
98 |
|
|
|
99 |
|
|
|
100 |
/*
|
|
|
101 |
Func: PrintSyntax
|
|
|
102 |
Args: String cmd - The command name to be displayed
|
|
|
103 |
Desc: Displays the syntax for the program
|
|
|
104 |
*/
|
|
|
105 |
void PrintSyntax ( CyString cmd )
|
|
|
106 |
{
|
|
|
107 |
printf ( "Syntax: %s <command>\n", cmd.c_str() );
|
|
|
108 |
printf ( "Commands:\n" );
|
134 |
cycrow |
109 |
printf ( "\t-v <spkfile>\n\t--view <spkfile>\n\t\tViews the contents of a spk file\n\n" );
|
1 |
cycrow |
110 |
printf ( "\t-e <spkfile> [destination]\n\t--extractall <spkfile> [destination]\n\t\tExtracts all the files to the destination directory [or current if no destiantion is set]\n\n" );
|
|
|
111 |
printf ( "\t-x <spkfile> <type> <file> [destination]\n\t--extract <spkfile> <type> <file> [destination]\n\t\tExtracts a single file of <type> to destination directory\n\n" );
|
|
|
112 |
printf ( "\t-x <multispkfile> <file> [destination]\n\t--extractspk <multispkfile> <spkfile> [destination]\n\t\tExtracts a single spk file from a Multi-Spk Package\n\n" );
|
|
|
113 |
printf ( "\t-c <spkfile>\n\t--create\n\t\tCreates a new spk file\n\n" );
|
|
|
114 |
printf ( "\t-a <spkfile> <type> <filename>\n\t--append <spkfile> <type> <filename>\n\t\tAppends a file to the package of set <type>\n\n" );
|
|
|
115 |
printf ( "\t-r <spkfile> <type> <filename>\n\t--remove <spkfile> <type> <filename>\n\t\tRemoves a file from the package of set <type>\n\n" );
|
|
|
116 |
printf ( "\t-r <multispkfile> <filename>\n\t--removespk <multispkfile> <filename>\n\t\tRemoves a spk file from the Multi-SPK package\n\n" );
|
|
|
117 |
printf ( "\t-m <spkfile> <spkfile>\n\t--mergemulti <spkfile> <spkfile>\n\t\tMerges spk files together, the second file will be merged into the first\n\n" );
|
|
|
118 |
printf ( "\t-n <multispkfile>\n\t--createmulti\n\t\tCreates a multi spk file, and adds the spkfiles in\n\n" );
|
|
|
119 |
printf ( "\t-s <multispkfile> [destination]\n\t--splitmulti <multispkfile> [destination]\n\t\tSplits a Multi-SPK file up, saves all the spk files to Destination\n\n" );
|
|
|
120 |
printf ( "\t--set <setting> [value]\n\t\tChanges the settings of the script\n\n" );
|
|
|
121 |
printf ( "\t--convertxsp <oldxsp> [newxsp]\n\t\tConverts an old XSP file into the new format\n\n");
|
|
|
122 |
printf ( "\t--createscript <packagescript>\n\t\tCreates a spk file from a packager script\n\n");
|
|
|
123 |
printf ( "\t--verifyscript <packagescript>\n\t\tChecks a packager script is valid without creating the resulting file\n\n");
|
|
|
124 |
printf ( "\t--generatescript <package> [packagescript]\n\t\tCreates a packager script (.sps) from a spk file\n\n");
|
|
|
125 |
printf ( "\t--extractship <modfile> <xspfile> [shipid]\n\t\tCreates an XSP ship file from a mod package\n\n");
|
|
|
126 |
printf ( "\t--generateupdatefile <package>\n\t\tCreates an update file for the spk/xsp file\n\n");
|
126 |
cycrow |
127 |
printf ( "\t--packagelist <filenames>\n\t\tThis will generate the update file to allow downloading packages from a server.\n\n");
|
|
|
128 |
// printf ( "\t--convertxspwizard <oldxsp> [newxsp]\n\t\tConverts an old XSP file into the new format\n\n");
|
1 |
cycrow |
129 |
}
|
|
|
130 |
|
|
|
131 |
void Settings(CyString filename, CyString settings, int argc, char **argv, CyString cmd)
|
|
|
132 |
{
|
|
|
133 |
if ( settings.Compare("author") )
|
|
|
134 |
{
|
|
|
135 |
if ( argc < 5 )
|
|
|
136 |
{
|
|
|
137 |
printf ( "Syntax: %s -set <spkfile> Author <authorname>\n\tSets the authors name of the package\n", cmd.c_str() );
|
|
|
138 |
return;
|
|
|
139 |
}
|
|
|
140 |
}
|
|
|
141 |
else
|
|
|
142 |
{
|
|
|
143 |
printf("Error! Unknown settings: %s\n", settings.c_str());
|
|
|
144 |
return;
|
|
|
145 |
}
|
|
|
146 |
|
|
|
147 |
// first chekc if file even exists
|
|
|
148 |
FILE *id = fopen ( filename.c_str(), "rb+" );
|
|
|
149 |
if ( !id )
|
|
|
150 |
{
|
|
|
151 |
printf ( "Error: File, %s, doesn't exist\n", filename.c_str() );
|
|
|
152 |
return;
|
|
|
153 |
}
|
|
|
154 |
fclose ( id );
|
|
|
155 |
|
175 |
cycrow |
156 |
int check = CSpkFile::CheckFile(filename.ToString());
|
1 |
cycrow |
157 |
if ( check == SPKFILE_SINGLE )
|
|
|
158 |
{
|
|
|
159 |
CSpkFile spkfile;
|
|
|
160 |
printf ( "* Opening SPK File, %s...\n", filename.c_str() );
|
175 |
cycrow |
161 |
if ( !spkfile.readFile(filename.ToString(), SPKREAD_ALL))
|
1 |
cycrow |
162 |
{
|
|
|
163 |
printf ( "Failed to open the spk files, %s\n", filename.c_str() );
|
|
|
164 |
return;
|
|
|
165 |
}
|
|
|
166 |
|
|
|
167 |
// now do the settings
|
|
|
168 |
if ( settings.Compare("author") )
|
|
|
169 |
{
|
50 |
cycrow |
170 |
spkfile.setAuthor(argv[4]);
|
|
|
171 |
printf( "Settings Author to: %s\n", spkfile.author().c_str());
|
1 |
cycrow |
172 |
}
|
|
|
173 |
|
175 |
cycrow |
174 |
spkfile.writeFile(filename.ToString());
|
1 |
cycrow |
175 |
printf ( "\nSPK file has been written sucessfully\n" );
|
|
|
176 |
}
|
|
|
177 |
else
|
|
|
178 |
printf ( "File, %s, is not a valid SPK file\n", filename.c_str() );
|
|
|
179 |
}
|
|
|
180 |
|
|
|
181 |
void SetRating ( CyString filename, int ease, int changing, int rec )
|
|
|
182 |
{
|
|
|
183 |
if ( ease > 5 )
|
|
|
184 |
ease = 5;
|
|
|
185 |
if ( changing > 5 )
|
|
|
186 |
changing = 5;
|
|
|
187 |
if ( changing > 5 )
|
|
|
188 |
changing = 5;
|
|
|
189 |
|
|
|
190 |
FILE *id = fopen ( filename.c_str(), "rb+" );
|
|
|
191 |
if ( !id )
|
|
|
192 |
{
|
|
|
193 |
printf ( "Error: File, %s, doesn't exist\n", filename.c_str() );
|
|
|
194 |
return;
|
|
|
195 |
}
|
|
|
196 |
fclose ( id );
|
|
|
197 |
|
175 |
cycrow |
198 |
int check = CSpkFile::CheckFile(filename.ToString());
|
1 |
cycrow |
199 |
if ( check == SPKFILE_SINGLE )
|
|
|
200 |
{
|
|
|
201 |
CSpkFile spkfile;
|
|
|
202 |
printf ( "* Opening SPK File, %s...\n", filename.c_str() );
|
175 |
cycrow |
203 |
if ( !spkfile.readFile(filename.ToString(), SPKREAD_ALL))
|
1 |
cycrow |
204 |
{
|
|
|
205 |
printf ( "Failed to open the spk files, %s\n", filename.c_str() );
|
|
|
206 |
return;
|
|
|
207 |
}
|
|
|
208 |
|
170 |
cycrow |
209 |
printf("File Format Version: %.2f\n", spkfile.fileVersion());
|
1 |
cycrow |
210 |
|
|
|
211 |
printf ( "Assigning Ease Of Use:\t\t%d\nAssigning Game Changing:\t%d\nAssigning Recommended:\t\t%d\n", ease, changing, rec);
|
46 |
cycrow |
212 |
spkfile.setEaseOfUse(ease);
|
|
|
213 |
spkfile.setGameChanging(changing);
|
|
|
214 |
spkfile.setRecommended(rec);
|
175 |
cycrow |
215 |
spkfile.writeFile(filename.ToString());
|
1 |
cycrow |
216 |
printf ( "\nSPK file has been written sucessfully\n" );
|
|
|
217 |
|
|
|
218 |
}
|
|
|
219 |
else
|
|
|
220 |
printf ( "File, %s, is not a valid SPK file\n", filename.c_str() );
|
|
|
221 |
}
|
|
|
222 |
|
185 |
cycrow |
223 |
Utils::String GetTerranConflictDir()
|
1 |
cycrow |
224 |
{
|
|
|
225 |
while ( true )
|
|
|
226 |
{
|
|
|
227 |
printf ( "\nPlease enter the directory for terran conflict: ");
|
185 |
cycrow |
228 |
Utils::String dir = GetInput();
|
|
|
229 |
if ( dir.empty() )
|
|
|
230 |
return Utils::String::Null();
|
1 |
cycrow |
231 |
|
|
|
232 |
// check if the directory exists
|
185 |
cycrow |
233 |
if ( CFileIO::Exists(dir + "/x3tc.exe") )
|
1 |
cycrow |
234 |
return dir;
|
|
|
235 |
printf("\nTerran Conflict installation doesn't exist: %s\n\n", dir.c_str());
|
|
|
236 |
}
|
|
|
237 |
|
185 |
cycrow |
238 |
return Utils::String::Null();
|
1 |
cycrow |
239 |
}
|
|
|
240 |
|
185 |
cycrow |
241 |
void ConvertXsp(const Utils::String &filename, const Utils::String &tofile, bool wizard)
|
1 |
cycrow |
242 |
{
|
|
|
243 |
// first chekc if file even exists
|
|
|
244 |
FILE *id = fopen ( filename.c_str(), "rb+" );
|
|
|
245 |
if ( !id )
|
|
|
246 |
{
|
|
|
247 |
printf ( "Error: File, %s, doesn't exist\n", filename.c_str() );
|
|
|
248 |
return;
|
|
|
249 |
}
|
|
|
250 |
fclose ( id );
|
|
|
251 |
|
|
|
252 |
// check its not a new format already
|
185 |
cycrow |
253 |
int check = CSpkFile::CheckFile(filename);
|
160 |
cycrow |
254 |
if ( check == SPKFILE_INVALID && CFileIO(filename).isFileExtension("xsp") )
|
1 |
cycrow |
255 |
{
|
|
|
256 |
printf ( "* Converting XSP File, %s... ", filename.c_str() );
|
|
|
257 |
CXspFile xspFile;
|
185 |
cycrow |
258 |
if ( !xspFile.ConvertOld(filename) )
|
1 |
cycrow |
259 |
{
|
|
|
260 |
printf ( "[ERROR]\n\nFailed to convert old xsp file, %s\n", filename.c_str() );
|
|
|
261 |
return;
|
|
|
262 |
}
|
|
|
263 |
|
|
|
264 |
printf ( "[DONE]\n");
|
|
|
265 |
|
|
|
266 |
CyString dir;
|
|
|
267 |
printf ("Do you want to create weapon masks for Terran conflict? ");
|
|
|
268 |
CyString input = GetInput();
|
|
|
269 |
if ( input.Compare("y") || input.Compare("yes") )
|
|
|
270 |
{
|
|
|
271 |
dir = GetTerranConflictDir();
|
|
|
272 |
if ( !dir.Empty() )
|
|
|
273 |
{
|
|
|
274 |
}
|
|
|
275 |
}
|
|
|
276 |
|
|
|
277 |
printf ( "* Writing XSP File, %s... ", tofile.c_str() );
|
|
|
278 |
// now we need to save it
|
185 |
cycrow |
279 |
if ( !xspFile.writeFile(tofile) )
|
1 |
cycrow |
280 |
printf ( "[ERROR]\n\nFailed to write file to, %s\n", tofile.c_str() );
|
|
|
281 |
else
|
|
|
282 |
printf ( "[DONE]\n\nFile: %s, has been converted to, %s\n", filename.c_str(), tofile.c_str() );
|
|
|
283 |
}
|
|
|
284 |
else
|
|
|
285 |
printf ( "Error: File, %s, is not an old style XSP file\n", filename.c_str() );
|
|
|
286 |
}
|
|
|
287 |
|
185 |
cycrow |
288 |
void ExtractShip(const Utils::String &catfile, const Utils::String &to, Utils::String shipid)
|
1 |
cycrow |
289 |
{
|
185 |
cycrow |
290 |
if ( !CFileIO::Exists(catfile) )
|
1 |
cycrow |
291 |
{
|
|
|
292 |
printf ( "Error: Mod File, %s, does not exist\n", catfile.c_str() );
|
|
|
293 |
return;
|
|
|
294 |
}
|
|
|
295 |
|
36 |
cycrow |
296 |
CVirtualFileSystem *pVfs = new CVirtualFileSystem();
|
185 |
cycrow |
297 |
if ( !pVfs->loadMod(catfile) ) {
|
1 |
cycrow |
298 |
printf("Error: Unable to read mod file, %s\n", catfile.c_str());
|
36 |
cycrow |
299 |
delete pVfs;
|
1 |
cycrow |
300 |
return;
|
|
|
301 |
}
|
|
|
302 |
|
101 |
cycrow |
303 |
Utils::CStringList *ships = pVfs->getTShipsEntries();
|
1 |
cycrow |
304 |
if ( !ships )
|
|
|
305 |
{
|
|
|
306 |
printf("Error: Failed to read %s::types\\TShips.pck\n", catfile.c_str());
|
36 |
cycrow |
307 |
delete pVfs;
|
1 |
cycrow |
308 |
return;
|
|
|
309 |
}
|
|
|
310 |
|
|
|
311 |
// now get the ship line to extract
|
101 |
cycrow |
312 |
Utils::String tShipsLine;
|
185 |
cycrow |
313 |
if (shipid.empty())
|
1 |
cycrow |
314 |
{
|
|
|
315 |
// no ship id, lets get one
|
101 |
cycrow |
316 |
Utils::String ids[2];
|
1 |
cycrow |
317 |
int i = 0;
|
|
|
318 |
int id = 0;
|
116 |
cycrow |
319 |
for ( Utils::SStringList *str = ships->first(); str; str = ships->next() )
|
1 |
cycrow |
320 |
{
|
116 |
cycrow |
321 |
ids[i++] = str->data;
|
1 |
cycrow |
322 |
if ( i >= 2 )
|
|
|
323 |
{
|
|
|
324 |
printf("[%3d][%30s]\t[%3d][%30s]\n", id - 1, ids[0].c_str(), id, ids[1].c_str());
|
|
|
325 |
for ( i = 0; i < 2; i++ )
|
|
|
326 |
ids[i] = "";
|
|
|
327 |
i = 0;
|
|
|
328 |
}
|
|
|
329 |
++id;
|
|
|
330 |
}
|
|
|
331 |
if ( i == 1 )
|
|
|
332 |
printf("[%3d][%30s]\n", id, ids[0].c_str());
|
|
|
333 |
printf("Enter ID to use > ");
|
|
|
334 |
shipid = GetInput();
|
|
|
335 |
|
185 |
cycrow |
336 |
if ( shipid.isNumber() )
|
|
|
337 |
tShipsLine = ships->get(shipid.toInt())->str;
|
1 |
cycrow |
338 |
else
|
185 |
cycrow |
339 |
tShipsLine = ships->findData(shipid, true);
|
1 |
cycrow |
340 |
}
|
|
|
341 |
else
|
185 |
cycrow |
342 |
ships->findData(shipid, true);
|
1 |
cycrow |
343 |
|
101 |
cycrow |
344 |
if ( tShipsLine.empty() )
|
1 |
cycrow |
345 |
{
|
|
|
346 |
printf("Error, %s is not a valid ship id to use\n", shipid.c_str());
|
36 |
cycrow |
347 |
delete pVfs;
|
1 |
cycrow |
348 |
return;
|
|
|
349 |
}
|
|
|
350 |
|
|
|
351 |
// now we have the tships to use, lets start to extract the ship
|
101 |
cycrow |
352 |
printf("Extracting ship from %s, Ship=%s\n", catfile.c_str(), tShipsLine.token(";", -2).c_str());
|
1 |
cycrow |
353 |
|
|
|
354 |
CXspFile ship;
|
101 |
cycrow |
355 |
if ( ship.extractShip(pVfs, tShipsLine.token(";", -2), 0) )
|
1 |
cycrow |
356 |
{
|
|
|
357 |
printf ( "Ship has been successfully extracted\n" );
|
|
|
358 |
|
170 |
cycrow |
359 |
printf("\t- Models:\t %d\n", ship.countFiles(FILETYPE_SHIPMODEL));
|
|
|
360 |
printf("\t- Textures:\t %d\n", ship.countFiles(FILETYPE_SHIPOTHER));
|
1 |
cycrow |
361 |
printf("\t- Dummies:\t %d\n", ship.GetDummies()->size());
|
|
|
362 |
printf("\t- Components:\t %d\n", ship.GetComponents()->size());
|
170 |
cycrow |
363 |
printf("\t- Bodies:\t %d\n", ship.getBodies().size());
|
1 |
cycrow |
364 |
printf("\t- Cockpits:\t %d\n", ship.GetCockpits()->size());
|
|
|
365 |
printf("\t- Text Entries:\t %d\n", ship.GetTexts()->size());
|
|
|
366 |
|
|
|
367 |
printf("\nEnter the name for the ship: ");
|
127 |
cycrow |
368 |
ship.setName(GetInput());
|
1 |
cycrow |
369 |
printf("Enter the author for the ship: ");
|
127 |
cycrow |
370 |
ship.setAuthor(GetInput());
|
1 |
cycrow |
371 |
printf("Enter the version for the ship: V");
|
127 |
cycrow |
372 |
ship.setVersion(GetInput());
|
1 |
cycrow |
373 |
printf("Enter the description for the ship: ");
|
127 |
cycrow |
374 |
ship.setDescription(GetInput());
|
1 |
cycrow |
375 |
|
|
|
376 |
struct tm *currDate;
|
|
|
377 |
char dateString[100];
|
|
|
378 |
time_t now = time(NULL);
|
|
|
379 |
currDate = localtime( &now );
|
|
|
380 |
strftime(dateString, sizeof dateString, "%d/%m/%Y", currDate);
|
50 |
cycrow |
381 |
ship.setCreationDate(dateString);
|
1 |
cycrow |
382 |
|
|
|
383 |
printf("\nWriting file: %s...\n", to.c_str());
|
185 |
cycrow |
384 |
if ( ship.writeFile(to) )
|
1 |
cycrow |
385 |
printf("Ship file has been created: %s\n", to.c_str());
|
|
|
386 |
else
|
|
|
387 |
printf("Error: Unable to write ship file, %s\n", to.c_str());
|
|
|
388 |
}
|
|
|
389 |
else
|
|
|
390 |
printf("Error: Unable to extract the ship\n");
|
36 |
cycrow |
391 |
|
|
|
392 |
delete pVfs;
|
1 |
cycrow |
393 |
}
|
|
|
394 |
|
|
|
395 |
CyString GetGameName(int game)
|
|
|
396 |
{
|
|
|
397 |
switch(game)
|
|
|
398 |
{
|
|
|
399 |
case GAME_X2:
|
|
|
400 |
return "X2: The Threat";
|
|
|
401 |
case GAME_X3:
|
|
|
402 |
return "X3: Reunion";
|
|
|
403 |
case GAME_X3TC:
|
|
|
404 |
return "X3: Terran Conflict";
|
|
|
405 |
case GAME_X3AP:
|
|
|
406 |
return "X3: Albion Prelude";
|
126 |
cycrow |
407 |
case GAME_X3FL:
|
|
|
408 |
return "X3: Farnham's Legacy";
|
1 |
cycrow |
409 |
}
|
|
|
410 |
return "Unknown";
|
|
|
411 |
}
|
134 |
cycrow |
412 |
void DisplayVersion(const Utils::String &filename)
|
1 |
cycrow |
413 |
{
|
|
|
414 |
// first chekc if file even exists
|
|
|
415 |
FILE *id = fopen ( filename.c_str(), "rb+" );
|
|
|
416 |
if ( !id )
|
|
|
417 |
{
|
|
|
418 |
printf ( "Error: File, %s, doesn't exist\n", filename.c_str() );
|
|
|
419 |
return;
|
|
|
420 |
}
|
|
|
421 |
fclose ( id );
|
|
|
422 |
|
|
|
423 |
bool read = false;
|
|
|
424 |
CBaseFile *pBaseFile = NULL;
|
|
|
425 |
|
|
|
426 |
int check = CSpkFile::CheckFile ( filename );
|
|
|
427 |
if ( check == SPKFILE_BASE )
|
|
|
428 |
{
|
|
|
429 |
pBaseFile = new CBaseFile();
|
|
|
430 |
printf ( "* Opening SPK File, %s...\n", filename.c_str() );
|
175 |
cycrow |
431 |
if ( !pBaseFile->readFile(filename, SPKREAD_NODATA))
|
1 |
cycrow |
432 |
{
|
|
|
433 |
printf ( "Failed to open the spk files, %s\n", filename.c_str() );
|
|
|
434 |
return;
|
|
|
435 |
}
|
|
|
436 |
read = true;
|
|
|
437 |
}
|
|
|
438 |
else if ( check == SPKFILE_SINGLE )
|
|
|
439 |
{
|
|
|
440 |
pBaseFile = (CBaseFile *)new CSpkFile();
|
|
|
441 |
printf ( "* Opening SPK File, %s...\n", filename.c_str() );
|
175 |
cycrow |
442 |
if ( !pBaseFile->readFile(filename, SPKREAD_NODATA))
|
1 |
cycrow |
443 |
{
|
|
|
444 |
printf ( "Failed to open the spk files, %s\n", filename.c_str() );
|
|
|
445 |
return;
|
|
|
446 |
}
|
|
|
447 |
read = true;
|
|
|
448 |
}
|
|
|
449 |
else if ( check == SPKFILE_SINGLESHIP )
|
|
|
450 |
{
|
|
|
451 |
pBaseFile = (CBaseFile *)new CXspFile();
|
|
|
452 |
printf ( "* Opening XSP File, %s...\n", filename.c_str() );
|
175 |
cycrow |
453 |
if ( !pBaseFile->readFile(filename, SPKREAD_NODATA))
|
1 |
cycrow |
454 |
{
|
|
|
455 |
printf ( "Failed to open the xsp files, %s\n", filename.c_str() );
|
|
|
456 |
return;
|
|
|
457 |
}
|
|
|
458 |
read = true;
|
|
|
459 |
}
|
|
|
460 |
// otherwise its an old ship file
|
160 |
cycrow |
461 |
else if ( CFileIO(filename).isFileExtension("xsp") )
|
1 |
cycrow |
462 |
{
|
|
|
463 |
printf ( "* Converting XSP File, %s...\n", filename.c_str() );
|
|
|
464 |
pBaseFile = new CXspFile;
|
134 |
cycrow |
465 |
if ( !((CXspFile *)pBaseFile)->ConvertOld(filename) )
|
1 |
cycrow |
466 |
{
|
|
|
467 |
delete pBaseFile;
|
|
|
468 |
pBaseFile = NULL;
|
|
|
469 |
printf ( "Failed to convert old xsp file, %s\n", filename.c_str() );
|
|
|
470 |
return;
|
|
|
471 |
}
|
|
|
472 |
check = SPKFILE_SINGLESHIP;
|
|
|
473 |
read = true;
|
|
|
474 |
}
|
|
|
475 |
|
|
|
476 |
if ( pBaseFile && read)
|
|
|
477 |
{
|
|
|
478 |
CPackages p;
|
134 |
cycrow |
479 |
p.startup(".", ".", ".");
|
1 |
cycrow |
480 |
|
|
|
481 |
CSpkFile *pSpkFile = NULL;
|
|
|
482 |
CXspFile *pXspFile = NULL;
|
|
|
483 |
if ( check == SPKFILE_SINGLE )
|
|
|
484 |
pSpkFile = (CSpkFile *)pBaseFile;
|
|
|
485 |
else
|
|
|
486 |
pXspFile = (CXspFile *)pBaseFile;
|
|
|
487 |
|
170 |
cycrow |
488 |
printf("File Format Version: %.2f\n", pBaseFile->fileVersion());
|
1 |
cycrow |
489 |
|
|
|
490 |
CyString sType;
|
|
|
491 |
if ( check == SPKFILE_SINGLESHIP )
|
|
|
492 |
sType = "Ship";
|
|
|
493 |
else
|
|
|
494 |
sType = "Package";
|
|
|
495 |
|
50 |
cycrow |
496 |
printf ( "%s Name: %s\n", sType.c_str(), pBaseFile->name().c_str() );
|
49 |
cycrow |
497 |
if ( !pBaseFile->email().empty() )
|
50 |
cycrow |
498 |
printf ( "%s Author: %s (%s)\n", sType.c_str(), pBaseFile->author().c_str(), pBaseFile->email().c_str() );
|
1 |
cycrow |
499 |
else
|
50 |
cycrow |
500 |
printf ( "%s Author: %s\n", sType.c_str(), pBaseFile->author().c_str() );
|
|
|
501 |
if ( !pBaseFile->version().empty() ) printf ( "%s Version: %s\n", sType.c_str(), pBaseFile->version().c_str() );
|
1 |
cycrow |
502 |
|
|
|
503 |
//for game
|
|
|
504 |
printf("For Games: ");
|
|
|
505 |
if ( !pBaseFile->AnyGameCompatability() )
|
|
|
506 |
printf("All");
|
|
|
507 |
else
|
152 |
cycrow |
508 |
printf("%s", p.getGameTypesString(pBaseFile, true).c_str());
|
1 |
cycrow |
509 |
printf("\n");
|
|
|
510 |
|
|
|
511 |
if ( pXspFile )
|
|
|
512 |
{
|
|
|
513 |
printf ("Ship Display Name: %s\n", pXspFile->GetShipName(44).c_str());
|
|
|
514 |
if ( pXspFile->IsExistingShip() )
|
|
|
515 |
printf ( "Ship ID: %s (Replace Existing Ship)\n", pXspFile->GetShipID().c_str() );
|
|
|
516 |
else
|
|
|
517 |
printf ( "Ship ID: %s\n", pXspFile->GetShipID().c_str() );
|
|
|
518 |
|
|
|
519 |
if ( pXspFile->AnyShipyards() )
|
|
|
520 |
{
|
|
|
521 |
printf ( "Add To Shipyards:\n" );
|
|
|
522 |
for ( int i = 1; i <= GetMaxShipyards(); i *= 2 )
|
|
|
523 |
{
|
|
|
524 |
if ( pXspFile->IsShipyard(i) )
|
|
|
525 |
printf("\t%s\n", GetShipyardName(i).c_str());
|
|
|
526 |
}
|
|
|
527 |
}
|
|
|
528 |
|
|
|
529 |
for ( SWeaponMask *text = pXspFile->GetLaserMasks()->First(); text; text = pXspFile->GetLaserMasks()->Next() )
|
|
|
530 |
printf ( "Laser Mask, Game: %s, Mask: %d\n", GetGameName(text->iGame).c_str(), text->iMask);
|
|
|
531 |
for ( SWeaponMask *text = pXspFile->GetMissileMasks()->First(); text; text = pXspFile->GetMissileMasks()->Next() )
|
|
|
532 |
printf ( "Missile Mask, Game: %s, Mask: %d\n", GetGameName(text->iGame).c_str(), text->iMask);
|
|
|
533 |
|
|
|
534 |
if ( pXspFile->GetOriginalDescription() )
|
|
|
535 |
printf("Use Existing Text, ID: %d\n", pXspFile->GetOriginalDescription());
|
|
|
536 |
|
|
|
537 |
if ( pXspFile->AnyTexts() )
|
|
|
538 |
{
|
|
|
539 |
for ( SText *text = pXspFile->GetTexts()->First(); text; text = pXspFile->GetTexts()->Next() )
|
|
|
540 |
{
|
|
|
541 |
printf("Ship Text, Language: %d\n", text->iId);
|
39 |
cycrow |
542 |
if ( !text->sName.empty() )
|
1 |
cycrow |
543 |
printf("\tName: %s\n", text->sName.c_str());
|
39 |
cycrow |
544 |
if ( !text->sDesc.empty() )
|
1 |
cycrow |
545 |
printf("\tDescription: %s\n", text->sDesc.c_str());
|
|
|
546 |
}
|
|
|
547 |
}
|
|
|
548 |
|
|
|
549 |
if ( pXspFile->AnyComponents() )
|
|
|
550 |
{
|
|
|
551 |
printf ( "Component Entries:\n" );
|
|
|
552 |
for ( SComponent *c = pXspFile->GetComponents()->First(); c; c = pXspFile->GetComponents()->Next() )
|
|
|
553 |
printf ( "\t%s\n\t\t%s\n\t\t\t%s\n", c->sSection.c_str(), c->sSection2.c_str(), c->sData.c_str());
|
|
|
554 |
}
|
|
|
555 |
if ( pXspFile->AnyDummies() )
|
|
|
556 |
{
|
|
|
557 |
printf ( "Dummy Entries:\n" );
|
|
|
558 |
for ( SDummy *d = pXspFile->GetDummies()->First(); d; d = pXspFile->GetDummies()->Next() )
|
|
|
559 |
printf ( "\t%s\n\t\t%s\n", d->sSection.c_str(), d->sData.c_str());
|
|
|
560 |
}
|
|
|
561 |
if ( pXspFile->AnyCockpits() )
|
|
|
562 |
{
|
|
|
563 |
printf ( "Cockpit Entries:\n" );
|
|
|
564 |
for ( SCockpit *c = pXspFile->GetCockpits()->First(); c; c = pXspFile->GetCockpits()->Next() )
|
|
|
565 |
printf("\t%s\n", c->sCockpit.c_str());
|
|
|
566 |
}
|
165 |
cycrow |
567 |
if ( pXspFile->anyCutData() )
|
1 |
cycrow |
568 |
{
|
165 |
cycrow |
569 |
printf ( "CutData Entries [%d]:\n", pXspFile->getCutData().size() );
|
|
|
570 |
for(auto itr = pXspFile->getCutData().begin(); itr != pXspFile->getCutData().end(); itr++)
|
|
|
571 |
printf("\t%s\n", (*itr)->str.c_str());
|
1 |
cycrow |
572 |
}
|
|
|
573 |
}
|
|
|
574 |
|
50 |
cycrow |
575 |
if ( !pBaseFile->creationDate().empty() ) printf ( "Creation Date: %s\n", pBaseFile->creationDate().c_str() );
|
48 |
cycrow |
576 |
if ( !pBaseFile->description().empty() ) printf ( "Description: %s\n", pBaseFile->description().c_str() );
|
1 |
cycrow |
577 |
if ( pSpkFile )
|
|
|
578 |
{
|
|
|
579 |
if ( pSpkFile->IsLibrary() )
|
|
|
580 |
printf ( "Script Type: Library\n" );
|
|
|
581 |
else if ( pSpkFile->IsPatch() )
|
|
|
582 |
printf ( "Script Type: Patch Mod\n" );
|
|
|
583 |
else if ( pSpkFile->IsCustomStart() )
|
|
|
584 |
printf ( "Script Type: Custom Start\n" );
|
|
|
585 |
else if ( pSpkFile->IsPackageUpdate() )
|
|
|
586 |
printf ( "Script Type: Package Update\n" );
|
10 |
cycrow |
587 |
else if ( !pSpkFile->GetScriptTypeString(44).empty() )
|
1 |
cycrow |
588 |
printf ( "Script Type: %s\n", pSpkFile->GetScriptTypeString(44).c_str() );
|
|
|
589 |
|
|
|
590 |
if ( !pSpkFile->GetWaresList()->empty() )
|
|
|
591 |
{
|
|
|
592 |
for ( CListNode<SWares> * wNode = pSpkFile->GetWaresList()->Front(); wNode; wNode = wNode->next() )
|
|
|
593 |
{
|
|
|
594 |
SWares *w = wNode->Data();
|
|
|
595 |
printf ( "Ware: (%c) %s\n", w->cType, CSpkFile::GetWareText(w, 44).c_str() );
|
|
|
596 |
CyString desc = CSpkFile::GetWareDesc(w, 44);
|
|
|
597 |
if ( !desc.Empty() )
|
|
|
598 |
printf ( "\tDescription: %s\n", desc.c_str() );
|
|
|
599 |
}
|
|
|
600 |
}
|
|
|
601 |
}
|
49 |
cycrow |
602 |
if ( !pBaseFile->forumLink().empty() ) printf ( "Forum Link: %s\n", pBaseFile->forumLink().c_str() );
|
|
|
603 |
if ( !pBaseFile->webSite().empty() ) printf ( "Web Site Address: %s\n", pBaseFile->webSite().c_str() );
|
|
|
604 |
if ( !pBaseFile->webAddress().empty() ) printf ( "Update Address: %s\n", pBaseFile->webAddress().c_str() );
|
1 |
cycrow |
605 |
|
162 |
cycrow |
606 |
if ( pBaseFile->anyWebMirrors() )
|
1 |
cycrow |
607 |
{
|
|
|
608 |
printf("Update Mirror Addresses:\n");
|
162 |
cycrow |
609 |
for ( int i = 0; i < pBaseFile->getMaxWebMirrors(); i++ )
|
|
|
610 |
printf ("\t%s\n", pBaseFile->getWebMirror(i).c_str());
|
1 |
cycrow |
611 |
}
|
|
|
612 |
if ( pSpkFile )
|
|
|
613 |
{
|
10 |
cycrow |
614 |
if ( (!pSpkFile->GetOtherName().empty()) && (!pSpkFile->GetOtherAuthor().empty()) )
|
1 |
cycrow |
615 |
printf ( "Script is a child to the mod: %s by %s\n", pSpkFile->GetOtherName().c_str(), pSpkFile->GetOtherAuthor().c_str() );
|
|
|
616 |
}
|
|
|
617 |
|
|
|
618 |
if ( pBaseFile->AnyDependacies() )
|
|
|
619 |
{
|
|
|
620 |
printf ( "Required Dependacies:\n" );
|
|
|
621 |
for ( SNeededLibrary *needed = pBaseFile->GetNeededLibraries()->First(); needed; needed = pBaseFile->GetNeededLibraries()->Next() )
|
|
|
622 |
printf ( "\t%s by %s (Minimum Version=%s)\n", needed->sName.c_str(), needed->sAuthor.c_str(), needed->sMinVersion.c_str() );
|
|
|
623 |
}
|
46 |
cycrow |
624 |
if ( pBaseFile->easeOfUse() != -1 ) printf ( "Ease Of Use Rating: %d\n", pBaseFile->easeOfUse() );
|
|
|
625 |
if ( pBaseFile->gameChanging() != -1 ) printf ( "Game Changing Rating: %d\n", pBaseFile->gameChanging() );
|
|
|
626 |
if ( pBaseFile->recommended() != -1 ) printf ( "Recommendation Rating: %d\n", pBaseFile->recommended() );
|
170 |
cycrow |
627 |
if (pBaseFile->icon())
|
|
|
628 |
printf ( "Icon File Found, Type: %s, Size: %s\n", pBaseFile->iconExt().c_str(), pBaseFile->icon()->dataSizeString().c_str() );
|
1 |
cycrow |
629 |
|
|
|
630 |
if ( pBaseFile->GetFileList()->size() )
|
|
|
631 |
{
|
134 |
cycrow |
632 |
printf("\nListing files in package:\n");
|
1 |
cycrow |
633 |
CLinkList<C_File> *list = pBaseFile->GetFileList();
|
134 |
cycrow |
634 |
|
|
|
635 |
for (unsigned int game = 0; game < 31; ++game)
|
|
|
636 |
{
|
|
|
637 |
bool heading = true;
|
|
|
638 |
for (C_File *file = list->First(); file; file = list->Next())
|
|
|
639 |
{
|
|
|
640 |
bool display = false;
|
|
|
641 |
if (game == 0 && (!file->game() || file->game() == GAME_ALLNEW))
|
|
|
642 |
display = true;
|
|
|
643 |
if (game > 0 && file->game() & (1 << game))
|
|
|
644 |
display = true;
|
|
|
645 |
|
|
|
646 |
if (display)
|
|
|
647 |
{
|
|
|
648 |
if (heading)
|
|
|
649 |
{
|
|
|
650 |
Utils::String sGame = p.GetGameExe()->GetGameNameFromType(game - 1);
|
|
|
651 |
printf("\tGame: %s\n", sGame.c_str());
|
|
|
652 |
heading = false;
|
|
|
653 |
}
|
178 |
cycrow |
654 |
printf("\t\t%s (%s) Size: %s\n", file->getNameDirectory(pBaseFile).c_str(), file->fileTypeString().c_str(), file->dataSizeString().c_str());
|
134 |
cycrow |
655 |
|
|
|
656 |
}
|
|
|
657 |
}
|
|
|
658 |
}
|
|
|
659 |
|
1 |
cycrow |
660 |
}
|
|
|
661 |
else
|
|
|
662 |
printf ( "\nThere are currently no files in the package\n" );
|
|
|
663 |
}
|
|
|
664 |
else if ( check == SPKFILE_MULTI )
|
|
|
665 |
{
|
|
|
666 |
CMultiSpkFile spkfile;
|
|
|
667 |
printf ( "* Opening Multi-SPK file, %s...\n", filename.c_str() );
|
175 |
cycrow |
668 |
if ( !pBaseFile->readFile(filename, false))
|
1 |
cycrow |
669 |
{
|
|
|
670 |
printf ( "Error: Failed to open the Multi-SPK file, %s\n", filename.c_str() );
|
|
|
671 |
return;
|
|
|
672 |
}
|
|
|
673 |
|
177 |
cycrow |
674 |
printf ( "Multi Package Name: %s\n", spkfile.name().c_str() );
|
1 |
cycrow |
675 |
printf ( "Selection Mode: " );
|
177 |
cycrow |
676 |
if (spkfile.isSelection ())
|
1 |
cycrow |
677 |
printf ( "On\n" );
|
|
|
678 |
else
|
|
|
679 |
printf ( "Off\n" );
|
|
|
680 |
|
|
|
681 |
CLinkList<SMultiSpkFile> *list = spkfile.GetFileList();
|
|
|
682 |
for ( SMultiSpkFile *ms = list->First(); ms; ms = list->Next() )
|
|
|
683 |
{
|
|
|
684 |
printf ( "File, %s:\n", ms->sName.c_str() );
|
|
|
685 |
printf ( "\tSize: %s\n", SPK::GetSizeString (ms->lSize).c_str() );
|
176 |
cycrow |
686 |
if ( (!ms->sScriptName.empty()) && (!ms->sScriptAuthor.empty()) )
|
1 |
cycrow |
687 |
printf ( "\tScript: %s %s by %s\n", ms->sScriptName.c_str(), ms->sScriptVersion.c_str(), ms->sScriptAuthor.c_str() );
|
|
|
688 |
printf ( "\tDefault Install: " );
|
|
|
689 |
if ( ms->bOn )
|
|
|
690 |
printf ( "Yes\n" );
|
|
|
691 |
else
|
|
|
692 |
printf ( "No\n" );
|
|
|
693 |
}
|
|
|
694 |
}
|
|
|
695 |
else
|
|
|
696 |
printf ( "File, %s, is not a valid SPK file\n", filename.c_str() );
|
|
|
697 |
|
|
|
698 |
if ( pBaseFile )
|
|
|
699 |
delete pBaseFile;
|
|
|
700 |
}
|
|
|
701 |
|
|
|
702 |
void AppendFile ( CyString sfile, CyString type, CyString addfile )
|
|
|
703 |
{
|
155 |
cycrow |
704 |
int t = GetFileTypeFromString(type.ToString());
|
1 |
cycrow |
705 |
if ( t == -1 )
|
|
|
706 |
{
|
|
|
707 |
printf ( "The file type \"%s\" is invalid\n", type.c_str() );
|
|
|
708 |
return;
|
|
|
709 |
}
|
|
|
710 |
|
175 |
cycrow |
711 |
int check = CSpkFile::CheckFile(sfile.ToString());
|
1 |
cycrow |
712 |
CBaseFile *pBaseFile = 0;
|
|
|
713 |
if ( check == SPKFILE_SINGLE )
|
|
|
714 |
pBaseFile = new CSpkFile();
|
|
|
715 |
else if ( check == SPKFILE_SINGLESHIP )
|
|
|
716 |
pBaseFile = new CXspFile();
|
|
|
717 |
else if ( check == SPKFILE_BASE )
|
|
|
718 |
pBaseFile = new CBaseFile();
|
|
|
719 |
|
|
|
720 |
if ( !pBaseFile )
|
|
|
721 |
{
|
|
|
722 |
printf ( "Error: Invalid file format, unable to open\n" );
|
|
|
723 |
return;
|
|
|
724 |
}
|
|
|
725 |
|
|
|
726 |
printf ( "Opening File, %s... ", sfile.c_str() );
|
175 |
cycrow |
727 |
if ( !pBaseFile->readFile(sfile.ToString()))
|
1 |
cycrow |
728 |
{
|
|
|
729 |
printf ( "(Error)\nUnable to open the file, %s\n", sfile.c_str() );
|
|
|
730 |
return;
|
|
|
731 |
}
|
|
|
732 |
printf ( "(Done)\n" );
|
|
|
733 |
|
|
|
734 |
MyProgress progress(0);
|
|
|
735 |
|
|
|
736 |
printf ( "Adding file %s to package\n\t>", addfile.c_str() );
|
|
|
737 |
|
155 |
cycrow |
738 |
if ( pBaseFile->appendFile(addfile.ToString(), t, 0, false, Utils::String::Null(), &progress))
|
1 |
cycrow |
739 |
{
|
|
|
740 |
progress.PrintDone();
|
|
|
741 |
printf ( "< (Done)\n" );
|
|
|
742 |
|
175 |
cycrow |
743 |
pBaseFile->writeFile(sfile.ToString());
|
1 |
cycrow |
744 |
printf ( "\nFile has been written sucessfully\n" );
|
|
|
745 |
}
|
|
|
746 |
else
|
|
|
747 |
printf ( "< (Error)\n" );
|
|
|
748 |
}
|
|
|
749 |
|
|
|
750 |
void RemoveFile ( CyString sfile, CyString type, CyString addfile )
|
|
|
751 |
{
|
|
|
752 |
FILE *id = fopen ( sfile.c_str(), "rb+" );
|
|
|
753 |
if ( !id )
|
|
|
754 |
{
|
|
|
755 |
printf ( "Error: File, %s, doesn't exist\n", sfile.c_str() );
|
|
|
756 |
return;
|
|
|
757 |
}
|
|
|
758 |
|
|
|
759 |
if ( addfile.Empty() )
|
|
|
760 |
{
|
|
|
761 |
printf ( "Error: Remove filename is invalid\n" );
|
|
|
762 |
return;
|
|
|
763 |
}
|
172 |
cycrow |
764 |
FileType t = GetFileTypeFromString(type.ToString());
|
|
|
765 |
if (t == FileType::FILETYPE_UNKNOWN)
|
1 |
cycrow |
766 |
{
|
|
|
767 |
printf ( "The file type \"%s\" is invalid\n", type.c_str() );
|
|
|
768 |
return;
|
|
|
769 |
}
|
|
|
770 |
|
175 |
cycrow |
771 |
int check = CSpkFile::CheckFile(sfile.ToString());
|
1 |
cycrow |
772 |
CBaseFile *pBaseFile = 0;
|
|
|
773 |
if ( check == SPKFILE_SINGLE )
|
|
|
774 |
pBaseFile = new CSpkFile();
|
|
|
775 |
else if ( check == SPKFILE_SINGLESHIP )
|
|
|
776 |
pBaseFile = new CXspFile();
|
|
|
777 |
else if ( check == SPKFILE_BASE )
|
|
|
778 |
pBaseFile = new CBaseFile();
|
|
|
779 |
|
|
|
780 |
if ( pBaseFile )
|
|
|
781 |
{
|
|
|
782 |
printf ( "Opening File, %s... ", sfile.c_str() );
|
175 |
cycrow |
783 |
if ( !pBaseFile->readFile(sfile.ToString()))
|
1 |
cycrow |
784 |
{
|
|
|
785 |
printf ( "(Error)\nUnable to open the file, %s\n", sfile.c_str() );
|
|
|
786 |
return;
|
|
|
787 |
}
|
|
|
788 |
printf ( "(Done)\n" );
|
|
|
789 |
|
|
|
790 |
printf ( "Removing file, %s, from Package\n", addfile.c_str() );
|
|
|
791 |
|
172 |
cycrow |
792 |
if(pBaseFile->removeFile(addfile.ToString(), t))
|
1 |
cycrow |
793 |
{
|
|
|
794 |
printf ( "File, %s, has been remove from package\n", addfile.c_str() );
|
175 |
cycrow |
795 |
pBaseFile->writeFile(sfile.ToString());
|
1 |
cycrow |
796 |
printf ( "File has been written to disk successfully\n" );
|
|
|
797 |
}
|
|
|
798 |
else
|
|
|
799 |
printf ( "Unable to remove the file, %s, from the package\n", addfile.c_str() );
|
|
|
800 |
}
|
|
|
801 |
else if ( check == SPKFILE_MULTI )
|
|
|
802 |
{
|
|
|
803 |
CMultiSpkFile spkfile;
|
|
|
804 |
printf ( "Opening Multi-SPK file, %s...", sfile.c_str() );
|
177 |
cycrow |
805 |
if ( !spkfile.readFile(sfile.ToString()))
|
1 |
cycrow |
806 |
{
|
|
|
807 |
printf ( "(Error)\nUnable to open the Multi-SPK file, %s\n", sfile.c_str() );
|
|
|
808 |
return;
|
|
|
809 |
}
|
|
|
810 |
printf ( "(Done)\n" );
|
|
|
811 |
|
177 |
cycrow |
812 |
const SMultiSpkFile *ms = spkfile.findFile ( type.ToString() );
|
1 |
cycrow |
813 |
if ( !ms )
|
|
|
814 |
{
|
|
|
815 |
printf ( "Unable to find the file \"%s\" in the package\n", type.c_str() );
|
|
|
816 |
return;
|
|
|
817 |
}
|
|
|
818 |
|
|
|
819 |
printf ( "Removing file, %s, from Package\n", addfile.c_str() );
|
177 |
cycrow |
820 |
if (!spkfile.removeFile(ms))
|
1 |
cycrow |
821 |
{
|
|
|
822 |
printf ( "Error: Unable to remove file, %s, from package\n", type.c_str() );
|
|
|
823 |
return;
|
|
|
824 |
}
|
|
|
825 |
|
|
|
826 |
printf ( "Writing SPK File, %s... ", sfile.c_str() );
|
177 |
cycrow |
827 |
if (spkfile.writeFile(sfile.ToString()))
|
1 |
cycrow |
828 |
printf ( "(Done)\n" );
|
|
|
829 |
else
|
|
|
830 |
printf ( "(Error)\n" );
|
|
|
831 |
}
|
|
|
832 |
else
|
|
|
833 |
printf ( "Error: Invalid file format, unable to open\n" );
|
|
|
834 |
}
|
|
|
835 |
|
|
|
836 |
|
|
|
837 |
void CreateMultiFile ( CyString filename )
|
|
|
838 |
{
|
|
|
839 |
printf ( "* Creating new Multi-SPK File, %s\n\n", filename.c_str() );
|
|
|
840 |
|
|
|
841 |
FILE *id = fopen ( filename.c_str(), "rb+" );
|
|
|
842 |
if ( id )
|
|
|
843 |
{
|
|
|
844 |
fclose ( id );
|
|
|
845 |
printf ( "* File already exists, unable to create\n" );
|
|
|
846 |
return;
|
|
|
847 |
}
|
|
|
848 |
|
|
|
849 |
id = fopen ( filename.c_str(), "wb" );
|
|
|
850 |
if ( !id )
|
|
|
851 |
{
|
|
|
852 |
printf ( "* Unable to open file for writing\n" );
|
|
|
853 |
return;
|
|
|
854 |
}
|
|
|
855 |
fclose ( id );
|
|
|
856 |
remove ( filename.c_str() );
|
|
|
857 |
|
|
|
858 |
CMultiSpkFile spkfile;
|
|
|
859 |
|
|
|
860 |
CyString sInput;
|
|
|
861 |
printf ( "Enter Multi-Spk Package Name: " );
|
177 |
cycrow |
862 |
spkfile.setName(GetInput());
|
1 |
cycrow |
863 |
|
|
|
864 |
while ( true )
|
|
|
865 |
{
|
|
|
866 |
printf ( "\nDo you want users to select scripts to install? (Y/N): " );
|
|
|
867 |
CyString i = GetInput();
|
|
|
868 |
i = i.ToUpper();
|
|
|
869 |
if ( i == "Y" )
|
177 |
cycrow |
870 |
spkfile.setSelection(true);
|
1 |
cycrow |
871 |
if ( (i == "Y") || (i == "N") )
|
|
|
872 |
break;
|
|
|
873 |
}
|
|
|
874 |
|
|
|
875 |
while ( true )
|
|
|
876 |
{
|
|
|
877 |
printf ( "\nEnter Spk File to add (Enter \"0\" to finish): " );
|
|
|
878 |
sInput = GetInput();
|
|
|
879 |
if ( sInput == "0" )
|
|
|
880 |
break;
|
|
|
881 |
|
|
|
882 |
// check if file can be opened
|
|
|
883 |
FILE *id2 = fopen ( sInput.c_str(), "rb+" );
|
|
|
884 |
if ( !id2 )
|
|
|
885 |
printf ( "Error: Unable to open SPK file %s\n", sInput.c_str() );
|
|
|
886 |
else
|
|
|
887 |
{
|
|
|
888 |
fclose ( id2 );
|
177 |
cycrow |
889 |
if ( !spkfile.addFile(sInput.ToString()))
|
1 |
cycrow |
890 |
printf ( "Error: Unable to add SPK file to package\n" );
|
|
|
891 |
else
|
|
|
892 |
printf ( "File Added to package (%s)\n", sInput.c_str() );
|
|
|
893 |
}
|
|
|
894 |
}
|
|
|
895 |
|
177 |
cycrow |
896 |
if ( spkfile.numFiles() < 1 )
|
1 |
cycrow |
897 |
printf ( "\nError: You have added no files, you must add at least one file to create a package\n" );
|
|
|
898 |
else
|
|
|
899 |
{
|
|
|
900 |
printf ( "Writing MultiSpk file... " );
|
177 |
cycrow |
901 |
if ( spkfile.writeFile(filename.ToString()))
|
1 |
cycrow |
902 |
printf ( "(Done)\n" );
|
|
|
903 |
else
|
|
|
904 |
printf ( "(Error)\n" );
|
|
|
905 |
}
|
|
|
906 |
|
|
|
907 |
}
|
|
|
908 |
|
|
|
909 |
void CreateFile ( CyString filename )
|
|
|
910 |
{
|
|
|
911 |
printf ( "* Creating new SPK File, %s\n\n", filename.c_str() );
|
|
|
912 |
|
|
|
913 |
FILE *id = fopen ( filename.c_str(), "rb+" );
|
|
|
914 |
if ( id )
|
|
|
915 |
{
|
|
|
916 |
fclose ( id );
|
|
|
917 |
printf ( "* File already exists, unable to create\n" );
|
|
|
918 |
return;
|
|
|
919 |
}
|
|
|
920 |
|
|
|
921 |
id = fopen ( filename.c_str(), "wb" );
|
|
|
922 |
if ( !id )
|
|
|
923 |
{
|
|
|
924 |
printf ( "* Unable to open file for writing\n" );
|
|
|
925 |
return;
|
|
|
926 |
}
|
|
|
927 |
fclose ( id );
|
|
|
928 |
remove ( filename.c_str() );
|
|
|
929 |
|
|
|
930 |
CSpkFile spkfile;
|
|
|
931 |
|
|
|
932 |
printf ( "Enter Script Name: " );
|
127 |
cycrow |
933 |
spkfile.setName(GetInput());
|
1 |
cycrow |
934 |
|
|
|
935 |
printf ( "Enter Script Author: " );
|
127 |
cycrow |
936 |
spkfile.setAuthor(GetInput());
|
1 |
cycrow |
937 |
|
|
|
938 |
printf ( "Enter Script Version: " );
|
127 |
cycrow |
939 |
spkfile.setVersion(GetInput());
|
1 |
cycrow |
940 |
|
|
|
941 |
printf ( "Enter Script Description: " );
|
127 |
cycrow |
942 |
spkfile.setDescription(GetInput());
|
1 |
cycrow |
943 |
|
|
|
944 |
struct tm *currDate;
|
|
|
945 |
char dateString[100];
|
|
|
946 |
time_t now = time(NULL);
|
|
|
947 |
|
|
|
948 |
currDate = localtime( &now );
|
|
|
949 |
strftime(dateString, sizeof dateString, "%d %m %Y", currDate);
|
50 |
cycrow |
950 |
spkfile.setCreationDate(dateString);
|
1 |
cycrow |
951 |
|
175 |
cycrow |
952 |
spkfile.writeFile(filename.ToString(), NULL);
|
1 |
cycrow |
953 |
printf ( "SPK file has been written to disk: %s\n", filename.c_str() );
|
|
|
954 |
}
|
|
|
955 |
|
129 |
cycrow |
956 |
void ExtractFiles (const Utils::String &sfile, const Utils::String &dir, int game )
|
1 |
cycrow |
957 |
{
|
|
|
958 |
// First checks if the file exists by opening it
|
|
|
959 |
FILE *id = fopen ( sfile.c_str(), "rb+" );
|
|
|
960 |
if ( !id )
|
|
|
961 |
{
|
|
|
962 |
printf ( "Error: File, %s, doesn't exist\n", sfile.c_str() );
|
|
|
963 |
return;
|
|
|
964 |
}
|
|
|
965 |
fclose ( id );
|
|
|
966 |
|
129 |
cycrow |
967 |
CPackages packages;
|
|
|
968 |
packages.startup(".", ".", ".");
|
|
|
969 |
|
1 |
cycrow |
970 |
int check = CSpkFile::CheckFile ( sfile );
|
|
|
971 |
|
|
|
972 |
// extracts a file from single packages file
|
|
|
973 |
if ( check == SPKFILE_SINGLE || check == SPKFILE_BASE || check == SPKFILE_SINGLESHIP )
|
|
|
974 |
{
|
|
|
975 |
// creates the spkfile object
|
|
|
976 |
CBaseFile *pBaseFile = 0;
|
|
|
977 |
if ( check == SPKFILE_SINGLE )
|
|
|
978 |
pBaseFile = (CBaseFile *)new CSpkFile();
|
|
|
979 |
else if ( check == SPKFILE_SINGLESHIP )
|
|
|
980 |
pBaseFile = (CBaseFile *)new CXspFile();
|
|
|
981 |
else
|
|
|
982 |
pBaseFile = new CBaseFile();
|
|
|
983 |
|
|
|
984 |
printf ( "Opening File, %s... ", sfile.c_str() );
|
|
|
985 |
// reads the file into memory
|
|
|
986 |
// the SPKREAD_NODATA flag causes it to just read the settings, and skips the file data
|
175 |
cycrow |
987 |
if ( !pBaseFile->readFile(sfile, SPKREAD_NODATA))
|
1 |
cycrow |
988 |
{
|
|
|
989 |
printf ( "(Error)\nUnable to open the file, %s\n", sfile.c_str() );
|
|
|
990 |
return;
|
|
|
991 |
}
|
|
|
992 |
printf ( "(Done)\n" );
|
|
|
993 |
|
134 |
cycrow |
994 |
if(game == 0)
|
|
|
995 |
printf("Extracting all files from archive...\n\n");
|
1 |
cycrow |
996 |
else
|
134 |
cycrow |
997 |
printf("Extracting %s files from archive...\n\n", packages.GetGameExe()->GetGameNameFromType(game - 1).c_str());
|
|
|
998 |
|
|
|
999 |
CFileProgress info(&packages, pBaseFile, "Extracting");
|
|
|
1000 |
if (packages.extractAll(pBaseFile, dir, game, true, &info) )
|
|
|
1001 |
printf ( "\n(Done)\nFiles have been extracted successfully\n" );
|
|
|
1002 |
else
|
|
|
1003 |
printf ( "\n(Error)\nThere was a problem extracting the files\n" );
|
1 |
cycrow |
1004 |
}
|
|
|
1005 |
else
|
|
|
1006 |
printf("Invalid package file, %s\n", sfile.c_str());
|
|
|
1007 |
}
|
|
|
1008 |
|
|
|
1009 |
|
|
|
1010 |
/*
|
|
|
1011 |
Func: AppendMultiFile
|
|
|
1012 |
Args: String toFile - The spk file to append onto
|
|
|
1013 |
String addfile - The spk file to append
|
|
|
1014 |
Desc: Appends a spk file into a Multi-Spk Archive
|
|
|
1015 |
If toFile is a single spk file, it will be converted to a Multi-Spk File
|
|
|
1016 |
if addfile is a Multi-Spk file, all files from it will be appended
|
|
|
1017 |
*/
|
|
|
1018 |
void AppendMultiFile ( CyString toFile, CyString addfile )
|
|
|
1019 |
{
|
|
|
1020 |
// create destination object
|
|
|
1021 |
CMultiSpkFile spkfile;
|
|
|
1022 |
|
|
|
1023 |
// checks the destination
|
175 |
cycrow |
1024 |
int checkto = CSpkFile::CheckFile(toFile.ToString());
|
1 |
cycrow |
1025 |
|
|
|
1026 |
// if the destination is a single file, then convert it to a Multi-Spk package
|
|
|
1027 |
if ( checkto == SPKFILE_SINGLE )
|
|
|
1028 |
{
|
|
|
1029 |
// adds the single file to the Multi-Spk object
|
|
|
1030 |
// Add file also reads it into memory
|
177 |
cycrow |
1031 |
if ( !spkfile.addFile(toFile.ToString()))
|
1 |
cycrow |
1032 |
{
|
|
|
1033 |
printf ( "Error: Unable to create Multi-Spk file\n" );
|
|
|
1034 |
return;
|
|
|
1035 |
}
|
|
|
1036 |
}
|
|
|
1037 |
else
|
|
|
1038 |
{
|
|
|
1039 |
// if its already a multispk file, then simply open it and read it to memory
|
177 |
cycrow |
1040 |
if ( !spkfile.readFile(toFile.ToString()))
|
1 |
cycrow |
1041 |
{
|
|
|
1042 |
printf ( "Error: Unable to open Multi-Spk file, %s\n", toFile.c_str() );
|
|
|
1043 |
return;
|
|
|
1044 |
}
|
|
|
1045 |
}
|
|
|
1046 |
|
|
|
1047 |
// now add the file into the Multi-Spk Object
|
|
|
1048 |
// the AddFile function will handle both single and Multi-Spk files
|
|
|
1049 |
// So you dont need to test what the appending file is
|
177 |
cycrow |
1050 |
if ( spkfile.addFile(addfile.ToString()))
|
1 |
cycrow |
1051 |
{
|
|
|
1052 |
|
|
|
1053 |
// if it added correctly, then simply write the new Multi-Spk Object to disk
|
|
|
1054 |
printf ( "File, %s, has been added to Multi-Spk Package\n", addfile.c_str() );
|
|
|
1055 |
printf ( "Saving Multi-Spk File: %s... ", toFile.c_str() );
|
177 |
cycrow |
1056 |
if ( spkfile.writeFile(toFile.ToString()))
|
1 |
cycrow |
1057 |
printf ( "(Done)\n" );
|
|
|
1058 |
else
|
|
|
1059 |
printf ( "(Error)\n" );
|
|
|
1060 |
}
|
|
|
1061 |
else
|
|
|
1062 |
printf ( "Error: Unable to add files, %s, to Multi-Spk Package\n", addfile.c_str() );
|
|
|
1063 |
}
|
|
|
1064 |
|
|
|
1065 |
/*
|
|
|
1066 |
Func: ExtractFile
|
|
|
1067 |
Args: String sfile - the spk file to read from
|
|
|
1068 |
String type - the type of the file to find
|
|
|
1069 |
String addfile - The filename to extract
|
|
|
1070 |
String dir - The directory to extract to
|
|
|
1071 |
Desc: Finds and extracts a file from a Spk Package
|
|
|
1072 |
*/
|
134 |
cycrow |
1073 |
void ExtractFile (const Utils::String &sfile, const Utils::String &type, const Utils::String &addfile, const Utils::String &dir)
|
1 |
cycrow |
1074 |
{
|
|
|
1075 |
// First checks if the file exists by opening it
|
|
|
1076 |
FILE *id = fopen ( sfile.c_str(), "rb+" );
|
|
|
1077 |
if ( !id )
|
|
|
1078 |
{
|
|
|
1079 |
printf ( "Error: File, %s, doesn't exist\n", sfile.c_str() );
|
|
|
1080 |
return;
|
|
|
1081 |
}
|
|
|
1082 |
fclose ( id );
|
|
|
1083 |
|
|
|
1084 |
// now check the type of file it is, using the static function CheckFile(filename).
|
|
|
1085 |
// This will return the type of file
|
|
|
1086 |
// SPK_INVALID - Invalid file format, wont be able to open
|
|
|
1087 |
// SPK_SINGLE - A Single spk package file
|
|
|
1088 |
// SPK_MULTI - A Multi-Spk Archive
|
|
|
1089 |
// SPK_BASE - A Base File
|
|
|
1090 |
// SPK_SINGLESHIP - A Ship file
|
|
|
1091 |
int check = CSpkFile::CheckFile ( sfile );
|
|
|
1092 |
|
|
|
1093 |
// extracts a file from single packages file
|
|
|
1094 |
if ( check == SPKFILE_SINGLE || check == SPKFILE_BASE || check == SPKFILE_SINGLESHIP )
|
|
|
1095 |
{
|
|
|
1096 |
// first get the file type is valid
|
|
|
1097 |
// converts the string type into its filetype flag
|
170 |
cycrow |
1098 |
FileType t = GetFileTypeFromString(type);
|
1 |
cycrow |
1099 |
// incorrect text type, display the error
|
170 |
cycrow |
1100 |
if (t == FileType::FILETYPE_UNKNOWN)
|
1 |
cycrow |
1101 |
{
|
|
|
1102 |
printf ( "The file type \"%s\" is invalid\n", type.c_str() );
|
|
|
1103 |
return;
|
|
|
1104 |
}
|
|
|
1105 |
|
|
|
1106 |
// creates the spkfile object
|
|
|
1107 |
CBaseFile *pBaseFile = 0;
|
|
|
1108 |
if ( check == SPKFILE_SINGLE )
|
|
|
1109 |
pBaseFile = (CBaseFile *)new CSpkFile();
|
|
|
1110 |
else if ( check == SPKFILE_SINGLESHIP )
|
|
|
1111 |
pBaseFile = (CBaseFile *)new CXspFile();
|
|
|
1112 |
else
|
|
|
1113 |
pBaseFile = new CBaseFile();
|
|
|
1114 |
|
|
|
1115 |
printf ( "Opening File, %s... ", sfile.c_str() );
|
|
|
1116 |
// reads the file into memory
|
|
|
1117 |
// the SPKREAD_NODATA flag causes it to just read the settings, and skips the file data
|
175 |
cycrow |
1118 |
if ( !pBaseFile->readFile(sfile, SPKREAD_NODATA))
|
1 |
cycrow |
1119 |
{
|
|
|
1120 |
printf ( "(Error)\nUnable to open the file, %s\n", sfile.c_str() );
|
|
|
1121 |
return;
|
|
|
1122 |
}
|
|
|
1123 |
|
|
|
1124 |
// No read all the file data into memory
|
|
|
1125 |
// This can be done all together in the ReadFile function
|
|
|
1126 |
// Doing it seperatly allows you to save time if an error occurs, so you dont have to wait for it to read the whole thing
|
|
|
1127 |
pBaseFile->ReadAllFilesToMemory ();
|
|
|
1128 |
|
|
|
1129 |
printf ( "(Done)\n" );
|
|
|
1130 |
|
|
|
1131 |
// uses the FindFile function to find the selected file in the archive
|
|
|
1132 |
// requires the filename, type and custom directory (only for Extra File Type)
|
170 |
cycrow |
1133 |
C_File *f = pBaseFile->findFile(addfile, t);
|
1 |
cycrow |
1134 |
if ( !f )
|
|
|
1135 |
{
|
|
|
1136 |
printf ( "Unable to find the file \"%s\" in the package\n", addfile.c_str() );
|
|
|
1137 |
return;
|
|
|
1138 |
}
|
|
|
1139 |
|
|
|
1140 |
// creates the directory so it can be extracted
|
|
|
1141 |
CDirIO Dir(dir);
|
160 |
cycrow |
1142 |
if ( !Dir.create(f->getDirectory(pBaseFile)) )
|
1 |
cycrow |
1143 |
{
|
|
|
1144 |
printf ( "Unable to create the directory \"%s\" to extract into\n", dir.c_str() );
|
|
|
1145 |
return;
|
|
|
1146 |
}
|
|
|
1147 |
|
|
|
1148 |
// sets up the progress pointer
|
|
|
1149 |
// if it uses 7zip, the progress will be displayed in the command prompt
|
|
|
1150 |
MyProgress progress(0);
|
|
|
1151 |
printf ( "Extracting the file from package\n\t>" );
|
|
|
1152 |
|
|
|
1153 |
// Extracts the file to the specified directory
|
175 |
cycrow |
1154 |
if ( !pBaseFile->extractFile(f, dir, true, &progress))
|
1 |
cycrow |
1155 |
printf ( "< (Error)\nUnable to extract the file\n" );
|
|
|
1156 |
else
|
|
|
1157 |
{
|
|
|
1158 |
progress.PrintDone ();
|
|
|
1159 |
printf ( "< (Done)\nFile has been extracted successfully\n" );
|
|
|
1160 |
}
|
|
|
1161 |
}
|
|
|
1162 |
|
|
|
1163 |
// the file is a Multi-Spk File, extracts a single spk file from the archive
|
|
|
1164 |
else if ( check == SPKFILE_MULTI )
|
|
|
1165 |
{
|
|
|
1166 |
// creates MultiSpkFile object
|
|
|
1167 |
CMultiSpkFile spkfile;
|
|
|
1168 |
printf ( "Opening Multi-SPK file, %s...", sfile.c_str() );
|
|
|
1169 |
|
|
|
1170 |
// reads the MultiSpkFile into memory
|
177 |
cycrow |
1171 |
if ( !spkfile.readFile(sfile))
|
1 |
cycrow |
1172 |
{
|
|
|
1173 |
printf ( "(Error)\nUnable to open the Multi-SPK file, %s\n", sfile.c_str() );
|
|
|
1174 |
return;
|
|
|
1175 |
}
|
|
|
1176 |
printf ( "(Done)\n" );
|
|
|
1177 |
|
|
|
1178 |
// searchs the archive for a matching file
|
177 |
cycrow |
1179 |
const SMultiSpkFile *ms = spkfile.findFile(type);
|
1 |
cycrow |
1180 |
if ( !ms )
|
|
|
1181 |
{
|
|
|
1182 |
printf ( "Unable to find the file \"%s\" in the package\n", type.c_str() );
|
|
|
1183 |
return;
|
|
|
1184 |
}
|
|
|
1185 |
|
|
|
1186 |
// extracts the file from the archive, to the given directory
|
|
|
1187 |
printf ( "Extracting SPK file, %s, from package... ", ms->sName.c_str() );
|
177 |
cycrow |
1188 |
if (spkfile.extractFile(ms, addfile))
|
1 |
cycrow |
1189 |
printf ( "(Done)\n" );
|
|
|
1190 |
else
|
|
|
1191 |
printf ( "(Error)\n" );
|
|
|
1192 |
}
|
|
|
1193 |
else
|
|
|
1194 |
printf ( "Error: Invalid file format, unable to open\n" );
|
|
|
1195 |
}
|
|
|
1196 |
|
|
|
1197 |
/*
|
|
|
1198 |
Func: SplitMulti
|
|
|
1199 |
Args: String filename - the filename of the multispk file to open
|
|
|
1200 |
String dest - The destination directory to extract the files to
|
|
|
1201 |
Desc: Splits a multi-spk file into its seperate spk files
|
|
|
1202 |
*/
|
|
|
1203 |
void SplitMulti ( CyString filename, CyString dest )
|
|
|
1204 |
{
|
|
|
1205 |
// Check the file type, Must return SPKFILE_MULTI, otherwise its not a Multi-Spk Packages
|
175 |
cycrow |
1206 |
if ( CSpkFile::CheckFile(filename.ToString()) != SPKFILE_MULTI )
|
1 |
cycrow |
1207 |
{
|
|
|
1208 |
printf ( "Error: The file is not a Multi-Spk packages\n" );
|
|
|
1209 |
return;
|
|
|
1210 |
}
|
|
|
1211 |
|
|
|
1212 |
printf ( "Spliting Multi-SPK File to, %s... ", dest.c_str() );
|
|
|
1213 |
|
|
|
1214 |
// create the MultiSpkFile object
|
|
|
1215 |
CMultiSpkFile spkfile;
|
|
|
1216 |
|
|
|
1217 |
// Splits the files to the destination
|
177 |
cycrow |
1218 |
if ( !spkfile.splitMulti(filename.ToString(), dest.ToString()))
|
1 |
cycrow |
1219 |
{
|
|
|
1220 |
printf ( "(Error)\nUnable to split Multi-SPK package, %s\n", filename.c_str() );
|
|
|
1221 |
return;
|
|
|
1222 |
}
|
|
|
1223 |
|
|
|
1224 |
printf ( "(Done)\n" );
|
|
|
1225 |
}
|
|
|
1226 |
|
127 |
cycrow |
1227 |
Utils::String GetAsk(const Utils::String &command)
|
1 |
cycrow |
1228 |
{
|
|
|
1229 |
printf("(ASK) Enter the value for, %s: ", command.c_str());
|
|
|
1230 |
return GetInput();
|
|
|
1231 |
}
|
|
|
1232 |
|
126 |
cycrow |
1233 |
void GenerateUpdateList(int argc, char **argv)
|
|
|
1234 |
{
|
|
|
1235 |
Utils::String currentDir = CFileIO(argv[0]).dir();
|
|
|
1236 |
CDirIO Dir(currentDir);
|
|
|
1237 |
|
|
|
1238 |
Utils::CStringList list;
|
|
|
1239 |
for (int i = 2; i < argc; ++i)
|
|
|
1240 |
{
|
|
|
1241 |
Utils::String file(argv[i]);
|
|
|
1242 |
if (CFileIO::Exists(file))
|
|
|
1243 |
list.pushBack(file, "file");
|
|
|
1244 |
else if (CFileIO::Exists(Dir.file(file)))
|
|
|
1245 |
list.pushBack(Dir.file(file), "file");
|
|
|
1246 |
else if (CDirIO::Exists(file))
|
|
|
1247 |
list.pushBack(file, "dir");
|
|
|
1248 |
else if (CDirIO::Exists(Dir.dir(file)))
|
|
|
1249 |
list.pushBack(Dir.dir(file), "dir");
|
|
|
1250 |
else
|
|
|
1251 |
list.pushBack(file, "pattern");
|
|
|
1252 |
}
|
|
|
1253 |
|
|
|
1254 |
if (list.empty())
|
|
|
1255 |
printf("unable to find any packages");
|
|
|
1256 |
else
|
|
|
1257 |
{
|
|
|
1258 |
Utils::CStringList fileList;
|
|
|
1259 |
for (auto itr = list.begin(); itr != list.end(); itr++)
|
|
|
1260 |
{
|
|
|
1261 |
Utils::String file = (*itr)->str;
|
|
|
1262 |
Utils::String data = (*itr)->data;
|
|
|
1263 |
if (data == "file")
|
|
|
1264 |
fileList.pushBack(file);
|
|
|
1265 |
else if (data == "dir")
|
|
|
1266 |
{
|
|
|
1267 |
CDirIO dir(file);
|
|
|
1268 |
Utils::CStringList d;
|
|
|
1269 |
if (dir.dirList(d))
|
|
|
1270 |
{
|
|
|
1271 |
for (auto itr2 = d.begin(); itr2 != d.end(); itr2++)
|
|
|
1272 |
{
|
|
|
1273 |
Utils::String ext = CFileIO((*itr2)->str).extension().lower();
|
|
|
1274 |
if(ext == "xsp" || ext == "spk")
|
|
|
1275 |
fileList.pushBack(dir.file((*itr2)->str));
|
|
|
1276 |
}
|
|
|
1277 |
}
|
|
|
1278 |
}
|
|
|
1279 |
else if (data == "pattern")
|
|
|
1280 |
{
|
|
|
1281 |
CFileIO f(file);
|
|
|
1282 |
CDirIO dir(f.dir());
|
|
|
1283 |
|
|
|
1284 |
if (!dir.exists())
|
|
|
1285 |
dir = CDirIO(Dir.dir(dir.dir()));
|
|
|
1286 |
|
|
|
1287 |
Utils::CStringList d;
|
|
|
1288 |
if (dir.dirList(d, Utils::String::Null(), f.filename()))
|
|
|
1289 |
{
|
|
|
1290 |
for (auto itr2 = d.begin(); itr2 != d.end(); itr2++)
|
|
|
1291 |
{
|
|
|
1292 |
Utils::String ext = CFileIO((*itr2)->str).extension().lower();
|
|
|
1293 |
if (ext == "xsp" || ext == "spk")
|
|
|
1294 |
fileList.pushBack(dir.file((*itr2)->str));
|
|
|
1295 |
}
|
|
|
1296 |
}
|
|
|
1297 |
}
|
|
|
1298 |
}
|
|
|
1299 |
|
|
|
1300 |
if (fileList.empty())
|
|
|
1301 |
printf("unable to find any packages");
|
|
|
1302 |
else
|
|
|
1303 |
{
|
|
|
1304 |
CPackages packages;
|
|
|
1305 |
|
|
|
1306 |
Utils::CStringList filedata;
|
|
|
1307 |
for (auto itr = fileList.begin(); itr != fileList.end(); itr++)
|
|
|
1308 |
{
|
|
|
1309 |
printf("Reading file: %s\n", (*itr)->str.c_str());
|
|
|
1310 |
|
|
|
1311 |
int error = 0;
|
182 |
cycrow |
1312 |
CBaseFile *p = packages.openPackage((*itr)->str, &error, 0, SPKREAD_NODATA);
|
126 |
cycrow |
1313 |
if (!p)
|
|
|
1314 |
{
|
|
|
1315 |
printf("\tERROR!\n");
|
|
|
1316 |
continue;
|
|
|
1317 |
}
|
|
|
1318 |
printf("\tData extracted: %s %s by %s\n", p->name().c_str(), p->version().c_str(), p->author().c_str());
|
|
|
1319 |
if (!p->creationDate().empty())
|
|
|
1320 |
printf("\t\tCreated: %s\n", p->creationDate().c_str());
|
|
|
1321 |
if(!p->description().empty())
|
|
|
1322 |
printf("\t\t%s\n", p->description().c_str());
|
|
|
1323 |
|
|
|
1324 |
filedata.pushBack(CPackages::FormatAvailablePackageData(p));
|
|
|
1325 |
delete p;
|
|
|
1326 |
}
|
|
|
1327 |
|
|
|
1328 |
if (filedata.empty())
|
|
|
1329 |
printf("unable to find any packages");
|
|
|
1330 |
else
|
|
|
1331 |
{
|
|
|
1332 |
Utils::String dest = Dir.file("xpackagedata.dat");
|
|
|
1333 |
if (CFileIO(dest).writeFile(&filedata))
|
|
|
1334 |
printf("web update file, xpackagedata.dat, generated");
|
|
|
1335 |
else
|
|
|
1336 |
printf("unable to write update file");
|
|
|
1337 |
}
|
|
|
1338 |
}
|
|
|
1339 |
}
|
|
|
1340 |
}
|
|
|
1341 |
|
182 |
cycrow |
1342 |
void GenerateUpdateFile(const Utils::String &spkfile)
|
1 |
cycrow |
1343 |
{
|
182 |
cycrow |
1344 |
if (!CFileIO::Exists(spkfile))
|
1 |
cycrow |
1345 |
{
|
|
|
1346 |
printf("Error: The package file, %s, does not exist", spkfile.c_str());
|
|
|
1347 |
return;
|
|
|
1348 |
}
|
|
|
1349 |
|
182 |
cycrow |
1350 |
int check = CSpkFile::CheckFile(spkfile);
|
1 |
cycrow |
1351 |
if ( check == SPKFILE_MULTI )
|
|
|
1352 |
{
|
|
|
1353 |
printf("Error: Multi-Package files currently not supported\n");
|
|
|
1354 |
return;
|
|
|
1355 |
}
|
|
|
1356 |
else if ( check == SPKFILE_OLD )
|
|
|
1357 |
{
|
|
|
1358 |
printf("Error: unable to read old format spk file, try spkconvert first\n");
|
|
|
1359 |
return;
|
|
|
1360 |
}
|
|
|
1361 |
else if ( check == SPKFILE_INVALID )
|
|
|
1362 |
{
|
|
|
1363 |
printf("Error: %s doesn't appear to be a valid package file\n", spkfile.c_str());
|
|
|
1364 |
return;
|
|
|
1365 |
}
|
|
|
1366 |
|
|
|
1367 |
CPackages p;
|
|
|
1368 |
int error;
|
182 |
cycrow |
1369 |
CBaseFile *package = p.openPackage(spkfile, &error, 0, SPKREAD_NODATA);
|
1 |
cycrow |
1370 |
if ( !package )
|
|
|
1371 |
{
|
|
|
1372 |
printf("Error: unable to open package file, %s, Error=%d\n", spkfile.c_str(), error);
|
|
|
1373 |
return;
|
|
|
1374 |
}
|
|
|
1375 |
|
134 |
cycrow |
1376 |
Utils::String file = package->createUpdateFile(CFileIO(spkfile).dir());
|
102 |
cycrow |
1377 |
if ( file.empty() )
|
|
|
1378 |
printf("Error: unable to create update file for: %s, Directory=%s\n", spkfile.c_str(), CFileIO(spkfile).dir().c_str());
|
1 |
cycrow |
1379 |
else
|
|
|
1380 |
printf("Update file: %s has been created for package, %s\n", file.c_str(), spkfile.c_str());
|
|
|
1381 |
|
|
|
1382 |
delete package;
|
|
|
1383 |
|
|
|
1384 |
}
|
|
|
1385 |
|
126 |
cycrow |
1386 |
void GeneratePackagerScript(const Utils::String &spkfile, CyString toFile, int game)
|
1 |
cycrow |
1387 |
{
|
126 |
cycrow |
1388 |
if (!CFileIO::Exists(spkfile))
|
1 |
cycrow |
1389 |
{
|
|
|
1390 |
printf("Error: The package file, %s, does not exist", spkfile.c_str());
|
|
|
1391 |
return;
|
|
|
1392 |
}
|
|
|
1393 |
|
|
|
1394 |
int check = CSpkFile::CheckFile(spkfile);
|
|
|
1395 |
if ( check == SPKFILE_MULTI )
|
|
|
1396 |
{
|
|
|
1397 |
printf("Error: Cant generate a script from a multi-spk file\n");
|
|
|
1398 |
return;
|
|
|
1399 |
}
|
|
|
1400 |
else if ( check == SPKFILE_OLD )
|
|
|
1401 |
{
|
|
|
1402 |
printf("Error: unable to read old format spk file, try spkconvert first\n");
|
|
|
1403 |
return;
|
|
|
1404 |
}
|
|
|
1405 |
else if ( check == SPKFILE_INVALID )
|
|
|
1406 |
{
|
|
|
1407 |
printf("Error: %s doesn't appear to be a spk file\n", spkfile.c_str());
|
|
|
1408 |
return;
|
|
|
1409 |
}
|
|
|
1410 |
|
|
|
1411 |
CPackages p;
|
127 |
cycrow |
1412 |
p.startup(".", ".", ".");
|
1 |
cycrow |
1413 |
int error;
|
182 |
cycrow |
1414 |
CBaseFile *package = p.openPackage(spkfile, &error, 0, SPKREAD_NODATA);
|
1 |
cycrow |
1415 |
if ( !package )
|
|
|
1416 |
{
|
|
|
1417 |
printf("Error: unable to open package files, %s, Error=%d\n", spkfile.c_str(), error);
|
|
|
1418 |
return;
|
|
|
1419 |
}
|
|
|
1420 |
|
126 |
cycrow |
1421 |
Utils::CStringList list;
|
127 |
cycrow |
1422 |
if ( !p.generatePackagerScript(package, true, &list, game) )
|
1 |
cycrow |
1423 |
{
|
|
|
1424 |
printf("Error: Unable to generate packager script\n");
|
|
|
1425 |
return;
|
|
|
1426 |
}
|
|
|
1427 |
|
|
|
1428 |
if ( toFile.Empty() )
|
160 |
cycrow |
1429 |
toFile = CFileIO(spkfile).GetDirIO().file(package->name() + "_" + package->author() + ".sps");
|
1 |
cycrow |
1430 |
|
|
|
1431 |
// save package file
|
185 |
cycrow |
1432 |
if ( CFileIO(toFile.ToString()).writeFile(&list) )
|
1 |
cycrow |
1433 |
printf("Packager script, %s, has been geenrated\n", toFile.c_str());
|
|
|
1434 |
else
|
|
|
1435 |
printf("Error: unable to write packager script, %s\n", toFile.c_str());
|
|
|
1436 |
|
|
|
1437 |
delete package;
|
|
|
1438 |
}
|
|
|
1439 |
|
|
|
1440 |
/*
|
|
|
1441 |
Func: LoadPackagerScript
|
|
|
1442 |
Args: String filename - The filename of the packager script to load
|
|
|
1443 |
Desc: Loads the packager scripts and creates a spk/xsp file from it
|
|
|
1444 |
*/
|
131 |
cycrow |
1445 |
void LoadPackagerScript(const Utils::String &filename, bool verify)
|
1 |
cycrow |
1446 |
{
|
131 |
cycrow |
1447 |
if ( !CFileIO::Exists(filename) )
|
1 |
cycrow |
1448 |
{
|
|
|
1449 |
printf("Error: The packager script, %s, does not exist", filename.c_str());
|
|
|
1450 |
return;
|
|
|
1451 |
}
|
|
|
1452 |
|
131 |
cycrow |
1453 |
Utils::String myDoc;
|
1 |
cycrow |
1454 |
#ifdef _WIN32
|
|
|
1455 |
TCHAR pszPath[MAX_PATH];
|
|
|
1456 |
if (SUCCEEDED(SHGetFolderPath(NULL, CSIDL_PERSONAL, NULL, SHGFP_TYPE_CURRENT, pszPath)))
|
|
|
1457 |
{
|
|
|
1458 |
myDoc = (char *)pszPath;
|
|
|
1459 |
}
|
|
|
1460 |
#endif
|
|
|
1461 |
|
|
|
1462 |
if ( verify )
|
|
|
1463 |
printf("Verifying Packager Script: %s\n", filename.c_str());
|
|
|
1464 |
|
|
|
1465 |
CPackages p;
|
131 |
cycrow |
1466 |
p.startup(".", ".", myDoc);
|
|
|
1467 |
Utils::CStringList malformed, unknown;
|
1 |
cycrow |
1468 |
|
131 |
cycrow |
1469 |
Utils::String curDir = CFileIO(filename).dir();
|
|
|
1470 |
if ( curDir.empty() ) curDir = "./";
|
1 |
cycrow |
1471 |
|
131 |
cycrow |
1472 |
Utils::CStringList variables;
|
|
|
1473 |
variables.pushBack("$PATH", curDir);
|
1 |
cycrow |
1474 |
|
134 |
cycrow |
1475 |
CFileProgress info(&p, NULL, "Adding File");
|
|
|
1476 |
CBaseFile *package = p.LoadPackagerScript(filename, -1, (verify) ? NULL : &GetAsk, &malformed, &unknown, &variables, &info);
|
1 |
cycrow |
1477 |
|
134 |
cycrow |
1478 |
printf("\n");
|
|
|
1479 |
|
1 |
cycrow |
1480 |
if ( verify )
|
|
|
1481 |
{
|
131 |
cycrow |
1482 |
if ( !malformed.empty() )
|
1 |
cycrow |
1483 |
{
|
131 |
cycrow |
1484 |
printf("Malformed Lines (%d):\n", malformed.size());
|
|
|
1485 |
for(auto itr = malformed.begin(); itr != malformed.end(); itr++)
|
|
|
1486 |
printf("\t(Line %3d) %s\n", (*itr)->data.toInt(), (*itr)->str.c_str());
|
1 |
cycrow |
1487 |
}
|
131 |
cycrow |
1488 |
if ( !unknown.empty() )
|
1 |
cycrow |
1489 |
{
|
131 |
cycrow |
1490 |
printf("Unknown Commands (%d):\n", unknown.size());
|
|
|
1491 |
for (auto itr = unknown.begin(); itr != unknown.end(); itr++)
|
|
|
1492 |
printf("\t* Command: %s = %s\n", (*itr)->str.c_str(), (*itr)->data.c_str());
|
1 |
cycrow |
1493 |
}
|
|
|
1494 |
}
|
|
|
1495 |
|
|
|
1496 |
if ( !package )
|
|
|
1497 |
{
|
|
|
1498 |
if ( verify )
|
|
|
1499 |
printf("Error: There are errors in the packager script which prevents it from being created\n");
|
|
|
1500 |
else
|
|
|
1501 |
printf("Error: Unable to create package, from script: %s\n", filename.c_str());
|
|
|
1502 |
}
|
|
|
1503 |
else
|
|
|
1504 |
{
|
131 |
cycrow |
1505 |
Utils::String saveto = package->filename();
|
|
|
1506 |
saveto = saveto.findReplace("$DEFAULTDIR", curDir + "/");
|
|
|
1507 |
saveto = saveto.findReplace("$PATH", curDir);
|
|
|
1508 |
saveto = saveto.findReplace("\\", "/");
|
|
|
1509 |
saveto = saveto.findReplace("//", "/");
|
|
|
1510 |
if ( !saveto.right(4).Compare(".spk") && package->GetType() != TYPE_XSP )
|
1 |
cycrow |
1511 |
saveto += ".spk";
|
131 |
cycrow |
1512 |
else if ( !saveto.right(4).Compare(".xsp") && package->GetType() == TYPE_XSP )
|
1 |
cycrow |
1513 |
saveto += ".xsp";
|
102 |
cycrow |
1514 |
printf("Saving file to: %s\n", CFileIO(saveto).fullFilename().c_str());
|
1 |
cycrow |
1515 |
if ( verify )
|
|
|
1516 |
printf("Package can be created from this script\n");
|
|
|
1517 |
else
|
|
|
1518 |
{
|
|
|
1519 |
// write script
|
175 |
cycrow |
1520 |
if ( package->writeFile(saveto) )
|
1 |
cycrow |
1521 |
{
|
|
|
1522 |
if ( package->AutoGenerateUpdateFile() )
|
134 |
cycrow |
1523 |
package->createUpdateFile(CFileIO(saveto).dir());
|
1 |
cycrow |
1524 |
printf("Package: %s was created\n", saveto.c_str());
|
|
|
1525 |
}
|
|
|
1526 |
else
|
|
|
1527 |
printf("Error! There was a problem writing the package\n");
|
|
|
1528 |
}
|
|
|
1529 |
|
50 |
cycrow |
1530 |
saveto = package->exportFilename();
|
131 |
cycrow |
1531 |
if ( !saveto.empty() ) {
|
|
|
1532 |
saveto = saveto.findReplace("$DEFAULTDIR", curDir + "/");
|
|
|
1533 |
saveto = saveto.findReplace("$PATH", curDir);
|
|
|
1534 |
saveto = saveto.findReplace("\\", "/");
|
|
|
1535 |
saveto = saveto.findReplace("//", "/");
|
102 |
cycrow |
1536 |
printf("Exporting file to: %s\n", CFileIO(saveto).fullFilename().c_str());
|
1 |
cycrow |
1537 |
if ( verify )
|
|
|
1538 |
printf("Package can be exported from this script\n");
|
|
|
1539 |
else
|
|
|
1540 |
{
|
|
|
1541 |
// export
|
175 |
cycrow |
1542 |
if ( package->saveToArchive(saveto, 0, p.GetGameExe()) ) {
|
1 |
cycrow |
1543 |
if ( package->IsAnyGameInPackage() ) {
|
|
|
1544 |
for ( int i = 0; i < p.GetGameExe()->GetNumGames(); i++ ) {
|
|
|
1545 |
if ( package->IsGameInPackage(i + 1) ) {
|
102 |
cycrow |
1546 |
Utils::String exportFile = CFileIO(saveto).dir() + "/" + CFileIO(saveto).baseName() + "_" + CBaseFile::ConvertGameToString(i + 1) + "." + CFileIO(saveto).extension();
|
175 |
cycrow |
1547 |
package->saveToArchive(exportFile, i + 1, p.GetGameExe());
|
1 |
cycrow |
1548 |
}
|
|
|
1549 |
}
|
|
|
1550 |
}
|
|
|
1551 |
printf("Package: %s was exported\n", saveto.c_str());
|
|
|
1552 |
}
|
|
|
1553 |
else
|
|
|
1554 |
printf("Error! There was a problem exporting the package\n");
|
|
|
1555 |
}
|
|
|
1556 |
}
|
|
|
1557 |
}
|
|
|
1558 |
}
|
|
|
1559 |
|
|
|
1560 |
/*
|
|
|
1561 |
Main entry point to program
|
|
|
1562 |
*/
|
|
|
1563 |
int main ( int argc, char **argv )
|
|
|
1564 |
{
|
|
|
1565 |
// display program header to command prompt
|
126 |
cycrow |
1566 |
printf ( "\nSPKTool V1.50 (SPK File Version %.2f) 14/02/2021 Created by Cycrow\n\n", (float)FILEVERSION );
|
1 |
cycrow |
1567 |
|
|
|
1568 |
// parse the cmd name
|
|
|
1569 |
CyString cmd (argv[0]);
|
|
|
1570 |
cmd = cmd.FindReplace ( "\\", "/" );
|
|
|
1571 |
g_dir = cmd.GetToken ( 0, cmd.NumToken('/') - 1, '/' );
|
|
|
1572 |
cmd = cmd.GetToken ( cmd.NumToken('/'), '/' );
|
|
|
1573 |
|
|
|
1574 |
g_read = false;
|
|
|
1575 |
|
|
|
1576 |
// not enough arguments, display the syntax and exit
|
|
|
1577 |
if ( argc < 2 )
|
|
|
1578 |
{
|
|
|
1579 |
PrintSyntax ( cmd );
|
|
|
1580 |
exit ( 1 );
|
|
|
1581 |
}
|
|
|
1582 |
|
|
|
1583 |
CyString fileTypes;
|
|
|
1584 |
for ( int i = 0; i < FILETYPE_MAX; i++ )
|
|
|
1585 |
{
|
|
|
1586 |
CyString sT = GetFileTypeString(i);
|
|
|
1587 |
if ( !sT.Empty() )
|
|
|
1588 |
{
|
|
|
1589 |
if ( fileTypes.Empty() )
|
|
|
1590 |
fileTypes = sT;
|
|
|
1591 |
else
|
|
|
1592 |
{
|
|
|
1593 |
fileTypes += ", ";
|
|
|
1594 |
fileTypes += sT;
|
|
|
1595 |
}
|
|
|
1596 |
}
|
|
|
1597 |
}
|
|
|
1598 |
|
|
|
1599 |
// get the command flag
|
134 |
cycrow |
1600 |
Utils::String command(argv[1]);
|
1 |
cycrow |
1601 |
|
|
|
1602 |
// display the contents of the spk file
|
134 |
cycrow |
1603 |
if ( command == "-v" || command == "--view" || command == "--version")
|
1 |
cycrow |
1604 |
{
|
|
|
1605 |
if ( argc < 3 )
|
|
|
1606 |
printf ( "Syntax: %s -v <spkfile>\n\tWill open and display the contents of the spkfile\n", cmd.c_str() );
|
|
|
1607 |
else
|
134 |
cycrow |
1608 |
DisplayVersion(argv[2]);
|
1 |
cycrow |
1609 |
}
|
|
|
1610 |
|
|
|
1611 |
// creates a new spk file
|
|
|
1612 |
else if ( command == "-c" || command == "--create" )
|
|
|
1613 |
{
|
|
|
1614 |
if ( argc < 3 )
|
|
|
1615 |
printf ( "Syntax:\n\t%s -c <spkfile>\n\t%s --create <spkfile>\n\t\tThis will create a new SPK file and allow you to set some basic settings for the file\n", cmd.c_str(), cmd.c_str() );
|
|
|
1616 |
else
|
|
|
1617 |
CreateFile ( argv[2] );
|
|
|
1618 |
}
|
|
|
1619 |
|
|
|
1620 |
// appends a file onto the spk archive
|
|
|
1621 |
else if ( command == "-a" || command == "--append" )
|
|
|
1622 |
{
|
|
|
1623 |
if ( argc < 4 )
|
|
|
1624 |
printf ( "Syntax:\n\t%s -a <spkfile> <type> <filename>\n\t%s --append <spkfile> <type> <filename>\n\t\tThis will append the file into the archive and compress it according to the files default compression\n\t<type> = %s\n", cmd.c_str(), cmd.c_str(), fileTypes.c_str() );
|
|
|
1625 |
else
|
|
|
1626 |
{
|
|
|
1627 |
CyString arg4;
|
|
|
1628 |
if ( argc > 4 )
|
|
|
1629 |
arg4 = argv[4];
|
|
|
1630 |
AppendFile ( argv[2], argv[3], arg4 );
|
|
|
1631 |
}
|
|
|
1632 |
}
|
|
|
1633 |
|
|
|
1634 |
// removes a file from the spk archive
|
|
|
1635 |
else if ( command == "-r" || command == "--remove" || command == "--removespk" )
|
|
|
1636 |
{
|
|
|
1637 |
if ( argc < 4 )
|
|
|
1638 |
{
|
|
|
1639 |
printf ( "Syntax:\n\t%s -r <spkfile> <type> <filename>\n\t%s --remove <spkfile> <type> <filename\n\t\tThis will remove a file from the archive\n\t<type> = %s\n", cmd.c_str(), cmd.c_str(), fileTypes.c_str() );
|
|
|
1640 |
printf ( "\t%s -r <multispkfile> <filename>\n\t%s --removespk <multispkfile> <filename>\n\t\tThis will remove a spk file from the Multi-SPK package\n", cmd.c_str(), cmd.c_str() );
|
|
|
1641 |
}
|
|
|
1642 |
else
|
|
|
1643 |
{
|
|
|
1644 |
CyString arg4;
|
|
|
1645 |
if ( argc > 4 )
|
|
|
1646 |
arg4 = argv[4];
|
|
|
1647 |
RemoveFile ( argv[2], argv[3], arg4 );
|
|
|
1648 |
}
|
|
|
1649 |
}
|
|
|
1650 |
|
|
|
1651 |
// extracts a file from a spk file
|
|
|
1652 |
else if ( command == "--extractspk" )
|
|
|
1653 |
{
|
|
|
1654 |
if ( argc < 4 )
|
|
|
1655 |
printf ( "Syntax:\n\t%s --extractspk <multispkfile> <filename> [destination]\n\tThis will extract a spk file from the Multi-Spk package and save it to the destination path\n", cmd.c_str() );
|
|
|
1656 |
else
|
|
|
1657 |
{
|
134 |
cycrow |
1658 |
Utils::String arg4;
|
1 |
cycrow |
1659 |
if ( argc > 4 )
|
|
|
1660 |
arg4 = argv[3];
|
134 |
cycrow |
1661 |
ExtractFile(argv[2], argv[3], arg4, Utils::String::Null());
|
1 |
cycrow |
1662 |
}
|
|
|
1663 |
}
|
|
|
1664 |
else if ( command == "-x" || command == "--extract")
|
|
|
1665 |
{
|
|
|
1666 |
if ( argc < 4 )
|
|
|
1667 |
{
|
|
|
1668 |
printf ( "Syntax:\n\t%s -x <spkfile> <type> <filename> [destination]\n\tThis will extract a file from the package and save it to the corect path in <directory>\n\t<type> = %s\n", cmd.c_str(), fileTypes.c_str() );
|
|
|
1669 |
printf ( "\t%s -x <multispkfile> <filename> [destination]\n\tThis will extract a spk file from the Multi-Spk package and save it to the destination path\n", cmd.c_str() );
|
|
|
1670 |
}
|
|
|
1671 |
else
|
|
|
1672 |
{
|
134 |
cycrow |
1673 |
Utils::String arg5, arg4;
|
1 |
cycrow |
1674 |
if ( argc > 5 )
|
|
|
1675 |
arg5 = argv[5];
|
|
|
1676 |
if ( argc > 4 )
|
|
|
1677 |
arg4 = argv[4];
|
134 |
cycrow |
1678 |
ExtractFile(argv[2], argv[3], arg4, arg5);
|
1 |
cycrow |
1679 |
}
|
|
|
1680 |
}
|
|
|
1681 |
|
|
|
1682 |
// extracts all the files from an archive
|
|
|
1683 |
else if ( command == "-e" || command == "--extractall" )
|
|
|
1684 |
{
|
|
|
1685 |
if ( argc < 3 )
|
|
|
1686 |
printf ( "Syntax:\n\t%s -e <spkfile> [destination]\n\t--extractall <spkfile> <game> [destination]\n\t\tThis will extract all files of a set game into the destination directory\n\n\t\tGame = 0 will extract all files", cmd.c_str() );
|
|
|
1687 |
else
|
|
|
1688 |
{
|
129 |
cycrow |
1689 |
Utils::String arg4;
|
1 |
cycrow |
1690 |
if ( argc > 4 )
|
|
|
1691 |
arg4 = argv[4];
|
134 |
cycrow |
1692 |
ExtractFiles(argv[2], arg4, CBaseFile::GetGameFromString(argv[3]));
|
1 |
cycrow |
1693 |
}
|
|
|
1694 |
}
|
|
|
1695 |
|
|
|
1696 |
// creates a multispk archive
|
|
|
1697 |
else if ( command == "-n" || command == "--createmulti" )
|
|
|
1698 |
{
|
|
|
1699 |
if ( argc < 3 )
|
|
|
1700 |
printf ( "Syntax:\n\t%s -n <multispkfile>\n\t%s --createmulti <multispkfile>\n\t\tThis will create a multispk file and allow you to add spk files to it\n", cmd.c_str(), cmd.c_str() );
|
|
|
1701 |
else
|
|
|
1702 |
CreateMultiFile ( argv[2] );
|
|
|
1703 |
}
|
|
|
1704 |
|
|
|
1705 |
// merges 2 multi-spk archives together, or appends a single spk file into a multi-spk file
|
|
|
1706 |
else if ( command == "-m" || command == "--mergemulti" )
|
|
|
1707 |
{
|
|
|
1708 |
if ( argc < 4 )
|
|
|
1709 |
printf ( "Syntax:\n\t%s -m <spkfile1> <spkfile2>\n\t%s --mergemulti <spkfile1> <spkfile2>\n\t\tThis will add spkfile2 into spkfile1, if spkfile1 is a normal SPK file, it will be saved into a Multi-Spk file\nspkfile2 can also be a Multi-Spk file, all files within it will be added\n", cmd.c_str(), cmd.c_str() );
|
|
|
1710 |
else
|
|
|
1711 |
AppendMultiFile ( argv[2], argv[3] );
|
|
|
1712 |
}
|
|
|
1713 |
|
|
|
1714 |
// splits the multi-spk file, exracts all spk files
|
|
|
1715 |
else if ( command == "-s" || command == "--splitmulti" )
|
|
|
1716 |
{
|
|
|
1717 |
if ( argc < 3 )
|
|
|
1718 |
printf ( "Syntax: %s -s <multispkfile> [destination]\n\tSplits the Multi-SPK file and saves each spk file to the destiantion directory\n", cmd.c_str() );
|
|
|
1719 |
else
|
|
|
1720 |
{
|
|
|
1721 |
CyString arg3;
|
|
|
1722 |
if ( argc > 3 )
|
|
|
1723 |
arg3 = argv[3];
|
|
|
1724 |
SplitMulti ( argv[2], arg3 );
|
|
|
1725 |
}
|
|
|
1726 |
}
|
|
|
1727 |
|
|
|
1728 |
else if ( command == "--set" )
|
|
|
1729 |
{
|
|
|
1730 |
if ( argc < 4 )
|
|
|
1731 |
printf ( "Syntax: %s --set <spkfile> <setting> [values]\n\tSets various settings in the package\n", cmd.c_str() );
|
|
|
1732 |
else
|
|
|
1733 |
Settings(argv[2], argv[3], argc, argv, cmd);
|
|
|
1734 |
}
|
|
|
1735 |
else if ( command == "--setrating" )
|
|
|
1736 |
{
|
|
|
1737 |
if ( argc < 6 )
|
|
|
1738 |
printf ( "Syntax: %s --setrating <spkfile> <easeofuse> <gamechanging> <recommended>\n\tSets the rating of the spk package\n", cmd.c_str() );
|
|
|
1739 |
else
|
|
|
1740 |
SetRating(argv[2], CyString(argv[3]).ToInt(), CyString(argv[4]).ToInt(), CyString(argv[5]).ToInt());
|
|
|
1741 |
}
|
|
|
1742 |
else if ( command == "--convertxsp" || command == "--convertxspwizard" )
|
|
|
1743 |
{
|
|
|
1744 |
if ( argc < 3 )
|
|
|
1745 |
printf ( "Syntax: %s %s <xspfile> [newxspfile]\n\tConverts an old format xsp file to work with the new format\n", cmd.c_str(), command.c_str() );
|
|
|
1746 |
else
|
|
|
1747 |
{
|
185 |
cycrow |
1748 |
Utils::String arg3;
|
1 |
cycrow |
1749 |
if ( argc > 3 )
|
|
|
1750 |
arg3 = argv[3];
|
|
|
1751 |
ConvertXsp(argv[2], arg3, (command == "--convertxspwizard") ? true : false);
|
|
|
1752 |
}
|
|
|
1753 |
}
|
|
|
1754 |
else if ( command == "--createscript" )
|
|
|
1755 |
{
|
|
|
1756 |
if ( argc < 3 )
|
|
|
1757 |
printf ( "Syntax:\n\t%s --createscript <packagerscript>\n\t\tThis will create a spk/xsp file from a packager script\n", cmd.c_str() );
|
|
|
1758 |
else
|
|
|
1759 |
LoadPackagerScript ( argv[2], false );
|
|
|
1760 |
}
|
|
|
1761 |
else if ( command == "--generatescript" )
|
|
|
1762 |
{
|
|
|
1763 |
if ( argc < 3 )
|
126 |
cycrow |
1764 |
printf ( "Syntax:\n\t%s --generatescript <package> [packagerscript]\n\t\tThis will generate a packager script file from a spk/xsp file.\n", cmd.c_str() );
|
1 |
cycrow |
1765 |
else
|
|
|
1766 |
{
|
|
|
1767 |
if ( argc < 4 )
|
126 |
cycrow |
1768 |
GeneratePackagerScript ( argv[2], "", 0);
|
1 |
cycrow |
1769 |
else
|
126 |
cycrow |
1770 |
GeneratePackagerScript ( argv[2], argv[3], 0);
|
1 |
cycrow |
1771 |
}
|
|
|
1772 |
}
|
|
|
1773 |
else if ( command == "--verifyscript" )
|
|
|
1774 |
{
|
|
|
1775 |
if ( argc < 3 )
|
|
|
1776 |
printf ( "Syntax:\n\t%s --verifyscript <packagerscript>\n\t\tThis will read a packager script and check its correct without creating the resulting spk/xsp file\n", cmd.c_str() );
|
|
|
1777 |
else
|
|
|
1778 |
LoadPackagerScript ( argv[2], true );
|
|
|
1779 |
}
|
|
|
1780 |
else if ( command == "--extractship" )
|
|
|
1781 |
{
|
|
|
1782 |
if ( argc < 4 )
|
|
|
1783 |
printf ( "Syntax:\n\t%s --extractship <modfile> <xspfile> [shipid]\n\t\tThis will create an xsp ship file by extracting from a mod file\n", cmd.c_str() );
|
|
|
1784 |
else
|
|
|
1785 |
{
|
|
|
1786 |
if ( argc < 5 )
|
|
|
1787 |
ExtractShip ( argv[2], argv[3], "" );
|
|
|
1788 |
else
|
|
|
1789 |
ExtractShip ( argv[2], argv[3], argv[4] );
|
|
|
1790 |
}
|
|
|
1791 |
}
|
126 |
cycrow |
1792 |
else if (command == "--generateupdatefile")
|
1 |
cycrow |
1793 |
{
|
126 |
cycrow |
1794 |
if (argc < 3)
|
|
|
1795 |
printf("Syntax:\n\t%s --generateupdatefile <package>\n\t\tThis will generate the update file to allow auto updates for a package\n", cmd.c_str());
|
|
|
1796 |
else
|
|
|
1797 |
GenerateUpdateFile(argv[2]);
|
|
|
1798 |
}
|
|
|
1799 |
else if (command == "--packagelist")
|
|
|
1800 |
{
|
|
|
1801 |
if (argc < 3)
|
|
|
1802 |
printf("Syntax:\n\t%s --packagelist <filenames>\n\t\tThis will generate the update file to allow downloading packages from a server.\n", cmd.c_str());
|
1 |
cycrow |
1803 |
else
|
126 |
cycrow |
1804 |
GenerateUpdateList(argc, argv);
|
1 |
cycrow |
1805 |
}
|
|
|
1806 |
|
|
|
1807 |
// not a valid switch, display syntax
|
|
|
1808 |
else
|
|
|
1809 |
PrintSyntax ( cmd );
|
|
|
1810 |
|
|
|
1811 |
#ifdef _DEBUG
|
|
|
1812 |
char pause;
|
|
|
1813 |
scanf ( "%s", &pause );
|
|
|
1814 |
#endif
|
|
|
1815 |
|
|
|
1816 |
return 0;
|
|
|
1817 |
}
|