Subversion Repositories spk

Rev

Rev 104 | Rev 125 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 104 Rev 121
Line 17... Line 17...
17
#undef GetEnvironmentVariable
17
#undef GetEnvironmentVariable
18
 
18
 
19
enum {LISTGROUP_INSTALLED, LISTGROUP_SHIP, LISTGROUP_FAKE, LISTGROUP_LIBRARY, LISTGROUP_MOD, LISTGROUP_ARCHIVE};
19
enum {LISTGROUP_INSTALLED, LISTGROUP_SHIP, LISTGROUP_FAKE, LISTGROUP_LIBRARY, LISTGROUP_MOD, LISTGROUP_ARCHIVE};
20
 
20
 
21
namespace PluginManager {
21
namespace PluginManager {
-
 
22
 
-
 
23
	void MainGui::OpenDirectoryControl()
-
 
24
	{
-
 
25
		DirectoryControl ^dialog = gcnew DirectoryControl(m_pPackages, m_pDirList, m_pRemovedDirList);
-
 
26
		if (dialog->ShowDialog(this) == System::Windows::Forms::DialogResult::OK)
-
 
27
		{
-
 
28
			Utils::CStringList *dirs = dialog->directories();
-
 
29
			Utils::CStringList *removed = dialog->removeDirectories();
-
 
30
 
-
 
31
			// check if the current directory has been remove
-
 
32
			bool isRemoved = m_pPackages->IsLoaded() && removed->contains(m_pPackages->getCurrentDirectory(), true);
-
 
33
 
-
 
34
			// add all removed directories to list
-
 
35
			m_pRemovedDirList->clear();
-
 
36
			for (auto itr = removed->begin(); itr != removed->end(); itr++)
-
 
37
				m_pRemovedDirList->pushBack(m_pPackages->getProperDir((*itr)->str), (*itr)->data);
-
 
38
 
-
 
39
			bool changed = false;
-
 
40
 
-
 
41
			Utils::String current;
-
 
42
			if (ComboDir->SelectedIndex == (ComboDir->Items->Count - 1))
-
 
43
				current = _S(ComboDir->Text);
-
 
44
			else
-
 
45
				current = m_pDirList->get(ComboDir->SelectedIndex)->str;
-
 
46
 
-
 
47
			// remove any directories from main list that are not removed
-
 
48
			for (int i = m_pDirList->size() - 1; i >= 0; --i)
-
 
49
			{
-
 
50
				Utils::String dir = m_pDirList->get(i)->str;
-
 
51
				if (m_pRemovedDirList->contains(dir))
-
 
52
				{
-
 
53
					m_pDirList->removeAt(i);
-
 
54
					changed = true;
-
 
55
				}
-
 
56
			}
-
 
57
 
-
 
58
			// now add any remaining directories
-
 
59
			for (auto itr = dirs->begin(); itr != dirs->end(); itr++)
-
 
60
			{
-
 
61
				Utils::String dir = m_pPackages->getProperDir((*itr)->str);
-
 
62
				if (!m_pDirList->contains(dir))
-
 
63
				{
-
 
64
					int lang = m_pPackages->GetGameLanguage(dir);
-
 
65
					if(lang > 0)
-
 
66
						m_pDirList->pushBack(dir, Utils::String::Number(lang) + "|" + (*itr)->data);
-
 
67
					else
-
 
68
						m_pDirList->pushBack(dir, (*itr)->data);
-
 
69
					changed = true;
-
 
70
				}
-
 
71
			}
-
 
72
 
-
 
73
			if (isRemoved)
-
 
74
				ComboDir->SelectedIndex = ComboDir->Items->Count - 1;
-
 
75
			else if (changed)
-
 
76
				UpdateDirList(current);
-
 
77
		}
-
 
78
	}
-
 
79
 
-
 
80
	void MainGui::AboutDialog()
-
 
81
	{
-
 
82
		CBaseFile *pm = m_pPackages->FindScriptByAuthor("PluginManager");
-
 
83
		System::String ^scriptVer = "None";
-
 
84
		if (pm)
-
 
85
		{
-
 
86
			scriptVer = _US(pm->version());
-
 
87
			if (!pm->creationDate().empty())
-
 
88
				scriptVer += " (" + _US(pm->creationDate()) + ")";
-
 
89
		}
-
 
90
		About ^about = gcnew About(GetVersionString(), PMLDATE, scriptVer, m_bAdvanced);
-
 
91
		about->ShowDialog(this);
-
 
92
	}
-
 
93
 
22
 
94
 
23
	void MainGui::CheckProtectedDir()
95
	void MainGui::CheckProtectedDir()
24
	{
96
	{
-
 
97
		if (!m_pPackages || !m_pPackages->IsLoaded())
25
		Utils::String dir;
98
			return;
-
 
99
 
-
 
100
		Utils::String dir = m_pPackages->getCurrentDirectory();
26
		if ( m_pDirList->Head() ) {
101
		if(!dir.empty())
-
 
102
		{
27
			m_bDirLocked = false;
103
			m_bDirLocked = false;
28
			dir = m_pDirList->Head()->str.ToString();
-
 
29
 
104
 
30
			// write a file in the directory
105
			// write a file in the directory
31
			String ^sDir = _US(dir.findReplace("/", "\\"));
106
			String ^sDir = _US(dir.findReplace("/", "\\"));
32
			bool written = true;
107
			bool written = true;
33
			StreamWriter ^sw = nullptr;
108
			StreamWriter ^sw = nullptr;
34
			try {
109
			try {
35
				sw = System::IO::File::CreateText(sDir + "\\checklock.xpmtest");
110
				sw = System::IO::File::CreateText(sDir + "\\checklock.xpmtest");
36
				sw->WriteLine("can write");
111
				sw->WriteLine("can write");
37
			}	
112
			}	
38
			catch (System::Exception ^) {
113
			catch (System::Exception ^) {
39
				written = false;
114
				written = false;
40
			}
115
			}
41
			finally	{
116
			finally	{
42
				if ( sw )
117
				if ( sw )
43
					delete (IDisposable ^)sw;
118
					delete (IDisposable ^)sw;
44
			}
119
			}
45
 
120
 
Line 102... Line 177...
102
				}
177
				}
103
			}
178
			}
104
		}
179
		}
105
	}
180
	}
106
 
181
 
107
	void MainGui::GetGameDirs(CyString &dir, bool askDir, bool askDirAddon)
182
	void MainGui::UpdateDirList(const Utils::String &current)
108
	{
183
	{
-
 
184
		System::String ^checkCurrent = ComboDir->Text;
-
 
185
		System::String ^selected = nullptr;
-
 
186
		bool foundCurrent = false;
-
 
187
 
-
 
188
		ComboDir->Items->Clear();
-
 
189
 
109
		if ( CDirIO(dir).Exists() )
190
		if (m_pDirList && !m_pDirList->empty())
110
		{
191
		{
111
			CyString gameName = m_pPackages->GetGameName(dir);
192
			for(auto itr = m_pDirList->begin(); itr != m_pDirList->end(); itr++)
112
			if ( !gameName.Empty() )
-
 
113
			{
193
			{
114
				if ( !m_pDirList->FindString(dir) && !m_pRemovedDirList->FindString(dir) ) {
-
 
115
					int lang = m_pPackages->GetGameLanguage(dir);
-
 
116
					if ( !askDir || MessageBox::Show(this, "New Game Directory Found:\n" + SystemStringFromCyString(dir) + " [" + SystemStringFromCyString(gameName) + "]\n\nDo you wish to add this?", "Add New Game", MessageBoxButtons::YesNo, MessageBoxIcon::Question) == Windows::Forms::DialogResult::Yes ) {
194
				System::String ^str;
117
						if ( lang )
195
				if ((*itr)->data.isin("|"))
118
							m_pDirList->;PushFront(dir, CyString::Number(lang) + "|" + gameName);
196
					str = _US((*itr)->str + " [" + (*itr)->data.tokens("|", 2) + "] (Language: " + CPackages::ConvertLanguage((*itr)->;data.token("|", 1).toInt()) + ")");
119
						else
197
				else
120
							m_pDirList->PushFront(dir, gameName);
198
					str = _US((*itr)->str + " [" + (*itr)->data + "]");
121
					}
-
 
122
					else {
-
 
123
						m_pRemovedDirList->PushBack(dir);
199
				ComboDir->Items->Add(str);
124
					}
200
 
-
 
201
				if (!current.empty() && current.Compare((*itr)->str))
125
				}
202
					selected = str;
126
 
203
 
127
				// check for any addons
-
 
128
				CyStringList addons;
-
 
129
				if ( m_pPackages->GetGameAddons(addons, dir) ) {
-
 
130
					for ( SStringList *str = addons.Head(); str; str = str->next ) {
-
 
131
						CyString exe = CDirIO(dir).File(str->str);
-
 
132
						dir = CDirIO(dir).Dir(str->data);
-
 
133
						if ( CDirIO(dir).Exists() && !m_pDirList->FindString(dir) && !m_pRemovedDirList->FindString(dir) ) {
-
 
134
							gameName = m_pPackages->GetGameName(exe);
-
 
135
							if ( !gameName.Empty() ) {
-
 
136
								int lang = m_pPackages->GetGameLanguage(dir);
-
 
137
								if ( !askDirAddon || MessageBox::Show(this, "New Game Directory Found:\n" + SystemStringFromCyString(dir) + " [" + SystemStringFromCyString(gameName) + "]\n\nDo you wish to add this?", "Add New Game", MessageBoxButtons::YesNo, MessageBoxIcon::Question) == Windows::Forms::DialogResult::Yes ) {
204
				if (!foundCurrent && System::String::Compare(str, checkCurrent) == 0)
138
									if ( lang )
205
					foundCurrent = true;
139
										m_pDirList->PushFront(dir, CyString::Number(lang) + "|" + gameName);
-
 
140
									else
-
 
141
										m_pDirList->PushFront(dir, gameName);
-
 
142
								}
-
 
143
								else {
-
 
144
									m_pRemovedDirList->PushBack(dir);
-
 
145
								}
-
 
146
							}
-
 
147
						}
-
 
148
					}
-
 
149
				}
-
 
150
			}
206
			}
151
		}
207
		}
-
 
208
 
-
 
209
		ComboDir->Items->Add("-- None --");
-
 
210
		if (selected && selected->Length > 0)
-
 
211
			ComboDir->Text = selected;
-
 
212
		else if (current == "-- None --")
-
 
213
			ComboDir->Text = "-- None --";
-
 
214
		else if(!foundCurrent || !ComboDir->Text || ComboDir->Text->Length < 1)
-
 
215
			ComboDir->Text = ComboDir->Items[0]->ToString();
-
 
216
 
-
 
217
		this->UpdateRunButton();
152
	}
218
	}
