Subversion Repositories spk

Rev

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

Rev 129 Rev 130
Line 135... Line 135...
135
{
135
{
136
	m_bDontDeleteData = false;
136
	m_bDontDeleteData = false;
137
	m_bUsedMalloc = false;
137
	m_bUsedMalloc = false;
138
	m_sData = NULL;
138
	m_sData = NULL;
139
	Reset ();
139
	Reset ();
140
	SetFilename(filename);
140
	setFilename(filename);
141
}
141
}
142
 
142
 
143
C_File::~C_File()
143
C_File::~C_File()
144
{
144
{
145
	DeleteData ();
145
	DeleteData ();
Line 153... Line 153...
153
	Return: Directory String
153
	Return: Directory String
154
	Desc:	Returns the directory the file goes into, based on m_sDir and Filetype
154
	Desc:	Returns the directory the file goes into, based on m_sDir and Filetype
155
*/
155
*/
156
CyString C_File::GetDirectory ( CBaseFile *file )
156
CyString C_File::GetDirectory ( CBaseFile *file )
157
{
157
{
158
	if ( IsFakePatch() )
-
 
159
		return "";
-
 
160
 
-
 
161
	if ( (m_iFileType == FILETYPE_MOD) && (m_sDir == "Patch") )
-
 
162
		return "PluginManager/Patch";
-
 
163
 
-
 
164
	if ( (!m_sDir.Empty()) && (m_iFileType != FILETYPE_README) && m_sDir != "." )
-
 
165
	{
-
 
166
		CyString dir = m_sDir.FindReplace ( "\\", "/" );
-
 
167
		if ( file )
-
 
168
		{
-
 
169
			dir = dir.FindReplace ( "$scriptname", file->GetNameValidFile() );
-
 
170
			dir = dir.FindReplace ( "$scriptauthor", CyString(file->author()) );
-
 
171
		}
-
 
172
		return dir;
-
 
173
	}
-
 
174
 
-
 
175
	switch ( m_iFileType )
-
 
176
	{
-
 
177
		case FILETYPE_SCRIPT:
-
 
178
			return "Scripts";
-
 
179
		case FILETYPE_TEXT:
-
 
180
			return "T";
-
 
181
		case FILETYPE_README:
-
 
182
		{
-
 
183
			if ( file )
-
 
184
				return CyString("PluginManager/Readme/") + file->GetNameValidFile();
-
 
185
			return "PluginManager/Readme";
-
 
186
		}
-
 
187
		case FILETYPE_MAP:
-
 
188
			return "Maps";
-
 
189
		case FILETYPE_MOD:
-
 
190
//			if ( (file) && (file->IsPatch()) )
-
 
191
//				return "Mods/Patch";
-
 
192
			return "Mods";
-
 
193
		case FILETYPE_UNINSTALL:
-
 
194
			return "PluginManager/Uninstall";
-
 
195
		case FILETYPE_SOUND:
-
 
196
			if ( CFileIO(m_sName).CheckFileExtension("wav") )
-
 
197
				return "s";
-
 
198
			return "Soundtrack";
-
 
199
		case FILETYPE_EXTRA:
-
 
200
			return "PluginManager/Extras";
-
 
201
		case FILETYPE_SCREEN:
-
 
202
			return "loadscr";
-
 
203
		case FILETYPE_ADVERT:
-
 
204
			return "PluginManager/Graphics";
-
 
205
		case FILETYPE_MISSION:
-
 
206
			return "Director";
158
	return getDirectory(file);
207
	}
-
 
208
	return NullString;
-
 
209
}
159
}
210
 
160
 
211
Utils::String C_File::getDirectory(CBaseFile *file) const
161
Utils::String C_File::getDirectory(CBaseFile *file) const
212
{
162
{
213
	if (IsFakePatch())
163
	if (IsFakePatch())
Line 227... Line 177...
227
			dir = dir.findReplace("$scriptauthor", file->author());
177
			dir = dir.findReplace("$scriptauthor", file->author());
228
		}
178
		}
229
		return dir;
179
		return dir;
230
	}
180
	}
231
 
181
 
232
	return GetDirectory(m_iFileType, m_sName.ToString(), file);
182
	return C_File::GetDirectory(m_iFileType, _sName, file);
