Subversion Repositories spk

Rev

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

Rev 130 Rev 131
Line 100... Line 100...
100
##########################################################################################
100
##########################################################################################
101
##################                Base Class Functions                  ##################
101
##################                Base Class Functions                  ##################
102
##########################################################################################
102
##########################################################################################
103
*/
103
*/
104
 
104
 
-
 
105
const CLinkList<C_File> *CBaseFile::fileList() const
-
 
106
{
-
 
107
	return &m_lFiles;
-
 
108
}
105
CLinkList<C_File> *CBaseFile::fileList(int type) const
109
CLinkList<C_File> *CBaseFile::fileList(int type) const
106
{
110
{
107
	CLinkList<C_File> *list = new CLinkList<C_File>;
111
	CLinkList<C_File> *list = new CLinkList<C_File>;
108
	for ( CListNode<C_File> *node = m_lFiles.Front(); node; node = node->next() )
112
	for ( CListNode<C_File> *node = m_lFiles.Front(); node; node = node->next() )
109
	{
113
	{
Line 2143... Line 2147...
2143
 
2147
 
2144
	return true;
2148
	return true;
2145
}
2149
}
2146
 
2150
 
2147
 
2151
 
2148
bool CBaseFile::ExtractFile ( C_File *file, CyString dir, bool includedir, CProgressInfo *progress )
2152
bool CBaseFile::ExtractFile(C_File *file, CyString dir, bool includedir, CProgressInfo *progress)
-
 
2153
{
-
 
2154
	return extractFile(file, dir.ToString(), includedir, progress);
-
 
2155
}
-
 
2156
bool CBaseFile::extractFile(C_File *file, const Utils::String &dir, bool includedir, CProgressInfo *progress)
-
 
2157
{
-
 
2158
	if (ReadFileToMemory(file))
-
 
2159
	{
-
 
2160
		// now finally, uncompress the file
-
 
2161
		long len = 0;
-
 
2162
		unsigned char *data = file->UncompressData(&len, progress);
-
 
2163
		if (!data)
-
 
2164
		{
-
 
2165
			// attempt a file decompress
-
 
2166
			if (file->GetCompressionType() == SPKCOMPRESS_7ZIP)
-
 
2167
			{
-
 
2168
				if (file->UncompressToFile(dir, this, includedir, progress))
-
 
2169
					return true;
-
 
2170
			}
-
 
2171
			return false;
-
 
2172
		}
-
 
2173
 
-
 
2174
		if (!file->writeToDir(dir, this, includedir, Utils::String::Null(), data, len))
-
 
2175
			return false;
-
 
2176
 
-
 
2177
		return true;
-
 
2178
 
-
 
2179
	}
-
 
2180
	else
-
 
2181
		return false;
-
 
2182
}
-
 
2183
bool CBaseFile::extractFile(C_File *file, const Utils::String &dir, unsigned int game, const Utils::CStringList &gameAddons, bool includedir, CProgressInfo *progress)
2149
{
2184
{
2150
	if ( ReadFileToMemory ( file ) )
2185
	if (ReadFileToMemory(file))
2151
	{
2186
	{
-
 
2187
		CDirIO Dir(dir);
-
 
2188
		Utils::String addonDir;
-
 
2189
		if (file->isFileInAddon())
-
 
2190
		{
-
 
2191
			int addonGame = file->getForSingleGame();
-
 
2192
			if (!addonGame) addonGame = game;
-
 
2193
 
-
 
2194
			if (addonGame > 0)
-
 
2195
				addonDir = gameAddons.findString(Utils::String::Number(addonGame));
-
 
2196
		}
-
 
2197
 
-
 
2198
		if (!addonDir.empty())
-
 
2199
			Dir.cd(addonDir);
-
 
2200
 
-
 
2201
		// create directory first
-
 
2202
		Dir.create(file->getDirectory(this));
-
 
2203
 
2152
		// now finally, uncompress the file
2204
		// now finally, uncompress the file
2153
		long len = 0;
2205
		long len = 0;
2154
		unsigned char *data = file->UncompressData ( &len, progress );
2206
		unsigned char *data = file->UncompressData(&len, progress);
2155
		if ( !data )
2207
		if (!data)
2156
		{
2208
		{
2157
			// attempt a file decompress
2209
			// attempt a file decompress
2158
			if ( file->GetCompressionType() == SPKCOMPRESS_7ZIP )
2210
			if (file->GetCompressionType() == SPKCOMPRESS_7ZIP)
2159
			{
2211
			{
2160
				if ( file->UncompressToFile ( dir, this, includedir, progress ) )
2212
				if (file->UncompressToFile(Dir.dir(), this, includedir, progress))
2161
					return true;
2213
					return true;
2162
			}
2214
			}
2163
			return false;
2215
			return false;
2164
		}
2216
		}
2165
 
2217
 
2166
		if ( !file->writeToDir(dir.ToString(), this, includedir, Utils::String::Null(), data, len) )
2218
		if (!file->writeToDir(Dir.dir(), this, includedir, Utils::String::Null(), data, len))
2167
			return false;
2219
			return false;
2168
 
2220
 
2169
		return true;
2221
		return true;
2170
 
2222
 
2171
	}
2223
	}
2172
	else
2224
	else
2173
		return false;
2225
		return false;
2174
}
2226
}
2175
 
2227
 
2176
bool CBaseFile::ExtractFile ( int filenum, CyString dir, bool includedir, CProgressInfo *progress )
2228
bool CBaseFile::ExtractFile(int filenum, CyString dir, bool includedir, CProgressInfo *progress)
-
 
2229
{
-
 
2230
	// invalid valus
-
 
2231
	if (filenum < 0)
-
 
2232
		return false;
-
 
2233
	// out of range
-
 
2234
	if (filenum > m_lFiles.size())
-
 
2235
		return false;
-
 
2236
 
-
 
2237
	// get the file pointer
-
 
2238
	C_File *file = m_lFiles.Get(filenum);
-
 
2239
	return extractFile(file, dir.ToString(), includedir, progress);
-
 
2240
}
-
 
2241
 
-
 
2242
bool CBaseFile::extractFile(int filenum, const Utils::String &dir, unsigned int game, const Utils::CStringList &gameAddons, bool includedir, CProgressInfo *progress)
-
 
2243
{
-
 
2244
	// invalid valus
-
 
2245
	if (filenum < 0)
-
 
2246
		return false;
-
 
2247
	// out of range
-
 
2248
	if (filenum > m_lFiles.size())
-
 
2249
		return false;
-
 
2250
 
-
 
2251
	// get the file pointer
-
 
2252
	C_File *file = m_lFiles.Get(filenum);
-
 
2253
	return extractFile(file, dir, game, gameAddons, includedir, progress);
-
 
2254
}
-
 
2255
 
-
 
2256
bool CBaseFile::extractFile(int filenum, const Utils::String &dir, bool includedir, CProgressInfo *progress)
2177
{
2257
{
2178
	// invalid valus
2258
	// invalid valus
2179
	if ( filenum < 0 )
2259
	if (filenum < 0)
2180
		return false;
2260
		return false;
2181
	// out of range
2261
	// out of range
2182
	if ( filenum > m_lFiles.size() )
2262
	if (filenum > m_lFiles.size())
2183
		return false;
2263
		return false;
2184
 
2264
 
2185
	// get the file pointer
2265
	// get the file pointer
2186
	C_File *file = m_lFiles.Get ( filenum );
2266
	C_File *file = m_lFiles.Get(filenum);
2187
	return ExtractFile ( file, dir, includedir, progress );
2267
	return ExtractFile(file, dir, includedir, progress);
2188
}
2268
}
2189
 
2269
 
2190
bool CBaseFile::extractAll(const Utils::String &dir, int game, const Utils::CStringList &gameAddons, bool includedir, CProgressInfo *progress)
2270
bool CBaseFile::extractAll(const Utils::String &dir, int game, const Utils::CStringList &gameAddons, bool includedir, CProgressInfo *progress)
2191
{
2271
{
2192
	// no file to read from
2272
	// no file to read from
Line 2583... Line 2663...
2583
		}
2663
		}
2584
 
2664
 
2585
		bool done = false;
2665
		bool done = false;
2586
		if ( wildcard )
2666
		if ( wildcard )
2587
		{
2667
		{
2588
			Utils::String base = f->Data()->GetBaseName().ToString();
2668
			Utils::String base = f->Data()->baseName();
2589
			if ( f->Data()->GetFileType() == FILETYPE_SCRIPT )
2669
			if ( f->Data()->fileType() == FILETYPE_SCRIPT )
2590
			{
2670
			{
2591
				if ( base.token(".", 1).Compare("plugin") || base.token(".", 1).Compare("lib") )
2671
				if ( base.token(".", 1).Compare("plugin") || base.token(".", 1).Compare("lib") )
2592
				{
2672
				{
2593
					name += f->Data()->GetDirectory(this).ToString() + "/" + base.tokens(".", 1, 2) + ".*";
2673
					name += f->Data()->getDirectory(this) + "/" + base.tokens(".", 1, 2) + ".*";
2594
					done = true;
2674
					done = true;
2595
				}
2675
				}
2596
				else if ( base.token(".", 1).Compare("al") && !base.token(".", 2).Compare("plugin") )
2676
				else if ( base.token(".", 1).Compare("al") && !base.token(".", 2).Compare("plugin") )
2597
				{
2677
				{
2598
					name += f->Data()->GetDirectory(this).ToString() + "/" + base.tokens(".", 1, 2) + ".*";
2678
					name += f->Data()->getDirectory(this) + "/" + base.tokens(".", 1, 2) + ".*";
2599
					done = true;
2679
					done = true;
2600
				}
2680
				}
2601
			}
2681
			}
2602
			else if ( f->Data()->GetFileType() == FILETYPE_TEXT )
2682
			else if ( f->Data()->fileType() == FILETYPE_TEXT )
2603
			{
2683
			{
2604
				if ( base.contains("-L") )
2684
				if ( base.contains("-L") )
2605
				{
2685
				{
2606
					name += f->Data()->GetDirectory(this).ToString() + "/" + base.token("-L", 1) + "-L*";
2686
					name += f->Data()->getDirectory(this) + "/" + base.token("-L", 1) + "-L*";
2607
					done = true;
2687
					done = true;
2608
				}
2688
				}
2609
				else
2689
				else
2610
				{
2690
				{
2611
					name += f->Data()->GetDirectory(this).ToString() + "/*" + base.right(4) + ".*";
2691
					name += f->Data()->getDirectory(this) + "/*" + base.right(4) + ".*";
2612
					done = true;
2692
					done = true;
2613
				}
2693
				}
2614
			}
2694
			}
2615
		}
2695
		}
2616
 
2696
 
2617
		if ( !done )
2697
		if ( !done )
2618
			name += f->Data()->GetNameDirectory(this).ToString();
2698
			name += f->Data()->getNameDirectory(this);
2619
 
2699
 
2620
		if ( !f->Data()->GetDir().Empty() )
2700
		if ( !f->Data()->dir().empty() )
2621
		{
2701
		{
2622
			name += "|";
2702
			name += "|";
2623
			name += f->Data()->GetDir().ToString();
2703
			name += f->Data()->dir();
2624
		}
2704
		}
2625
		Utils::String s = "GAME ";
2705
		Utils::String s = "GAME ";
2626
		if (!f->Data()->game() || f->Data()->game() == GAME_ALLNEW)
2706
		if (!f->Data()->game() || f->Data()->game() == GAME_ALLNEW)
2627
			s += CBaseFile::ConvertGameToString(f->Data()->game());
2707
			s += CBaseFile::ConvertGameToString(f->Data()->game());
2628
		else
2708
		else
Line 2742... Line 2822...
2742
	else
2822
	else
2743
		Found->iVersion = version;
2823
		Found->iVersion = version;
2744
	_changed();
2824
	_changed();
2745
}
2825
}
2746
 