153
 
219
 
154
	void MainGui::UpdateDirList()
220
	void MainGui::UpdateRunButton()
155
	{
221
	{
156
		ComboDir->Items->;Clear();
222
		if (!m_pPackages || !m_pPackages->;IsLoaded())
157
 
223
		{
158
		if ( !m_pDirList || !m_pDirList->Head() )
224
			ButRun->Visible = false;
159
			return;
225
			return;
160
 
-
 
161
		for ( SStringList *node = m_pDirList->Head(); node; node = node->next )
-
 
162
		{
-
 
163
			System::String ^str;
-
 
164
			if ( node->data.IsIn("|") )
-
 
165
				str = SystemStringFromCyString(node->str + " [" + node->data.GetToken("|", 2) + "] (Language: " + CPackages::ConvertLanguage(node->data.GetToken("|", 1, 1).ToInt()) + ")");
-
 
166
			else
-
 
167
				str = SystemStringFromCyString(node->str + " [" + node->data + "]");
-
 
168
			ComboDir->Items->Add(str);
-
 
169
 
-
 
170
			// first item 
-
 
171
			if ( node == m_pDirList->Head() )
-
 
172
				ComboDir->Text = str;
-
 
173
		}
226
		}
174
 
227
 
175
		this->UpdateRunButton();
-
 
176
	}
-
 
177
 
-
 
178
	void MainGui::UpdateRunButton()
-
 
179
	{
-
 
180
		ButRun->Text = "Run: " + SystemStringFromCyString(m_pPackages->GetGameName());
228
		ButRun->Text = "Run: " + _US(m_pPackages->getGameName());
-
 
229
		ButRun->Visible = true;
181
		
230
		
182
		CyString exe = m_pPackages->GetGameExe()->GetGameRunExe(m_pPackages->GetCurrentDirectory().ToString());
231
		Utils::String exe = m_pPackages->GetGameExe()->GetGameRunExe(m_pPackages->getCurrentDirectory());
183
		if ( CFileIO(exe).ExistsOld() )
232
		if ( CFileIO(exe).exists() )
184
		{
233
		{
185
			exe = exe.FindReplace("/", "\\");
234
			exe = exe.findReplace("/", "\\");
186
			wchar_t wText[200];
235
			wchar_t wText[200];
187
			::MultiByteToWideChar(CP_ACP, NULL, (char *)exe.c_str(), -1, wText, exe.Length() + 1);
236
			::MultiByteToWideChar(CP_ACP, NULL, (char *)exe.c_str(), -1, wText, exe.length() + 1);
188
 
237
 
189
			System::Drawing::Icon ^myIcon;
238
			System::Drawing::Icon ^myIcon;
190
			SHFILEINFO *shinfo = new SHFILEINFO();
239
			SHFILEINFO *shinfo = new SHFILEINFO();
191
 
240
 
192
			if ( FAILED(SHGetFileInfo(wText, 0, shinfo, sizeof(shinfo), SHGFI_ICON | SHGFI_LARGEICON)) )
241
			if ( FAILED(SHGetFileInfo(wText, 0, shinfo, sizeof(shinfo), SHGFI_ICON | SHGFI_LARGEICON)) )
Line 419... Line 468...
419
		ListPackages->LargeImageList->ImageSize = System::Drawing::Size(32, 32);
468
		ListPackages->LargeImageList->ImageSize = System::Drawing::Size(32, 32);
420
		ListPackages->LargeImageList->ColorDepth = Windows::Forms::ColorDepth::Depth32Bit;
469
		ListPackages->LargeImageList->ColorDepth = Windows::Forms::ColorDepth::Depth32Bit;
421
		ListPackages->SmallImageList->ImageSize = System::Drawing::Size(16, 16);
470
		ListPackages->SmallImageList->ImageSize = System::Drawing::Size(16, 16);
422
		ListPackages->SmallImageList->ColorDepth = Windows::Forms::ColorDepth::Depth32Bit;
471
		ListPackages->SmallImageList->ColorDepth = Windows::Forms::ColorDepth::Depth32Bit;
423
 
472
 
-
 
473
		if (m_pPackages && m_pPackages->IsLoaded())
-
 
474
		{
424
		int index = this->imageList1->Images->IndexOfKey("package.png");
475
			int index = this->imageList1->Images->IndexOfKey("package.png");
425
		if ( index != -1 )
476
			if (index != -1)
426
		{
477
			{
427
			ListPackages->SmallImageList->Images->Add("package", this->imageList1->Images[index]);
478
				ListPackages->SmallImageList->Images->Add("package", this->imageList1->Images[index]);
428
			ListPackages->LargeImageList->Images->Add("package", this->imageList1->Images[index]);
479
				ListPackages->LargeImageList->Images->Add("package", this->imageList1->Images[index]);
429
		}
480
			}
430
		index = this->imageList1->Images->IndexOfKey("ship.png");
481
			index = this->imageList1->Images->IndexOfKey("ship.png");
431
		if ( index != -1 )
482
			if (index != -1)
432
		{
483
			{
433
			ListPackages->SmallImageList->Images->Add("ship", this->imageList1->Images[index]);
484
				ListPackages->SmallImageList->Images->Add("ship", this->imageList1->Images[index]);
434
			ListPackages->LargeImageList->Images->Add("ship", this->imageList1->Images[index]);
485
				ListPackages->LargeImageList->Images->Add("ship", this->imageList1->Images[index]);
435
		}
486
			}
436
		index = this->imageList1->Images->IndexOfKey("fake.png");
487
			index = this->imageList1->Images->IndexOfKey("fake.png");
437
		if ( index != -1 )
488
			if (index != -1)
438
		{
489
			{
439
			ListPackages->SmallImageList->Images->Add("fake", this->imageList1->Images[index]);
490
				ListPackages->SmallImageList->Images->Add("fake", this->imageList1->Images[index]);
440
			ListPackages->LargeImageList->Images->Add("fake", this->imageList1->Images[index]);
491
				ListPackages->LargeImageList->Images->Add("fake", this->imageList1->Images[index]);
441
		}
492
			}
442
		index = this->imageList1->Images->IndexOfKey("library.png");
493
			index = this->imageList1->Images->IndexOfKey("library.png");
443
		if ( index != -1 )
494
			if (index != -1)
444
		{
495
			{
445
			ListPackages->SmallImageList->Images->Add("library", this->imageList1->Images[index]);
496
				ListPackages->SmallImageList->Images->Add("library", this->imageList1->Images[index]);
446
			ListPackages->LargeImageList->Images->Add("library", this->imageList1->Images[index]);
497
				ListPackages->LargeImageList->Images->Add("library", this->imageList1->Images[index]);
447
		}
498
			}
448
 
499
 
449
		index = this->imageList1->Images->IndexOfKey("archive.png");
500
			index = this->imageList1->Images->IndexOfKey("archive.png");
450
		if ( index != -1 )
501
			if (index != -1)
451
		{
502
			{
452
			ListPackages->SmallImageList->Images->Add("archive", this->imageList1->Images[index]);
503
				ListPackages->SmallImageList->Images->Add("archive", this->imageList1->Images[index]);
453
			ListPackages->LargeImageList->Images->Add("archive", this->imageList1->Images[index]);
504
				ListPackages->LargeImageList->Images->Add("archive", this->imageList1->Images[index]);
454
		}
505
			}
455
 
506
 
456
		AddIconToPackages("tick");
507
			AddIconToPackages("tick");
457
		AddIconToPackages("no");
508
			AddIconToPackages("no");
458
 
509
 
459
		ListViewGroup ^group = gcnew ListViewGroup("Installed Scripts", HorizontalAlignment::Left);
510
			ListViewGroup ^group = gcnew ListViewGroup("Installed Scripts", HorizontalAlignment::Left);
460
		ListPackages->Groups->Add(group);
511
			ListPackages->Groups->Add(group);
461
		ListViewGroup ^shipGroup = gcnew ListViewGroup("Installed Ships", HorizontalAlignment::Left);
512
			ListViewGroup ^shipGroup = gcnew ListViewGroup("Installed Ships", HorizontalAlignment::Left);
462
		ListPackages->Groups->Add(shipGroup);
513
			ListPackages->Groups->Add(shipGroup);
463
		ListViewGroup ^fakeGroup = gcnew ListViewGroup("Fake Patches", HorizontalAlignment::Left);
514
			ListViewGroup ^fakeGroup = gcnew ListViewGroup("Fake Patches", HorizontalAlignment::Left);
464
		ListPackages->Groups->Add(fakeGroup);
515
			ListPackages->Groups->Add(fakeGroup);
465
		ListViewGroup ^libGroup = gcnew ListViewGroup("Script Libraries", HorizontalAlignment::Left);
516
			ListViewGroup ^libGroup = gcnew ListViewGroup("Script Libraries", HorizontalAlignment::Left);
466
		ListPackages->Groups->Add(libGroup);
517
			ListPackages->Groups->Add(libGroup);
467
		ListViewGroup ^modGroup = gcnew ListViewGroup("Current Mod Addons", HorizontalAlignment::Left);
518
			ListViewGroup ^modGroup = gcnew ListViewGroup("Current Mod Addons", HorizontalAlignment::Left);
468
		ListPackages->Groups->Add(modGroup);
519
			ListPackages->Groups->Add(modGroup);
469
		ListViewGroup ^arcGroup = gcnew ListViewGroup("Installed Archives", HorizontalAlignment::Left);
520
			ListViewGroup ^arcGroup = gcnew ListViewGroup("Installed Archives", HorizontalAlignment::Left);
470
		ListPackages->Groups->Add(arcGroup);
521
			ListPackages->Groups->Add(arcGroup);
471
 
522
 
472
		// sort the items
523
			// sort the items
473
		if ( m_pPackages )
-
 
474
		{
-
 
475
			m_pPackages->AssignPackageNumbers();
524
			m_pPackages->AssignPackageNumbers();
476
			this->_DisplayPackages(NULL, nullptr);
525
			this->_DisplayPackages(NULL, nullptr);
-
 
526
 
-
 
527
			PackageListSelected(ListPackages, gcnew System::EventArgs());
-
 
528
 
-
 
529
			// update the status bar
-
 
530
			LabelStatus->Text = "Plugins Available: " + (m_pPackages->CountPackages(TYPE_BASE, false) - m_pPackages->CountBuiltInPackages(false)) + " (" + (m_pPackages->CountPackages(TYPE_BASE, true) - m_pPackages->CountBuiltInPackages(true)) + " Enabled)";
477
		}
531
		}
-
 
532
		else
-
 
533
			LabelStatus->Text = "No current directory";
478
 
534
 
479
		PackageListSelected(ListPackages, gcnew System::EventArgs());
-
 
480
		ListPackages->AutoResizeColumns(ColumnHeaderAutoResizeStyle::HeaderSize);
535
		ListPackages->AutoResizeColumns(ColumnHeaderAutoResizeStyle::HeaderSize);
481
 
-
 
482
		// update the status bar
-
 
483
		LabelStatus->Text = "Plugins Available: " + (m_pPackages->CountPackages(TYPE_BASE, false) - m_pPackages->CountBuiltInPackages(false))+ " (" + (m_pPackages->CountPackages(TYPE_BASE, true) - m_pPackages->CountBuiltInPackages(true)) + " Enabled)";
-
 
484
	}
536
	}
485
 
537
 
486
	void MainGui::StartCheckTimer()
538
	void MainGui::StartCheckTimer()
487
	{
539
	{
488
		System::Windows::Forms::Timer ^timer = gcnew System::Windows::Forms::Timer();
540
		System::Windows::Forms::Timer ^timer = gcnew System::Windows::Forms::Timer();
Line 517... Line 569...
517
 
569
 
518
		if ( m_pPackages->IsVanilla() )
570
		if ( m_pPackages->IsVanilla() )
519
			m_pMenuBar->Vanilla();
571
			m_pMenuBar->Vanilla();
520
		else
572
		else
521
			m_pMenuBar->Modified();
573
			m_pMenuBar->Modified();
-
 
574
 
-
 
575
		// enable/disable if directory is loaded
-
 
576
		bool isLoaded = m_pPackages && m_pPackages->IsLoaded();
-
 
577
		GroupPackages->Enabled = isLoaded;
-
 
578
		m_pMenuBar->SetLoaded(isLoaded);
522
	}
579
	}
523
 
580
 
524
	//
581
	//
525
	// Install a package
582
	// Install a package
526
	// Called from either install button, or from command line
583
	// Called from either install button, or from command line
527
	//
584
	//
Line 581... Line 638...
581
				}
638
				}
