| 121 | cycrow | 1 | #include "../stdafx.h"
 | 
        
           |  |  | 2 | #include "DirectoryControl.h"
 | 
        
           |  |  | 3 |   | 
        
           |  |  | 4 | using namespace PluginManager;
 | 
        
           |  |  | 5 |   | 
        
           |  |  | 6 | DirectoryControl::DirectoryControl(CPackages *packages, Utils::CStringList *currentDirs, Utils::CStringList *removedDirs)
 | 
        
           |  |  | 7 | {
 | 
        
           |  |  | 8 | 	InitializeComponent();
 | 
        
           |  |  | 9 |   | 
        
           |  |  | 10 | 	this->listView1->LargeImageList = this->imageListGames;
 | 
        
           |  |  | 11 | 	this->listView1->SmallImageList = this->imageListGames;
 | 
        
           |  |  | 12 | 	this->listView2->LargeImageList = this->imageListGames;
 | 
        
           |  |  | 13 | 	this->listView2->SmallImageList = this->imageListGames;
 | 
        
           |  |  | 14 |   | 
        
           |  |  | 15 | 	_packages = packages;
 | 
        
           |  |  | 16 | 	_lDirs = new Utils::CStringList();
 | 
        
           |  |  | 17 | 	_lRemoveDirs = new Utils::CStringList();
 | 
        
           |  |  | 18 | 	_lFoundDirs = new Utils::CStringList();
 | 
        
           |  |  | 19 |   | 
        
           |  |  | 20 | 	this->getAllDirs(currentDirs, removedDirs);
 | 
        
           |  |  | 21 | 	this->UpdateGameDirs();
 | 
        
           |  |  | 22 | 	this->UpdateFoundDirs();
 | 
        
           |  |  | 23 | }
 | 
        
           |  |  | 24 |   | 
        
           |  |  | 25 | DirectoryControl::~DirectoryControl()
 | 
        
           |  |  | 26 | {
 | 
        
           |  |  | 27 | 	if (components)
 | 
        
           |  |  | 28 | 	{
 | 
        
           |  |  | 29 | 		delete components;
 | 
        
           |  |  | 30 | 	}
 | 
        
           |  |  | 31 |   | 
        
           |  |  | 32 | 	delete _lDirs;
 | 
        
           |  |  | 33 | 	delete _lRemoveDirs;
 | 
        
           |  |  | 34 | 	delete _lFoundDirs;
 | 
        
           |  |  | 35 | }
 | 
        
           |  |  | 36 |   | 
        
           |  |  | 37 | void DirectoryControl::AddFoundDir(const Utils::String &dir)
 | 
        
           |  |  | 38 | {
 | 
        
           |  |  | 39 | 	if (CDirIO(dir).exists())
 | 
        
           |  |  | 40 | 	{
 | 
        
           |  |  | 41 | 		Utils::String gameName = _packages->GetGameExe()->GetGameName(dir);
 | 
        
           |  |  | 42 | 		if (!gameName.empty())
 | 
        
           |  |  | 43 | 		{
 | 
        
           |  |  | 44 | 			if (!_lFoundDirs->contains(dir, true) && !_lDirs->contains(dir, true) && !_lRemoveDirs->contains(dir, true))
 | 
        
           |  |  | 45 | 			{
 | 
        
           |  |  | 46 | 				Utils::String exe = dir.findReplace("\\", "/").findReplace("//", "/");
 | 
        
           |  |  | 47 | 				_lFoundDirs->pushBack(exe, _packages->GetGameExe()->GetGameName(exe));
 | 
        
           |  |  | 48 | 			}
 | 
        
           |  |  | 49 | 		}
 | 
        
           |  |  | 50 | 	}
 | 
        
           |  |  | 51 | }
 | 
        
           |  |  | 52 |   | 
        
           |  |  | 53 | void DirectoryControl::FindAllAddons(const Utils::String &exe, bool checkBase)
 | 
        
           |  |  | 54 | {
 | 
        
           |  |  | 55 | 	CDirIO Dir(exe);
 | 
        
           |  |  | 56 |   | 
        
           |  |  | 57 | 	if (checkBase && _packages->GetGameExe()->isAddon(exe))
 | 
        
           |  |  | 58 | 	{
 | 
        
           |  |  | 59 | 		Utils::String base = _packages->GetGameRunExe(_packages->GetGameExe()->GetGameDir(exe));
 | 
        
           |  |  | 60 | 		if (CFileIO::Exists(base))
 | 
        
           |  |  | 61 | 		{
 | 
        
           |  |  | 62 | 			AddFoundDir(base);
 | 
        
           |  |  | 63 | 			FindAllAddons(base, false);
 | 
        
           |  |  | 64 | 			return;
 | 
        
           |  |  | 65 | 		}
 | 
        
           |  |  | 66 | 	}
 | 
        
           |  |  | 67 |   | 
        
           |  |  | 68 | 	if (Dir.isFile())
 | 
        
           |  |  | 69 | 	{
 | 
        
           |  |  | 70 | 		CFileIO file(exe);
 | 
        
           |  |  | 71 | 		if (file.exists())
 | 
        
           |  |  | 72 | 		{
 | 
        
           |  |  | 73 | 			// dont include addons, only the base game
 | 
        
           |  |  | 74 | 			if (!_packages->GetGameExe()->isAddon(exe))
 | 
        
           |  |  | 75 | 			{
 | 
        
           |  |  | 76 | 				CDirIO dir(file.dir());
 | 
        
           |  |  | 77 | 				Utils::CStringList list;
 | 
        
           |  |  | 78 | 				// get all the addons from a base game
 | 
        
           |  |  | 79 | 				if (_packages->GetGameAddons(list, _packages->GetGameExe()->GetProperDir(exe)))
 | 
        
           |  |  | 80 | 				{
 | 
        
           |  |  | 81 | 					for (Utils::SStringList *a_item = list.first(); a_item; a_item = list.next())
 | 
        
           |  |  | 82 | 					{
 | 
        
           |  |  | 83 | 						//check both the exe and the data directory exists
 | 
        
           |  |  | 84 | 						if (dir.exists(a_item->data) && dir.exists(a_item->str))
 | 
        
           |  |  | 85 | 						{
 | 
        
           |  |  | 86 | 							Utils::String newFile = dir.file(a_item->str);
 | 
        
           |  |  | 87 | 							AddFoundDir(newFile);
 | 
        
           |  |  | 88 | 						}
 | 
        
           |  |  | 89 | 					}
 | 
        
           |  |  | 90 | 				}
 | 
        
           |  |  | 91 | 			}
 | 
        
           |  |  | 92 | 		}
 | 
        
           |  |  | 93 | 	}
 | 
        
           |  |  | 94 | 	else if (Dir.exists())
 | 
        
           |  |  | 95 | 	{
 | 
        
           |  |  | 96 | 		Utils::CStringList list;
 | 
        
           |  |  | 97 | 		// get all the addons from a base game
 | 
        
           |  |  | 98 | 		if (_packages->GetGameAddons(list, _packages->GetGameExe()->GetProperDir(exe)))
 | 
        
           |  |  | 99 | 		{
 | 
        
           |  |  | 100 | 			for (Utils::SStringList *a_item = list.first(); a_item; a_item = list.next())
 | 
        
           |  |  | 101 | 			{
 | 
        
           |  |  | 102 | 				//check both the exe and the data directory exists
 | 
        
           |  |  | 103 | 				if (Dir.exists(a_item->data) && Dir.exists(a_item->str))
 | 
        
           |  |  | 104 | 				{
 | 
        
           |  |  | 105 | 					Utils::String newFile = Dir.file(a_item->str);
 | 
        
           |  |  | 106 | 					AddFoundDir(newFile);
 | 
        
           |  |  | 107 | 				}
 | 
        
           |  |  | 108 | 			}
 | 
        
           |  |  | 109 | 		}
 | 
        
           |  |  | 110 | 	}
 | 
        
           |  |  | 111 | }
 | 
        
           |  |  | 112 |   | 
        
           |  |  | 113 | void DirectoryControl::getAllDirs(Utils::CStringList *currentDirs, Utils::CStringList *removedDirs)
 | 
        
           |  |  | 114 | {
 | 
        
           |  |  | 115 | 	if (currentDirs)
 | 
        
           |  |  | 116 | 	{
 | 
        
           |  |  | 117 | 		for (auto itr = currentDirs->begin(); itr != currentDirs->end(); itr++)
 | 
        
           |  |  | 118 | 		{
 | 
        
           |  |  | 119 | 			Utils::String data = (*itr)->data;
 | 
        
           |  |  | 120 | 			if(data.isin("|"))
 | 
        
           |  |  | 121 | 				_lDirs->pushBack(_packages->GetGameRunExe((*itr)->str), data.tokens("|", 2));
 | 
        
           |  |  | 122 | 			else
 | 
        
           |  |  | 123 | 				_lDirs->pushBack(_packages->GetGameRunExe((*itr)->str), data);
 | 
        
           |  |  | 124 | 		}
 | 
        
           |  |  | 125 | 	}
 | 
        
           |  |  | 126 | 	if (removedDirs)
 | 
        
           |  |  | 127 | 	{
 | 
        
           |  |  | 128 | 		for (auto itr = removedDirs->begin(); itr != removedDirs->end(); itr++)
 | 
        
           |  |  | 129 | 			_lRemoveDirs->pushBack(_packages->GetGameRunExe((*itr)->str), (*itr)->data);
 | 
        
           |  |  | 130 | 	}
 | 
        
           |  |  | 131 |   | 
        
           |  |  | 132 | 	// find other dirs
 | 
        
           |  |  | 133 | 	System::String ^progfile = Environment::GetFolderPath(Environment::SpecialFolder::ProgramFiles);
 | 
        
           |  |  | 134 | 	Utils::CStringList gameDirs;		
 | 
        
           |  |  | 135 | 	gameDirs.pushBack("HKCU\\Software\\Deepsilver\\X2 The Threat", "INSTALL_DIR");
 | 
        
           |  |  | 136 | 	gameDirs.pushBack("HKCU\\Software\\Deepsilver\\X3 Reunion", "INSTALL_DIR");
 | 
        
           |  |  | 137 | 	gameDirs.pushBack("HKCU\\Software\\Egosoft\\X3TC", "INSTALL_DIR");
 | 
        
           |  |  | 138 | 	gameDirs.pushBack("Steam\\x2 - the threat");
 | 
        
           |  |  | 139 | 	gameDirs.pushBack("Steam\\x3 - reunion");
 | 
        
           |  |  | 140 | 	gameDirs.pushBack("Steam\\x3 terran conflict");
 | 
        
           |  |  | 141 | 	// some custom directories to look for
 | 
        
           |  |  | 142 | 	gameDirs.pushBack("%PROGRAMFILES%\\Egosoft\\X2 The Threat");
 | 
        
           |  |  | 143 | 	gameDirs.pushBack("%PROGRAMFILES%\\Egosoft\\X3 Reunion");
 | 
        
           |  |  | 144 | 	gameDirs.pushBack("%PROGRAMFILES%\\Egosoft\\X3 Terran Conflict");
 | 
        
           |  |  | 145 | 	gameDirs.pushBack("C:\\Games\\X2");
 | 
        
           |  |  | 146 | 	gameDirs.pushBack("C:\\Games\\X3");
 | 
        
           |  |  | 147 | 	gameDirs.pushBack("C:\\Games\\X3TC");
 | 
        
           |  |  | 148 | 	gameDirs.pushBack("D:\\Games\\X2");
 | 
        
           |  |  | 149 | 	gameDirs.pushBack("D:\\Games\\X3");
 | 
        
           |  |  | 150 | 	gameDirs.pushBack("D:\\Games\\X3TC");	
 | 
        
           |  |  | 151 | 	for (Utils::SStringList *strNode = gameDirs.first(); strNode; strNode = gameDirs.next())
 | 
        
           |  |  | 152 | 	{
 | 
        
           |  |  | 153 | 		Utils::String sFirst = strNode->str.token("\\", 1);
 | 
        
           |  |  | 154 | 		Utils::String sRest = strNode->str.tokens("\\", 2);
 | 
        
           |  |  | 155 |   | 
        
           |  |  | 156 | 		if (sFirst.Compare("HKCU") || sFirst.Compare("HKLM"))
 | 
        
           |  |  | 157 | 		{
 | 
        
           |  |  | 158 | 			RegistryKey ^searchKey = nullptr;
 | 
        
           |  |  | 159 | 			if (sFirst.Compare("HKCU"))
 | 
        
           |  |  | 160 | 				searchKey = Registry::CurrentUser->OpenSubKey(_US(sRest));
 | 
        
           |  |  | 161 | 			else if (sFirst.Compare("HKLM"))
 | 
        
           |  |  | 162 | 				searchKey = Registry::LocalMachine->OpenSubKey(_US(sRest));
 | 
        
           |  |  | 163 |   | 
        
           |  |  | 164 | 			if (searchKey)
 | 
        
           |  |  | 165 | 			{
 | 
        
           |  |  | 166 | 				System::String ^regRead = System::Convert::ToString(searchKey->GetValue(_US(strNode->data)));
 | 
        
           |  |  | 167 | 				if (regRead)
 | 
        
           |  |  | 168 | 					AddFoundDir(_packages->GetGameExe()->GetGameRunExe(_S(regRead)));
 | 
        
           |  |  | 169 | 			}
 | 
        
           |  |  | 170 | 		}
 | 
        
           |  |  | 171 | 		else if (sFirst.Compare("Steam"))
 | 
        
           |  |  | 172 | 		{
 | 
        
           |  |  | 173 | 			RegistryKey ^steamKey = Registry::CurrentUser->OpenSubKey("Software\\Valve\\Steam");
 | 
        
           |  |  | 174 | 			if (steamKey)
 | 
        
           |  |  | 175 | 			{
 | 
        
           |  |  | 176 | 				System::String ^regRead = System::Convert::ToString(steamKey->GetValue("SteamPath"));
 | 
        
           |  |  | 177 | 				if (regRead)
 | 
        
           |  |  | 178 | 				{
 | 
        
           |  |  | 179 | 					Utils::String steamDir = _S(regRead);
 | 
        
           |  |  | 180 | 					if (!steamDir.empty())
 | 
        
           |  |  | 181 | 					{
 | 
        
           |  |  | 182 | 						Utils::String dir = steamDir + "\\steamapps\\common\\" + sRest;
 | 
        
           |  |  | 183 | 						AddFoundDir(_packages->GetGameExe()->GetGameRunExe(dir.findReplace("\\", "/").findReplace("//", "/")));
 | 
        
           |  |  | 184 | 					}
 | 
        
           |  |  | 185 | 				}
 | 
        
           |  |  | 186 | 			}
 | 
        
           |  |  | 187 | 		}
 | 
        
           |  |  | 188 | 		else
 | 
        
           |  |  | 189 | 		{
 | 
        
           |  |  | 190 | 			Utils::String dir = strNode->str;
 | 
        
           |  |  | 191 | 			dir = dir.findReplace("\\", "/").findReplace("//", "/");
 | 
        
           |  |  | 192 | 			dir = dir.findReplace("%PROGRAMFILES%", _S(progfile));
 | 
        
           |  |  | 193 | 			AddFoundDir(_packages->GetGameExe()->GetGameRunExe(dir));
 | 
        
           |  |  | 194 | 		}
 | 
        
           |  |  | 195 | 	}
 | 
        
           |  |  | 196 |   | 
        
           |  |  | 197 | 	// now add all addons for already added dirs
 | 
        
           |  |  | 198 | 	for(int i = _lFoundDirs->size() - 1; i >= 0; --i)
 | 
        
           |  |  | 199 | 		FindAllAddons(_lFoundDirs->get(i)->str, true);
 | 
        
           |  |  | 200 | 	for (auto itr = _lRemoveDirs->begin(); itr != _lRemoveDirs->end(); ++itr)
 | 
        
           |  |  | 201 | 		FindAllAddons((*itr)->str, true);
 | 
        
           |  |  | 202 | 	for (auto itr = _lDirs->begin(); itr != _lDirs->end(); ++itr)
 | 
        
           |  |  | 203 | 		FindAllAddons((*itr)->str, true);
 | 
        
           |  |  | 204 | }
 | 
        
           |  |  | 205 |   | 
        
           |  |  | 206 | void DirectoryControl::UpdateGameDirs()
 | 
        
           |  |  | 207 | {
 | 
        
           |  |  | 208 | 	this->listView1->Items->Clear();
 | 
        
           |  |  | 209 | 	for (Utils::SStringList *s_item = _lDirs->first(); s_item; s_item = _lDirs->next()) {
 | 
        
           |  |  | 210 | 		Utils::String dir = _packages->GetGameExe()->GetProperDir(s_item->str);
 | 
        
           |  |  | 211 | 		ListViewItem ^item = gcnew ListViewItem(_US(dir));
 | 
        
           |  |  | 212 |   | 
        
           |  |  | 213 | 		int iGame = _packages->GetGameExe()->GetGameType(s_item->str);
 | 
        
           |  |  | 214 | 		item->ImageIndex = iGame;
 | 
        
           |  |  | 215 |   | 
        
           |  |  | 216 | 		item->SubItems->Add(_US(s_item->data));
 | 
        
           |  |  | 217 | 		if (CFileIO::Exists(s_item->str))
 | 
        
           |  |  | 218 | 		{
 | 
        
           |  |  | 219 | 			ListViewItem::ListViewSubItem ^i = _packages->isCurrentDir(dir) ? item->SubItems->Add("Active") : item->SubItems->Add("OK");
 | 
        
           |  |  | 220 | 			i->ForeColor = Color::Green;
 | 
        
           |  |  | 221 | 			item->SubItems->Add(_US(_packages->ConvertLanguage(_packages->GetGameLanguage(CFileIO(s_item->str).dir()))));
 | 
        
           |  |  | 222 | 		}
 | 
        
           |  |  | 223 | 		else
 | 
        
           |  |  | 224 | 		{
 | 
        
           |  |  | 225 | 			ListViewItem::ListViewSubItem ^i = item->SubItems->Add("Not Found");
 | 
        
           |  |  | 226 | 			i->ForeColor = Color::Red;
 | 
        
           |  |  | 227 | 			item->SubItems->Add("-");
 | 
        
           |  |  | 228 | 		}
 | 
        
           |  |  | 229 |   | 
        
           |  |  | 230 | 		item->SubItems->Add(_US(_packages->GetGameExe()->isAddon(s_item->str) ? "Yes" : "No"));
 | 
        
           |  |  | 231 | 		item->SubItems->Add(_US(s_item->str));
 | 
        
           |  |  | 232 | 		this->listView1->Items->Add(item);
 | 
        
           |  |  | 233 |   | 
        
           |  |  | 234 | 	}
 | 
        
           |  |  | 235 |   | 
        
           |  |  | 236 | 	this->listView1->AutoResizeColumns(ColumnHeaderAutoResizeStyle::HeaderSize);
 | 
        
           |  |  | 237 | 	this->ColumnStatus->Width = 100;
 | 
        
           |  |  | 238 | 	this->ColumnDirectory->Width += 50;
 | 
        
           |  |  | 239 | 	this->ColumnID->Width = 0;
 | 
        
           |  |  | 240 |   | 
        
           |  |  | 241 | 	this->removeButton->Enabled = (this->listView1->SelectedItems->Count) ? true : false;
 | 
        
           |  |  | 242 | }
 | 
        
           |  |  | 243 |   | 
        
           |  |  | 244 | void DirectoryControl::UpdateFoundDirs()
 | 
        
           |  |  | 245 | {
 | 
        
           |  |  | 246 | 	this->listView2->Items->Clear();
 | 
        
           |  |  | 247 | 	for (Utils::SStringList *s_item = _lRemoveDirs->first(); s_item; s_item = _lRemoveDirs->next()) {
 | 
        
           |  |  | 248 | 		if (CFileIO::Exists(s_item->str)) {
 | 
        
           |  |  | 249 | 			ListViewItem ^item = gcnew ListViewItem(_US(_packages->GetGameExe()->GetProperDir(s_item->str)));
 | 
        
           |  |  | 250 | 			int iGame = _packages->GetGameExe()->GetGameType(s_item->str);
 | 
        
           |  |  | 251 | 			item->ImageIndex = iGame;
 | 
        
           |  |  | 252 | 			item->SubItems->Add(_US(s_item->data));
 | 
        
           |  |  | 253 | 			item->SubItems->Add(_US(_packages->ConvertLanguage(_packages->GetGameLanguage(CFileIO(s_item->str).dir()))));
 | 
        
           |  |  | 254 | 			item->SubItems->Add(_US(_packages->GetGameExe()->isAddon(s_item->str) ? "Yes" : "No"));
 | 
        
           |  |  | 255 | 			item->SubItems->Add(_US(s_item->str));
 | 
        
           |  |  | 256 | 			this->listView2->Items->Add(item);
 | 
        
           |  |  | 257 | 		}
 | 
        
           |  |  | 258 | 	}
 | 
        
           |  |  | 259 |   | 
        
           |  |  | 260 | 	for (Utils::SStringList *s_item = _lFoundDirs->first(); s_item; s_item = _lFoundDirs->next()) {
 | 
        
           |  |  | 261 | 		if (CFileIO::Exists(s_item->str)) {
 | 
        
           |  |  | 262 | 			ListViewItem ^item = gcnew ListViewItem(_US(_packages->GetGameExe()->GetProperDir(s_item->str)));
 | 
        
           |  |  | 263 | 			int iGame = _packages->GetGameExe()->GetGameType(s_item->str);
 | 
        
           |  |  | 264 | 			item->ImageIndex = iGame;
 | 
        
           |  |  | 265 | 			item->SubItems->Add(_US(_packages->GetGameExe()->GetGameName(s_item->str)));
 | 
        
           |  |  | 266 | 			item->SubItems->Add(_US(_packages->ConvertLanguage(_packages->GetGameLanguage(CFileIO(s_item->str).dir()))));
 | 
        
           |  |  | 267 | 			item->SubItems->Add(_US(_packages->GetGameExe()->isAddon(s_item->str) ? "Yes" : "No"));
 | 
        
           |  |  | 268 | 			item->SubItems->Add(_US(s_item->str));
 | 
        
           |  |  | 269 | 			this->listView2->Items->Add(item);
 | 
        
           |  |  | 270 | 		}
 | 
        
           |  |  | 271 | 	}
 | 
        
           |  |  | 272 |   | 
        
           |  |  | 273 | 	this->listView2->AutoResizeColumns(ColumnHeaderAutoResizeStyle::HeaderSize);
 | 
        
           |  |  | 274 | 	this->ColumnDir2->Width += 50;
 | 
        
           |  |  | 275 | 	this->ColumnID2->Width = 0;
 | 
        
           |  |  | 276 |   | 
        
           |  |  | 277 | 	this->ButtonAddFound->Enabled = (this->listView2->SelectedItems->Count) ? true : false;
 | 
        
           |  |  | 278 | }
 | 
        
           |  |  | 279 |   | 
        
           |  |  | 280 | System::Void DirectoryControl::button1_Click(System::Object^  sender, System::EventArgs^  e)
 | 
        
           |  |  | 281 | {
 | 
        
           |  |  | 282 | 	OpenFileDialog ^ofd = gcnew OpenFileDialog();
 | 
        
           |  |  | 283 | 	ofd->Filter = "X-Universe Executable|";
 | 
        
           |  |  | 284 | 	String ^games = "";
 | 
        
           |  |  | 285 | 	for (int i = 0; i < _packages->GetGameExe()->GetNumGames(); i++)
 | 
        
           |  |  | 286 | 	{
 | 
        
           |  |  | 287 | 		SGameExe *exe = _packages->GetGameExe()->GetGame(i);
 | 
        
           |  |  | 288 | 		if (i) ofd->Filter += ";";
 | 
        
           |  |  | 289 | 		ofd->Filter += _US(exe->sExe);
 | 
        
           |  |  | 290 | 		games += "|" + _US(exe->sName) + "|" + _US(exe->sExe);
 | 
        
           |  |  | 291 | 	}
 | 
        
           |  |  | 292 | 	ofd->Filter += games;
 | 
        
           |  |  | 293 | 	ofd->FilterIndex = 1;
 | 
        
           |  |  | 294 | 	ofd->RestoreDirectory = true;
 | 
        
           |  |  | 295 | 	if (ofd->ShowDialog(this) == System::Windows::Forms::DialogResult::OK)
 | 
        
           |  |  | 296 | 	{
 | 
        
           |  |  | 297 | 		Utils::String file = _S(ofd->FileName);
 | 
        
           |  |  | 298 | 		Utils::String dir = _S(IO::FileInfo(ofd->FileName).DirectoryName);
 | 
        
           |  |  | 299 | 		// check its a valid directory
 | 
        
           |  |  | 300 | 		if (!dir.empty())
 | 
        
           |  |  | 301 | 		{
 | 
        
           |  |  | 302 | 			Utils::String gameName = _packages->GetGameName(file).ToString();
 | 
        
           |  |  | 303 | 			if (gameName.empty())
 | 
        
           |  |  | 304 | 				MessageBox::Show(this, "No X-Universe game found in folder:\n" + _US(dir), "Add Directory Error", MessageBoxButtons::OK, MessageBoxIcon::Error);
 | 
        
           |  |  | 305 | 			else
 | 
        
           |  |  | 306 | 			{
 | 
        
           |  |  | 307 | 				// lets check if theres an old folder
 | 
        
           |  |  | 308 | 				if (_packages->isOldDir(dir))
 | 
        
           |  |  | 309 | 				{
 | 
        
           |  |  | 310 | 					if (MessageBox::Show(this, "Game directory: " + _US(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?", "Update Game Directory", MessageBoxButtons::YesNo, MessageBoxIcon::Question) != System::Windows::Forms::DialogResult::Yes)
 | 
        
           |  |  | 311 | 						return;
 | 
        
           |  |  | 312 | 				}
 | 
        
           |  |  | 313 | 				Utils::String properDir = _packages->GetProperDir(file).ToString();
 | 
        
           |  |  | 314 | 				_lRemoveDirs->remove(properDir, true);
 | 
        
           |  |  | 315 | 				_lDirs->pushBack(file.findReplace("\\", "/").findReplace("//", "/"), gameName);
 | 
        
           |  |  | 316 |   | 
        
           |  |  | 317 | 				// now add any connected dirs
 | 
        
           |  |  | 318 | 				if (_packages->GetGameExe()->isAddon(file))
 | 
        
           |  |  | 319 | 				{
 | 
        
           |  |  | 320 | 					Utils::String baseExe = _packages->GetGameRunExe(_packages->GetGameExe()->GetGameDir(file));
 | 
        
           |  |  | 321 | 					if (CFileIO::Exists(baseExe))
 | 
        
           |  |  | 322 | 					{
 | 
        
           |  |  | 323 | 						this->AddFoundDir(baseExe);
 | 
        
           |  |  | 324 | 						this->FindAllAddons(baseExe, false);
 | 
        
           |  |  | 325 | 					}
 | 
        
           |  |  | 326 | 				}
 | 
        
           |  |  | 327 | 				else
 | 
        
           |  |  | 328 | 					this->FindAllAddons(file, false);
 | 
        
           |  |  | 329 |   | 
        
           |  |  | 330 | 				UpdateGameDirs();
 | 
        
           |  |  | 331 | 				UpdateFoundDirs();
 | 
        
           |  |  | 332 | 			}
 | 
        
           |  |  | 333 | 		}
 | 
        
           |  |  | 334 | 	}
 | 
        
           |  |  | 335 | }
 | 
        
           |  |  | 336 |   | 
        
           |  |  | 337 | System::Void DirectoryControl::listView1_SelectedIndexChanged(System::Object^  sender, System::EventArgs^  e) 
 | 
        
           |  |  | 338 | {
 | 
        
           |  |  | 339 | 	this->removeButton->Enabled = (this->listView1->SelectedItems->Count) ? true : false;
 | 
        
           |  |  | 340 | }
 | 
        
           |  |  | 341 |   | 
        
           |  |  | 342 | System::Void DirectoryControl::removeButton_Click(System::Object^  sender, System::EventArgs^  e) 
 | 
        
           |  |  | 343 | {
 | 
        
           |  |  | 344 | 	bool anyDone = false;
 | 
        
           |  |  | 345 | 	for (int i = 0; i < this->listView1->SelectedItems->Count; ++i)
 | 
        
           |  |  | 346 | 	{
 | 
        
           |  |  | 347 | 		String ^s = this->listView1->SelectedItems[i]->SubItems[this->listView1->SelectedItems[i]->SubItems->Count - 1]->Text;
 | 
        
           |  |  | 348 |   | 
        
           |  |  | 349 | 		Utils::String dir = _packages->getProperDir(_S(s));
 | 
        
           |  |  | 350 | 		if (_packages->isCurrentDir(dir))
 | 
        
           |  |  | 351 | 		{
 | 
        
           |  |  | 352 | 			if (MessageBox::Show(this, "The game directory: " + _US(dir) + "\nIs currently the active game directory, are you sure you want to remove it?", "Remove Game Directory", MessageBoxButtons::YesNo, MessageBoxIcon::Question) == Windows::Forms::DialogResult::No)
 | 
        
           |  |  | 353 | 				continue;
 | 
        
           |  |  | 354 | 		}
 | 
        
           |  |  | 355 | 		anyDone = true;
 | 
        
           |  |  | 356 | 		_lRemoveDirs->pushBack(_S(s), _lDirs->findString(_S(s)));
 | 
        
           |  |  | 357 | 		_lDirs->remove(_S(s), false);
 | 
        
           |  |  | 358 | 	}
 | 
        
           |  |  | 359 |   | 
        
           |  |  | 360 | 	if (anyDone)
 | 
        
           |  |  | 361 | 	{
 | 
        
           |  |  | 362 | 		UpdateGameDirs();
 | 
        
           |  |  | 363 | 		UpdateFoundDirs();
 | 
        
           |  |  | 364 | 	}
 | 
        
           |  |  | 365 | }
 | 
        
           |  |  | 366 |   | 
        
           |  |  | 367 | System::Void DirectoryControl::listView2_SelectedIndexChanged(System::Object^  sender, System::EventArgs^  e) 
 | 
        
           |  |  | 368 | {
 | 
        
           |  |  | 369 | 	this->ButtonAddFound->Enabled = (this->listView2->SelectedItems->Count) ? true : false;
 | 
        
           |  |  | 370 | }
 | 
        
           |  |  | 371 |   | 
        
           |  |  | 372 | System::Void DirectoryControl::ButtonAddFound_Click(System::Object^  sender, System::EventArgs^  e) 
 | 
        
           |  |  | 373 | {
 | 
        
           |  |  | 374 | 	for (int i = 0; i < this->listView2->SelectedItems->Count; ++i)
 | 
        
           |  |  | 375 | 	{
 | 
        
           |  |  | 376 | 		String ^s = this->listView2->SelectedItems[i]->SubItems[this->listView2->SelectedItems[i]->SubItems->Count - 1]->Text;
 | 
        
           |  |  | 377 | 		_lDirs->pushBack(_S(s), _packages->GetGameExe()->GetGameName(_S(s)));
 | 
        
           |  |  | 378 | 		_lFoundDirs->remove(_S(s), false);
 | 
        
           |  |  | 379 | 		_lRemoveDirs->remove(_S(s), false);
 | 
        
           |  |  | 380 | 	}
 | 
        
           |  |  | 381 |   | 
        
           |  |  | 382 | 	UpdateGameDirs();
 | 
        
           |  |  | 383 | 	UpdateFoundDirs();
 | 
        
           |  |  | 384 | }
 | 
        
           |  |  | 385 |   | 
        
           |  |  | 386 | System::Void DirectoryControl::listView1_DoubleClick(System::Object^  sender, System::EventArgs^  e)
 | 
        
           |  |  | 387 | {
 | 
        
           |  |  | 388 | 	String ^s = this->listView1->SelectedItems[0]->SubItems[this->listView1->SelectedItems[0]->SubItems->Count - 1]->Text;
 | 
        
           |  |  | 389 | 	if (s && s->Length > 0)
 | 
        
           |  |  | 390 | 	{
 | 
        
           |  |  | 391 | 	}
 | 
        
           |  |  | 392 | }
 | 
        
           |  |  | 393 |   | 
        
           |  |  | 394 | System::Void DirectoryControl::listView2_DoubleClick(System::Object^  sender, System::EventArgs^  e)
 | 
        
           |  |  | 395 | {
 | 
        
           |  |  | 396 | 	String ^s = this->listView2->SelectedItems[0]->SubItems[this->listView2->SelectedItems[0]->SubItems->Count - 1]->Text;
 | 
        
           |  |  | 397 | 	if (s && s->Length > 0)
 | 
        
           |  |  | 398 | 	{
 | 
        
           |  |  | 399 | 		_lDirs->pushBack(_S(s), _packages->GetGameExe()->GetGameName(_S(s)));
 | 
        
           |  |  | 400 | 		_lFoundDirs->remove(_S(s), false);
 | 
        
           |  |  | 401 | 		_lRemoveDirs->remove(_S(s), false);
 | 
        
           |  |  | 402 |   | 
        
           |  |  | 403 | 		UpdateGameDirs();
 | 
        
           |  |  | 404 | 		UpdateFoundDirs();
 | 
        
           |  |  | 405 | 	}
 | 
        
           |  |  | 406 | }
 | 
        
           |  |  | 407 |   | 
        
           |  |  | 408 | Utils::CStringList *DirectoryControl::directories()
 | 
        
           |  |  | 409 | {
 | 
        
           |  |  | 410 | 	return _lDirs;
 | 
        
           |  |  | 411 | }
 | 
        
           |  |  | 412 | Utils::CStringList *DirectoryControl::removeDirectories()
 | 
        
           |  |  | 413 | {
 | 
        
           |  |  | 414 | 	return _lRemoveDirs;
 | 
        
           |  |  | 415 | }
 | 
        
           |  |  | 416 |   |