2826
 
-
 
2827
Utils::String CBaseFile::_replaceFilename(const Utils::String &fname)
-
 
2828
{
-
 
2829
	Utils::String filename = fname;
-
 
2830
	Utils::String cdate = this->creationDate().findReplace("/", ".").remove(' ');
-
 
2831
	if (filename.isin("$AUTOSAVE"))
-
 
2832
	{
-
 
2833
		if (this->GetType() == TYPE_XSP)
-
 
2834
			filename = filename.findReplace("$AUTOSAVE", "$NAME-V$VERSION-$CDATE.xsp");
-
 
2835
		else
-
 
2836
			filename = filename.findReplace("$AUTOSAVE", "$NAME-V$VERSION-$CDATE.spk");
-
 
2837
	}
-
 
2838
	filename = filename.findReplace("$NAME", this->name().remove(' '));
-
 
2839
	filename = filename.findReplace("$AUTHOR", this->author().remove(' '));
-
 
2840
	filename = filename.findReplace("$DATE", cdate);
-
 
2841
	filename = filename.findReplace("$CDATE", cdate);
-
 
2842
	filename = filename.findReplace("$VERSION", this->version());
-
 
2843
 
-
 
2844
	return filename;
-
 
2845
}
2747
bool CBaseFile::LoadPackageData(const Utils::String &sFirst, const Utils::String &sRest, const Utils::String &sMainGame, Utils::CStringList &otherGames, Utils::CStringList &gameAddons)
2846
bool CBaseFile::LoadPackageData(const Utils::String &sFirst, const Utils::String &sRest, const Utils::String &sMainGame, Utils::CStringList &otherGames, Utils::CStringList &gameAddons)
2748
{
2847
{
2749
	if ( sFirst.Compare("Name") )					this->setName(sRest);
2848
	if ( sFirst.Compare("Name") )					this->setName(sRest);
2750
	else if ( sFirst.Compare("Author") )			this->setAuthor(sRest);
2849
	else if ( sFirst.Compare("Author") )			this->setAuthor(sRest);
2751
	else if ( sFirst.Compare("ScriptName") )
2850
	else if ( sFirst.Compare("ScriptName") )
Line 2775... Line 2874...
2775
		this->AddGameCompatability(CBaseFile::GetGameFromString(sGame), sRest.token(" ", 2));
2874
		this->AddGameCompatability(CBaseFile::GetGameFromString(sGame), sRest.token(" ", 2));
2776
	}
2875
	}