582
 
639
 
583
				if ( !builtin )
640
				if ( !builtin )
584
					this->DisplayMessageBox(false, "Open Package Error", "Error Opening: " + file + "\n" + errorStr, MessageBoxButtons::OK, MessageBoxIcon::Stop);
641
					this->DisplayMessageBox(false, "Open Package Error", "Error Opening: " + file + "\n" + errorStr, MessageBoxButtons::OK, MessageBoxIcon::Stop);
585
				errored = true;
642
				errored = true;
586
			}
643
			}
587
			else
644
			else
588
			{
645
			{
589
				if ( builtin )
646
				if ( builtin )
590
				{
647
				{
591
					package->SetOverrideFiles(builtin);
648
					package->SetOverrideFiles(builtin);
592
					if ( m_pPackages->PrepareInstallPackage(package, false, false, IC_WRONGGAME|IC_WRONGVERSION|IC_OLDVERSION) != INSTALLCHECK_OK )
649
					if ( m_pPackages->PrepareInstallPackage(package, false, false, IC_WRONGGAME|IC_WRONGVERSION|IC_OLDVERSION) != INSTALLCHECK_OK )
Line 598... Line 655...
598
					if ( errorNum != INSTALLCHECK_OK )
655
					if ( errorNum != INSTALLCHECK_OK )
599
					{
656
					{
600
						if ( errorNum == INSTALLCHECK_NOSHIP )
657
						if ( errorNum == INSTALLCHECK_NOSHIP )
601
						{
658
						{
602
							this->DisplayMessageBox(false, "No Ships", "Ships are not supported for " + SystemStringFromCyString(m_pPackages->GetGameName()), MessageBoxButtons::OK, MessageBoxIcon::Stop);
659
							this->DisplayMessageBox(false, "No Ships", "Ships are not supported for " + SystemStringFromCyString(m_pPackages->GetGameName()), MessageBoxButtons::OK, MessageBoxIcon::Stop);
603
							errored = true;
660
							errored = true;
604
						}
661
						}
605
						else if ( m_pPackages->PrepareInstallPackage(package, false, false, IC_MODIFIED) != INSTALLCHECK_OK )
662
						else if ( m_pPackages->PrepareInstallPackage(package, false, false, IC_MODIFIED) != INSTALLCHECK_OK )
606
						{
663
						{
607
							this->DisplayMessageBox(false, "Installing", "Currently in Vanilla Mode, Package is not an Vanilla Package\n" + SystemStringFromCyString(package->GetLanguageName(m_pPackages->GetLanguage())) + "\n\nSwitch to modified mode if you wish to install this package", MessageBoxButtons::OK, MessageBoxIcon::Question);
664
							this->DisplayMessageBox(false, "Installing", "Currently in Vanilla Mode, Package is not an Vanilla Package\n" + SystemStringFromCyString(package->GetLanguageName(m_pPackages->GetLanguage())) + "\n\nSwitch to modified mode if you wish to install this package", MessageBoxButtons::OK, MessageBoxIcon::Question);
608
							errored = true;
665
							errored = true;
609
						}
666
						}
Line 615... Line 672...
615
					if ( compat )
672
					if ( compat )
616
					{
673
					{
617
						String ^message = "\nConflicts with:\n";
674
						String ^message = "\nConflicts with:\n";
618
						for ( CBaseFile *p = packages.First(); p; p = packages.Next() )
675
						for ( CBaseFile *p = packages.First(); p; p = packages.Next() )
619
							message += SystemStringFromCyString(p->GetFullPackageName(m_pPackages->GetLanguage())) + "\n";
676
							message += SystemStringFromCyString(p->GetFullPackageName(m_pPackages->GetLanguage())) + "\n";
620
 
677
 
621
						if ( MessageBox::Show(this, SystemStringFromCyString(package->GetFullPackageName(m_pPackages->GetLanguage())) + ":\nIncompatabilities found with installed fake patches\n" + message + "\n\nDo you still wish to install?", "Packages Incompatable", MessageBoxButtons::YesNo, MessageBoxIcon::Warning) != Windows::Forms::DialogResult::Yes )
678
						if ( MessageBox::Show(this, SystemStringFromCyString(package->GetFullPackageName(m_pPackages->GetLanguage())) + ":\nIncompatabilities found with installed fake patches\n" + message + "\n\nDo you still wish to install?", "Packages Incompatable", MessageBoxButtons::YesNo, MessageBoxIcon::Warning) != Windows::Forms::DialogResult::Yes )
622
						{
679
						{
623
							m_pPackages->RemovePreparedInstall(package);
680
							m_pPackages->RemovePreparedInstall(package);
624
							errored = true;
681
							errored = true;
625
						}
682
						}
Line 713... Line 770...
713
			{
770
			{
714
				for ( CBaseFile *p = packageList.First(); p; p = packageList.Next() )
771
				for ( CBaseFile *p = packageList.First(); p; p = packageList.Next() )
715
				{
772
				{
716
					m_pPi->AddPackageWithGroup(SystemStringFromCyString(p->GetLanguageName(m_pPackages->GetLanguage())), _US(p->author()), _US(p->version()), "Enabled", "Enable Packages");
773
					m_pPi->AddPackageWithGroup(SystemStringFromCyString(p->GetLanguageName(m_pPackages->GetLanguage())), _US(p->author()), _US(p->version()), "Enabled", "Enable Packages");
717
					display = "Package Enabled\n\n" + SystemStringFromCyString(p->GetFullPackageName(m_pPackages->GetLanguage()));
774
					display = "Package Enabled\n\n" + SystemStringFromCyString(p->GetFullPackageName(m_pPackages->GetLanguage()));
718
				}
775
				}
719
			}
776
			}
720
			else
777
			else
721
				this->DisplayMessageBox(true, "Enable Error", "Error Enabling packages", MessageBoxButtons::OK, MessageBoxIcon::Stop);
778
				this->DisplayMessageBox(true, "Enable Error", "Error Enabling packages", MessageBoxButtons::OK, MessageBoxIcon::Stop);
722
		}
779
		}
723
 
780
 
724
		if ( m_pPi->PackageCount() == 1 )
781
		if ( m_pPi->PackageCount() == 1 )
725
			this->DisplayMessageBox(true, "Packages Enabled/Disabled", display, MessageBoxButtons::OK, MessageBoxIcon::Information);
782
			this->DisplayMessageBox(true, "Packages Enabled/Disabled", display, MessageBoxButtons::OK, MessageBoxIcon::Information);
Line 804... Line 861...
804
			}
861
			}
805
		}
862
		}
806
 
863
 
807
		if ( !frombackground )
864
		if ( !frombackground )
808
			this->Background_Finished();
865
			this->Background_Finished();
809
	}
866
	}
