Subversion Repositories spk

Rev

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

Rev 218 Rev 224
Line 83... Line 83...
83
		m_sFilename = filename;
83
		m_sFilename = filename;
84
 
84
 
85
		if ( !base )
85
		if ( !base )
86
		{
86
		{
87
			int error;
87
			int error;
88
			m_pPackage = m_pP->openPackage(_S(filename), &error);
88
			m_pPackage = m_pP->openPackage(_WS(filename), &error);
89
			if ( !m_pPackage )
89
			if ( !m_pPackage )
90
				return false;
90
				return false;
91
		}
91
		}
92
		else
92
		else
93
			m_pPackage = base;
93
			m_pPackage = base;
Line 99... Line 99...
99
 
99
 
100
		if ( m_pPackage->AnyFileType(FILETYPE_ADVERT) )
100
		if ( m_pPackage->AnyFileType(FILETYPE_ADVERT) )
101
		{
101
		{
102
			for ( C_File *f = m_pPackage->GetFirstFile(FILETYPE_ADVERT); f; f = m_pPackage->GetNextFile(f) )
102
			for ( C_File *f = m_pPackage->GetFirstFile(FILETYPE_ADVERT); f; f = m_pPackage->GetNextFile(f) )
103
			{
103
			{
104
				f->setFullDir(_S(System::IO::Path::GetTempPath()));
104
				f->setFullDir(_WS(System::IO::Path::GetTempPath()));
105
				long size;
105
				long size;
106
				unsigned char *data = f->UncompressData(&size, 0);
106
				unsigned char *data = f->UncompressData(&size, 0);
107
				if ( data && size )
107
				if ( data && size )
108
				{
108
				{
109
					if ( f->writeFilePointer(data, size) )
109
					if ( f->writeFilePointer(data, size) )
Line 1134... Line 1134...
1134
		ofd->RestoreDirectory = true;
1134
		ofd->RestoreDirectory = true;
1135
		ofd->Multiselect = true;
1135
		ofd->Multiselect = true;
1136
		ofd->Title = "Select File(s) to add to package";
1136
		ofd->Title = "Select File(s) to add to package";
1137
		if ( ofd->ShowDialog(this) == System::Windows::Forms::DialogResult::OK )
1137
		if ( ofd->ShowDialog(this) == System::Windows::Forms::DialogResult::OK )
1138
		{
1138
		{
1139
			Utils::String dir;
1139
			Utils::WString dir;
1140
			if ( C_File::DoesTypeHaveExtraDir(ofd->FilterIndex - 1) )
1140
			if ( C_File::DoesTypeHaveExtraDir(ofd->FilterIndex - 1) )
1141
			{
1141
			{
1142
				InputBox ^input = gcnew InputBox("Enter the directory to add files to", ((ofd->FilterIndex - 1) == FILETYPE_EXTRA) ? "PluginManager/Extras/$scriptname" : "");
1142
				InputBox ^input = gcnew InputBox("Enter the directory to add files to", ((ofd->FilterIndex - 1) == FILETYPE_EXTRA) ? "PluginManager/Extras/$scriptname" : "");
1143
				if ( input->ShowDialog(this) == System::Windows::Forms::DialogResult::OK )
1143
				if ( input->ShowDialog(this) == System::Windows::Forms::DialogResult::OK )
1144
					dir = _S(input->GetInput());
1144
					dir = _WS(input->GetInput());
1145
			}
1145
			}
1146
			array<System::String ^> ^fileArray = ofd->FileNames;
1146
			array<System::String ^> ^fileArray = ofd->FileNames;
1147
			for ( int i = 0; i < fileArray->Length; i++ )
1147
			for ( int i = 0; i < fileArray->Length; i++ )
1148
			{
1148
			{
1149
				System::String ^file = fileArray[i];
1149
				System::String ^file = fileArray[i];
1150
				FileType filetype = m_pP->adjustFileType(_S(file), static_cast<FileType>(ofd->FilterIndex - 1));
1150
				FileType filetype = m_pP->adjustFileType(_WS(file), static_cast<FileType>(ofd->FilterIndex - 1));
1151
				C_File *f = m_pPackage->addFile(_S(file), dir, filetype, this->ComboGameFilter->SelectedIndex > 1 ? (1 << (this->ComboGameFilter->SelectedIndex - 1) | 1 << 31) : 0);
1151
				C_File *f = m_pPackage->addFile(_WS(file), dir, filetype, this->ComboGameFilter->SelectedIndex > 1 ? (1 << (this->ComboGameFilter->SelectedIndex - 1) | 1 << 31) : 0);
1152
				if ( (ofd->FilterIndex - 1) == FILETYPE_MOD )
1152
				if ( (ofd->FilterIndex - 1) == FILETYPE_MOD )
1153
					m_pPackage->addFile(CFileIO(_S(file)).changeFileExtension(L"dat").toString(), dir, filetype);
1153
					m_pPackage->addFile(CFileIO(_WS(file)).changeFileExtension(L"dat"), dir, filetype);
1154
			}
1154
			}
1155
			m_pPackage->updateSigned(false);
1155
			m_pPackage->updateSigned(false);
1156
			this->UpdateFileList();
1156
			this->UpdateFileList();
1157
			this->UpdateDisplayPic();
1157
			this->UpdateDisplayPic();
1158
			this->UpdateChanged();
1158
			this->UpdateChanged();
Line 1304... Line 1304...
1304
					else
1304
					else
1305
						ofd->Filter = "Package Files (*.spk)|*.spk";
1305
						ofd->Filter = "Package Files (*.spk)|*.spk";
1306
					ofd->FilterIndex = 1;
1306
					ofd->FilterIndex = 1;
1307
					ofd->RestoreDirectory = true;
1307
					ofd->RestoreDirectory = true;
1308
					if ( ofd->ShowDialog(this) == System::Windows::Forms::DialogResult::OK )
1308
					if ( ofd->ShowDialog(this) == System::Windows::Forms::DialogResult::OK )
1309
						m_pPackage->setFilename(_S(ofd->FileName));
1309
						m_pPackage->setFilename(_WS(ofd->FileName));
1310
					else
1310
					else
1311
					{
1311
					{
1312
						 e->Cancel = true;
1312
						 e->Cancel = true;
1313
						 return;
1313
						 return;
1314
					}
1314
					}
1315
				}
1315
				}
1316
 
1316
 
1317
				if ( !m_pPackage->writeFile(m_pPackage->filename().toString()) )
1317
				if ( !m_pPackage->writeFile(m_pPackage->filename()) )
1318
				{
1318
				{
1319
					e->Cancel = true;
1319
					e->Cancel = true;
1320
					MessageBox::Show("Unable to save package\n" + _US(m_pPackage->filename()), "Save Error", MessageBoxButtons::OK, MessageBoxIcon::Error);
1320
					MessageBox::Show("Unable to save package\n" + _US(m_pPackage->filename()), "Save Error", MessageBoxButtons::OK, MessageBoxIcon::Error);
1321
					return;
1321
					return;
1322
				}
1322
				}
Line 1370... Line 1370...
1370
 
1370
 
1371
		if ( ofd->ShowDialog(this) == System::Windows::Forms::DialogResult::OK )
1371
		if ( ofd->ShowDialog(this) == System::Windows::Forms::DialogResult::OK )
1372
		{
1372
		{
1373
			array<System::String ^> ^fileArray = ofd->FileNames;
1373
			array<System::String ^> ^fileArray = ofd->FileNames;
1374
			for ( int i = 0; i < fileArray->Length; i++ )
1374
			for ( int i = 0; i < fileArray->Length; i++ )
1375
				m_pDisplayFile = m_pPackage->addFile(_S(fileArray[i]), "", FILETYPE_ADVERT);
1375
				m_pDisplayFile = m_pPackage->addFile(_WS(fileArray[i]), L"", FILETYPE_ADVERT);
1376
 
1376
 
1377
			this->UpdateDisplayPic();
1377
			this->UpdateDisplayPic();
1378
			this->UpdateFileList();
1378
			this->UpdateFileList();
1379
		}
1379
		}
1380
	}
1380
	}
Line 1388... Line 1388...
1388
		ofd->Multiselect = false;
1388
		ofd->Multiselect = false;
1389
		ofd->Title = "Select the Icon file to add";
1389
		ofd->Title = "Select the Icon file to add";
1390
 
1390
 
1391
		if ( ofd->ShowDialog(this) == System::Windows::Forms::DialogResult::OK )
1391
		if ( ofd->ShowDialog(this) == System::Windows::Forms::DialogResult::OK )
1392
		{
1392
		{
1393
			Utils::String file = _S(ofd->FileName);
1393
			Utils::WString file = _WS(ofd->FileName);
1394
			C_File *icon = new C_File(file);
1394
			C_File *icon = new C_File(file);
1395
			if ( icon->ReadFromFile() )
1395
			if ( icon->ReadFromFile() )
1396
				m_pPackage->setIcon(icon, CFileIO(file).extension().toString());
1396
				m_pPackage->setIcon(icon, CFileIO(file).extension());
1397
 
1397
 
1398
			this->UpdateDisplayIcon();
1398
			this->UpdateDisplayIcon();
1399
			this->UpdateChanged();
1399
			this->UpdateChanged();
1400
		}
1400
		}
1401
	}
1401
	}
Line 1404... Line 1404...
1404
	{
1404
	{
1405
		if ( this->TextText->Text->Length )
1405
		if ( this->TextText->Text->Length )
1406
		{
1406
		{
1407
			if ( this->ListLang->SelectedIndex >= 0 )
1407
			if ( this->ListLang->SelectedIndex >= 0 )
1408
			{
1408
			{
1409
				int lang = _S(this->ListLang->Text).toInt();
1409
				int lang = _WS(this->ListLang->Text).toInt();
1410
				if ( this->RadioInstallAfter->Checked )			m_pPackage->addInstallText(lang, false, _S(this->TextText->Text));
1410
				if ( this->RadioInstallAfter->Checked )			m_pPackage->addInstallText(lang, false, _WS(this->TextText->Text));
1411
				else if ( this->RadioInstallBefore->Checked )	m_pPackage->addInstallText(lang, true, _S(this->TextText->Text));
1411
				else if ( this->RadioInstallBefore->Checked )	m_pPackage->addInstallText(lang, true, _WS(this->TextText->Text));
1412
				else if ( this->RadioUninstallBefore->Checked )	m_pPackage->addUninstallText(lang, true, _S(this->TextText->Text));
1412
				else if ( this->RadioUninstallBefore->Checked )	m_pPackage->addUninstallText(lang, true, _WS(this->TextText->Text));
1413
				else if ( this->RadioUninstallAfter->Checked )	m_pPackage->addUninstallText(lang, false, _S(this->TextText->Text));
1413
				else if ( this->RadioUninstallAfter->Checked )	m_pPackage->addUninstallText(lang, false, _WS(this->TextText->Text));
1414
				this->UpdateChanged();
1414
				this->UpdateChanged();
1415
			}
1415
			}
1416
		}
1416
		}
1417
	}
1417
	}
1418
 
1418
 
Line 1431... Line 1431...
1431
			Hashtable ^catText = gcnew Hashtable();
1431
			Hashtable ^catText = gcnew Hashtable();
1432
 
1432
 
1433
			if ( String::Compare(IO::FileInfo(ofd->FileName).Extension, ".cat") == 0 )
1433
			if ( String::Compare(IO::FileInfo(ofd->FileName).Extension, ".cat") == 0 )
1434
			{
1434
			{
1435
				Utils::WStringList readText;
1435
				Utils::WStringList readText;
1436
				if ( m_pP->readTextPage(_S(ofd->FileName), readText, false, 17) )
1436
				if ( m_pP->readTextPage(_WS(ofd->FileName), readText, false, 17) )
1437
				{
1437
				{
1438
					for(auto itr = readText.begin(); itr != readText.end(); itr++)
1438
					for(auto itr = readText.begin(); itr != readText.end(); itr++)
1439
					{
1439
					{
1440
						String ^key = _US((*itr)->str);
1440
						String ^key = _US((*itr)->str);
1441
						if ( catText->ContainsKey(key) )
1441
						if ( catText->ContainsKey(key) )
Line 1445... Line 1445...
1445
					}
1445
					}
1446
				}
1446
				}
1447
			}
1447
			}
1448
 
1448
 
1449
			Utils::WStringList list;
1449
			Utils::WStringList list;
1450
			if (m_pP->loadShipData(_S(ofd->FileName), list))
1450
			if (m_pP->loadShipData(_WS(ofd->FileName), list))
1451
			{
1451
			{
1452
				LoadShip ^ls = gcnew LoadShip();
1452
				LoadShip ^ls = gcnew LoadShip();
1453
				for(auto itr = list.begin(); itr != list.end(); itr++)
1453
				for(auto itr = list.begin(); itr != list.end(); itr++)
1454
				{
1454
				{
1455
					int tId = (*itr)->data.token(L";", 7).toInt();
1455
					int tId = (*itr)->data.token(L";", 7).toInt();
Line 1613... Line 1613...
1613
					}
1613
					}
1614
 
1614
 
1615
					if ( dummy->ShowDialog(this) == Windows::Forms::DialogResult::OK )
1615
					if ( dummy->ShowDialog(this) == Windows::Forms::DialogResult::OK )
1616
					{
1616
					{
1617
						if ( edit )
1617
						if ( edit )
1618
							xsp->removeBodies(_S(m_pSelectedItem->Text + ";" + m_pSelectedItem->SubItems[1]->Text));
1618
							xsp->removeBodies(_WS(m_pSelectedItem->Text + ";" + m_pSelectedItem->SubItems[1]->Text));
1619
						xsp->addBodies(_S(dummy->GetSection() + ";" + dummy->GetData()));
1619
						xsp->addBodies(_WS(dummy->GetSection() + ";" + dummy->GetData()));
1620
						if ( !edit )
1620
						if ( !edit )
1621
							this->UpdateShipPartList();
1621
							this->UpdateShipPartList();
1622
						else
1622
						else
1623
						{
1623
						{
1624
							m_pSelectedItem->Text = dummy->GetSection();
1624
							m_pSelectedItem->Text = dummy->GetSection();
Line 1634... Line 1634...
1634
					input->Large();
1634
					input->Large();
1635
					if ( input->ShowDialog(this) == Windows::Forms::DialogResult::OK )
1635
					if ( input->ShowDialog(this) == Windows::Forms::DialogResult::OK )
1636
					{
1636
					{
1637
						if ( edit )
1637
						if ( edit )
1638
							xsp->removeAnimation(_WS(m_pSelectedItem->Text));
1638
							xsp->removeAnimation(_WS(m_pSelectedItem->Text));
1639
						xsp->addAnimation(_S(input->GetInput()));
1639
						xsp->addAnimation(_WS(input->GetInput()));
1640
						this->UpdateShipPartList();
1640
						this->UpdateShipPartList();
1641
					}
1641
					}
1642
				}
1642
				}
1643
				break;
1643
				break;
1644
		 }
1644
		 }
Line 1692... Line 1692...
1692
		if ( String::Compare(IO::FileInfo(file).Extension, ".xml") == 0 )
1692
		if ( String::Compare(IO::FileInfo(file).Extension, ".xml") == 0 )
1693
			return file;
1693
			return file;
1694
		
1694
		
1695
		if ( String::Compare(IO::FileInfo(file).Extension, ".pck") == 0 )
1695
		if ( String::Compare(IO::FileInfo(file).Extension, ".pck") == 0 )
1696
		{
1696
		{
1697
			C_File F(_S(file));
1697
			C_File F(_WS(file));
1698
			F.UnPCKFile();
1698
			F.UnPCKFile();
1699
			if ( F.writeToFile(CPackages::tempDirectory().toString() + "tmp.dat"))
1699
			if ( F.writeToFile(CPackages::tempDirectory() + L"tmp.dat"))
1700
				return _US(CPackages::tempDirectory() + L"tmp.dat");
1700
				return _US(CPackages::tempDirectory() + L"tmp.dat");
1701
		}
1701
		}
1702
		else if ( String::Compare(IO::FileInfo(file).Extension, ".cat") == 0 )
1702
		else if ( String::Compare(IO::FileInfo(file).Extension, ".cat") == 0 )
1703
		{
1703
		{
1704
			CCatFile cat;
1704
			CCatFile cat;
1705
			if ( cat.open(_S(file), "", CATREAD_CATDECRYPT, false) == CATERR_NONE )
1705
			if ( cat.open(_WS(file), L"", CATREAD_CATDECRYPT, false) == CATERR_NONE )
1706
			{
1706
			{
1707
				if ( cat.extractFile(_S("types\\" + type + ".pck"), CPackages::tempDirectory().toString() + "tmp.dat"))
1707
				if ( cat.extractFile(_WS("types\\" + type + L".pck"), CPackages::tempDirectory() + L"tmp.dat"))
1708
					return _US(CPackages::tempDirectory() + L"tmp.dat");
1708
					return _US(CPackages::tempDirectory() + L"tmp.dat");
1709
			}
1709
			}
1710
		}
1710
		}
1711
 
1711
 
1712
		return "";
1712
		return "";
Line 1717... Line 1717...
1717
		return ((Form1 ^)this->MdiParent)->gameDirectories();
1717
		return ((Form1 ^)this->MdiParent)->gameDirectories();
1718
	}
1718
	}
1719
 
1719
 
1720
	void PackageForm::ImportData(String ^file, int type)
1720
	void PackageForm::ImportData(String ^file, int type)
1721
	{
1721
	{
1722
		CFileIO F(_S(file));
1722
		CFileIO F(_WS(file));
1723
		if ( !F.exists() )
1723
		if ( !F.exists() )
1724
			return;
1724
			return;
1725
 
1725
 
1726
		std::vector<Utils::WString> lines;
1726
		std::vector<Utils::WString> lines;
1727
		if(!F.readLines(lines))
1727
		if(!F.readLines(lines))
Line 1877... Line 1877...
1877
		}
1877
		}
1878
	}
1878
	}
