Subversion Repositories spk

Rev

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