810
 
867
 
811
	void MainGui::ClearSelectedItems()
868
	void MainGui::ClearSelectedItems()
812
	{
869
	{
813
		for ( int i = 0; i < this->ListPackages->Items->Count; i++ )
870
		for ( int i = 0; i < this->ListPackages->Items->Count; i++ )
814
			this->ListPackages->Items[i]->Selected = false;
871
			this->ListPackages->Items[i]->Selected = false;
815
		PackageListSelected(ListPackages, gcnew System::EventArgs());
872
		PackageListSelected(ListPackages, gcnew System::EventArgs());
816
	}
873
	}
817
 
874
 
818
	bool MainGui::StartInstalling(bool builtin, bool background, bool archive)
875
	bool MainGui::StartInstalling(bool builtin, bool background, bool archive)
819
	{
876
	{
820
		// no packages to install
877
		// no packages to install
821
		if ( !m_pPackages->GetNumPackagesInQueue() )
878
		if ( !m_pPackages->GetNumPackagesInQueue() )
822
			return false;
879
			return false;
823
 
880
 
824
		// clear selected
881
		// clear selected
825
		this->ClearSelectedItems();
882
		this->ClearSelectedItems();
826
 
883
 
827
		// lets install them now
884
		// lets install them now
828
		CLinkList<CBaseFile> lCheckPackages;
885
		CLinkList<CBaseFile> lCheckPackages;
Line 833... Line 890...
833
				CBaseFile *package = pNode->Data();
890
				CBaseFile *package = pNode->Data();
834
				CSpkFile *spk = (CSpkFile *)package;
891
				CSpkFile *spk = (CSpkFile *)package;
835
 
892
 
836
				CyStringList missingList;
893
				CyStringList missingList;
837
				if ( m_pPackages->GetMissingDependacies(package, &missingList) )
894
				if ( m_pPackages->GetMissingDependacies(package, &missingList) )
838
				{
895
				{
839
					CyString requires;
896
					CyString requires;
840
					for ( SStringList *strNode = missingList.Head(); strNode; strNode = strNode->next )
897
					for ( SStringList *strNode = missingList.Head(); strNode; strNode = strNode->next )
841
					{
898
					{
842
						if ( strNode->str.IsIn("|") )
899
						if ( strNode->str.IsIn("|") )
843
							requires += strNode->str.GetToken("|", 1, 1) + " V" + strNode->str.GetToken("|", 2, 2) + " by " + strNode->data;
900
							requires += strNode->str.GetToken("|", 1, 1) + " V" + strNode->str.GetToken("|", 2, 2) + " by " + strNode->data;
Line 846... Line 903...
846
						requires += "\n";
903
						requires += "\n";
847
					}
904
					}
848
					this->DisplayMessageBox(false, "Installing", "Missing Package for " + SystemStringFromCyString(package->GetLanguageName(m_pPackages->GetLanguage())) + "\nRequires:\n" + SystemStringFromCyString(requires), MessageBoxButtons::OK, MessageBoxIcon::Exclamation);
905
					this->DisplayMessageBox(false, "Installing", "Missing Package for " + SystemStringFromCyString(package->GetLanguageName(m_pPackages->GetLanguage())) + "\nRequires:\n" + SystemStringFromCyString(requires), MessageBoxButtons::OK, MessageBoxIcon::Exclamation);
849
				}
906
				}
850
			}
907
			}
851
		}
908
		}
852
 
909
 
853
		// no packages to install
910
		// no packages to install
854
		if ( !m_pPackages->GetNumPackagesInQueue() )
911
		if ( !m_pPackages->GetNumPackagesInQueue() )
855
		{
912
		{
856
			this->Enabled = true;
913
			this->Enabled = true;
857
			this->ProgressBar->Hide();
914
			this->ProgressBar->Hide();
858
			return false;
915
			return false;
859
		}
916
		}
860
 
917
 
861
		ProgressBar->Show();
918
		ProgressBar->Show();
862
		this->Enabled = false;
919
		this->Enabled = false;
863
 
920
 
864
		if ( builtin )
921
		if ( builtin )
865
		{
922
		{
866
			if ( background )
923
			if ( background )
867
				this->StartBackground(MGUI_BACKGROUND_INSTALLBUILTIN);
924
				this->StartBackground(MGUI_BACKGROUND_INSTALLBUILTIN);
868
			else
925
			else
869
				this->DoInstall(builtin, false);
926
				this->DoInstall(builtin, false);
870
		}
927
		}
871
		else if ( archive )
928
		else if ( archive )
872
		{
929
		{
873
			if ( background )
930
			if ( background )
Line 926... Line 983...
926
		backgroundWorker1->RunWorkerAsync();
983
		backgroundWorker1->RunWorkerAsync();
927
		m_bRunningBackground = true;
984
		m_bRunningBackground = true;
928
		return true;
985
		return true;
929
	}
986
	}
930
 
987
 
931
	void MainGui::ChangeDirectory(CyString dir)
988
	void MainGui::CloseCurrentDirectory()
