| 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 | 
              | 
        
        
            | 
            | 
           47 | 
           void Form1::parseCommandArguments(array<System::String ^> ^args)
  | 
        
        
            | 
            | 
           48 | 
           {
  | 
        
        
            | 
            | 
           49 | 
           	int switchType = SWITCH_NONE;
  | 
        
        
            | 
            | 
           50 | 
              | 
        
        
            | 
            | 
           51 | 
           	if ( args ) {
  | 
        
        
            | 
            | 
           52 | 
           		ArrayList ^list = gcnew ArrayList();
  | 
        
        
            | 
            | 
           53 | 
           		for ( int i = 0; i < args->Length; i++ ) {
  | 
        
        
            | 
            | 
           54 | 
           			String ^str = args[i];
  | 
        
        
            | 
            | 
           55 | 
           			if ( switchType != SWITCH_NONE ) {
  | 
        
        
            | 
            | 
           56 | 
           				switch(switchType) {
  | 
        
        
            | 
            | 
           57 | 
           					case SWITCH_CREATE:
  | 
        
        
            | 
            | 
           58 | 
           						this->SavePackagerScript(str);
  | 
        
        
            | 
            | 
           59 | 
           						m_bAutoClose = true;
  | 
        
        
            | 
            | 
           60 | 
           						break;
  | 
        
        
            | 
            | 
           61 | 
           					case SWITCH_EXTRACT:
  | 
        
        
            | 
            | 
           62 | 
           						this->ExtractPackage(str, false);
  | 
        
        
            | 
            | 
           63 | 
           						m_bAutoClose = true;
  | 
        
        
            | 
            | 
           64 | 
           						break;
  | 
        
        
            | 
            | 
           65 | 
           					case SWITCH_EXTRACTHERE:
  | 
        
        
            | 
            | 
           66 | 
           						this->ExtractPackage(str, true);
  | 
        
        
            | 
            | 
           67 | 
           						m_bAutoClose = true;
  | 
        
        
            | 
            | 
           68 | 
           						break;
  | 
        
        
            | 
            | 
           69 | 
           					case SWITCH_EXPORT:
  | 
        
        
            | 
            | 
           70 | 
           						this->ExportPackage(str);
  | 
        
        
            | 
            | 
           71 | 
           						m_bAutoClose = true;
  | 
        
        
            | 
            | 
           72 | 
           						break;
  | 
        
        
            | 
            | 
           73 | 
           				}
  | 
        
        
            | 
            | 
           74 | 
           				switchType = SWITCH_NONE;
  | 
        
        
            | 
            | 
           75 | 
           			}
  | 
        
        
            | 
            | 
           76 | 
           			else if ( !String::Compare(str, "--create", true) ) {
  | 
        
        
            | 
            | 
           77 | 
           				switchType = SWITCH_CREATE;			
  | 
        
        
            | 
            | 
           78 | 
           			}
  | 
        
        
            | 
            | 
           79 | 
           			else if ( !String::Compare(str, "--extract", true) ) {
  | 
        
        
            | 
            | 
           80 | 
           				switchType = SWITCH_EXTRACT;
  | 
        
        
            | 
            | 
           81 | 
           			}
  | 
        
        
            | 
            | 
           82 | 
           			else if ( !String::Compare(str, "--extracthere", true) ) {
  | 
        
        
            | 
            | 
           83 | 
           				switchType = SWITCH_EXTRACTHERE;
  | 
        
        
            | 
            | 
           84 | 
           			}
  | 
        
        
            | 
            | 
           85 | 
           			else if ( !String::Compare(str, "--export", true) ) {
  | 
        
        
            | 
            | 
           86 | 
           				switchType = SWITCH_EXPORT;
  | 
        
        
            | 
            | 
           87 | 
           			}
  | 
        
        
            | 
            | 
           88 | 
           			else {
  | 
        
        
            | 
            | 
           89 | 
           				list->Add(args[i]);
  | 
        
        
            | 
            | 
           90 | 
           			}
  | 
        
        
            | 
            | 
           91 | 
           		}
  | 
        
        
            | 
            | 
           92 | 
              | 
        
        
            | 
            | 
           93 | 
           		if ( list->Count ) {
  | 
        
        
            | 
            | 
           94 | 
           			this->OpenFiles(list, true, true);
  | 
        
        
            | 
            | 
           95 | 
           			m_bAutoClose = false;
  | 
        
        
            | 
            | 
           96 | 
           		}
  | 
        
        
            | 
            | 
           97 | 
           	}
  | 
        
        
            | 
            | 
           98 | 
           }
  | 
        
        
            | 
            | 
           99 | 
              | 
        
        
            | 
            | 
           100 | 
              | 
        
        
            | 
            | 
           101 | 
           String ^Form1::getShipSelection(CVirtualFileSystem *pVfs)
  | 
        
        
            | 
            | 
           102 | 
           {
  | 
        
        
           | 101 | 
           cycrow | 
           103 | 
           	Utils::CStringList *ships = pVfs->getTShipsEntries();
  | 
        
        
            | 
            | 
           104 | 
           	if ( ships ) {
  | 
        
        
            | 
            | 
           105 | 
           		this->LoadText(pVfs);
  | 
        
        
           | 94 | 
           cycrow | 
           106 | 
              | 
        
        
           | 36 | 
           cycrow | 
           107 | 
           		LoadShip ^ls = gcnew LoadShip();
  | 
        
        
           | 101 | 
           cycrow | 
           108 | 
           		for(Utils::SStringList *str = ships->First(); str; str = ships->Next()) {
  | 
        
        
            | 
            | 
           109 | 
           			int tId = str->str.token(";", 7).toLong();
  | 
        
        
           | 94 | 
           cycrow | 
           110 | 
           			String ^name = _US(pVfs->findText(0, 17, tId));
  | 
        
        
           | 101 | 
           cycrow | 
           111 | 
           			String ^race = _US(pVfs->findText(0, 1266, str->str.token(";", 46).toLong()));
  | 
        
        
           | 94 | 
           cycrow | 
           112 | 
           			String ^text = race + " " + name;
  | 
        
        
           | 101 | 
           cycrow | 
           113 | 
           			int variation = str->str.token(";", 51).toLong();
  | 
        
        
           | 36 | 
           cycrow | 
           114 | 
           			if ( variation )
  | 
        
        
           | 94 | 
           cycrow | 
           115 | 
           				text = text + " " + _US(pVfs->findText(0, 17, 10000 + variation));
  | 
        
        
           | 101 | 
           cycrow | 
           116 | 
           			ls->AddShip(_US(str->data), text);
  | 
        
        
           | 36 | 
           cycrow | 
           117 | 
           		}
  | 
        
        
            | 
            | 
           118 | 
              | 
        
        
            | 
            | 
           119 | 
           		if ( ls->ShowDialog(this) == System::Windows::Forms::DialogResult::OK )	{
  | 
        
        
           | 101 | 
           cycrow | 
           120 | 
           			Utils::String line = pVfs->getTShipsEntry(_S(ls->GetData()));
  | 
        
        
            | 
            | 
           121 | 
              | 
        
        
            | 
            | 
           122 | 
           			if ( !line.empty() ) {
  | 
        
        
           | 36 | 
           cycrow | 
           123 | 
           				return ls->GetData();
  | 
        
        
            | 
            | 
           124 | 
           			}
  | 
        
        
            | 
            | 
           125 | 
           		}
  | 
        
        
            | 
            | 
           126 | 
           		else return "";
  | 
        
        
            | 
            | 
           127 | 
           	}
  | 
        
        
            | 
            | 
           128 | 
              | 
        
        
            | 
            | 
           129 | 
           	return nullptr;
  | 
        
        
            | 
            | 
           130 | 
           }
  | 
        
        
            | 
            | 
           131 | 
              | 
        
        
            | 
            | 
           132 | 
           void Form1::ImportShip()
  | 
        
        
            | 
            | 
           133 | 
           {
  | 
        
        
            | 
            | 
           134 | 
           	OpenFileDialog ^ofd = gcnew OpenFileDialog();
  | 
        
        
            | 
            | 
           135 | 
           	ofd->Filter = "X Catalog Files (*.cat)|*.cat";
  | 
        
        
            | 
            | 
           136 | 
           	ofd->Title = "Select the mod file to import a ship from";
  | 
        
        
            | 
            | 
           137 | 
           	ofd->FilterIndex = 1;
  | 
        
        
            | 
            | 
           138 | 
           	ofd->RestoreDirectory = true;
  | 
        
        
            | 
            | 
           139 | 
           	ofd->Multiselect = false;
  | 
        
        
            | 
            | 
           140 | 
              | 
        
        
            | 
            | 
           141 | 
           	CVirtualFileSystem *vfs = new CVirtualFileSystem();
  | 
        
        
            | 
            | 
           142 | 
              | 
        
        
            | 
            | 
           143 | 
           	if ( ofd->ShowDialog(this) == System::Windows::Forms::DialogResult::OK )
  | 
        
        
            | 
            | 
           144 | 
           	{
  | 
        
        
            | 
            | 
           145 | 
           		if ( !vfs->loadMod(CyStringFromSystemString(ofd->FileName).ToString()) ) {
  | 
        
        
            | 
            | 
           146 | 
           			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);
  | 
        
        
            | 
            | 
           147 | 
           			return;
  | 
        
        
            | 
            | 
           148 | 
           		}
  | 
        
        
            | 
            | 
           149 | 
           		this->UseWaitCursor = true;
  | 
        
        
            | 
            | 
           150 | 
              | 
        
        
            | 
            | 
           151 | 
           		vfs->updateModTexts(17);
  | 
        
        
            | 
            | 
           152 | 
              | 
        
        
            | 
            | 
           153 | 
           		String ^shipID = getShipSelection(vfs);
  | 
        
        
           | 39 | 
           cycrow | 
           154 | 
           		if ( !shipID ) {
  | 
        
        
           | 77 | 
           cycrow | 
           155 | 
           			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 | 
           156 | 
           		}
  | 
        
        
            | 
            | 
           157 | 
           		else if ( shipID->Length ) {
  | 
        
        
           | 36 | 
           cycrow | 
           158 | 
           			String ^loadMod = ofd->FileName;
  | 
        
        
            | 
            | 
           159 | 
           			CXspFile *newShip = NULL;
  | 
        
        
            | 
            | 
           160 | 
              | 
        
        
            | 
            | 
           161 | 
           			while ( true ) {
  | 
        
        
            | 
            | 
           162 | 
           				Creator::ImportShip ^import = gcnew Creator::ImportShip(shipID, vfs);
  | 
        
        
            | 
            | 
           163 | 
           				import->ShowDialog(this);
  | 
        
        
            | 
            | 
           164 | 
           				newShip = (import->Error()) ? NULL : import->GetShip();
  | 
        
        
            | 
            | 
           165 | 
           				if ( !newShip ) {
  | 
        
        
            | 
            | 
           166 | 
           					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 ) {
  | 
        
        
            | 
            | 
           167 | 
           						// load in another file
  | 
        
        
            | 
            | 
           168 | 
           						if ( ofd->ShowDialog(this) == System::Windows::Forms::DialogResult::OK ) {
  | 
        
        
            | 
            | 
           169 | 
           							loadMod = ofd->FileName;
  | 
        
        
            | 
            | 
           170 | 
           							if ( !vfs->loadMod(CyStringFromSystemString(loadMod).ToString()) ) {
  | 
        
        
            | 
            | 
           171 | 
           								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);
  | 
        
        
            | 
            | 
           172 | 
           								break;
  | 
        
        
            | 
            | 
           173 | 
           							}
  | 
        
        
            | 
            | 
           174 | 
           						}
  | 
        
        
            | 
            | 
           175 | 
           						else break;
  | 
        
        
            | 
            | 
           176 | 
           					}
  | 
        
        
            | 
            | 
           177 | 
           					else break;
  | 
        
        
            | 
            | 
           178 | 
           				}
  | 
        
        
            | 
            | 
           179 | 
           				else break;	
  | 
        
        
            | 
            | 
           180 | 
           			}
  | 
        
        
            | 
            | 
           181 | 
              | 
        
        
            | 
            | 
           182 | 
           			if ( newShip ) {
  | 
        
        
            | 
            | 
           183 | 
           				PackageForm ^childForm = this->OpenPackage(true, newShip, "", "Imported Ship");
  | 
        
        
            | 
            | 
           184 | 
           				childForm->Text = "Imported Ship";
  | 
        
        
           | 50 | 
           cycrow | 
           185 | 
           				newShip->adjustChanged(true);
  | 
        
        
           | 36 | 
           cycrow | 
           186 | 
           				childForm->UpdateChanged();
  | 
        
        
           | 107 | 
           cycrow | 
           187 | 
           				childForm->WindowState = Windows::Forms::FormWindowState::Maximized;
  | 
        
        
           | 36 | 
           cycrow | 
           188 | 
           			}
  | 
        
        
            | 
            | 
           189 | 
              | 
        
        
            | 
            | 
           190 | 
           		}
  | 
        
        
            | 
            | 
           191 | 
              | 
        
        
            | 
            | 
           192 | 
           		this->UseWaitCursor = false;
  | 
        
        
            | 
            | 
           193 | 
           	}
  | 
        
        
            | 
            | 
           194 | 
              | 
        
        
            | 
            | 
           195 | 
           	delete vfs;
  | 
        
        
            | 
            | 
           196 | 
           }
  | 
        
        
            | 
            | 
           197 | 
              | 
        
        
            | 
            | 
           198 | 
              | 
        
        
            | 
            | 
           199 | 
           void Form1::ImportShipFromVFS()
  | 
        
        
            | 
            | 
           200 | 
           {
  | 
        
        
            | 
            | 
           201 | 
           	// some way to select the VFS to use
  | 
        
        
           | 94 | 
           cycrow | 
           202 | 
           	SelectFilesystem ^Filesystem = gcnew SelectFilesystem(_pGameDir);
  | 
        
        
           | 36 | 
           cycrow | 
           203 | 
           	if ( Filesystem->ShowDialog(this) != System::Windows::Forms::DialogResult::OK ) {
  | 
        
        
            | 
            | 
           204 | 
           		return;
  | 
        
        
            | 
            | 
           205 | 
           	}
  | 
        
        
            | 
            | 
           206 | 
              | 
        
        
           | 94 | 
           cycrow | 
           207 | 
           	Utils::String dir = Filesystem->gameDir();
  | 
        
        
           | 36 | 
           cycrow | 
           208 | 
           	CyString mod;
  | 
        
        
            | 
            | 
           209 | 
           	if ( Filesystem->gameMod() ) {
  | 
        
        
           | 94 | 
           cycrow | 
           210 | 
           		mod = CyString(dir) + "/mods/" + CyStringFromSystemString(Filesystem->gameMod()) + ".cat";
  | 
        
        
           | 36 | 
           cycrow | 
           211 | 
           	}
  | 
        
        
            | 
            | 
           212 | 
              | 
        
        
           | 94 | 
           cycrow | 
           213 | 
           	CVirtualFileSystem *vfs = _pGameDir->selectedVFS();
  | 
        
        
            | 
            | 
           214 | 
              | 
        
        
            | 
            | 
           215 | 
           	if ( !vfs ) {
  | 
        
        
            | 
            | 
           216 | 
           		MessageBox::Show(this, "Error: Couldn't open Virtual File System", "Error Importing Ship", MessageBoxButtons::OK, MessageBoxIcon::Error);
  | 
        
        
            | 
            | 
           217 | 
           		return;
  | 
        
        
            | 
            | 
           218 | 
           	}
  | 
        
        
            | 
            | 
           219 | 
              | 
        
        
           | 36 | 
           cycrow | 
           220 | 
           	// load a mod on top of the VFS
  | 
        
        
            | 
            | 
           221 | 
           	if ( !mod.Empty() ) {
  | 
        
        
           | 94 | 
           cycrow | 
           222 | 
           		if ( !vfs->loadMod(mod.ToString()) ) {
  | 
        
        
           | 36 | 
           cycrow | 
           223 | 
           			MessageBox::Show(this, "There was a problem trying to open the mod file\n" + Filesystem->gameMod(), "Error Importing Ship", MessageBoxButtons::OK, MessageBoxIcon::Error);
  | 
        
        
            | 
            | 
           224 | 
           			return;
  | 
        
        
            | 
            | 
           225 | 
           		}
  | 
        
        
           | 94 | 
           cycrow | 
           226 | 
           		vfs->updateModTexts(17);
  | 
        
        
           | 36 | 
           cycrow | 
           227 | 
           	}
  | 
        
        
            | 
            | 
           228 | 
              | 
        
        
            | 
            | 
           229 | 
           	// get the ship id to load
  | 
        
        
           | 94 | 
           cycrow | 
           230 | 
           	String ^shipID = getShipSelection(vfs);
  | 
        
        
           | 36 | 
           cycrow | 
           231 | 
           	if ( !shipID ) {
  | 
        
        
            | 
            | 
           232 | 
           		MessageBox::Show(this, "There was a problem trying to load ship data from VFS\n", "Error Importing Ship", MessageBoxButtons::OK, MessageBoxIcon::Error);
  | 
        
        
            | 
            | 
           233 | 
           	}
  | 
        
        
            | 
            | 
           234 | 
           	else if ( shipID->Length ) {
  | 
        
        
            | 
            | 
           235 | 
           		// import the ship
  | 
        
        
           | 94 | 
           cycrow | 
           236 | 
           		Creator::ImportShip ^import = gcnew Creator::ImportShip(shipID, vfs);
  | 
        
        
           | 36 | 
           cycrow | 
           237 | 
           		import->ShowDialog(this);
  | 
        
        
            | 
            | 
           238 | 
              | 
        
        
            | 
            | 
           239 | 
           		// create the new form with ship data
  | 
        
        
            | 
            | 
           240 | 
           		if ( !import->Error() ) {
  | 
        
        
            | 
            | 
           241 | 
           			PackageForm ^childForm = this->OpenPackage(true, import->GetShip(), "", "Imported Ship");
  | 
        
        
            | 
            | 
           242 | 
           			childForm->Text = "Imported Ship";
  | 
        
        
           | 50 | 
           cycrow | 
           243 | 
           			import->GetShip()->adjustChanged(true);
  | 
        
        
           | 36 | 
           cycrow | 
           244 | 
           			childForm->UpdateChanged();
  | 
        
        
           | 107 | 
           cycrow | 
           245 | 
           			childForm->WindowState = Windows::Forms::FormWindowState::Maximized;
  | 
        
        
           | 36 | 
           cycrow | 
           246 | 
           		}
  | 
        
        
            | 
            | 
           247 | 
           	}
  | 
        
        
            | 
            | 
           248 | 
              | 
        
        
            | 
            | 
           249 | 
           	// remove any mods that we have loaded
  | 
        
        
           | 94 | 
           cycrow | 
           250 | 
           	vfs->clearMods();
  | 
        
        
           | 36 | 
           cycrow | 
           251 | 
           }
  | 
        
        
            | 
            | 
           252 | 
              | 
        
        
            | 
            | 
           253 | 
           } //NAMESPACE
  |