Subversion Repositories spk

Rev

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

Rev 126 Rev 127
Line 35... Line 35...
35
#include "x2bc/x2bc_common/realfile_stream.h"
35
#include "x2bc/x2bc_common/realfile_stream.h"
36
*/
36
*/
37
#include "../Windows/libx2bc.h"
37
#include "../Windows/libx2bc.h"
38
 
38
 
39
//////////////////////////////////////////////////////////////////////
39
//////////////////////////////////////////////////////////////////////
-
 
40
// STATIC FUNCTIONS
-
 
41
//////////////////////////////////////////////////////////////////////
-
 
42
 
-
 
43
Utils::String C_File::GetDirectory(FileType eType, const Utils::String &filename, CBaseFile *file)
-
 
44
{
-
 
45
	switch (eType)
-
 
46
	{
-
 
47
	case FILETYPE_SCRIPT:
-
 
48
		return "Scripts";
-
 
49
	case FILETYPE_TEXT:
-
 
50
		return "T";
-
 
51
	case FILETYPE_README:
-
 
52
	{
-
 
53
		if (file)
-
 
54
			return Utils::String("PluginManager/Readme/") + file->GetNameValidFile().ToString();
-
 
55
		return "PluginManager/Readme";
-
 
56
	}
-
 
57
	case FILETYPE_MAP:
-
 
58
		return "Maps";
-
 
59
	case FILETYPE_MOD:
-
 
60
		return "Mods";
-
 
61
	case FILETYPE_UNINSTALL:
-
 
62
		return "PluginManager/Uninstall";
-
 
63
	case FILETYPE_SOUND:
-
 
64
		if (!filename.empty() && !CFileIO(filename).CheckFileExtension("wav"))
-
 
65
			return "Soundtrack";
-
 
66
		return "s";
-
 
67
	case FILETYPE_SOUNDTRACK:
-
 
68
		return "Soundtrack";
-
 
69
	case FILETYPE_EXTRA:
-
 
70
		return "PluginManager/Extras";
-
 
71
	case FILETYPE_SCREEN:
-
 
72
		return "loadscr";
-
 
73
	case FILETYPE_ADVERT:
-
 
74
		return "PluginManager/Graphics";
-
 
75
	case FILETYPE_MISSION:
-
 
76
		return "Director";
-
 
77
	}
-
 
78
	return Utils::String::Null();
-
 
79
}
-
 
80
 
-
 
81
bool C_File::DoesTypeHaveExtraDir(int i)
-
 
82
{
-
 
83
	switch (i)
-
 
84
	{
-
 
85
	case FILETYPE_EXTRA:
-
 
86
	case FILETYPE_SHIPSCENE:
-
 
87
	case FILETYPE_COCKPITSCENE:
-
 
88
	case FILETYPE_SHIPMODEL:
-
 
89
	case FILETYPE_SHIPOTHER:
-
 
90
		return true;
-
 
91
	}
-
 
92
	return false;
-
 
93
}
-
 
94
 
-
 
95
//////////////////////////////////////////////////////////////////////
40
// Construction/Destruction
96
// Construction/Destruction
41
//////////////////////////////////////////////////////////////////////
97
//////////////////////////////////////////////////////////////////////
42
 
98
 
43
void CProgressInfoDone::DoingFile ( C_File *file )
99
void CProgressInfoDone::DoingFile ( C_File *file )
44
{
100
{
Line 73... Line 129...
73
	m_bUsedMalloc = false;
129
	m_bUsedMalloc = false;
74
	m_sData = NULL;
130
	m_sData = NULL;
75
	Reset();
131
	Reset();
76
}
132
}
77
 
133
 
78
C_File::C_File ( CyString filename )
134
C_File::C_File(const Utils::String &filename)
79
{
-
 
80
	m_bDontDeleteData = false;
-
 
81
	m_bUsedMalloc = false;
-
 
82
	m_sData = NULL;
-
 
83
	Reset ();
-
 
84
	SetFilename ( filename );
-
 
85
}
-
 
86
 
-
 
87
C_File::C_File ( const char *filename )
-
 
88
{
135
{
89
	m_bDontDeleteData = false;
136
	m_bDontDeleteData = false;
90
	m_bUsedMalloc = false;
137
	m_bUsedMalloc = false;
91
	m_sData = NULL;
138
	m_sData = NULL;
92
	Reset ();
139
	Reset ();
93
	SetFilename ( CyString(filename) );
140
	SetFilename(filename);
94
}
141
}
95
 
142
 