932
	{
989
	{
933
		if ( m_pPackages->IsCurrentDir(dir) )
-
 
934
			return;
-
 
935
 
-
 
936
		if ( m_pPackages->IsLoaded() )
990
		if (m_pPackages->IsLoaded())
937
		{
991
		{
938
			if ( m_pPackages->CloseDir(0, 0, true) )
992
			if (m_pPackages->CloseDir(0, 0, true))
939
			{
993
			{
940
				// write the modname
994
				// write the modname
941
				if ( !m_pPackages->GetModKey().Empty() )
995
				if (!m_pPackages->GetModKey().Empty())
942
					PluginManager::WriteRegistryValue(m_pPackages->GetModKey(), m_pPackages->GetSelectedModName());
996
					PluginManager::WriteRegistryValue(m_pPackages->GetModKey(), m_pPackages->GetSelectedModName());
943
				m_pPackages->Reset();
997
				m_pPackages->Reset();
944
			}
998
			}
945
			else
999
			else
946
			{
1000
			{
947
				this->DisplayMessageBox(true, "Error", "unable to close directory", MessageBoxButtons::OK, MessageBoxIcon::Error);
1001
				this->DisplayMessageBox(true, "Error", "unable to close directory", MessageBoxButtons::OK, MessageBoxIcon::Error);
948
				return;
1002
				return;
949
			}
1003
			}
950
		}
1004
		}
951
 
1005
 
952
		m_pPackages->Reset();
1006
		m_pPackages->Reset();
-
 
1007
	}
-
 
1008
 
-
 
1009
	void MainGui::ChangeDirectory(const Utils::String &dir)
-
 
1010
	{
-
 
1011
		if ( m_pPackages->isCurrentDir(dir) )
-
 
1012
			return;
-
 
1013
 
-
 
1014
		CloseCurrentDirectory();
953
 
1015
 
954
		if ( m_pPackages->Read(dir, 0) )
1016
		if ( m_pPackages->read(dir, 0) )
955
		{
1017
		{
956
			if ( m_iSaveGameManager == 1 )
1018
			if ( m_iSaveGameManager == 1 )
957
				m_pPackages->RestoreSaves();
1019
				m_pPackages->RestoreSaves();
958
			m_pPackages->UpdatePackages();
1020
			m_pPackages->UpdatePackages();
959
			m_pPackages->ReadGameLanguage(true);
1021
			m_pPackages->ReadGameLanguage(true);
960
			this->UpdateRunButton();
-
 
961
			System::String ^mod = PluginManager::ReadRegistryValue(m_pPackages->GetModKey());
1022
			System::String ^mod = PluginManager::ReadRegistryValue(m_pPackages->GetModKey());
962
			m_pPackages->SetMod(CyStringFromSystemString(mod));
1023
			m_pPackages->SetMod(CyStringFromSystemString(mod));
963
		}
1024
		}
964
		else
1025
		else
965
		{
1026
		{
966
			this->DisplayMessageBox(true, "Error", "unable to open new directory", MessageBoxButtons::OK, MessageBoxIcon::Error);
1027
			this->DisplayMessageBox(true, "Error", "unable to open new directory", MessageBoxButtons::OK, MessageBoxIcon::Error);
967
			this->Close();
1028
			this->CloseCurrentDirectory();
968
		}
1029
		}
969
	}
1030
	}
970
 
1031
 
971
	CBaseFile *MainGui::FindPackageFromList(ListViewItem ^item)
1032
	CBaseFile *MainGui::FindPackageFromList(ListViewItem ^item)
972
	{
1033
	{
Line 1091... Line 1152...
1091
		}
1152
		}
1092
 
1153
 
1093
		// enable/disable the buttons connected to the package list
1154
		// enable/disable the buttons connected to the package list
1094
		ButUninstall->Enabled = buttonEnabled;
1155
		ButUninstall->Enabled = buttonEnabled;
1095
		ButDisable->Enabled = buttonEnabled;
1156
		ButDisable->Enabled = buttonEnabled;
1096
	}
-
 
1097
 
-
 
1098
	void MainGui::AddDirectoryEvent(System::Object ^Sender, System::EventArgs ^E)
-
 
1099
	{
-
 
1100
		OpenFileDialog ^ofd = gcnew OpenFileDialog();
-
 
1101
		ofd->Filter = "X-Universe Executable|";
-
 
1102
		String ^games = "";
-
 
1103
		for ( int i = 0; i < m_pPackages->GetGameExe()->GetNumGames(); i++ )
-
 
1104
		{
-
 
1105
			SGameExe *exe = m_pPackages->GetGameExe()->GetGame(i);
-
 
1106
			if ( i ) ofd->Filter += ";";
-
 
1107
			ofd->Filter += SystemStringFromCyString(exe->sExe);
-
 
1108
			games += "|" + SystemStringFromCyString(exe->sName) + "|" + SystemStringFromCyString(exe->sExe);
-
 
1109
		}
-
 
1110
		ofd->Filter += games;
-
 
1111
		ofd->FilterIndex = 1;
-
 
1112
		ofd->RestoreDirectory = true;
-
 
1113
		if ( ofd->ShowDialog(this) == System::Windows::Forms::DialogResult::OK )
-
 
1114
		{
-
 
1115
			CyString file = CyStringFromSystemString(ofd->FileName);
-
 
1116
			CyString dir = CyStringFromSystemString(IO::FileInfo(ofd->FileName).DirectoryName);
-
 
1117
			// check its a valid directory
-
 
1118
			if ( !dir.Empty() )
-
 
1119
			{
-
 
1120
				CyString gameName = m_pPackages->GetGameName(file);
-
 
1121
				if ( gameName.Empty() )
-
 
1122
					this->DisplayMessageBox(false, "Add Directory Error", "No X-Universe game found in folder:\n" + SystemStringFromCyString(dir), MessageBoxButtons::OK, MessageBoxIcon::Error);
-
 
1123
				else
-
 
1124
				{
-
 
1125
					// lets check if theres an old folder
-
 
1126
					if ( m_pPackages->isOldDir(dir.ToString()) )
-
 
1127
					{
-
 
1128
						if ( this->DisplayMessageBox(false, "Update Game Directory", "Game directory: " + SystemStringFromCyString(dir) + "\nIs currently being controled by the old plugin manager\nIf you continue, you will be unable to use the old version again\nDo you wish to continue?", MessageBoxButtons::YesNo, MessageBoxIcon::Question) != System::Windows::Forms::DialogResult::Yes )
-
 
1129
							return;
-
 
1130
					}
-
 
1131
					m_iBackgroundTask = MGUI_BACKGROUND_ADDDIR;
-
 
1132
					this->Enabled = false;
-
 
1133
					CyString properDir = m_pPackages->GetProperDir(file);
-
 
1134
					ComboDir->Items->Add(SystemStringFromCyString(properDir));
-
 
1135
					ComboDir->Text = SystemStringFromCyString(properDir);
-
 
1136
 
-
 
1137
					m_pRemovedDirList->Remove(properDir, true);
-
 
1138
					GetGameDirs(dir, false, m_pPackages->GetAddonDir(file).Empty());
-
 
1139
					/*int lang = m_pPackages->GetGameLanguage(dir);
-
 
1140
					if ( lang )
-
 
1141
						m_pDirList->PushFront(properDir, CyString::Number(lang) + "|" + gameName);
-
 
1142
					else
-
 
1143
						m_pDirList->PushFront(properDir, gameName);*/
-
 
1144
					this->StartBackground(MGUI_BACKGROUND_ADDDIR, SystemStringFromCyString(properDir));
-
 
1145
				}
-
 
1146
			}
-
 
1147
		}
-
 
1148
	}
1157
	}
1149
 
1158
 
1150
	bool MainGui::EnablePackage(CBaseFile *p)
1159
	bool MainGui::EnablePackage(CBaseFile *p)
1151
	{
1160
	{
1152
		if ( !m_pPackages->PrepareEnablePackage(p) )
1161
		if ( !m_pPackages->PrepareEnablePackage(p) )
Line 1243... Line 1252...
1243
	{
1252
	{
1244
		this->Enabled = false;
1253
		this->Enabled = false;
1245
		PackageBrowser ^mod = gcnew PackageBrowser(m_pPackages, this->imageList1);
1254
		PackageBrowser ^mod = gcnew PackageBrowser(m_pPackages, this->imageList1);
1246
		if ( !mod->AnyPackages() )
1255
		if ( !mod->AnyPackages() )
1247
		{
1256
		{
1248
			System::String ^game;
-
 
1249
			if ( m_pDirList && m_pDirList->Count() && m_pDirList->Head() )
-
 
1250
			{
-
 
1251
				CyString sGame = m_pDirList->Head()->data;
1257
			System::String ^game = _US(m_pPackages->getGameName());
1252
				if ( sGame.IsIn("|") )
-
 
1253
					sGame = sGame.GetToken("|", 2);
-
 
1254
				game = SystemStringFromCyString(sGame);
-
 
1255
			}
-
 
1256
			this->DisplayMessageBox(false, "No Available Packages", "No available packages found for " + game, MessageBoxButtons::OK, MessageBoxIcon::Exclamation);
1258
			this->DisplayMessageBox(false, "No Available Packages", "No available packages found for " + game, MessageBoxButtons::OK, MessageBoxIcon::Exclamation);
1257
 
1259
 
1258
			this->Enabled = true;
1260
			this->Enabled = true;
1259
			return;
1261
			return;
1260
		}
1262
		}
Line 1553... Line 1555...
1553
		}
1555
		}
1554
	}
1556
	}