2777
	else if ( sFirst.Compare("Description") )		this->setDescription(sRest);
2876
	else if ( sFirst.Compare("Description") )		this->setDescription(sRest);
2778
	else if ( sFirst.Compare("AutoSave") || sFirst.Compare("AutoExport") || sFirst.Compare("AutoRarExport") || sFirst.Compare("AutoZipExport") )
2877
	else if ( sFirst.Compare("AutoSave") || sFirst.Compare("AutoExport") || sFirst.Compare("AutoRarExport") || sFirst.Compare("AutoZipExport") )
2779
	{
2878
	{
2780
		Utils::String filename = sRest;
2879
		Utils::String filename = _replaceFilename(sRest);
2781
		Utils::String cdate = this->creationDate().findReplace("/", ".").remove(' ');
-
 
2782
		if ( filename.isin("$AUTOSAVE") )
-
 
2783
		{
-
 
2784
			if ( this->GetType() == TYPE_XSP )
-
 
2785
				filename = filename.findReplace("$AUTOSAVE", "$NAME-V$VERSION-$CDATE.xsp");
-
 
2786
			else
-
 
2787
				filename = filename.findReplace("$AUTOSAVE", "$NAME-V$VERSION-$CDATE.spk");
-
 
2788
		}
-
 
2789
		filename = filename.findReplace("$NAME", this->name().remove(' '));
-
 
2790
		filename = filename.findReplace("$AUTHOR", this->author().remove(' '));
-
 
2791
		filename = filename.findReplace("$DATE", cdate);
-
 
2792
		filename = filename.findReplace("$CDATE", cdate);
-
 
2793
		filename = filename.findReplace("$VERSION", this->version());
-
 
2794
 
2880
 
2795
		if ( sFirst.Compare("AutoZipExport") || sFirst.Compare("AutoExport") )
2881
		if ( sFirst.Compare("AutoZipExport") || sFirst.Compare("AutoExport") )
2796
			this->setExportFilename(CFileIO(filename).ChangeFileExtension("zip").ToString());
2882
			this->setExportFilename(CFileIO(filename).changeFileExtension("zip"));
2797
		else if ( sFirst.Compare("AutoRarExport") )
2883
		else if ( sFirst.Compare("AutoRarExport") )
2798
			this->setExportFilename(CFileIO(filename).ChangeFileExtension("rar").ToString());
2884
			this->setExportFilename(CFileIO(filename).changeFileExtension("rar"));
2799
		else
2885
		else
2800
			this->setFilename(filename);
2886
			this->setFilename(filename);
2801
	}
2887
	}