96
C_File::~C_File()
143
C_File::~C_File()
97
{
144
{
98
	DeleteData ();
145
	DeleteData ();
Line 180... Line 227...
180
			dir = dir.findReplace("$scriptauthor", file->author());
227
			dir = dir.findReplace("$scriptauthor", file->author());
181
		}
228
		}
182
		return dir;
229
		return dir;
183
	}
230
	}
184
 
231
 
185
	switch (m_iFileType)
-
 
186
	{
-
 
187
	case FILETYPE_SCRIPT:
-
 
188
		return "Scripts";
-
 
189
	case FILETYPE_TEXT:
-
 
190
		return "T";
-
 
191
	case FILETYPE_README:
-
 
192
	{
-
 
193
		if (file)
-
 
194
			return Utils::String("PluginManager/Readme/") + file->GetNameValidFile().ToString();
-
 
195
		return "PluginManager/Readme";
-
 
196
	}
-
 
197
	case FILETYPE_MAP:
-
 
198
		return "Maps";
-
 
199
	case FILETYPE_MOD:
-
 
200
		//			if ( (file) && (file->IsPatch()) )
-
 
201
		//				return "Mods/Patch";
-
 
202
		return "Mods";
-
 
203
	case FILETYPE_UNINSTALL:
-
 
204
		return "PluginManager/Uninstall";
-
 
205
	case FILETYPE_SOUND:
-
 
206
		if (CFileIO(m_sName).CheckFileExtension("wav"))
-
 
207
			return "s";
-
 
208
		return "Soundtrack";
-
 
209
	case FILETYPE_EXTRA:
-
 
210
		return "PluginManager/Extras";
-
 
211
	case FILETYPE_SCREEN:
-
 
212
		return "loadscr";
-
 
213
	case FILETYPE_ADVERT:
-
 
214
		return "PluginManager/Graphics";
-
 
215
	case FILETYPE_MISSION:
-
 
216
		return "Director";
-
 
217
	}
-
 
218
	return Utils::String::Null();
232
	return GetDirectory(m_iFileType, m_sName.ToString(), file);
219
}
233
}
220
 
234
 
221
 
-
 