1555
 
1557
 
1556
	void MainGui::ChangeDirectoryEvent(System::Object ^Sender, System::EventArgs ^E)
1558
	void MainGui::ChangeDirectoryEvent(System::Object ^Sender, System::EventArgs ^E)
1557
	{
1559
	{
1558
		if ( m_iBackgroundTask == MGUI_BACKGROUND_ADDDIR )
1560
		if (ComboDir->SelectedIndex == (ComboDir->Items->Count - 1))
1559
			return;
1561
		{
-
 
1562
			if (m_pPackages && m_pPackages->IsLoaded())
1560
 
1563
			{
-
 
1564
				this->Enabled = false;
1561
		CyString dir = CyStringFromSystemString(ComboDir->Text);
1565
				ProgressBar->Show();
1562
		if ( dir.NumToken(" [&quot;) )
1566
				this-&gt;CheckUnusedShared();
1563
			dir = dir.GetToken(" [", 1, dir.NumToken(" [") - 1);
1567
				this->StartBackground(MGUI_BACKGROUND_CLOSEDIR, "");
-
 
1568
			}
-
 
1569
		}
-
 
1570
		else if (ComboDir->SelectedIndex >= 0)
1564
 
1571
		{
-
 
1572
			Utils::String dir = m_pDirList->get(ComboDir->SelectedIndex)->str;
1565
		if ( !m_pPackages->IsCurrentDir(dir) )
1573
			if (!m_pPackages->isCurrentDir(dir))
1566
		{
1574
			{
1567
			this->Enabled = false;
1575
				this->Enabled = false;
-
 
1576
				ProgressBar->Show();
1568
			this->CheckUnusedShared();
1577
				this->CheckUnusedShared();
1569
			this->StartBackground(MGUI_BACKGROUND_CHANGEDIR, SystemStringFromCyString(dir));
1578
				this->StartBackground(MGUI_BACKGROUND_CHANGEDIR, _US(dir));
-
 
1579
			}
1570
		}
1580
		}
1571
	}
1581
	}
1572
 
1582
 
1573
	void MainGui::Background_DoWork(System::Object ^Sender, DoWorkEventArgs ^E)
1583
	void MainGui::Background_DoWork(System::Object ^Sender, DoWorkEventArgs ^E)
1574
	{
1584
	{
1575
		m_bDisplayMessage = false;
1585
		m_bDisplayMessage = false;
1576
		m_bDisplayDialog = false;
1586
		m_bDisplayDialog = false;
1577
 
1587
 
1578
		switch ( m_iBackgroundTask )
1588
		switch ( m_iBackgroundTask )
1579
		{
1589
		{
1580
			case MGUI_BACKGROUND_INSTALL:
1590
			case MGUI_BACKGROUND_INSTALL:
1581
				this->DoInstall(false, true);
1591
				this->DoInstall(false, true);
1582
				break;
1592
				break;
1583
			case MGUI_BACKGROUND_INSTALLBUILTIN:
1593
			case MGUI_BACKGROUND_INSTALLBUILTIN:
1584
				this->DoInstall(true, true);
1594
				this->DoInstall(true, true);
1585
				break;
1595
				break;
1586
			case MGUI_BACKGROUND_UNINSTALL:
1596
			case MGUI_BACKGROUND_UNINSTALL:
1587
				this->DoUninstall();
1597
				this->DoUninstall();
1588
				break;
1598
				break;
1589
			case MGUI_BACKGROUND_DISABLE:
1599
			case MGUI_BACKGROUND_DISABLE:
1590
				this->DoDisable();
1600
				this->DoDisable();
-
 
1601
				break;
-
 
1602
			case MGUI_BACKGROUND_CLOSEDIR:
-
 
1603
				this->CloseCurrentDirectory();
1591
				break;
1604
				break;
1592
			case MGUI_BACKGROUND_CHANGEDIR:
1605
			case MGUI_BACKGROUND_CHANGEDIR:
1593
			case MGUI_BACKGROUND_ADDDIR:
-
 
1594
				this->ChangeDirectory(CyStringFromSystemString(m_sBackgroundInfo));
1606
				this->ChangeDirectory(_S(m_sBackgroundInfo));
1595
				break;
1607
				break;
1596
			case MGUI_BACKGROUND_REMOVEDIR:
-
 
1597
				this->RemoveCurrentDirectory();
-
 
1598
		}
1608
		}
1599
	}
1609
	}
1600
 
1610
 
1601
	void MainGui::Background_Finished()
1611
	void MainGui::Background_Finished()
1602
	{
1612
	{
Line 1615... Line 1625...
1615
		}
1625
		}
1616
 
1626
 
1617
		m_bDisplayDialog = false;
1627
		m_bDisplayDialog = false;
1618
		m_bDisplayMessage = false;
1628
		m_bDisplayMessage = false;
1619
 
1629
 
1620
		if ( m_iBackgroundTask == MGUI_BACKGROUND_CHANGEDIR || m_iBackgroundTask == MGUI_BACKGROUND_ADDDIR )
1630
		if ( m_iBackgroundTask == MGUI_BACKGROUND_CHANGEDIR || m_iBackgroundTask == MGUI_BACKGROUND_CLOSEDIR)
1621
		{
1631
		{
1622
			// switch the dir list
1632
			// switch the dir list
-
 
1633
			Utils::String selectedDir;
-
 
1634
			if (ComboDir->SelectedIndex == ComboDir->Items->Count - 1)
1623
			if ( ComboDir->;Text )
1635
				selectedDir = _S(ComboDir->;Text);
-
 
1636
			else if (ComboDir->SelectedIndex >= 0)
1624
			{
1637
			{
1625
				CyString dir = CyStringFromSystemString(ComboDir->Text);
1638
				Utils::String dir = m_pDirList->get(ComboDir->SelectedIndex)->str;
-
 
1639
				selectedDir = dir;
1626
				if ( !dir.Empty() )
1640
				if ( !dir.empty() )
1627
				{
1641
				{
1628
					if ( (m_iBackgroundTask == MGUI_BACKGROUND_CHANGEDIR) && (dir.NumToken(" [")) )
1642
					if ( (m_iBackgroundTask == MGUI_BACKGROUND_CHANGEDIR) && (dir.countToken(" [")) )
1629
						dir = dir.GetToken(" [", 1, dir.NumToken(" [") - 1);
1643
						dir = dir.tokens(" [", 1);
1630
					if ( m_pDirList->FindString(dir) )
1644
					if ( m_pDirList->findString(dir) )
1631
					{
1645
					{
1632
						CyString data = m_pDirList->FindString(dir)->data;
1646
						Utils::String data = m_pDirList->findString(dir);
1633
						m_pDirList->Remove(dir, false);
1647
						m_pDirList->remove(dir, false);
1634
						m_pDirList->PushFront(dir, data);
1648
						m_pDirList->pushFront(dir, data);
1635
					}
1649
					}
1636
					else
1650
					else
1637
					{
1651
					{
1638
						int lang = m_pPackages->GetGameLanguage(dir);
1652
						int lang = m_pPackages->GetGameLanguage(dir);
1639
						if ( lang )
1653
						if ( lang )
1640
							m_pDirList->PushFront(dir, CyString::Number(lang) + "|" + m_pPackages->GetGameName(dir));
1654
							m_pDirList->pushFront(dir, Utils::String::Number(lang) + "|" + m_pPackages->getGameName(dir));
1641
						else
1655
						else
1642
							m_pDirList->PushFront(dir, m_pPackages->GetGameName(dir));
1656
							m_pDirList->pushFront(dir, m_pPackages->getGameName(dir));
1643
					}
1657
					}
-
 
1658
				}
-
 
1659
			}
1644
 
1660
 
1645
					this->UpdateDirList();
1661
			this->UpdateDirList(selectedDir);
1646
				}
1662
			this->UpdateRunButton();
1647
			}
-
 
1648
		}
1663
		}
1649
 
1664
 
1650
		// display any files that failed
1665
		// display any files that failed
1651
		if ( m_iBackgroundTask == MGUI_BACKGROUND_INSTALL )
1666
		if ( m_iBackgroundTask == MGUI_BACKGROUND_INSTALL )
1652
		{
1667
		{
Line 1664... Line 1679...
1664
				MessageBox::Show(this, "These files failed to install\n" + files, "Failed Files", MessageBoxButtons::OK, MessageBoxIcon::Warning);
1679
				MessageBox::Show(this, "These files failed to install\n" + files, "Failed Files", MessageBoxButtons::OK, MessageBoxIcon::Warning);
1665
		}
1680
		}
1666
 
1681
 
1667
		switch ( m_iBackgroundTask )
1682
		switch ( m_iBackgroundTask )
1668
		{
1683
		{
-
 
1684
			case MGUI_BACKGROUND_CLOSEDIR:
1669
			case MGUI_BACKGROUND_CHANGEDIR:
1685
			case MGUI_BACKGROUND_CHANGEDIR:
1670
			case MGUI_BACKGROUND_ADDDIR:
-
 
1671
				this->UpdateControls();
1686
				this->UpdateControls();
1672
				this->UpdatePackages();
1687
				this->UpdatePackages();
1673
				this->CheckProtectedDir();
1688
				this->CheckProtectedDir();
1674
				m_bRunningBackground = false;
1689
				m_bRunningBackground = false;
1675
				if ( this->UpdateBuiltInPackages() )
1690
				if ( this->UpdateBuiltInPackages() )
Line 1680... Line 1695...
1680
			case MGUI_BACKGROUND_INSTALLBUILTIN:
1695
			case MGUI_BACKGROUND_INSTALLBUILTIN:
1681
			case MGUI_BACKGROUND_UNINSTALL:
1696
			case MGUI_BACKGROUND_UNINSTALL:
1682
			case MGUI_BACKGROUND_DISABLE:
1697
			case MGUI_BACKGROUND_DISABLE:
1683
				this->UpdatePackages();
1698
				this->UpdatePackages();
1684
				break;
1699
				break;
1685
			case MGUI_BACKGROUND_REMOVEDIR:
-
 
1686
				ComboDir->Items->RemoveAt(0);
-
 
1687
				this->DisplayMessageBox(false, "Remove Directory", "Directory has been removed\n" + SystemStringFromCyString(m_pRemovedDirList->Tail()->str), MessageBoxButtons::OK, MessageBoxIcon::Information);
-
 
1688
				break;
-
 
1689
		}
-
 
1690
 
-
 
1691
		if ( m_iBackgroundTask == MGUI_BACKGROUND_ADDDIR )
-
 
1692
			this->DisplayMessageBox(false, "Add Game Folder", "Folder \"" + m_sBackgroundInfo + "\" added\nGame: " + SystemStringFromCyString(m_pPackages->GetGameName(CyStringFromSystemString(m_sBackgroundInfo))), MessageBoxButtons::OK, MessageBoxIcon::Information);
-
 
1693
 
-
 
1694
		else if ( m_iBackgroundTask == MGUI_BACKGROUND_REMOVEDIR )
-
 
1695
		{
-
 
1696
			// no more directories left
-
 
1697
			if ( m_pDirList->Empty() )
-
 
1698
			{
-
 
1699
				m_bRunningBackground = false;
-
 
1700
				this->Close();
-
 
1701
			}
-
 
1702
			// otherwise, open the next directory
-
 
1703
			else
-
 
1704
			{
-
 
1705
				m_bRunningBackground = false;
-
 
1706
				ComboDir->SelectedItem = ComboDir->Items[0];
-
 
1707
//				this->StartBackground(MGUI_BACKGROUND_CHANGEDIR, SystemStringFromCyString(m_pDirList->Head()->str));
-
 
1708
				return;
-
 
1709
			}
-
 
1710
		}
1700
		}
1711
 
1701
 
1712
		m_iBackgroundTask = MGUI_BACKGROUND_NONE;
1702
		m_iBackgroundTask = MGUI_BACKGROUND_NONE;
1713
 
1703
 
1714
		this->Enabled = true;
1704
		this->Enabled = true;
1715
 
-
 
-
 
1705
		ProgressBar->Hide();
1716
		m_bRunningBackground = false;
1706
		m_bRunningBackground = false;
1717
	}
1707
	}