2802
	else if ( sFirst.Compare("WebSite") )		this->setWebSite(sRest);
2888
	else if ( sFirst.Compare("WebSite") )		this->setWebSite(sRest);
2803
	else if ( sFirst.Compare("ForumLink") || sFirst.Compare("Forum") ) this->setForumLink(sRest);
2889
	else if ( sFirst.Compare("ForumLink") || sFirst.Compare("Forum") ) this->setForumLink(sRest);
Line 2839... Line 2925...
2839
		if ( icon->ReadFromFile() )
2925
		if ( icon->ReadFromFile() )
2840
			this->SetIcon(icon, CFileIO(sRest).GetFileExtension());
2926
			this->SetIcon(icon, CFileIO(sRest).GetFileExtension());
2841
	}
2927
	}
2842
	else if (sFirst.Compare("CombineGameFiles"))
2928
	else if (sFirst.Compare("CombineGameFiles"))
2843
		_bCombineFiles = sRest.Compare("true") || sRest.Compare("yes") || sRest.toInt();
2929
		_bCombineFiles = sRest.Compare("true") || sRest.Compare("yes") || sRest.toInt();
-
 
2930
	else if (sFirst.Compare("ExportZip"))
-
 
2931
	{
-
 
2932
		Utils::String ext = "zip";
-
 
2933
		Utils::String game = sRest.word(1);
-
 
2934
		Utils::String file = _replaceFilename(CFileIO(sRest.words(2)).fullFilename());
-
 
2935
		if (game.contains("|"))
-
 
2936
		{
-
 
2937
			int max;
-
 
2938
			Utils::String *games = game.tokenise("|", &max);
-
 
2939
			if (games)
-
 
2940
			{
-
 
2941
				for (int i = 0; i < max; ++i)
-
 
2942
				{
-
 
2943
					unsigned int g = CBaseFile::GetGameFromString(games[i]);
-
 
2944
					Utils::String filename = CFileIO(file).dir() + "/" + CFileIO(file).baseName() + "_" + CBaseFile::ConvertGameToString(g) + "." + ext;
-
 
2945
					this->addAutoExport(g, filename);
-
 
2946
				}
-
 
2947
				CLEANSPLIT(games, max);
-
 
2948
			}
-
 
2949
		}
-
 
2950
		else
-
 
2951
		{
-
 
2952
			unsigned int g = CBaseFile::GetGameFromString(game);
-
 
2953
			Utils::String filename = CFileIO(file).dir() + "/" + CFileIO(file).baseName() + "_" + CBaseFile::ConvertGameToString(g) + "." + ext;
-
 
2954
			this->addAutoExport(g, filename);
-
 
2955
		}
-
 
2956
	}
