| 36 | cycrow | 1 | #include "../StdAfx.h"
 | 
        
           |  |  | 2 | #include "Form1.h"
 | 
        
           |  |  | 3 |   | 
        
           |  |  | 4 | namespace Creator {
 | 
        
           |  |  | 5 |   | 
        
           |  |  | 6 | Form1::Form1(array<System::String ^> ^args)
 | 
        
           |  |  | 7 | {
 | 
        
           |  |  | 8 | 	InitializeComponent();
 | 
        
           |  |  | 9 |   | 
        
           | 95 | cycrow | 10 | 	System::String ^mydoc = Environment::GetFolderPath(Environment::SpecialFolder::Personal );
 | 
        
           |  |  | 11 |   | 
        
           | 36 | cycrow | 12 | 	m_bAutoClose = false;
 | 
        
           |  |  | 13 | 	m_pWait = nullptr;
 | 
        
           |  |  | 14 | 	this->shipToolStripMenuItem->Image = this->imageList1->Images[1];
 | 
        
           |  |  | 15 | 	this->shipToolStripMenuItem1->Image = this->imageList1->Images[1];
 | 
        
           |  |  | 16 | 	this->multiPackageToolStripMenuItem->Image = this->imageList1->Images[this->imageList1->Images->IndexOfKey("multi")];
 | 
        
           |  |  | 17 | 	this->Closed += gcnew System::EventHandler(this, &Form1::CloseEvent);
 | 
        
           |  |  | 18 |   | 
        
           |  |  | 19 | 	this->Text = "Package Creator " + GetVersionString();
 | 
        
           |  |  | 20 | 	m_pLoadedList = new CyStringList;
 | 
        
           | 95 | cycrow | 21 | 	_pGameDir = new CGameDirectories(_S(mydoc));
 | 
        
           | 94 | cycrow | 22 | 	_pGameDir->setLanguage(44);
 | 
        
           | 36 | cycrow | 23 |   | 
        
           |  |  | 24 | 	// default settings
 | 
        
           |  |  | 25 | 	m_settings = new SSettings;
 | 
        
           |  |  | 26 | 	m_settings->bGenerateUpdate = false;
 | 
        
           |  |  | 27 |   | 
        
           |  |  | 28 | 	m_iLocX = m_iLocY = -1;
 | 
        
           |  |  | 29 |   | 
        
           |  |  | 30 | 	this->toolTip1->SetToolTip(this->button1, "Closes all open windows, will ask about saving any that have been modified when they close");
 | 
        
           |  |  | 31 |   | 
        
           |  |  | 32 | 	m_pPackages = new CPackages;
 | 
        
           |  |  | 33 | 	m_pPackages->Startup(".", CyStringFromSystemString(IO::Path::GetTempPath()), CyStringFromSystemString(Environment::GetFolderPath(Environment::SpecialFolder::Personal )));
 | 
        
           |  |  | 34 | 	m_pPackages->SetLanguage(44);
 | 
        
           |  |  | 35 |   | 
        
           |  |  | 36 | 	this->LoadData();
 | 
        
           |  |  | 37 |   | 
        
           |  |  | 38 | 	this->UpdateDisplay();
 | 
        
           |  |  | 39 |   | 
        
           |  |  | 40 | 	// parse any switches
 | 
        
           |  |  | 41 | 	this->parseCommandArguments(args);
 | 
        
           | 95 | cycrow | 42 |   | 
        
           |  |  | 43 | 	if ( _pGameDir->isEmpty() )
 | 
        
           |  |  | 44 | 		_pGameDir->syncWithControlled(m_pPackages->GetGameExe());
 | 
        
           | 36 | cycrow | 45 | }
 | 
        
           |  |  | 46 |   | 
        
           | 109 | cycrow | 47 | bool Form1::CheckCommandArguments(array<System::String ^> ^args)
 | 
        
           |  |  | 48 | {
 | 
        
           |  |  | 49 | 	for ( int i = 0; i < args->Length; i++ ) {
 | 
        
           |  |  | 50 | 		String ^str = args[i];
 | 
        
           |  |  | 51 | 		if ( !String::Compare(str, "--create", true) )
 | 
        
           |  |  | 52 | 			return true;
 | 
        
           |  |  | 53 | 		else if ( !String::Compare(str, "--extract", true) )
 | 
        
           |  |  | 54 | 			return true;
 | 
        
           |  |  | 55 | 		else if ( !String::Compare(str, "--extracthere", true) )
 | 
        
           |  |  | 56 | 			return true;
 | 
        
           |  |  | 57 | 		else if ( !String::Compare(str, "--export", true) )
 | 
        
           |  |  | 58 | 			return true;
 | 
        
           |  |  | 59 | 	}
 | 
        
           |  |  | 60 |   | 
        
           |  |  | 61 | 	return false;
 | 
        
           |  |  | 62 | }
 | 
        
           |  |  | 63 |   | 
        
           | 36 | cycrow | 64 | void Form1::parseCommandArguments(array<System::String ^> ^args)
 | 
        
           |  |  | 65 | {
 | 
        
           |  |  | 66 | 	int switchType = SWITCH_NONE;
 | 
        
           |  |  | 67 |   | 
        
           |  |  | 68 | 	if ( args ) {
 | 
        
           |  |  | 69 | 		ArrayList ^list = gcnew ArrayList();
 | 
        
           |  |  | 70 | 		for ( int i = 0; i < args->Length; i++ ) {
 | 
        
           |  |  | 71 | 			String ^str = args[i];
 | 
        
           |  |  | 72 | 			if ( switchType != SWITCH_NONE ) {
 | 
        
           |  |  | 73 | 				switch(switchType) {
 | 
        
           |  |  | 74 | 					case SWITCH_CREATE:
 | 
        
           |  |  | 75 | 						this->SavePackagerScript(str);
 | 
        
           |  |  | 76 | 						m_bAutoClose = true;
 | 
        
           |  |  | 77 | 						break;
 | 
        
           |  |  | 78 | 					case SWITCH_EXTRACT:
 | 
        
           |  |  | 79 | 						this->ExtractPackage(str, false);
 | 
        
           |  |  | 80 | 						m_bAutoClose = true;
 | 
        
           |  |  | 81 | 						break;
 | 
        
           |  |  | 82 | 					case SWITCH_EXTRACTHERE:
 | 
        
           |  |  | 83 | 						this->ExtractPackage(str, true);
 | 
        
           |  |  | 84 | 						m_bAutoClose = true;
 | 
        
           |  |  | 85 | 						break;
 | 
        
           |  |  | 86 | 					case SWITCH_EXPORT:
 | 
        
           |  |  | 87 | 						this->ExportPackage(str);
 | 
        
           |  |  | 88 | 						m_bAutoClose = true;
 | 
        
           |  |  | 89 | 						break;
 | 
        
           |  |  | 90 | 				}
 | 
        
           |  |  | 91 | 				switchType = SWITCH_NONE;
 | 
        
           |  |  | 92 | 			}
 | 
        
           |  |  | 93 | 			else if ( !String::Compare(str, "--create", true) ) {
 | 
        
           |  |  | 94 | 				switchType = SWITCH_CREATE;			
 | 
        
           |  |  | 95 | 			}
 | 
        
           |  |  | 96 | 			else if ( !String::Compare(str, "--extract", true) ) {
 | 
        
           |  |  | 97 | 				switchType = SWITCH_EXTRACT;
 | 
        
           |  |  | 98 | 			}
 | 
        
           |  |  | 99 | 			else if ( !String::Compare(str, "--extracthere", true) ) {
 | 
        
           |  |  | 100 | 				switchType = SWITCH_EXTRACTHERE;
 | 
        
           |  |  | 101 | 			}
 | 
        
           |  |  | 102 | 			else if ( !String::Compare(str, "--export", true) ) {
 | 
        
           |  |  | 103 | 				switchType = SWITCH_EXPORT;
 | 
        
           |  |  | 104 | 			}
 | 
        
           |  |  | 105 | 			else {
 | 
        
           |  |  | 106 | 				list->Add(args[i]);
 | 
        
           |  |  | 107 | 			}
 | 
        
           |  |  | 108 | 		}
 | 
        
           |  |  | 109 |   | 
        
           |  |  | 110 | 		if ( list->Count ) {
 | 
        
           |  |  | 111 | 			this->OpenFiles(list, true, true);
 | 
        
           |  |  | 112 | 			m_bAutoClose = false;
 | 
        
           |  |  | 113 | 		}
 | 
        
           |  |  | 114 | 	}
 | 
        
           |  |  | 115 | }
 | 
        
           |  |  | 116 |   | 
        
           |  |  | 117 |   | 
        
           |  |  | 118 | String ^Form1::getShipSelection(CVirtualFileSystem *pVfs)
 | 
        
           |  |  | 119 | {
 | 
        
           | 101 | cycrow | 120 | 	Utils::CStringList *ships = pVfs->getTShipsEntries();
 | 
        
           |  |  | 121 | 	if ( ships ) {
 | 
        
           |  |  | 122 | 		this->LoadText(pVfs);
 | 
        
           | 94 | cycrow | 123 |   | 
        
           | 36 | cycrow | 124 | 		LoadShip ^ls = gcnew LoadShip();
 | 
        
           | 101 | cycrow | 125 | 		for(Utils::SStringList *str = ships->First(); str; str = ships->Next()) {
 | 
        
           |  |  | 126 | 			int tId = str->str.token(";", 7).toLong();
 | 
        
           | 94 | cycrow | 127 | 			String ^name = _US(pVfs->findText(0, 17, tId));
 | 
        
           | 101 | cycrow | 128 | 			String ^race = _US(pVfs->findText(0, 1266, str->str.token(";", 46).toLong()));
 | 
        
           | 94 | cycrow | 129 | 			String ^text = race + " " + name;
 | 
        
           | 101 | cycrow | 130 | 			int variation = str->str.token(";", 51).toLong();
 | 
        
           | 36 | cycrow | 131 | 			if ( variation )
 | 
        
           | 94 | cycrow | 132 | 				text = text + " " + _US(pVfs->findText(0, 17, 10000 + variation));
 | 
        
           | 101 | cycrow | 133 | 			ls->AddShip(_US(str->data), text);
 | 
        
           | 36 | cycrow | 134 | 		}
 | 
        
           |  |  | 135 |   | 
        
           |  |  | 136 | 		if ( ls->ShowDialog(this) == System::Windows::Forms::DialogResult::OK )	{
 | 
        
           | 101 | cycrow | 137 | 			Utils::String line = pVfs->getTShipsEntry(_S(ls->GetData()));
 | 
        
           |  |  | 138 |   | 
        
           |  |  | 139 | 			if ( !line.empty() ) {
 | 
        
           | 36 | cycrow | 140 | 				return ls->GetData();
 | 
        
           |  |  | 141 | 			}
 | 
        
           |  |  | 142 | 		}
 | 
        
           |  |  | 143 | 		else return "";
 | 
        
           |  |  | 144 | 	}
 | 
        
           |  |  | 145 |   | 
        
           |  |  | 146 | 	return nullptr;
 | 
        
           |  |  | 147 | }
 | 
        
           |  |  | 148 |   | 
        
           |  |  | 149 | void Form1::ImportShip()
 | 
        
           |  |  | 150 | {
 | 
        
           |  |  | 151 | 	OpenFileDialog ^ofd = gcnew OpenFileDialog();
 | 
        
           |  |  | 152 | 	ofd->Filter = "X Catalog Files (*.cat)|*.cat";
 | 
        
           |  |  | 153 | 	ofd->Title = "Select the mod file to import a ship from";
 | 
        
           |  |  | 154 | 	ofd->FilterIndex = 1;
 | 
        
           |  |  | 155 | 	ofd->RestoreDirectory = true;
 | 
        
           |  |  | 156 | 	ofd->Multiselect = false;
 | 
        
           |  |  | 157 |   | 
        
           |  |  | 158 | 	CVirtualFileSystem *vfs = new CVirtualFileSystem();
 | 
        
           |  |  | 159 |   | 
        
           |  |  | 160 | 	if ( ofd->ShowDialog(this) == System::Windows::Forms::DialogResult::OK )
 | 
        
           |  |  | 161 | 	{
 | 
        
           |  |  | 162 | 		if ( !vfs->loadMod(CyStringFromSystemString(ofd->FileName).ToString()) ) {
 | 
        
           |  |  | 163 | 			MessageBox::Show(this, "There was a problem when trying to import the ship\n" + ofd->FileName + "\n\nError: Unable to open mod file", "Error Importing Ship", MessageBoxButtons::OK, MessageBoxIcon::Error);
 | 
        
           |  |  | 164 | 			return;
 | 
        
           |  |  | 165 | 		}
 | 
        
           |  |  | 166 | 		this->UseWaitCursor = true;
 | 
        
           |  |  | 167 |   | 
        
           |  |  | 168 | 		vfs->updateModTexts(17);
 | 
        
           |  |  | 169 |   | 
        
           |  |  | 170 | 		String ^shipID = getShipSelection(vfs);
 | 
        
           | 39 | cycrow | 171 | 		if ( !shipID ) {
 | 
        
           | 77 | cycrow | 172 | 			MessageBox::Show(this, "There was a problem trying to load the mod file\n" + ofd->FileName + "\n\nNo TShips file found", "Error Importing Ship", MessageBoxButtons::OK, MessageBoxIcon::Error);
 | 
        
           | 39 | cycrow | 173 | 		}
 | 
        
           |  |  | 174 | 		else if ( shipID->Length ) {
 | 
        
           | 36 | cycrow | 175 | 			String ^loadMod = ofd->FileName;
 | 
        
           |  |  | 176 | 			CXspFile *newShip = NULL;
 | 
        
           |  |  | 177 |   | 
        
           |  |  | 178 | 			while ( true ) {
 | 
        
           |  |  | 179 | 				Creator::ImportShip ^import = gcnew Creator::ImportShip(shipID, vfs);
 | 
        
           |  |  | 180 | 				import->ShowDialog(this);
 | 
        
           |  |  | 181 | 				newShip = (import->Error()) ? NULL : import->GetShip();
 | 
        
           |  |  | 182 | 				if ( !newShip ) {
 | 
        
           |  |  | 183 | 					if ( MessageBox::Show(this, "There was a problem when trying to import the ship\n" + ofd->FileName + " (" + shipID + ")\n\nError: " + import->getErrorString() + "\n\nWould you like to read files from another mod as well?", "Error Importing Ship", MessageBoxButtons::YesNo, MessageBoxIcon::Question) == System::Windows::Forms::DialogResult::Yes ) {
 | 
        
           |  |  | 184 | 						// load in another file
 | 
        
           |  |  | 185 | 						if ( ofd->ShowDialog(this) == System::Windows::Forms::DialogResult::OK ) {
 | 
        
           |  |  | 186 | 							loadMod = ofd->FileName;
 | 
        
           |  |  | 187 | 							if ( !vfs->loadMod(CyStringFromSystemString(loadMod).ToString()) ) {
 | 
        
           |  |  | 188 | 								MessageBox::Show(this, "There was a problem when trying to import the ship\n" + ofd->FileName + " (" + shipID + ")\n\nError: Unable to open mod file", "Error Importing Ship", MessageBoxButtons::OK, MessageBoxIcon::Error);
 | 
        
           |  |  | 189 | 								break;
 | 
        
           |  |  | 190 | 							}
 | 
        
           |  |  | 191 | 						}
 | 
        
           |  |  | 192 | 						else break;
 | 
        
           |  |  | 193 | 					}
 | 
        
           |  |  | 194 | 					else break;
 | 
        
           |  |  | 195 | 				}
 | 
        
           |  |  | 196 | 				else break;	
 | 
        
           |  |  | 197 | 			}
 | 
        
           |  |  | 198 |   | 
        
           |  |  | 199 | 			if ( newShip ) {
 | 
        
           |  |  | 200 | 				PackageForm ^childForm = this->OpenPackage(true, newShip, "", "Imported Ship");
 | 
        
           |  |  | 201 | 				childForm->Text = "Imported Ship";
 | 
        
           | 50 | cycrow | 202 | 				newShip->adjustChanged(true);
 | 
        
           | 36 | cycrow | 203 | 				childForm->UpdateChanged();
 | 
        
           | 107 | cycrow | 204 | 				childForm->WindowState = Windows::Forms::FormWindowState::Maximized;
 | 
        
           | 36 | cycrow | 205 | 			}
 | 
        
           |  |  | 206 |   | 
        
           |  |  | 207 | 		}
 | 
        
           |  |  | 208 |   | 
        
           |  |  | 209 | 		this->UseWaitCursor = false;
 | 
        
           |  |  | 210 | 	}
 | 
        
           |  |  | 211 |   | 
        
           |  |  | 212 | 	delete vfs;
 | 
        
           |  |  | 213 | }
 | 
        
           |  |  | 214 |   | 
        
           |  |  | 215 |   | 
        
           |  |  | 216 | void Form1::ImportShipFromVFS()
 | 
        
           |  |  | 217 | {
 | 
        
           |  |  | 218 | 	// some way to select the VFS to use
 | 
        
           | 94 | cycrow | 219 | 	SelectFilesystem ^Filesystem = gcnew SelectFilesystem(_pGameDir);
 | 
        
           | 36 | cycrow | 220 | 	if ( Filesystem->ShowDialog(this) != System::Windows::Forms::DialogResult::OK ) {
 | 
        
           |  |  | 221 | 		return;
 | 
        
           |  |  | 222 | 	}
 | 
        
           |  |  | 223 |   | 
        
           | 94 | cycrow | 224 | 	Utils::String dir = Filesystem->gameDir();
 | 
        
           | 36 | cycrow | 225 | 	CyString mod;
 | 
        
           |  |  | 226 | 	if ( Filesystem->gameMod() ) {
 | 
        
           | 94 | cycrow | 227 | 		mod = CyString(dir) + "/mods/" + CyStringFromSystemString(Filesystem->gameMod()) + ".cat";
 | 
        
           | 36 | cycrow | 228 | 	}
 | 
        
           |  |  | 229 |   | 
        
           | 94 | cycrow | 230 | 	CVirtualFileSystem *vfs = _pGameDir->selectedVFS();
 | 
        
           |  |  | 231 |   | 
        
           |  |  | 232 | 	if ( !vfs ) {
 | 
        
           |  |  | 233 | 		MessageBox::Show(this, "Error: Couldn't open Virtual File System", "Error Importing Ship", MessageBoxButtons::OK, MessageBoxIcon::Error);
 | 
        
           |  |  | 234 | 		return;
 | 
        
           |  |  | 235 | 	}
 | 
        
           |  |  | 236 |   | 
        
           | 36 | cycrow | 237 | 	// load a mod on top of the VFS
 | 
        
           |  |  | 238 | 	if ( !mod.Empty() ) {
 | 
        
           | 94 | cycrow | 239 | 		if ( !vfs->loadMod(mod.ToString()) ) {
 | 
        
           | 36 | cycrow | 240 | 			MessageBox::Show(this, "There was a problem trying to open the mod file\n" + Filesystem->gameMod(), "Error Importing Ship", MessageBoxButtons::OK, MessageBoxIcon::Error);
 | 
        
           |  |  | 241 | 			return;
 | 
        
           |  |  | 242 | 		}
 | 
        
           | 94 | cycrow | 243 | 		vfs->updateModTexts(17);
 | 
        
           | 36 | cycrow | 244 | 	}
 | 
        
           |  |  | 245 |   | 
        
           |  |  | 246 | 	// get the ship id to load
 | 
        
           | 94 | cycrow | 247 | 	String ^shipID = getShipSelection(vfs);
 | 
        
           | 36 | cycrow | 248 | 	if ( !shipID ) {
 | 
        
           |  |  | 249 | 		MessageBox::Show(this, "There was a problem trying to load ship data from VFS\n", "Error Importing Ship", MessageBoxButtons::OK, MessageBoxIcon::Error);
 | 
        
           |  |  | 250 | 	}
 | 
        
           |  |  | 251 | 	else if ( shipID->Length ) {
 | 
        
           |  |  | 252 | 		// import the ship
 | 
        
           | 94 | cycrow | 253 | 		Creator::ImportShip ^import = gcnew Creator::ImportShip(shipID, vfs);
 | 
        
           | 36 | cycrow | 254 | 		import->ShowDialog(this);
 | 
        
           |  |  | 255 |   | 
        
           |  |  | 256 | 		// create the new form with ship data
 | 
        
           |  |  | 257 | 		if ( !import->Error() ) {
 | 
        
           |  |  | 258 | 			PackageForm ^childForm = this->OpenPackage(true, import->GetShip(), "", "Imported Ship");
 | 
        
           |  |  | 259 | 			childForm->Text = "Imported Ship";
 | 
        
           | 50 | cycrow | 260 | 			import->GetShip()->adjustChanged(true);
 | 
        
           | 36 | cycrow | 261 | 			childForm->UpdateChanged();
 | 
        
           | 107 | cycrow | 262 | 			childForm->WindowState = Windows::Forms::FormWindowState::Maximized;
 | 
        
           | 36 | cycrow | 263 | 		}
 | 
        
           |  |  | 264 | 	}
 | 
        
           |  |  | 265 |   | 
        
           |  |  | 266 | 	// remove any mods that we have loaded
 | 
        
           | 94 | cycrow | 267 | 	vfs->clearMods();
 | 
        
           | 36 | cycrow | 268 | }
 | 
        
           |  |  | 269 |   | 
        
           |  |  | 270 | } //NAMESPACE
 |