Subversion Repositories spk

Rev

Rev 77 | Rev 95 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

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