-
 
2957
	else if (sFirst.Compare("Extract"))
-
 
2958
	{
-
 
2959
		Utils::String game = sRest.word(1);
-
 
2960
		Utils::String dir = CDirIO(sRest.words(2)).dir();
-
 
2961
		if (game.contains("|"))
-
 
2962
		{
-
 
2963
			int max;
-
 
2964
			Utils::String *games = game.tokenise("|", &max);
-
 
2965
			if (games)
-
 
2966
			{
-
 
2967
				for(int i = 0; i < max; ++i)
-
 
2968
					this->addAutoExtract(CBaseFile::GetGameFromString(games[i]), dir);
-
 
2969
				CLEANSPLIT(games, max);
-
 
2970
			}
-
 
2971
		}
-
 
2972
		else
-
 
2973
			this->addAutoExtract(CBaseFile::GetGameFromString(game), dir);
-
 
2974
	}
2844
	else
2975
	else
2845
	{
2976
	{
2846
		Utils::String checkType = sFirst;
2977
		Utils::String checkType = sFirst;
2847
		bool shared = false;
2978
		bool shared = false;
2848
		if ( checkType.left(6).Compare("Shared") )
2979
		if ( checkType.left(6).Compare("Shared") )
Line 2882... Line 3013...
2882
					game |= 1 << g;
3013
					game |= 1 << g;
2883
			}
3014
			}