233
}
183
}
234
 
184
 
235
CyString C_File::GetNameDirectory(CBaseFile *file)
185
CyString C_File::GetNameDirectory(CBaseFile *file)
236
{
186
{
237
	CyString dir = GetDirectory(file);
187
	return getNameDirectory(file);
238
	if (!dir.Empty())
-
 
239
		dir += "/";
-
 
240
	return CyString(dir + m_sName).FindReplace("\\", "/").FindReplace("//", "/");
-
 
241
}
188
}
242
 
189
 
243
Utils::String C_File::getNameDirectory(CBaseFile *file) const
190
Utils::String C_File::getNameDirectory(CBaseFile *file) const
244
{
191
{
245
	Utils::String dir = getDirectory(file);
192
	Utils::String dir = getDirectory(file);
246
	if (!dir.empty())
193
	if (!dir.empty())
247
		dir += "/";
194
		dir += "/";
248
	return (dir + m_sName.ToString()).findReplace("\\", "/").findReplace("//", "/");
195
	return (dir + _sName).findReplace("\\", "/").findReplace("//", "/");
249
}
196
}
250
 
197
 
251
/*
198
/*
252
	Func:	Reset()
199
	Func:	Reset()
253
	Desc:	Resets the file data, clears all data inside
200
	Desc:	Resets the file data, clears all data inside
Line 347... Line 294...
347
{
294
{
348
	if ( m_iFileType != FILETYPE_TEXT )
295
	if ( m_iFileType != FILETYPE_TEXT )
349
		return -1;
296
		return -1;
350
 
297
 
351
	if ( filename.Empty() )
298
	if ( filename.Empty() )
352
		filename = m_sName;
299
		filename = _sName;
353
 
300
 
354
	CyString textid;
301
	CyString textid;
355
	if ( filename.IsIn("-L") || filename.IsIn("-l") )
302
	if ( filename.IsIn("-L") || filename.IsIn("-l") )
356
		textid = filename.GetToken("-", 1, 1);
303
		textid = filename.GetToken("-", 1, 1);
357
	else
304
	else
358
		textid = filename.GetToken(".", -1).Right(4);
305
		textid = filename.GetToken(".", -1).Right(4);
359
 
306
 
360
	if ( textid.IsNumber() ) return textid.ToInt();
307
	if ( textid.IsNumber() ) return textid.ToInt();
361
	return -1;
308
	return -1;
362
}
309
}
363
bool C_File::IsAutoTextFile ()
310
bool C_File::isAutoTextFile ()
364
{
311
{
365
	int textid = GetTextFileID();
312
	int textid = GetTextFileID();
366
	if ( textid == -1 ) return false;
313
	if ( textid == -1 ) return false;
367
 
314
 
368
	if ( textid <= 3 )
315
	if ( textid <= 3 )
Line 397... Line 344...
397
bool C_File::IsFakePatch() const
344
bool C_File::IsFakePatch() const
398
{
345
{
399
	if (m_iFileType != FILETYPE_MOD)
346
	if (m_iFileType != FILETYPE_MOD)
400
		return false;
347
		return false;
401
 
348
 
402
	Utils::String name = m_sName.ToString();
349
	Utils::String name = _sName;
403
 
350
 
404
	if (name.token(".", 1).toLong())
351
	if (name.token(".", 1).toLong())
405
		return true;
352
		return true;
406
 
353
 
407
	if (name.left(10) == "FakePatch_")
354
	if (name.left(10) == "FakePatch_")
Line 430... Line 377...
430
void C_File::setFilename(const Utils::String &filename)
377
void C_File::setFilename(const Utils::String &filename)
431
{
378
{
432
	Utils::String file = filename.findReplace ( "\\", "/" ).findReplace ( "//", "/" );
379
	Utils::String file = filename.findReplace ( "\\", "/" ).findReplace ( "//", "/" );
433
 
380
 
434
	_sFullDir = file.tokens("/", 1, -2);
381
	_sFullDir = file.tokens("/", 1, -2);
435
	m_sName = file.token("/", -1);
382
	_sName = file.token("/", -1);
436
	if ( _sFullDir.right(2) == "/." )
383
	if ( _sFullDir.right(2) == "/." )
437
		_sFullDir = _sFullDir.left(-2);
384
		_sFullDir = _sFullDir.left(-2);
438
 
385
 
439
	ReadFileSize ();
386
	ReadFileSize ();
440
 
387
 
Line 555... Line 502...
555
{
502
{
556
	Utils::String fullfile = _sFullDir;
503
	Utils::String fullfile = _sFullDir;
557
	if ( !fullfile.empty() )
504
	if ( !fullfile.empty() )
558
		fullfile += "/";
505
		fullfile += "/";
559
 
506
 
560
	if ( !m_sName.Empty() )
507
	if ( !_sName.empty() )
561
		fullfile += m_sName.ToString();
508
		fullfile += _sName;
562
 
509
 
563
	return fullfile;
510
	return fullfile;
564
}
511
}
565
 
512
 
566
bool C_File::isExternalFile() const
513
bool C_File::isExternalFile() const
Line 742... Line 689...
742
		return false;
689
		return false;
743
 
690
 
744
	if ( file->GetDir() != m_sDir )
691
	if ( file->GetDir() != m_sDir )
745
		return false;
692
		return false;
746
 
693
 
747
	if ( file->GetName() != m_sName )
694
	if ( file->name() != _sName )
748
	{
695
	{
749
		// check if the base name matches, but only for certain file extensions
696
		// check if the base name matches, but only for certain file extensions
750
		if (file->shouldCheckBaseName())
697
		if (file->shouldCheckBaseName())
751
		{
698
		{
752
			Utils::String baseName = CFileIO(file->GetName()).dir() + "/" + CFileIO(file->GetName()).baseName();
699
			Utils::String baseName = CFileIO(file->GetName()).dir() + "/" + CFileIO(file->GetName()).baseName();
753
			Utils::String compareBaseName = CFileIO(m_sName).dir() + "/" + CFileIO(m_sName).baseName();
700
			Utils::String compareBaseName = CFileIO(_sName).dir() + "/" + CFileIO(_sName).baseName();
754
			if (baseName.Compare(compareBaseName))
701
			if (baseName.Compare(compareBaseName))
755
				return true;
702
				return true;
756
		}
703
		}
757
		return false;
704
		return false;
758
	}
705
	}
Line 1357... Line 1304...
1357
 
1304
 
1358
	return FILETYPE_UNKNOWN;
1305
	return FILETYPE_UNKNOWN;
1359
}
1306
}
1360
 
1307
 
1361
 
1308
 
1362
CyString FormatErrorString(int error, CyString rest)
1309
Utils::String FormatErrorString(int error, const Utils::String &rest)
1363
{
1310
{
1364
	int max = 0;
1311
	int max = 0;
1365
	CyString *args = 0;
1312
	Utils::String *args = 0;
1366
 
1313
 
1367
	if ( !rest.Empty() )
1314
	if ( !rest.empty() )
1368
		args = rest.SplitToken('~', &max);
1315
		args = rest.tokenise("~", &max);
1369
 
1316
 
1370
	CyString errorStr;
1317
	Utils::String errorStr;
1371
	switch ( error )
1318
	switch ( error )
1372
	{
1319
	{
1373
		case SPKINSTALL_CREATEDIRECTORY:
1320
		case SPKINSTALL_CREATEDIRECTORY:
1374
			errorStr = "Creating Directory: %1";
1321
			errorStr = "Creating Directory: %1";
1375
			break;
1322
			break;
Line 1463... Line 1410...
1463
		case SPKINSTALL_ORPHANED_FAIL:
1410
		case SPKINSTALL_ORPHANED_FAIL:
1464
			errorStr = "Unable to remove Orphaned File: %1";
1411
			errorStr = "Unable to remove Orphaned File: %1";
1465
			break;
1412
			break;
1466
	}
1413
	}
1467
 
1414
 
1468
	CyString ret = errorStr.Args(args, max);
1415
	Utils::String ret = errorStr.args(args, max);
1469
	CLEANSPLIT(args, max)
1416
	CLEANSPLIT(args, max)
1470
	return ret;
1417
	return ret;
1471
}
1418
}
1472
 
1419
 
1473
 
1420
 
Line 1789... Line 1736...
1789
}
1736
}
1790
 
1737
 
1791
CyString C_File::GetBaseName ()
1738
CyString C_File::GetBaseName ()
1792
{
1739
{
1793
	// remove any directory
1740
	// remove any directory
1794
	CyString file = m_sName.GetToken ( "/", m_sName.NumToken ( '/' ) );
1741
	Utils::String file = _sName.token("/", -1);
1795
 
1742
 
1796
	// remove file extension
1743
	// remove file extension
1797
	file = file.GetToken ( ".", 1, file.NumToken ( '.' ) - 1 );
-
 
1798
 
-
 
1799
	return file;
1744
	return file.token(".", -1);
1800
}
1745
}
1801
 
1746
 
1802
void C_File::CopyData(C_File *oldFile, bool includeData)
1747
void C_File::CopyData(C_File *oldFile, bool includeData)
1803
{
1748
{
1804
	SetFilename(oldFile->GetFullFilename());
1749
	SetFilename(oldFile->GetFullFilename());
Line 1828... Line 1773...
1828
float GetLibraryVersion() { return (float)LIBRARYVERSION; }
1773
float GetLibraryVersion() { return (float)LIBRARYVERSION; }
1829
float GetFileFormatVersion() { return (float)FILEVERSION; }
1774
float GetFileFormatVersion() { return (float)FILEVERSION; }
1830
 
1775
 
1831
CyString C_File::ChangeFileExt(CyString ext)
1776
CyString C_File::ChangeFileExt(CyString ext)
1832
{
1777
{
-
 
1778
	_sName = CFileIO(_sName).changeFileExtension(ext.ToString());
-
 
1779
	return _sName;
-
 
1780
}
-
 
1781
 
-
 
1782
Utils::String C_File::fileExt() const 
-
 
1783
{ 
-
 
1784
	return _sName.token(".", -1); 
-
 
1785
}
-
 
1786
 
-
 
1787
const Utils::String &C_File::changeFileExt(const Utils::String &ext)
-
 
1788
{
1833
	m_sName = CFileIO(m_sName).ChangeFileExtension(ext);
1789
	_sName = CFileIO(_sName).changeFileExtension(ext);
1834
	return m_sName;
1790
	return _sName;
1835
}
1791
}
1836
 
1792
 
1837
bool C_File::CheckPackedExtension()
1793
bool C_File::CheckPackedExtension()
1838
{
1794
{
1839
	CyString ext = this->GetFileExt();
1795
	CyString ext = this->GetFileExt();
Line 1847... Line 1803...
1847
	return false;
1803
	return false;
1848
}
1804
}
1849
 
1805
 
1850
bool C_File::shouldCheckBaseName() const
1806
bool C_File::shouldCheckBaseName() const
1851
{
1807
{
1852
	Utils::String ext = CFileIO(m_sName).extension();
1808
	Utils::String ext = CFileIO(_sName).extension();
1853
	if (ext == "xml" || ext == "txt" || ext == "pck")
1809
	if (ext == "xml" || ext == "txt" || ext == "pck")
1854
		return true;
1810
		return true;
1855
	if (ext == "bod" || ext == "bob" || ext == "pbb" || ext == "pbd")
1811
	if (ext == "bod" || ext == "bob" || ext == "pbb" || ext == "pbd")
1856
		return true;
1812
		return true;
1857
	return false;
1813
	return false;
Line 2073... Line 2029...
2073
			if (!fullfile.empty())
2029
			if (!fullfile.empty())
2074
				fullfile += "/";
2030
				fullfile += "/";
2075
			fullfile += d;
2031
			fullfile += d;
2076
		}
2032
		}
2077
	}
2033
	}
2078
	if (!m_sName.Empty())
2034
	if (!_sName.empty())
2079
	{
2035
	{
2080
		if (!fullfile.empty())
2036
		if (!fullfile.empty())
2081
			fullfile += "/";
2037
			fullfile += "/";
2082
		fullfile += m_sName.ToString();
2038
		fullfile += _sName;
2083
	}
2039
	}
2084
 
2040
 
2085
	fullfile = fullfile.findReplace("\\", "/");
2041
	fullfile = fullfile.findReplace("\\", "/");
2086
	return fullfile;
2042
	return fullfile;
2087
}
2043
}