Rev 116 | Rev 224 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed
#include "../StdAfx.h"#include "Form1.h"namespace Creator {Form1::Form1(array<System::String ^> ^args){InitializeComponent();System::String ^mydoc = Environment::GetFolderPath(Environment::SpecialFolder::Personal );m_bAutoClose = false;m_pWait = nullptr;this->shipToolStripMenuItem->Image = this->imageList1->Images[1];this->shipToolStripMenuItem1->Image = this->imageList1->Images[1];this->multiPackageToolStripMenuItem->Image = this->imageList1->Images[this->imageList1->Images->IndexOfKey("multi")];this->Closed += gcnew System::EventHandler(this, &Form1::CloseEvent);this->Text = "Package Creator " + GetVersionString();m_pLoadedList = new CyStringList;_pGameDir = new CGameDirectories(_S(mydoc));_pGameDir->setLanguage(44);// default settingsm_settings = new SSettings;m_settings->bGenerateUpdate = false;m_iLocX = m_iLocY = -1;this->toolTip1->SetToolTip(this->button1, "Closes all open windows, will ask about saving any that have been modified when they close");m_pPackages = new CPackages;m_pPackages->startup(".", _S(IO::Path::GetTempPath()), _S(Environment::GetFolderPath(Environment::SpecialFolder::Personal )));m_pPackages->SetLanguage(44);this->LoadData();this->UpdateDisplay();// parse any switchesthis->parseCommandArguments(args);if ( _pGameDir->isEmpty() )_pGameDir->syncWithControlled(m_pPackages->GetGameExe());}Form1::!Form1(){}bool Form1::CheckCommandArguments(array<System::String ^> ^args){for ( int i = 0; i < args->Length; i++ ) {String ^str = args[i];if ( !String::Compare(str, "--create", true) )return true;else if ( !String::Compare(str, "--extract", true) )return true;else if ( !String::Compare(str, "--extracthere", true) )return true;else if ( !String::Compare(str, "--export", true) )return true;}return false;}void Form1::parseCommandArguments(array<System::String ^> ^args){int switchType = SWITCH_NONE;if ( args ) {ArrayList ^list = gcnew ArrayList();for ( int i = 0; i < args->Length; i++ ) {String ^str = args[i];if ( switchType != SWITCH_NONE ) {switch(switchType) {case SWITCH_CREATE:this->SavePackagerScript(str);m_bAutoClose = true;break;case SWITCH_EXTRACT:this->ExtractPackage(str, false);m_bAutoClose = true;break;case SWITCH_EXTRACTHERE:this->ExtractPackage(str, true);m_bAutoClose = true;break;case SWITCH_EXPORT:this->ExportPackage(str);m_bAutoClose = true;break;}switchType = SWITCH_NONE;}else if ( !String::Compare(str, "--create", true) ) {switchType = SWITCH_CREATE;}else if ( !String::Compare(str, "--extract", true) ) {switchType = SWITCH_EXTRACT;}else if ( !String::Compare(str, "--extracthere", true) ) {switchType = SWITCH_EXTRACTHERE;}else if ( !String::Compare(str, "--export", true) ) {switchType = SWITCH_EXPORT;}else {list->Add(args[i]);}}if ( list->Count ) {this->OpenFiles(list, true, true);m_bAutoClose = false;}}}String ^Form1::getShipSelection(CVirtualFileSystem *pVfs, System::String ^*shipName){Utils::CStringList *ships = pVfs->getTShipsEntries();if ( ships ) {this->LoadText(pVfs);LoadShip ^ls = gcnew LoadShip();for(Utils::SStringList *str = ships->first(); str; str = ships->next()) {int tId = str->str.token(";", 7).toLong();String ^name = _US(pVfs->findText(0, 17, tId));String ^race = (str->str.token(";", 46).toLong() == 0) ? "" : _US(pVfs->findText(0, 1266, str->str.token(";", 46).toLong()));String ^text = race + " " + name;int variation = str->str.token(";", 51).toLong();if ( variation && variation != 20 )text = text + " " + _US(pVfs->findText(0, 17, 10000 + variation));ls->AddShip(_US(str->data), text);}if ( ls->ShowDialog(this) == System::Windows::Forms::DialogResult::OK ) {Utils::String line = pVfs->getTShipsEntry(_S(ls->GetData()));if ( !line.empty() ) {if ( shipName ) {(*shipName) = ls->GetShipName();}return ls->GetData();}}else return "";}return nullptr;}void Form1::ImportShip(){OpenFileDialog ^ofd = gcnew OpenFileDialog();ofd->Filter = "X Catalog Files (*.cat)|*.cat";ofd->Title = "Select the mod file to import a ship from";ofd->FilterIndex = 1;ofd->RestoreDirectory = true;ofd->Multiselect = false;CVirtualFileSystem *vfs = new CVirtualFileSystem();if ( ofd->ShowDialog(this) == System::Windows::Forms::DialogResult::OK ){if ( !vfs->loadMod(CyStringFromSystemString(ofd->FileName).ToString()) ) {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);return;}this->UseWaitCursor = true;vfs->updateModTexts(17);String ^shipName = "";String ^shipID = getShipSelection(vfs, &shipName);if ( !shipID ) {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);}else if ( shipID->Length ) {String ^loadMod = ofd->FileName;CXspFile *newShip = NULL;while ( true ) {Creator::ImportShip ^import = gcnew Creator::ImportShip(shipID, shipName, vfs);import->ShowDialog(this);newShip = (import->Error()) ? NULL : import->GetShip();if ( !newShip ) {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 ) {// load in another fileif ( ofd->ShowDialog(this) == System::Windows::Forms::DialogResult::OK ) {loadMod = ofd->FileName;if ( !vfs->loadMod(CyStringFromSystemString(loadMod).ToString()) ) {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);break;}}else break;}else break;}else break;}if ( newShip ) {PackageForm ^childForm = this->OpenPackage(true, newShip, "", "Imported Ship");childForm->Text = "Imported Ship";newShip->adjustChanged(true);childForm->UpdateChanged();childForm->WindowState = Windows::Forms::FormWindowState::Maximized;}}this->UseWaitCursor = false;}delete vfs;}void Form1::ImportShipFromVFS(){// some way to select the VFS to useSelectFilesystem ^Filesystem = gcnew SelectFilesystem(_pGameDir);if ( Filesystem->ShowDialog(this) != System::Windows::Forms::DialogResult::OK ) {return;}Utils::String dir = Filesystem->gameDir();CyString mod;if ( Filesystem->gameMod() ) {mod = CyString(dir) + "/mods/" + CyStringFromSystemString(Filesystem->gameMod()) + ".cat";}CVirtualFileSystem *vfs = _pGameDir->selectedVFS();if ( !vfs ) {MessageBox::Show(this, "Error: Couldn't open Virtual File System", "Error Importing Ship", MessageBoxButtons::OK, MessageBoxIcon::Error);return;}// load a mod on top of the VFSif ( !mod.Empty() ) {if ( !vfs->loadMod(mod.ToString()) ) {MessageBox::Show(this, "There was a problem trying to open the mod file\n" + Filesystem->gameMod(), "Error Importing Ship", MessageBoxButtons::OK, MessageBoxIcon::Error);return;}vfs->updateModTexts(17);}// get the ship id to loadString ^shipName = "";String ^shipID = getShipSelection(vfs, &shipName);if ( !shipID ) {MessageBox::Show(this, "There was a problem trying to load ship data from VFS\n", "Error Importing Ship", MessageBoxButtons::OK, MessageBoxIcon::Error);}else if ( shipID->Length ) {// import the shipCreator::ImportShip ^import = gcnew Creator::ImportShip(shipID, shipName, vfs);import->ShowDialog(this);// create the new form with ship dataif ( !import->Error() ) {PackageForm ^childForm = this->OpenPackage(true, import->GetShip(), "", "Imported Ship");childForm->Text = "Imported Ship";import->GetShip()->adjustChanged(true);childForm->UpdateChanged();childForm->WindowState = Windows::Forms::FormWindowState::Maximized;}}// remove any mods that we have loadedvfs->clearMods();}} //NAMESPACE