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 18... Line 18...
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
 
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
 
-
 
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;
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
	{
109
		if ( CDirIO(dir).Exists() )
-
 
110
		{
-
 
111
			CyString gameName = m_pPackages->GetGameName(dir);
-
 
112
			if ( !gameName.Empty() )
-
 
113
			{
-
 
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 ) {
184
		System::String ^checkCurrent = ComboDir->Text;
117
						if ( lang )
-
 
118
							m_pDirList->PushFront(dir, CyString::Number(lang) + "|" + gameName);
-
 
119
						else
-
 
120
							m_pDirList->PushFront(dir, gameName);
185
		System::String ^selected = nullptr;
121
					}
-
 
122
					else {
-
 
123
						m_pRemovedDirList->PushBack(dir);
186
		bool foundCurrent = false;
124
					}
-
 
125
				}
-
 
126
 
187
 
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 ) {
-
 
138
									if ( lang )
-
 
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
			}
-
 
151
		}
-
 
152
	}
-
 
153
 
-
 
154
	void MainGui::UpdateDirList()
-
 
155
	{
-
 
156
		ComboDir->Items->Clear();
188
		ComboDir->Items->Clear();
157
 
189
 
158
		if ( !m_pDirList || !m_pDirList->Head() )
190
		if (m_pDirList && !m_pDirList->empty())
159
			return;
-
 
160
 
-
 
161
		for ( SStringList *node = m_pDirList->Head(); node; node = node->next )
-
 
162
		{
191
		{
-
 
192
			for(auto itr = m_pDirList->begin(); itr != m_pDirList->end(); itr++)
-
 
193
			{
163
			System::String ^str;
194
				System::String ^str;
164
			if ( node->data.IsIn("|") )
195
				if ((*itr)->data.isin("|"))
165
				str = SystemStringFromCyString(node->str + " [" + node->data.GetToken("|", 2) + "] (Language: " + CPackages::ConvertLanguage(node->data.GetToken("|", 1, 1).ToInt()) + ")");
196
					str = _US((*itr)->str + " [" + (*itr)->data.tokens("|", 2) + "] (Language: " + CPackages::ConvertLanguage((*itr)->data.token("|", 1).toInt()) + ")");
166
			else
197
				else
167
				str = SystemStringFromCyString(node->str + " [" + node->data + "]");
198
					str = _US((*itr)->str + " [" + (*itr)->data + "]");
168
			ComboDir->Items->Add(str);
199
				ComboDir->Items->Add(str);
-
 
200
 
-
 
201
				if (!current.empty() && current.Compare((*itr)->str))
-
 
202
					selected = str;
169
 
203
 
170
			// first item 
-
 
171
			if ( node == m_pDirList->Head() )
204
				if (!foundCurrent && System::String::Compare(str, checkCurrent) == 0)
172
				ComboDir->Text = str;
205
					foundCurrent = true;
-
 
206
			}
173
		}
207
		}
174
 
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
 
175
		this->UpdateRunButton();
217
		this->UpdateRunButton();
176
	}
218
	}
177
 
219
 
178
	void MainGui::UpdateRunButton()
220
	void MainGui::UpdateRunButton()