1718
 
1708
 
1719
	void MainGui::Background_Progress(System::Object ^Sender, ProgressChangedEventArgs ^E)
1709
	void MainGui::Background_Progress(System::Object ^Sender, ProgressChangedEventArgs ^E)
1720
	{
1710
	{
1721
		this->ProgressBar->Value = E->ProgressPercentage;
1711
		this->ProgressBar->Value = E->ProgressPercentage;
1722
	}
1712
	}
1723
 
1713
 
1724
	bool MainGui::UpdateBuiltInPackages()
1714
	bool MainGui::UpdateBuiltInPackages()
1725
	{
1715
	{
-
 
1716
		// no current directory
-
 
1717
		if (!m_pPackages || !m_pPackages->IsLoaded())
-
 
1718
			return false;
-
 
1719
 
1726
		// find all built-in packages
1720
		// find all built-in packages
1727
		System::String ^dir = ".\\Required";
1721
		System::String ^dir = ".\\Required";
1728
 
1722
 
1729
		if ( System::IO::Directory::Exists(dir) ) 
1723
		if ( System::IO::Directory::Exists(dir) ) 
1730
		{
1724
		{
Line 1776... Line 1770...
1776
	// Auto Update
1770
	// Auto Update
1777
	////
1771
	////
1778
	void MainGui::AutoUpdate()
1772
	void MainGui::AutoUpdate()
1779
	{
1773
	{
1780
		if ( !m_bAutoUpdate || !System::IO::File::Exists( ".\\AutoUpdater.exe") )
1774
		if ( !m_bAutoUpdate || !System::IO::File::Exists( ".\\AutoUpdater.exe") )
1781
			return;
1775
			return;
1782
 
1776
 
1783
		// load the dir list
1777
		// load the dir list
1784
		if ( !m_pUpdateList )
1778
		if ( !m_pUpdateList )
1785
		{
1779
		{
1786
			m_pUpdateList = new CyStringList;
1780
			m_pUpdateList = new CyStringList;
Line 1888... Line 1882...
1888
								download = rest.GetToken(" ", 3);
1882
								download = rest.GetToken(" ", 3);
1889
							else
1883
							else
1890
							{
1884
							{
1891
								download += "|";
1885
								download += "|";
1892
								download += rest.GetToken(" ", 3);
1886
								download += rest.GetToken(" ", 3);
1893
							}
1887
							}
1894
						}
1888
						}
1895
					}
1889
					}
1896
				}
1890
				}
1897
			}
1891
			}
1898
 
1892
 
1899
			CLEANSPLIT(strs, max)
1893
			CLEANSPLIT(strs, max)
1900
 
1894
 
1901
			if ( !download.Empty() && !message.Empty() )
1895
			if ( !download.Empty() && !message.Empty() )
1902
			{
1896
			{
1903
				if ( this->DisplayMessageBox(false, "Updater", SystemStringFromCyString(message) + "Do You wish to download and install it?", MessageBoxButtons::YesNo, MessageBoxIcon::Question) == System::Windows::Forms::DialogResult::Yes )
1897
				if ( this->DisplayMessageBox(false, "Updater", SystemStringFromCyString(message) + "Do You wish to download and install it?", MessageBoxButtons::YesNo, MessageBoxIcon::Question) == System::Windows::Forms::DialogResult::Yes )
1904
				{
1898
				{
1905
					// absolute address
1899
					// absolute address
Line 2025... Line 2019...
2025
			{
2019
			{
2026
				m_pUpdateList->Head()->data = CyStringFromSystemString("!ERROR! " + ex->ToString());
2020
				m_pUpdateList->Head()->data = CyStringFromSystemString("!ERROR! " + ex->ToString());
2027
 
2021
 
2028
			}
2022
			}
2029
		}
2023
		}
2030
	}
-
 
2031
 
-
 
2032
	void MainGui::RemoveDirectory()
-
 
2033
	{
-
 
2034
		if ( !m_pPackages->IsLoaded() )
-
 
2035
			return;
-
 
2036
 
-
 
2037
		System::String ^remDir = SystemStringFromCyString(m_pPackages->GetCurrentDirectory());
-
 
2038
		this->Enabled = false;
-
 
2039
		if ( this->DisplayMessageBox(false, "Remove Directory", "Are you sure you want to remove this directory:\n" + remDir + "\n\nThis will remove all installed packages and clear any settings", MessageBoxButtons::YesNo, MessageBoxIcon::Question) != System::Windows::Forms::DialogResult::Yes)
-
 
2040
		{
-
 
2041
			this->Enabled = true;
-
 
2042
			return;
-
 
2043
		}
-
 
2044
 
-
 
2045
		this->StartBackground(MGUI_BACKGROUND_REMOVEDIR, remDir);
-
 
2046
	}
-
 
2047
 
-
 
2048
	bool MainGui::RemoveCurrentDirectory()
-
 
2049
	{
-
 
2050
		if ( !m_pPackages->RemoveCurrentDirectory() )
-
 
2051
			return false;
-
 
2052
 
-
 
2053
		// remove directory from list
-
 
2054
		m_pRemovedDirList->PushBack(m_pDirList->Head()->str, "", true);
-
 
2055
		m_pDirList->PopFront();
-
 
2056
 
-
 
2057
		return true;
-
 
2058
	}
2024
	}
