Subversion Repositories spk

Rev

Rev 178 | Rev 200 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 178 Rev 197
Line 192... Line 192...
192
public:
192
public:
193
	virtual void ProgressPercent ( float percent ) = 0;
193
	virtual void ProgressPercent ( float percent ) = 0;
194
};
194
};
195
 
195
 
196
 
196
 
197
Utils::String SPKEXPORT GetFileTypeString ( int type );
197
Utils::WString SPKEXPORT GetFileTypeString ( int type );
198
FileType SPKEXPORT GetFileTypeFromString(const Utils::String &type);
198
FileType SPKEXPORT GetFileTypeFromString(const Utils::WString &type);
199
Utils::String SPKEXPORT FormatErrorString (int error, const Utils::String &rest);
199
Utils::String SPKEXPORT FormatErrorString (int error, const Utils::String &rest);
200
float	 SPKEXPORT GetLibraryVersion ();
200
float	 SPKEXPORT GetLibraryVersion ();
201
float	 SPKEXPORT GetFileFormatVersion ();
201
float	 SPKEXPORT GetFileFormatVersion ();
202
 
202
 
203
class CBaseFile;
203
class CBaseFile;
204
class SPKEXPORT C_File
204
class SPKEXPORT C_File
205
{
205
{
206
public:
206
public:
207
	static Utils::String GetDirectory(FileType eType, const Utils::String &filename, CBaseFile *file);
207
	static Utils::WString GetDirectory(FileType eType, const Utils::WString &filename, CBaseFile *file);
208
	static bool DoesTypeHaveExtraDir(int i);
208
	static bool DoesTypeHaveExtraDir(int i);
209
 
209
 
210
public:
210
public:
211
 
211
 
212
	void clearUsed () { _iUsed = 0; }
212
	void clearUsed () { _iUsed = 0; }
213
	void incUsed () { ++_iUsed; }
213
	void incUsed () { ++_iUsed; }
214
	void DeleteData ();
214
	void DeleteData ();
215
	// varible setting functions
215
	// varible setting functions
216
	void setFileType(FileType t) { m_iFileType = t; }
216
	void setFileType(FileType t) { m_iFileType = t; }
217
	void setFilename(const Utils::String &filename);
217
	void setFilename(const Utils::WString &filename);
218
	void setName(const Utils::String &name) { _sName = name; }
218
	void setName(const Utils::WString &name) { _sName = name; }
219
	void setDir(const Utils::String &dir) { _sDir = dir; }
219
	void setDir(const Utils::WString &dir) { _sDir = dir; }
220
	void SetCreationTime ( time_t time ) { m_tTime = time; }
220
	void SetCreationTime ( time_t time ) { m_tTime = time; }
221
	void SetFileSize ( long size ) { m_lSize = size; }
221
	void SetFileSize ( long size ) { m_lSize = size; }
222
	void SetDataSize ( long size ) { m_lDataSize = size; }
222
	void SetDataSize ( long size ) { m_lDataSize = size; }
223
	void SetUncompressedDataSize ( long size ) { m_lUncomprDataSize = size; }
223
	void SetUncompressedDataSize ( long size ) { m_lUncomprDataSize = size; }
224
	void SetDataCompression ( int c ) { m_iDataCompression = c; }
224
	void SetDataCompression ( int c ) { m_iDataCompression = c; }
225
	void SetShared ( bool b ) { m_bShared = b; }
225
	void SetShared ( bool b ) { m_bShared = b; }
226
	void SetSigned ( bool b ) { m_bSigned = b; }
226
	void SetSigned ( bool b ) { m_bSigned = b; }
227
	void setFullDir(const Utils::String &dir) { _sFullDir = dir; }
227
	void setFullDir(const Utils::WString &dir) { _sFullDir = dir; }
228
	void setInMod (const Utils::String &s) { _sInMod = s; }
228
	void setInMod (const Utils::WString &s) { _sInMod = s; }
229
	void SetCompressedToFile ( bool b ) { m_bCompressedToFile = b; }
229
	void SetCompressedToFile ( bool b ) { m_bCompressedToFile = b; }
230
	void SetData(const unsigned char *data, size_t size) { m_sData = (unsigned char *)data, m_lDataSize = (long)size; }
230
	void SetData(const unsigned char *data, size_t size) { m_sData = (unsigned char *)data, m_lDataSize = (long)size; }
231
	void copyData(const unsigned char *data, size_t size);
231
	void copyData(const unsigned char *data, size_t size);
232
 
232
 
233
	// get functions
233
	// get functions
234
	int getUsed () { return _iUsed; }
234
	int getUsed () { return _iUsed; }
235
	int GetLastError () { return m_iLastError; }
235
	int GetLastError () { return m_iLastError; }
236
	int GetFileType() { return m_iFileType; }
236
	int GetFileType() { return m_iFileType; }
237
	FileType fileType() { return m_iFileType; }
237
	FileType fileType() { return m_iFileType; }
238
	const Utils::String &filename() const { return _sName; }
238
	const Utils::WString &filename() const { return _sName; }
239
	Utils::String fullFilename() { return _sFullDir + "/" + _sName; }
239
	Utils::WString fullFilename() { return _sFullDir + "/" + _sName; }
240
	long GetSize () { return m_lSize; }
240
	long GetSize () { return m_lSize; }
241
	time_t GetCreationTime () { return m_tTime; }
241
	time_t GetCreationTime () { return m_tTime; }
242
	const Utils::String &name() { return _sName; }
242
	const Utils::WString &name() { return _sName; }
243
	const Utils::String &dir() { return _sDir; }
243
	const Utils::WString &dir() { return _sDir; }
244
	Utils::String dataSizeString() const;
244
	Utils::WString dataSizeString() const;
245
	Utils::String uncompressedSizeString() const;
245
	Utils::WString uncompressedSizeString() const;
246
	Utils::String getDirectory(CBaseFile *spkfile) const;
246
	Utils::WString getDirectory(CBaseFile *spkfile) const;
247
	int GetVersion () { return m_iVersion; }
247
	int GetVersion () { return m_iVersion; }
248
	time_t GetLastModified() { return m_tTime; }
248
	time_t GetLastModified() { return m_tTime; }
249
	Utils::String fileTypeString() const { return ::GetFileTypeString(m_iFileType); }
249
	Utils::WString fileTypeString() const { return ::GetFileTypeString(m_iFileType); }
250
	Utils::String creationTimeString() const;
250
	Utils::WString creationTimeString() const;
251
	const Utils::String &getTempFile () const { return _sTmpFile; }
251
	const Utils::WString &getTempFile () const { return _sTmpFile; }
252
	const Utils::String fullDir() const { return _sFullDir; }
252
	const Utils::WString fullDir() const { return _sFullDir; }
253
	Utils::String baseName() const;
253
	Utils::WString baseName() const;
254
	const Utils::String &originalName() const { return _sOriginalName; }
254
	const Utils::WString &originalName() const { return _sOriginalName; }
255
	const Utils::String &getInMod() const { return _sInMod; }
255
	const Utils::WString &getInMod() const { return _sInMod; }
256
	const Utils::String &getSignature() { if ( !m_bUpdatedSignature ) updateSignature(); return _sSignature; }
256
	const Utils::WString &getSignature() { if ( !m_bUpdatedSignature ) updateSignature(); return _sSignature; }
257
	void updateSignature();
257
	void updateSignature();
258
	void changeBaseName(const Utils::String &b) { _sName = b + "." + this->fileExt(); }
258
	void changeBaseName(const Utils::WString &b) { _sName = b + "." + this->fileExt(); }
259
	bool renameScript(const Utils::String &baseName);
259
	bool renameScript(const Utils::WString &baseName);
260
	bool isInMod() { return !_sInMod.empty(); }
260
	bool isInMod() { return !_sInMod.empty(); }
261
 
261
 
262
	void FixOriginalName() { _sOriginalName = _sName; }
262
	void FixOriginalName() { _sOriginalName = _sName; }
263
	void SetOriginalName(const Utils::String &name) { _sOriginalName = name; }
263
	void SetOriginalName(const Utils::WString &name) { _sOriginalName = name; }
264
 
264
 
265
	bool isFileInAddon() const;
265
	bool isFileInAddon() const;
266
	bool IsFakePatch () const;
266
	bool IsFakePatch () const;
267
	bool isAutoTextFile();
267
	bool isAutoTextFile();
268
	int  textFileID(const Utils::String &name = Utils::String::Null()) const;
268
	int  textFileID(const Utils::WString &name = Utils::WString::Null()) const;
269
	bool IsCompressedToFile () { return m_bCompressedToFile; }
269
	bool IsCompressedToFile () { return m_bCompressedToFile; }
270
	bool CompareNew ( C_File *file );
270
	bool CompareNew ( C_File *file );
271
	Utils::String fileExt() const;
271
	Utils::WString fileExt() const;
272
	bool checkFileExt(const Utils::String& ext);
272
	bool checkFileExt(const Utils::WString& ext);
273
	const Utils::String &changeFileExt(const Utils::String &ext);
273
	const Utils::WString &changeFileExt(const Utils::WString &ext);
274
	bool CheckPackedExtension();
274
	bool CheckPackedExtension();
275
	bool shouldCheckBaseName() const;
275
	bool shouldCheckBaseName() const;
276
 
276
 
277
	int GetCompressionType () { return m_iDataCompression; }
277
	int GetCompressionType () { return m_iDataCompression; }
278
	long GetDataSize () { return m_lDataSize; }
278
	long GetDataSize () { return m_lDataSize; }
279
	// returns the Uncompressed Data size, based on how the file is loaded, ie view data, view pointer, etc
279
	// returns the Uncompressed Data size, based on how the file is loaded, ie view data, view pointer, etc
280
	long uncompressedDataSize() const;
280
	long uncompressedDataSize() const;
281
	Utils::String getNameDirectory(CBaseFile *spkfile) const;
281
	Utils::WString getNameDirectory(CBaseFile *spkfile) const;
282
 
282
 
283
	unsigned int game() const;
283
	unsigned int game() const;
284
	bool isForGame(int game) const;
284
	bool isForGame(int game) const;
285
	int getForSingleGame() const;
285
	int getForSingleGame() const;
286
	void setGame(unsigned int i);
286
	void setGame(unsigned int i);
Line 294... Line 294...
294
	bool ReadSignedFile();
294
	bool ReadSignedFile();
295
 
295
 
296
	// file reading functions
296
	// file reading functions
297
	long ReadFileSize ();
297
	long ReadFileSize ();
298
	time_t ReadLastModified ();
298
	time_t ReadLastModified ();
299
	bool readFromFile(const Utils::String filename);
299
	bool readFromFile(const Utils::WString filename);
300
	bool ReadFromFile ();
300
	bool ReadFromFile ();
301
	bool readFromFile(CFileIO &File);
301
	bool readFromFile(CFileIO &File);
302
	bool readFromFile(CFileIO &File, int lSize, bool bDoSize = true);
302
	bool readFromFile(CFileIO &File, int lSize, bool bDoSize = true);
303
	bool ReadFromData ( char *data, long size );
303
	bool ReadFromData ( char *data, long size );
304
	int ReadScriptVersion ();
304
	int ReadScriptVersion ();
305
	Utils::String filePointer() const;
305
	Utils::WString filePointer() const;
306
	bool isExternalFile() const;
306
	bool isExternalFile() const;
307
 
307
 
308
	// file writing functions
308
	// file writing functions
309
	bool writeToDir(const Utils::String &dir, CBaseFile *, bool = true, const Utils::String &appendDir = Utils::String::Null(), unsigned char * = NULL, long = 0);
309
	bool writeToDir(const Utils::WString &dir, CBaseFile *, bool = true, const Utils::WString &appendDir = Utils::WString::Null(), unsigned char * = NULL, long = 0);
310
	bool writeToFile(const Utils::String &filename, unsigned char * = NULL, long = 0);
310
	bool writeToFile(const Utils::WString &filename, unsigned char * = NULL, long = 0);
311
	bool writeFilePointer(unsigned char *cData = NULL, long len = 0);
311
	bool writeFilePointer(unsigned char *cData = NULL, long len = 0);
312
 
312
 
313
	// file compression functions
313
	// file compression functions
314
	unsigned char *CompressToData(int compressionType, unsigned long *outSize, CProgressInfo *progress = NULL, int level = DEFAULT_COMPRESSION_LEVEL);
314
	unsigned char *CompressToData(int compressionType, unsigned long *outSize, CProgressInfo *progress = NULL, int level = DEFAULT_COMPRESSION_LEVEL);
315
	bool uncompressToFile(const Utils::String &toFile, CBaseFile *spkFile, bool includeDir = true, CProgressInfo *progress = NULL);
315
	bool uncompressToFile(const Utils::WString &toFile, CBaseFile *spkFile, bool includeDir = true, CProgressInfo *progress = NULL);
316
	bool ChangeCompression(int compresstyp, CProgressInfo *progress);
316
	bool ChangeCompression(int compresstyp, CProgressInfo *progress);
317
	bool CompressData ( int compressionType, CProgressInfo * = NULL, int level = DEFAULT_COMPRESSION_LEVEL );
317
	bool CompressData ( int compressionType, CProgressInfo * = NULL, int level = DEFAULT_COMPRESSION_LEVEL );
318
	bool CompressFile ( CProgressInfo * = NULL );
318
	bool CompressFile ( CProgressInfo * = NULL );
319
	bool UncompressData ( CProgressInfo * = NULL );
319
	bool UncompressData ( CProgressInfo * = NULL );
320
	unsigned char *UncompressData ( long *size, CProgressInfo * = NULL );
320
	unsigned char *UncompressData ( long *size, CProgressInfo * = NULL );
Line 340... Line 340...
340
	bool BobDecompile();
340
	bool BobDecompile();
341
	bool BodCompile();
341
	bool BodCompile();
342
 
342
 
343
	// contructor/decontructor
343
	// contructor/decontructor
344
	C_File();
344
	C_File();
345
	C_File(const Utils::String &filename);
345
	C_File(const Utils::WString &filename);
346
	virtual ~C_File();
346
	virtual ~C_File();
347
 
347
 
348
protected:
348
protected:
349
	static int m_iTempNum; // Used when creating temp files, allows new tmp files without overrighing used ones
349
	static int m_iTempNum; // Used when creating temp files, allows new tmp files without overrighing used ones
350
 
350
 
351
	// private functions
351
	// private functions
352
	void Reset();
352
	void Reset();
353
	Utils::String _getFullFileToDir(const Utils::String &dir, bool includedir, CBaseFile *file) const;
353
	Utils::WString _getFullFileToDir(const Utils::WString &dir, bool includedir, CBaseFile *file) const;
354
 
354
 
355
	Utils::String  _sName; // just the filename
355
	Utils::WString  _sName; // just the filename
356
	Utils::String  _sDir;  // the extra dir (only for extras)
356
	Utils::WString  _sDir;  // the extra dir (only for extras)
357
	Utils::String  _sInMod; // in a mod files
357
	Utils::WString  _sInMod; // in a mod files
358
	Utils::String  _sSignature;
358
	Utils::WString  _sSignature;
359
 
359
 
360
	// file pointer varibles
360
	// file pointer varibles
361
	Utils::String  _sFullDir; // the full dir path of the file (This is used for file pointers when not loaded data in file)
361
	Utils::WString  _sFullDir; // the full dir path of the file (This is used for file pointers when not loaded data in file)
362
	long    m_lSize;  // size of current file pointer
362
	long    m_lSize;  // size of current file pointer
363
 
363
 
364
	// Main file varibles
364
	// Main file varibles
365
	int		m_iVersion;  // used when reading script versions
365
	int		m_iVersion;  // used when reading script versions
366
	bool	m_bSigned;   // signed status of file, installer only, read from file
366
	bool	m_bSigned;   // signed status of file, installer only, read from file
Line 375... Line 375...
375
	int		m_iDataCompression; // the current compression of m_sData
375
	int		m_iDataCompression; // the current compression of m_sData
376
 
376
 
377
	FileType m_iFileType; // type if file, ie Script, Text, etc
377
	FileType m_iFileType; // type if file, ie Script, Text, etc
378
 
378
 
379
	bool    m_bUsedMalloc; // malloc type of m_sData, so it can use with free() or delete
379
	bool    m_bUsedMalloc; // malloc type of m_sData, so it can use with free() or delete
380
	Utils::String	_sTmpFile;
380
	Utils::WString	_sTmpFile;
381
 
381
 
382
	bool	m_bCompressedToFile;
382
	bool	m_bCompressedToFile;
383
 
383
 
384
	bool    m_bSkip;
384
	bool    m_bSkip;
385
	bool	m_bLoaded;
385
	bool	m_bLoaded;
Line 387... Line 387...
387
	bool	m_bUpdatedSignature;
387
	bool	m_bUpdatedSignature;
388
 
388
 
389
	int		m_iPos;
389
	int		m_iPos;
390
	unsigned int _iGame;
390
	unsigned int _iGame;
391
 
391
 
392
	Utils::String _sOriginalName;
392
	Utils::WString _sOriginalName;
393
 
393
 
394
	int m_iLastError;
394
	int m_iLastError;
395
	bool	m_bDontDeleteData; // fix for bad data deleteion
395
	bool	m_bDontDeleteData; // fix for bad data deleteion
396
};
396
};
397
 
397