179
	{
221
	{
-
 
222
		if (!m_pPackages || !m_pPackages->IsLoaded())
-
 
223
		{
-
 
224
			ButRun->Visible = false;
-
 
225
			return;
-
 
226
		}
-
 
227
 
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
 
424
		int index = this->imageList1->Images->IndexOfKey("package.png");
-
 
425
		if ( index != -1 )
-
 
426
		{
-
 
427
			ListPackages->SmallImageList->Images->Add("package", this->imageList1->Images[index]);
-
 
428
			ListPackages->LargeImageList->Images->Add("package", this->imageList1->Images[index]);
-
 
429
		}
-
 
430
		index = this->imageList1->Images->IndexOfKey("ship.png");
473
		if (m_pPackages && m_pPackages->IsLoaded())
431
		if ( index != -1 )
-
 
432
		{
-
 
433
			ListPackages->SmallImageList->Images->Add("ship", this->imageList1->Images[index]);
-
 
434
			ListPackages->LargeImageList->Images->Add("ship", this->imageList1->Images[index]);
-
 
435
		}
-
 
436
		index = this->imageList1->Images->IndexOfKey("fake.png");
-
 
437
		if ( index != -1 )
-
 
438
		{
474
		{
-
 
475
			int index = this->imageList1->Images->IndexOfKey("package.png");
-
 
476
			if (index != -1)
-
 
477
			{
-
 
478
				ListPackages->SmallImageList->Images->Add("package", this->imageList1->Images[index]);
-
 
479
				ListPackages->LargeImageList->Images->Add("package", this->imageList1->Images[index]);
-
 
480
			}
-
 
481
			index = this->imageList1->Images->IndexOfKey("ship.png");
-
 
482
			if (index != -1)
-
 
483
			{
-
 
484
				ListPackages->SmallImageList->Images->Add("ship", this->imageList1->Images[index]);
-
 
485
				ListPackages->LargeImageList->Images->Add("ship", this->imageList1->Images[index]);
-
 
486
			}
-
 
487
			index = this->imageList1->Images->IndexOfKey("fake.png");
-
 
488
			if (index != -1)
-
 
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
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
			{
Line 948... Line 1002...
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 1093... Line 1154...
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
	}
1157
	}
1097
 
1158
 
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
	}
-
 
1149
 
-
 
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) )
1153
		{
1162
		{
1154
			if ( m_pPackages->GetError() == PKERR_NOPARENT )
1163
			if ( m_pPackages->GetError() == PKERR_NOPARENT )
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 )
-
 
1559
			return;
-
 
1560
 
-
 
1561
		CyString dir = CyStringFromSystemString(ComboDir->Text);
-
 
1562
		if ( dir.NumToken(" [") )
-
 
1563
			dir = dir.GetToken(" [", 1, dir.NumToken(" [") - 1);
1560
		if (ComboDir->SelectedIndex == (ComboDir->Items->Count - 1))
1564
 
-
 
1565
		if ( !m_pPackages->IsCurrentDir(dir) )
-
 
1566
		{
1561
		{
-
 
1562
			if (m_pPackages && m_pPackages->IsLoaded())
-
 
1563
			{
1567
			this->Enabled = false;
1564
				this->Enabled = false;
-
 
1565
				ProgressBar->Show();
1568
			this->CheckUnusedShared();
1566
				this->CheckUnusedShared();
-
 
1567
				this->StartBackground(MGUI_BACKGROUND_CLOSEDIR, "");
-
 
1568
			}
-
 
1569
		}
-
 
1570
		else if (ComboDir->SelectedIndex >= 0)
-
 
1571
		{
-
 
1572
			Utils::String dir = m_pDirList->get(ComboDir->SelectedIndex)->str;
-
 
1573
			if (!m_pPackages->isCurrentDir(dir))
-
 
1574
			{
-
 
1575
				this->Enabled = false;
-
 
1576
				ProgressBar->Show();
-
 
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
	{
Line 1587... Line 1597...
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();
1591
				break;
1601
				break;
-
 
1602
			case MGUI_BACKGROUND_CLOSEDIR:
-
 
1603
				this->CloseCurrentDirectory();
-
 
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
					}
1644
 
-
 
1645
					this->UpdateDirList();
-
 
1646
				}
1658
				}
1647
			}
1659
			}
-
 
1660
 
-
 
1661
			this->UpdateDirList(selectedDir);
-
 
1662
			this->UpdateRunButton();
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 2027... Line 2021...
2027
 
2021
 
2028
			}
2022
			}
2029
		}
2023
		}
2030
	}
2024
	}
2031
 
2025
 
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
	}
-
 
2059
 
-
 
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 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
}