2059
 
2025
 
2060
	void MainGui::LaunchGame()
2026
	void MainGui::LaunchGame()
2061
	{
2027
	{
2062
		if ( !System::IO::File::Exists(".\\GameLauncher.exe") )
2028
		if ( !System::IO::File::Exists(".\\GameLauncher.exe") )
2063
			return;
2029
			return;
2064
 
2030
 
2065
		m_sRun = SystemStringFromCyString(m_pPackages->GetGameRunExe());
2031
		m_sRun = _US(m_pPackages->GetGameRunExe());
2066
		this->Close();
2032
		this->Close();
2067
	}
2033
	}
2068
 
2034
 
2069
	bool MainGui::DisplayTip(int tipsection, int tip)
2035
	bool MainGui::DisplayTip(int tipsection, int tip)
2070
	{
2036
	{
Line 2073... Line 2039...
2073
 
2039
 
2074
		STips ^tips = (STips ^)m_lTips[tipsection];
2040
		STips ^tips = (STips ^)m_lTips[tipsection];
2075
		if ( !(tips->iTips & tip) )
2041
		if ( !(tips->iTips & tip) )
2076
		{
2042
		{
2077
			System::String ^sTip = cli::safe_cast<System::String ^>(tips->sTips[(tip >> 1)]);
2043
			System::String ^sTip = cli::safe_cast<System::String ^>(tips->sTips[(tip >> 1)]);
2078
 
2044
 
2079
			tips->iTips |= tip;
2045
			tips->iTips |= tip;
2080
 
2046
 
2081
			if ( this->DisplayMessageBox(false, "Plugin Manager Tip", sTip, MessageBoxButtons::YesNo, MessageBoxIcon::Question) == System::Windows::Forms::DialogResult::Yes )
2047
			if ( this->DisplayMessageBox(false, "Plugin Manager Tip", sTip, MessageBoxButtons::YesNo, MessageBoxIcon::Question) == System::Windows::Forms::DialogResult::Yes )
2082
				return true;
2048
				return true;
2083
			else 
2049
			else 
2084
				return false;
2050
				return false;
2085
		}
2051
		}
2086
 
2052
 
2087
		return true;
2053
		return true;
2088
	}
2054
	}
2089
 
2055
 
2090
	void MainGui::SetTipStrings(int section)
2056
	void MainGui::SetTipStrings(int section)
2091
	{
2057
	{
2092
		STips ^t = (STips ^)m_lTips[section];
2058
		STips ^t = (STips ^)m_lTips[section];
2093
		t->sTips = gcnew ArrayList();
2059
		t->sTips = gcnew ArrayList();
Line 2096... Line 2062...
2096
		{
2062
		{
2097
			case TIPSECTION_YESNO:
2063
			case TIPSECTION_YESNO:
2098
				t->sTips->Add("You are about to uninstall a ship, you need to make sure that there are no ships in the sector you was in when you saved, otherwise it could prevent the save from loading\n\nContinue Uninstalling Ship?");
2064
				t->sTips->Add("You are about to uninstall a ship, you need to make sure that there are no ships in the sector you was in when you saved, otherwise it could prevent the save from loading\n\nContinue Uninstalling Ship?");
2099
				t->sTips->Add("You are about to disable a ship, you need to make sure that there are no ships in the sector you was in when you saved, otherwise it could prevent the save from loading\n\nContinue Disabling Ship?");
2065
				t->sTips->Add("You are about to disable a ship, you need to make sure that there are no ships in the sector you was in when you saved, otherwise it could prevent the save from loading\n\nContinue Disabling Ship?");
2100
				break;
2066
				break;
2101
		}
2067
		}
2102
	}
2068
	}
2103
 
2069
 
2104
	System::Windows::Forms::DialogResult MainGui::DisplayMessageBox(bool inthread, System::String ^title, System::String ^text, MessageBoxButtons buttons, MessageBoxIcon icon)
2070
	System::Windows::Forms::DialogResult MainGui::DisplayMessageBox(bool inthread, System::String ^title, System::String ^text, MessageBoxButtons buttons, MessageBoxIcon icon)
2105
	{
2071
	{
2106
		if ( !inthread )
2072
		if ( !inthread )
2107
			return MessageBox::Show(this, text, title, buttons, icon);
2073
			return MessageBox::Show(this, text, title, buttons, icon);
Line 2122... Line 2088...
2122
		Point ^mousePoint = this->ListPackages->PointToClient(this->contextMenuStrip1->MousePosition);
2088
		Point ^mousePoint = this->ListPackages->PointToClient(this->contextMenuStrip1->MousePosition);
2123
		return  this->ListPackages->GetItemAt(mousePoint->X, mousePoint->Y);
2089
		return  this->ListPackages->GetItemAt(mousePoint->X, mousePoint->Y);
2124
	}
2090
	}
2125
 
2091
 
2126
	CBaseFile *MainGui::GetFileFromItem(ListViewItem ^item)
2092
	CBaseFile *MainGui::GetFileFromItem(ListViewItem ^item)
2127
	{
2093
	{
2128
		int num = System::Convert::ToInt32(item->Tag);
2094
		int num = System::Convert::ToInt32(item->Tag);
2129
		return m_pPackages->GetPackageAt(num);
2095
		return m_pPackages->GetPackageAt(num);
2130
	}
2096
	}
2131
 
2097
 
2132
	System::Void MainGui::OpenContextMenu(System::Object ^Sender, CancelEventArgs ^E)
2098
	System::Void MainGui::OpenContextMenu(System::Object ^Sender, CancelEventArgs ^E)
Line 2740... Line 2706...
2740
			}
2706
			}
2741
			else
2707
			else
2742
				MessageBox::Show(this, "There was an error writing file:\n" + ofd->FileName, "File Write Error", MessageBoxButtons::OK, MessageBoxIcon::Error);
2708
				MessageBox::Show(this, "There was an error writing file:\n" + ofd->FileName, "File Write Error", MessageBoxButtons::OK, MessageBoxIcon::Error);
2743
		}
2709
		}
2744
	}
2710
	}
-
 
2711
	System::Void MainGui::MainGui_Shown(System::Object^  sender, System::EventArgs^  e)
-
 
2712
	{
-
 
2713
		if (m_pDirList->empty())
-
 
2714
		{
-
 
2715
			if (MessageBox::Show(this, "You currently have no directories added, would you like to add them now?", "No Game Directories", MessageBoxButtons::YesNo, MessageBoxIcon::Question) == Windows::Forms::DialogResult::Yes)
-
 
2716
				this->OpenDirectoryControl();
-
 
2717
		}
-
 
2718
	}
-
 
2719
	
-
 
2720
	System::Void MainGui::MainGui_Load(System::Object^  sender, System::EventArgs^  e)
-
 
2721
	{
-
 
2722
		
-
 
2723
		if ( m_iSaveGameManager == -1 )
-
 
2724
		{
-
 
2725
			m_iSaveGameManager = 0;
-
 
2726
			/*
2745
}
2727
			if ( MessageBox::Show(this, "The save game manager will keep seperate save games for each directory and keeps vanilla and modified save games seperate\n\nDo you want to enable the save game manager?", "Save Game Manager", MessageBoxButtons::YesNo, MessageBoxIcon::Question) == Windows::Forms::DialogResult::Yes )
-
 
2728
			{
-
 
2729
				m_iSaveGameManager = 1;
-
 
2730
				this->PrepareSaveGameManager();
-
 
2731
			}
-
 
2732
			else
-
 
2733
				m_iSaveGameManager = 0;
-
 
2734
			*/
-
 
2735
		}
-
 
2736
		m_pMenuBar->SetSaveGameManager((m_iSaveGameManager == 1) ? true : false);
-
 
2737
 
-
 
2738
		// auto update
-
 
2739
		if (m_iSizeX != -1 && m_iSizeY != -1)
-
 
2740
			this->Size = System::Drawing::Size(m_iSizeX, m_iSizeY);
2746
 
2741
 
-
 
2742
		this->UpdateBuiltInPackages();
-
 
2743
		this->AutoUpdate();
-
 
2744
	}
-
 
2745
}