222
CyString C_File::GetNameDirectory ( CBaseFile *file )
235
CyString C_File::GetNameDirectory ( CBaseFile *file )
223
{
236
{
224
	CyString dir = GetDirectory( file );
237
	CyString dir = GetDirectory( file );
225
	if ( !dir.Empty() )
238
	if ( !dir.Empty() )
226
		dir += "/";
239
		dir += "/";
Line 234... Line 247...
234
*/
247
*/
235
void C_File::Reset ()
248
void C_File::Reset ()
236
{
249
{
237
	m_iLastError = SPKERR_NONE;
250
	m_iLastError = SPKERR_NONE;
238
	m_bLoaded = false;
251
	m_bLoaded = false;
239
	m_iFileType = -1;
252
	m_iFileType = FILETYPE_UNKNOWN;
240
	m_lSize = 0;
253
	m_lSize = 0;
241
	m_iVersion = 0;
254
	m_iVersion = 0;
242
	m_bSigned = false;
255
	m_bSigned = false;
243
	m_iUsed = 0;
256
	m_iUsed = 0;
244
	m_tTime = 0;
257
	m_tTime = 0;
Line 249... Line 262...
249
	m_bShared = false;
262
	m_bShared = false;
250
	m_bCompressedToFile = false;
263
	m_bCompressedToFile = false;
251
	m_bDisabled = false;
264
	m_bDisabled = false;
252
	m_bUpdatedSignature = false;
265
	m_bUpdatedSignature = false;
253
	m_iPos = -1;
266
	m_iPos = -1;
254
	m_iGame = 0;
267
	_iGame = 0;
255
}
268
}
256
 
269
 
257
bool C_File::UpdateSigned()
270
bool C_File::UpdateSigned()
258
{
271
{
259
	switch ( m_iFileType )
272
	switch ( m_iFileType )
Line 346... Line 359...
346
 
359
 
347
	if ( textid <= 3 )
360
	if ( textid <= 3 )
348
		return true;
361
		return true;
349
 
362
 
350
	// check for original name
363
	// check for original name
351
	if ( !m_sOriginalName.Empty() )
364
	if ( !_sOriginalName.empty() )
352
	{
365
	{
353
		textid = GetTextFileID(m_sOriginalName);
366
		textid = GetTextFileID(_sOriginalName);
354
		if ( textid >= 0 && textid <= 3 )
367
		if ( textid >= 0 && textid <= 3 )
355
			return true;
368
			return true;
356
	}
369
	}
357
 
370
 
358
	return false;
371
	return false;
Line 532... Line 545...
532
	if ( !m_sName.Empty() )
545
	if ( !m_sName.Empty() )
533
		fullfile += m_sName.ToString();
546
		fullfile += m_sName.ToString();
534
 
547
 
535
	return fullfile;
548
	return fullfile;
536
}
549
}
-
 
550
 
-
 
551
bool C_File::isExternalFile() const
-
 
552
{
-
 
553
	if (!m_sData && !m_lDataSize)
-
 
554
	{
-
 
555
		Utils::String file = this->filePointer();
-
 
556
		if (!file.empty() && CFileIO::Exists(file))
-
 
557
			return true;
-
 
558
	}
-
 
559
	return false;
-
 
560
}
-
 
561
 
537
/*
562
/*
538
	Func:	GetFilePointer
563
	Func:	GetFilePointer
539
	Desc:	Returns the file pointer name
564
	Desc:	Returns the file pointer name
540
			Joins dir and name together
565
			Joins dir and name together
541
			Works for relative paths as well
566
			Works for relative paths as well
Line 1302... Line 1327...
1302
	}
1327
	}
1303
 
1328
 
1304
	return Utils::String::Null();
1329
	return Utils::String::Null();
1305
}
1330
}
1306
 
1331
 
1307
int GetFileTypeFromString ( CyString type )
1332
FileType GetFileTypeFromString ( CyString type )
1308
{
1333
{
1309
	CyString ltype = type.ToLower();
1334
	CyString ltype = type.ToLower();
1310
	if ( ltype == "script" )
1335
	if ( ltype == "script" )
1311
		return FILETYPE_SCRIPT;
1336
		return FILETYPE_SCRIPT;
1312
	else if ( ltype == "text" )
1337
	else if ( ltype == "text" )
Line 1338... Line 1363...
1338
	else if ( ltype == "shipscene" )
1363
	else if ( ltype == "shipscene" )
1339
		return FILETYPE_SHIPSCENE;
1364
		return FILETYPE_SHIPSCENE;
1340
	else if ( ltype == "cockpitscene" )
1365
	else if ( ltype == "cockpitscene" )
1341
		return FILETYPE_COCKPITSCENE;
1366
		return FILETYPE_COCKPITSCENE;
1342
 
1367
 
1343
	return -1;
1368
	return FILETYPE_UNKNOWN;
1344
}
1369
}
1345
 
1370
 
1346
 
1371
 
1347
CyString FormatErrorString(int error, CyString rest)
1372
CyString FormatErrorString(int error, CyString rest)
1348
{
1373
{
Line 1789... Line 1814...
1789
	SetFilename(oldFile->GetFullFilename());
1814
	SetFilename(oldFile->GetFullFilename());
1790
	m_sDir = oldFile->GetDir();
1815
	m_sDir = oldFile->GetDir();
1791
	m_tTime = oldFile->GetCreationTime();
1816
	m_tTime = oldFile->GetCreationTime();
1792
	m_bShared = oldFile->IsShared();
1817
	m_bShared = oldFile->IsShared();
1793
	m_bSigned = oldFile->IsSigned();
1818
	m_bSigned = oldFile->IsSigned();
1794
	m_iFileType = oldFile->GetFileType();
1819
	m_iFileType = oldFile->fileType();
1795
	m_lSize = oldFile->GetSize();
1820
	m_lSize = oldFile->GetSize();
1796
	if ( includeData )
1821
	if ( includeData )
1797
	{
1822
	{
1798
		m_lDataSize = oldFile->GetDataSize();
1823
		m_lDataSize = oldFile->GetDataSize();
1799
		if ( m_sData )
1824
		if ( m_sData )
Line 1840... Line 1865...
1840
	if (ext == "bod" || ext == "bob" || ext == "pbb" || ext == "pbd")
1865
	if (ext == "bod" || ext == "bob" || ext == "pbb" || ext == "pbd")
1841
		return true;
1866
		return true;
1842
	return false;
1867
	return false;
1843
}
1868
}
1844
 
1869
 
-
 
1870
unsigned int C_File::game() const 
-
 
1871
{ 
-
 
1872
	return _iGame; 
-
 
1873
}
-
 
1874
 
-
 
1875
void C_File::setGame(unsigned int i) 
-
 
1876
{ 
-
 
1877
	if (i == 0 || i == 1 << 31)
-
 
1878
		_iGame = 0;
-
 
1879
	else
-
 
1880
		_iGame = i; 
-
 
1881
}
-
 
1882
 
1845
 
1883
 
1846
unsigned char *C_File::BobDecompile(size_t *size)
1884
unsigned char *C_File::BobDecompile(size_t *size)
1847
{
1885
{
1848
	(*size) = 0;
1886
	(*size) = 0;
1849
 
1887