1879
 
1879
 
1880
	void PackageForm::ImportAnimations(String ^file)
1880
	void PackageForm::ImportAnimations(String ^file)
1881
	{
1881
	{
1882
		CFileIO F(_S(file));
1882
		CFileIO F(_WS(file));
1883
		if ( !F.exists() )
1883
		if ( !F.exists() )
1884
			return;
1884
			return;
1885
 
1885
 
1886
		Utils::WStringList lines;
1886
		Utils::WStringList lines;
1887
		if(!F.readLines(lines))
1887
		if(!F.readLines(lines))
Line 1941... Line 1941...
1941
		int done = 0;
1941
		int done = 0;
1942
		if (ListFiles->SelectedItems->Count)
1942
		if (ListFiles->SelectedItems->Count)
1943
		{
1943
		{
1944
			for (int i = 0; i < ListFiles->SelectedItems->Count; i++)
1944
			for (int i = 0; i < ListFiles->SelectedItems->Count; i++)
1945
			{
1945
			{
1946
				int id = _S(cli::safe_cast<System::String ^>(this->ListFiles->SelectedItems[i]->Tag)).toInt();
1946
				int id = _WS(cli::safe_cast<System::String ^>(this->ListFiles->SelectedItems[i]->Tag)).toInt();
1947
				C_File *file = m_pPackage->GetFileList()->Get(id);
1947
				C_File *file = m_pPackage->GetFileList()->Get(id);
1948
				if (file) {
1948
				if (file) {
1949
					int iGame = Convert::ToInt32(item->Tag);
1949
					int iGame = Convert::ToInt32(item->Tag);
1950
					if(!iGame)
1950
					if(!iGame)
1951
						file->setGame(0);
1951
						file->setGame(0);
Line 1968... Line 1968...
1968
		int done = 0;
1968
		int done = 0;
1969
		if (ListFiles->SelectedItems->Count)
1969
		if (ListFiles->SelectedItems->Count)
1970
		{
1970
		{
1971
			for (int i = 0; i < ListFiles->SelectedItems->Count; i++)
1971
			for (int i = 0; i < ListFiles->SelectedItems->Count; i++)
1972
			{
1972
			{
1973
				int id = _S(cli::safe_cast<System::String ^>(this->ListFiles->SelectedItems[i]->Tag)).toInt();
1973
				int id = _WS(cli::safe_cast<System::String ^>(this->ListFiles->SelectedItems[i]->Tag)).toInt();
1974
				C_File *file = m_pPackage->GetFileList()->Get(id);
1974
				C_File *file = m_pPackage->GetFileList()->Get(id);
1975
				if (file) {
1975
				if (file) {
1976
					int iGame = Convert::ToInt32(item->Tag);
1976
					int iGame = Convert::ToInt32(item->Tag);
1977
					if (iGame)
1977
					if (iGame)
1978
						file->setGame(file->game() | 1 << iGame | 1 << 31);
1978
						file->setGame(file->game() | 1 << iGame | 1 << 31);
Line 1993... Line 1993...
1993
		int done = 0;
1993
		int done = 0;
1994
		if (ListFiles->SelectedItems->Count)
1994
		if (ListFiles->SelectedItems->Count)
1995
		{
1995
		{
1996
			for (int i = 0; i < ListFiles->SelectedItems->Count; i++)
1996
			for (int i = 0; i < ListFiles->SelectedItems->Count; i++)
1997
			{
1997
			{
1998
				int id = _S(cli::safe_cast<System::String ^>(this->ListFiles->SelectedItems[i]->Tag)).toInt();
1998
				int id = _WS(cli::safe_cast<System::String ^>(this->ListFiles->SelectedItems[i]->Tag)).toInt();
1999
				C_File *file = m_pPackage->GetFileList()->Get(id);
1999
				C_File *file = m_pPackage->GetFileList()->Get(id);
2000
				if (file) {
2000
				if (file) {
2001
					int iGame = Convert::ToInt32(item->Tag);
2001
					int iGame = Convert::ToInt32(item->Tag);
2002
					if (iGame)
2002
					if (iGame)
2003
						file->setGame(file->game() & ~(1 << iGame));
2003
						file->setGame(file->game() & ~(1 << iGame));