2884
			CLEANSPLIT(games, max);
3015
			CLEANSPLIT(games, max);
2885
		}
3016
		}
2886
		else
3017
		else
-
 
3018
		{
2887
			game = 1 << CBaseFile::GetGameFromString(gameStr);
3019
			unsigned int g = CBaseFile::GetGameFromString(gameStr);
-
 
3020
			if (g)
-
 
3021
				game = 1 << g;
-
 
3022
		}
2888
		rest = rest.tokens(" ", 3);
3023
		rest = rest.tokens(" ", 3);
2889
	}
3024
	}
2890
	if (game)
3025
	if (game)
2891
		game |= 1 << 31;
3026
		game |= 1 << 31;
2892
 
3027
 
Line 3170... Line 3305...
3170
	return CyString((long)error);
3305
	return CyString((long)error);
3171
}
3306
}
3172
 
3307
 
3173
bool CBaseFile::SaveToArchive(CyString filename, int game, const CGameExe *exes, CProgressInfo *progress)
3308
bool CBaseFile::SaveToArchive(CyString filename, int game, const CGameExe *exes, CProgressInfo *progress)
3174
{
3309
{
-
 
3310
	return saveToArchive(filename.ToString(), game, exes, progress);
-
 
3311
}
-
 
3312
bool CBaseFile::saveToArchive(const Utils::String &filename, int game, const CGameExe *exes, CProgressInfo *progress)
-
 
3313
{
-
 
3314
	CDirIO Dir(CFileIO(filename).dir());
-
 
3315
	if (!Dir.exists())
-
 
3316
		Dir.create();
-
 
3317
 
3175
	TCHAR buf[5000];
3318
	TCHAR buf[5000];
3176
	wsprintf(buf, L"%hs", filename.c_str());
3319
	wsprintf(buf, L"%hs", filename.c_str());
3177
 
3320
 
3178
	HZIP hz = CreateZip(buf, 0);
3321
	HZIP hz = CreateZip(buf, 0);
3179
	if (!hz) return false;
3322
	if (!hz) return false;
Line 3193... Line 3336...
3193
				continue;
3336
				continue;
3194
			// extracting for all games, so ignore files that have a game set
3337
			// extracting for all games, so ignore files that have a game set
3195
			if (!game && node->Data()->game() && node->Data()->game() != GAME_ALLNEW)
3338
			if (!game && node->Data()->game() && node->Data()->game() != GAME_ALLNEW)
3196
				continue;
3339
				continue;
3197
		}
3340
		}
3198
		Utils::String fname = node->Data()->GetNameDirectory(this).ToString();
3341
		Utils::String fname = node->Data()->getNameDirectory(this);
3199
 
3342
 
3200
		// use the addon directory
3343
		// use the addon directory
3201
		if (node->Data()->isFileInAddon() && exes)
3344
		if (node->Data()->isFileInAddon() && exes)
3202
		{
3345
		{
3203
			unsigned int whatGame = game;
3346
			unsigned int whatGame = game;