| 1 | cycrow | 1 | // PluginManager.cpp : main project file.
 | 
        
           |  |  | 2 |   | 
        
           |  |  | 3 | #include "stdafx.h"
 | 
        
           |  |  | 4 | #include "Forms\MainGui.h"
 | 
        
           |  |  | 5 | #include "Forms\StartUp.h"
 | 
        
           |  |  | 6 | #include "Languages.h"
 | 
        
           |  |  | 7 |   | 
        
           |  |  | 8 | using namespace PluginManager;
 | 
        
           |  |  | 9 | using namespace Microsoft::Win32;
 | 
        
           |  |  | 10 | using namespace System::IO;
 | 
        
           |  |  | 11 |   | 
        
           |  |  | 12 | #include <spk.h>
 | 
        
           |  |  | 13 | #undef GetTempPath
 | 
        
           |  |  | 14 | #undef GetCurrentDirectory
 | 
        
           |  |  | 15 |   | 
        
           |  |  | 16 | CPackages	packages;
 | 
        
           |  |  | 17 |   | 
        
           |  |  | 18 | [STAThreadAttribute]
 | 
        
           |  |  | 19 | int main(array<System::String ^> ^args)
 | 
        
           |  |  | 20 | {
 | 
        
           |  |  | 21 | 	// Enabling Windows XP visual effects before any controls are created
 | 
        
           |  |  | 22 | 	Application::EnableVisualStyles();
 | 
        
           |  |  | 23 | 	Application::SetCompatibleTextRenderingDefault(false); 
 | 
        
           |  |  | 24 |   | 
        
           |  |  | 25 | 	System::String ^tempDir = System::IO::Path::GetTempPath();
 | 
        
           |  |  | 26 | 	System::String ^mydoc = Environment::GetFolderPath(Environment::SpecialFolder::Personal );
 | 
        
           |  |  | 27 | 	System::String ^progfile = Environment::GetFolderPath(Environment::SpecialFolder::ProgramFiles );
 | 
        
           |  |  | 28 |   | 
        
           | 196 | cycrow | 29 | 	Utils::WStringList dirList;
 | 
        
           |  |  | 30 | 	Utils::WStringList remDirList;
 | 
        
           | 1 | cycrow | 31 | 	System::String ^gameArgs;
 | 
        
           |  |  | 32 | 	System::String ^openPackage;
 | 
        
           |  |  | 33 |   | 
        
           | 197 | cycrow | 34 | 	CLanguages::Instance()->setLanguage(44);
 | 
        
           | 1 | cycrow | 35 |   | 
        
           | 64 | cycrow | 36 | 	bool Advanced = false, fromLauncher = false, silent = false, gamerun = false;
 | 
        
           | 1 | cycrow | 37 | 	for ( int i = 0; i < args->Length; i++ )
 | 
        
           |  |  | 38 | 	{
 | 
        
           | 191 | cycrow | 39 | 		Utils::WString arg = _WS(args[i]);
 | 
        
           | 1 | cycrow | 40 |   | 
        
           | 64 | cycrow | 41 | 		if ( gamerun ) {
 | 
        
           |  |  | 42 | 			if ( gameArgs && gameArgs->Length ) gameArgs += " ";
 | 
        
           |  |  | 43 | 			gameArgs += args[i];
 | 
        
           |  |  | 44 | 		}
 | 
        
           | 1 | cycrow | 45 | 		// its a switch
 | 
        
           | 191 | cycrow | 46 | 		else if ( arg.left(2) == L"--" )
 | 
        
           | 1 | cycrow | 47 | 		{
 | 
        
           | 191 | cycrow | 48 | 			Utils::WString argSwitch = arg.token(L":", 1).lower();
 | 
        
           |  |  | 49 | 			Utils::WString argSwitchFirst = arg.token(L" ", 1).lower();
 | 
        
           |  |  | 50 | 			Utils::WString rest = arg.tokens(L":", 2);
 | 
        
           | 192 | cycrow | 51 | 			if (!rest.empty())
 | 
        
           | 1 | cycrow | 52 | 			{
 | 
        
           | 192 | cycrow | 53 | 				if (rest[0] == '"' && rest[rest.length() - 1] != '"')
 | 
        
           | 1 | cycrow | 54 | 				{
 | 
        
           | 192 | cycrow | 55 | 					rest.erase(0, 1);
 | 
        
           |  |  | 56 | 					while (i < args->Length)
 | 
        
           |  |  | 57 | 					{
 | 
        
           |  |  | 58 | 						i++;
 | 
        
           |  |  | 59 | 						Utils::WString argCheck = _WS(args[i]);
 | 
        
           |  |  | 60 | 						rest += " ";
 | 
        
           |  |  | 61 | 						rest += argCheck;
 | 
        
           |  |  | 62 | 						if (argCheck.right(1) == L"\"")
 | 
        
           |  |  | 63 | 							break;
 | 
        
           |  |  | 64 | 					}
 | 
        
           | 1 | cycrow | 65 | 				}
 | 
        
           | 192 | cycrow | 66 |   | 
        
           |  |  | 67 | 				if (rest.right(1) == L"\"")
 | 
        
           |  |  | 68 | 					rest.truncate(rest.length() - 1);
 | 
        
           | 1 | cycrow | 69 | 			}
 | 
        
           | 197 | cycrow | 70 | 			if ( argSwitch == L"--dir" && !rest.empty() )
 | 
        
           | 1 | cycrow | 71 | 			{
 | 
        
           | 197 | cycrow | 72 | 				Utils::WString gameName = packages.getGameName(rest);
 | 
        
           | 121 | cycrow | 73 | 				if ( !gameName.empty() )
 | 
        
           | 196 | cycrow | 74 | 					dirList.pushBack(rest, gameName);
 | 
        
           | 1 | cycrow | 75 | 			}
 | 
        
           |  |  | 76 |   | 
        
           | 197 | cycrow | 77 | 			if ( argSwitch == L"--advanced" )
 | 
        
           | 1 | cycrow | 78 | 				Advanced = true;
 | 
        
           | 197 | cycrow | 79 | 			else if ( argSwitch == L"--fromlauncher" )
 | 
        
           | 1 | cycrow | 80 | 				fromLauncher = true;
 | 
        
           | 197 | cycrow | 81 | 			else if ( argSwitch == L"--silent" )
 | 
        
           | 1 | cycrow | 82 | 				silent = true;
 | 
        
           | 197 | cycrow | 83 | 			else if ( argSwitch == L"--forceemp" )
 | 
        
           | 1 | cycrow | 84 | 				packages.SetForceEMP(true);
 | 
        
           | 197 | cycrow | 85 | 			else if (argSwitch == L"--gamerun" && !rest.empty())
 | 
        
           | 1 | cycrow | 86 | 			{
 | 
        
           | 191 | cycrow | 87 | 				gameArgs = _US(rest);
 | 
        
           | 1 | cycrow | 88 | 				break;
 | 
        
           |  |  | 89 | 			}
 | 
        
           | 197 | cycrow | 90 | 			else if ( argSwitch == L"--gamerun" ) {
 | 
        
           | 64 | cycrow | 91 | 				gamerun = true;
 | 
        
           |  |  | 92 | 			}
 | 
        
           | 197 | cycrow | 93 | 			else if ( argSwitchFirst == L"--gamerun" ) {
 | 
        
           | 64 | cycrow | 94 | 				gamerun = true;
 | 
        
           | 191 | cycrow | 95 | 				gameArgs = _US(arg.tokens(L" ", 2));
 | 
        
           | 64 | cycrow | 96 | 			}
 | 
        
           | 197 | cycrow | 97 | 			else if ( argSwitch == L"--noresume" )
 | 
        
           | 1 | cycrow | 98 | 			{
 | 
        
           |  |  | 99 | 				RegistryKey ^searchKey = Registry::CurrentUser->CreateSubKey("Software\\Egosoft\\PluginManagerSettings");
 | 
        
           |  |  | 100 | 				if ( searchKey )
 | 
        
           |  |  | 101 | 					searchKey->SetValue("DontAutoResume", 1);
 | 
        
           |  |  | 102 | 			}
 | 
        
           | 197 | cycrow | 103 | 			else if ( argSwitch == L"--resume" )
 | 
        
           | 1 | cycrow | 104 | 			{
 | 
        
           |  |  | 105 | 				int zero = 0;
 | 
        
           |  |  | 106 | 				RegistryKey ^searchKey = Registry::CurrentUser->CreateSubKey("Software\\Egosoft\\PluginManagerSettings");
 | 
        
           |  |  | 107 | 				if ( searchKey )
 | 
        
           |  |  | 108 | 					searchKey->SetValue("DontAutoResume", zero);
 | 
        
           |  |  | 109 | 			}
 | 
        
           | 197 | cycrow | 110 | 			else if ( argSwitch == L"--debug" ) {
 | 
        
           | 55 | cycrow | 111 | 				CFileLog *log = dynamic_cast<CFileLog *>(CFileLog::create());
 | 
        
           | 197 | cycrow | 112 | 				log->setFile(_WS(mydoc) + L"/Egosoft/pluginmanager.log");
 | 
        
           | 84 | cycrow | 113 | 				log->setFilter(CLog::Log_Install | CLog::Log_Uninstall | CLog::Log_IO | CLog::Log_Directory | CLog::Log_File);
 | 
        
           | 191 | cycrow | 114 | 				log->setLevel(rest.toInt());
 | 
        
           | 55 | cycrow | 115 | 			}
 | 
        
           | 1 | cycrow | 116 | 		}
 | 
        
           |  |  | 117 | 		// otherwise it must be a file to open
 | 
        
           |  |  | 118 | 		else
 | 
        
           | 191 | cycrow | 119 | 			openPackage = _US(arg);
 | 
        
           | 1 | cycrow | 120 | 	}
 | 
        
           |  |  | 121 |   | 
        
           | 84 | cycrow | 122 | #if _DEBUG
 | 
        
           |  |  | 123 | 	CFileLog *log = dynamic_cast<CFileLog *>(CFileLog::create());
 | 
        
           | 197 | cycrow | 124 | 	log->setFile(_WS(mydoc) + L"/Egosoft/pluginmanager.log");
 | 
        
           | 84 | cycrow | 125 | 	log->setFilter(CLog::Log_Install | CLog::Log_Uninstall | CLog::Log_IO | CLog::Log_Directory | CLog::Log_File);
 | 
        
           |  |  | 126 | 	log->setLevel(5);
 | 
        
           | 86 | cycrow | 127 | 	Advanced = true;
 | 
        
           | 84 | cycrow | 128 | #endif
 | 
        
           |  |  | 129 |   | 
        
           | 1 | cycrow | 130 | 	//TODO: Load languge xml
 | 
        
           |  |  | 131 | 	//Language.LoadLanguages();
 | 
        
           |  |  | 132 |   | 
        
           |  |  | 133 | 	// get the last language used
 | 
        
           |  |  | 134 | 	RegistryKey ^searchKeyLang = Registry::CurrentUser->OpenSubKey("Software\\Egosoft\\PluginManagerSettings");
 | 
        
           |  |  | 135 | 	if ( searchKeyLang )
 | 
        
           |  |  | 136 | 	{
 | 
        
           |  |  | 137 | 		int lang = System::Convert::ToInt32(searchKeyLang->GetValue("Language"));
 | 
        
           |  |  | 138 | 		if ( lang )
 | 
        
           | 197 | cycrow | 139 | 			CLanguages::Instance()->setLanguage(lang);
 | 
        
           | 1 | cycrow | 140 | 	}
 | 
        
           |  |  | 141 |   | 
        
           |  |  | 142 |   | 
        
           |  |  | 143 | 	bool firstInstance = false;
 | 
        
           |  |  | 144 | 	System::Threading::Mutex ^mut = gcnew System::Threading::Mutex(false, "Local\\XPluginManagerLite", firstInstance);
 | 
        
           |  |  | 145 | 	if ( !firstInstance )
 | 
        
           |  |  | 146 | 	{
 | 
        
           |  |  | 147 | 		if ( openPackage )
 | 
        
           |  |  | 148 | 		{
 | 
        
           |  |  | 149 | 			if ( File::Exists(mydoc + "\\Egosoft\\pluginmanager_load.dat") )
 | 
        
           |  |  | 150 | 			{
 | 
        
           |  |  | 151 | 				StreamWriter ^sw = File::AppendText(mydoc + "\\Egosoft\\pluginmanager_load.dat");
 | 
        
           |  |  | 152 | 				try 
 | 
        
           |  |  | 153 | 				{
 | 
        
           |  |  | 154 | 					sw->WriteLine("File: " + openPackage);
 | 
        
           |  |  | 155 | 				}
 | 
        
           |  |  | 156 | 				finally
 | 
        
           |  |  | 157 | 				{
 | 
        
           |  |  | 158 | 					if ( sw )
 | 
        
           |  |  | 159 | 						delete (IDisposable ^)sw;
 | 
        
           |  |  | 160 | 				}
 | 
        
           |  |  | 161 | 			}
 | 
        
           |  |  | 162 | 			else
 | 
        
           |  |  | 163 | 			{
 | 
        
           |  |  | 164 | 				StreamWriter ^sw = File::CreateText(mydoc + "\\Egosoft\\pluginmanager_load.dat");
 | 
        
           |  |  | 165 | 				try 
 | 
        
           |  |  | 166 | 				{
 | 
        
           |  |  | 167 | 					sw->WriteLine("File: " + openPackage);
 | 
        
           |  |  | 168 | 				}
 | 
        
           |  |  | 169 | 				finally
 | 
        
           |  |  | 170 | 				{
 | 
        
           |  |  | 171 | 					if ( sw )
 | 
        
           |  |  | 172 | 						delete (IDisposable ^)sw;
 | 
        
           |  |  | 173 | 				}
 | 
        
           |  |  | 174 | 			}
 | 
        
           |  |  | 175 | 		}
 | 
        
           |  |  | 176 | 		else if ( !silent )
 | 
        
           | 104 | cycrow | 177 | 			MessageBox::Show(_US(CLanguages::Instance()->findText(LS_STARTUP, LANGSTARTUP_ANOTHERINSTANCE)), _US(CLanguages::Instance()->findText(LS_STARTUP, LANGSTARTUP_ANOTHERINSTANCE_TITLE)), MessageBoxButtons::OK, MessageBoxIcon::Stop);
 | 
        
           | 1 | cycrow | 178 | 		return 0;
 | 
        
           |  |  | 179 | 	}
 | 
        
           |  |  | 180 |   | 
        
           |  |  | 181 | 	RegistryKey ^searchKey = Registry::CurrentUser->CreateSubKey("Software\\Egosoft\\PluginManagerSettings");
 | 
        
           |  |  | 182 | 	if ( searchKey )
 | 
        
           |  |  | 183 | 	{
 | 
        
           |  |  | 184 | 		searchKey->SetValue("Run", System::Windows::Forms::Application::ExecutablePath);
 | 
        
           |  |  | 185 | 		searchKey->SetValue("Version", (float)PMLVERSION);
 | 
        
           |  |  | 186 | 		searchKey->SetValue("Beta", (int)PMLBETA);
 | 
        
           |  |  | 187 | 	}
 | 
        
           |  |  | 188 |   | 
        
           |  |  | 189 |   | 
        
           |  |  | 190 | 	if ( File::Exists(mydoc + "\\Egosoft\\pluginmanager_load.dat") )
 | 
        
           |  |  | 191 | 		File::Delete(mydoc + "\\Egosoft\\pluginmanager_load.dat");
 | 
        
           |  |  | 192 | 	if ( File::Exists(tempDir + "\\AutoUpdater_old.exe") )
 | 
        
           |  |  | 193 | 		File::Delete(tempDir + "\\AutoUpdater_old.exe");
 | 
        
           |  |  | 194 |   | 
        
           | 197 | cycrow | 195 | 	packages.startup(L".", _WS(tempDir), _WS(mydoc), L"");
 | 
        
           | 1 | cycrow | 196 | 	packages.SetRenameText(true);
 | 
        
           |  |  | 197 |   | 
        
           |  |  | 198 | 	// Create the main window and run it
 | 
        
           |  |  | 199 | 	MainGui ^gui = gcnew MainGui(&packages, &dirList, &remDirList, Advanced);
 | 
        
           |  |  | 200 | 	gui->AddGameArgs(gameArgs);
 | 
        
           |  |  | 201 |   | 
        
           | 50 | cycrow | 202 |   | 
        
           | 1 | cycrow | 203 | 	// load in the config file
 | 
        
           | 197 | cycrow | 204 | 	CFileIO configFile(_WS(mydoc) + L"/Egosoft/pluginmanager.dat");
 | 
        
           | 1 | cycrow | 205 | 	bool anyDirs = false;
 | 
        
           | 52 | cycrow | 206 | 	if ( configFile.exists() )
 | 
        
           | 1 | cycrow | 207 | 	{
 | 
        
           | 223 | cycrow | 208 | 		std::vector<Utils::WString> readFile;
 | 
        
           |  |  | 209 | 		if(configFile.readLines(readFile))
 | 
        
           | 1 | cycrow | 210 | 		{
 | 
        
           | 223 | cycrow | 211 | 			for (size_t i = 0; i < readFile.size(); i++ )
 | 
        
           | 1 | cycrow | 212 | 			{
 | 
        
           | 223 | cycrow | 213 | 				Utils::WString line(readFile.at(i));
 | 
        
           |  |  | 214 | 				Utils::WString cmd = line.token(L":", 1).lower();
 | 
        
           |  |  | 215 | 				Utils::WString rest = line.tokens(L":", 2).removeFirstSpace();
 | 
        
           | 1 | cycrow | 216 |   | 
        
           | 223 | cycrow | 217 | 				if ( cmd == L"dir" )
 | 
        
           | 1 | cycrow | 218 | 				{
 | 
        
           |  |  | 219 | 					// first check its on the list
 | 
        
           | 223 | cycrow | 220 | 					if ( !dirList.contains(rest) )
 | 
        
           | 1 | cycrow | 221 | 					{
 | 
        
           | 197 | cycrow | 222 | 						Utils::WString gameName = packages.getGameName(rest);
 | 
        
           | 121 | cycrow | 223 | 						if ( !gameName.empty() )
 | 
        
           | 1 | cycrow | 224 | 						{
 | 
        
           | 182 | cycrow | 225 | 							int lang = packages.getGameLanguage(rest);
 | 
        
           | 1 | cycrow | 226 | 							if ( lang )
 | 
        
           | 197 | cycrow | 227 | 								dirList.pushBack(rest, Utils::WString::Number(lang) + L"|" + gameName);
 | 
        
           | 1 | cycrow | 228 | 							else
 | 
        
           | 121 | cycrow | 229 | 								dirList.pushBack(rest, gameName);
 | 
        
           | 1 | cycrow | 230 | 							anyDirs = true;
 | 
        
           |  |  | 231 | 						}
 | 
        
           |  |  | 232 | 					}
 | 
        
           |  |  | 233 | 				}
 | 
        
           | 223 | cycrow | 234 | 				else if ( cmd == L"remdir" )
 | 
        
           | 1 | cycrow | 235 | 				{
 | 
        
           |  |  | 236 | 					// first check its on the list
 | 
        
           | 223 | cycrow | 237 | 					if ( !remDirList.contains(rest) )
 | 
        
           | 1 | cycrow | 238 | 					{
 | 
        
           | 121 | cycrow | 239 | 						remDirList.pushBack(rest);
 | 
        
           | 1 | cycrow | 240 | 						anyDirs = true;
 | 
        
           |  |  | 241 | 					}
 | 
        
           |  |  | 242 | 				}
 | 
        
           | 223 | cycrow | 243 | 				else if ( cmd == L"experimental" )
 | 
        
           | 1 | cycrow | 244 | 					gui->SetExperimental(true);
 | 
        
           | 223 | cycrow | 245 | 				else if ( cmd == L"filterships" )
 | 
        
           | 1 | cycrow | 246 | 					gui->SetShips(true);
 | 
        
           | 223 | cycrow | 247 | 				else if ( cmd == L"filtersigned" )
 | 
        
           | 1 | cycrow | 248 | 					gui->SetOnlySigned(true);
 | 
        
           | 223 | cycrow | 249 | 				else if ( cmd == L"modselectordetails" )
 | 
        
           | 1 | cycrow | 250 | 					gui->SetModSelectorDetails(true);
 | 
        
           | 223 | cycrow | 251 | 				else if ( cmd == L"cheat" )
 | 
        
           | 1 | cycrow | 252 | 					gui->SetCheat(true);
 | 
        
           | 223 | cycrow | 253 | 				else if ( cmd == L"downloadable" )
 | 
        
           | 1 | cycrow | 254 | 					gui->SetDownloadable(true);
 | 
        
           | 223 | cycrow | 255 | 				else if ( cmd == L"noautoupdate" )
 | 
        
           | 1 | cycrow | 256 | 					gui->SetAutoUpdate(false);
 | 
        
           | 223 | cycrow | 257 | 				else if ( cmd == L"managersize" )
 | 
        
           |  |  | 258 | 					gui->SetSize(rest.token(L" ", 2).toLong(), rest.token(L" ", 1).toLong());
 | 
        
           |  |  | 259 | 				else if ( cmd == L"managerpos" )
 | 
        
           |  |  | 260 | 					gui->Location = System::Drawing::Point(rest.token(L" ", 1).toLong(), rest.token(L" ", 2).toLong());
 | 
        
           |  |  | 261 | 				else if ( cmd == L"managermax" )
 | 
        
           | 1 | cycrow | 262 | 					gui->WindowState = FormWindowState::Maximized;
 | 
        
           | 223 | cycrow | 263 | 				else if ( cmd == L"tips" )
 | 
        
           |  |  | 264 | 					gui->SetTips(rest.token(L" ", 1).toInt(), rest.token(L" ", 2).toInt());
 | 
        
           |  |  | 265 | 				else if ( cmd == L"ignorejoy" )
 | 
        
           | 121 | cycrow | 266 | 					gui->SetIgnoreJoy(rest.toInt());
 | 
        
           | 223 | cycrow | 267 | 				else if ( cmd == L"savegamemanager" )
 | 
        
           | 121 | cycrow | 268 | 					gui->SetSaveGameManager(rest.toInt());
 | 
        
           | 223 | cycrow | 269 | 				else if ( cmd == L"restoremodified" ) {
 | 
        
           | 1 | cycrow | 270 | 					CPackages p;
 | 
        
           | 223 | cycrow | 271 | 					p.startup(L".", _WS(tempDir), _WS(mydoc), L"");
 | 
        
           | 182 | cycrow | 272 | 					if ( p.read(rest) ) {
 | 
        
           | 1 | cycrow | 273 | 						p.SetVanilla(false);
 | 
        
           |  |  | 274 | 						p.PrepareEnableFromVanilla();
 | 
        
           | 183 | cycrow | 275 | 						p.enablePreparedPackages(0, 0, 0);
 | 
        
           |  |  | 276 | 						p.closeDir();
 | 
        
           | 1 | cycrow | 277 | 					}
 | 
        
           |  |  | 278 | 				}
 | 
        
           |  |  | 279 | 			}
 | 
        
           |  |  | 280 | 		}
 | 
        
           |  |  | 281 | 	}
 | 
        
           |  |  | 282 |   | 
        
           | 121 | cycrow | 283 | 	// still no directories, quit
 | 
        
           |  |  | 284 | 	if (dirList.empty() && openPackage)
 | 
        
           | 1 | cycrow | 285 | 	{
 | 
        
           | 121 | cycrow | 286 | 		MessageBox::Show("You dont currently have any controlled directories", "Open Package", MessageBoxButtons::OK, MessageBoxIcon::Error);
 | 
        
           |  |  | 287 | 		return 1;
 | 
        
           | 1 | cycrow | 288 | 	}
 | 
        
           |  |  | 289 |   | 
        
           | 196 | cycrow | 290 | 	Utils::WString dir = dirList.empty() ? L"" : dirList.first()->str;
 | 
        
           | 1 | cycrow | 291 |   | 
        
           |  |  | 292 | 	StartUp ^startup = gcnew StartUp(&packages, &dir, (openPackage) ? true : false, Advanced);
 | 
        
           |  |  | 293 | 	Application::Run(startup);
 | 
        
           |  |  | 294 |   | 
        
           |  |  | 295 | 	// opening a package from command line
 | 
        
           |  |  | 296 | 	if ( openPackage )
 | 
        
           |  |  | 297 | 	{
 | 
        
           |  |  | 298 | 		if ( gui->InstallPackage(openPackage, true, false, false) )
 | 
        
           |  |  | 299 | 		{
 | 
        
           | 182 | cycrow | 300 | 			if ( !packages.getModKey().empty() )
 | 
        
           |  |  | 301 | 				PluginManager::WriteRegistryValue(packages.getModKey(), packages.selectedModName());
 | 
        
           | 183 | cycrow | 302 | 			packages.closeDir(0, 0, true);
 | 
        
           | 1 | cycrow | 303 | 			return 0;
 | 
        
           |  |  | 304 | 		}
 | 
        
           |  |  | 305 | 		return 1;
 | 
        
           |  |  | 306 | 	}
 | 
        
           |  |  | 307 |   | 
        
           | 201 | cycrow | 308 | 	gui->UpdateDirList(L"");
 | 
        
           | 1 | cycrow | 309 | 	gui->UpdateControls();
 | 
        
           |  |  | 310 | 	gui->UpdatePackages();
 | 
        
           |  |  | 311 | 	gui->StartCheckTimer();
 | 
        
           | 133 | cycrow | 312 | 	gui->FindPackages();
 | 
        
           | 1 | cycrow | 313 |   | 
        
           | 182 | cycrow | 314 | 	System::String ^mod = PluginManager::ReadRegistryValue(packages.getModKey());
 | 
        
           | 160 | cycrow | 315 | 	packages.setMod(_S(mod));
 | 
        
           | 1 | cycrow | 316 |   | 
        
           |  |  | 317 | 	gui->CheckProtectedDir();
 | 
        
           |  |  | 318 | 	Application::Run(gui);
 | 
        
           |  |  | 319 |   | 
        
           |  |  | 320 | 	// close directory 
 | 
        
           |  |  | 321 | 	if ( packages.IsLoaded() )
 | 
        
           |  |  | 322 | 	{
 | 
        
           | 182 | cycrow | 323 | 		if ( !packages.getModKey().empty() )
 | 
        
           |  |  | 324 | 			PluginManager::WriteRegistryValue(packages.getModKey(), packages.selectedModName());
 | 
        
           | 1 | cycrow | 325 | 		if ( packages.AnyUnusedShared() )
 | 
        
           |  |  | 326 | 		{
 | 
        
           |  |  | 327 | 			if ( MessageBox::Show("You have some unused shared files, would you like to remove these?", "Remove Shared Files", MessageBoxButtons::YesNo, MessageBoxIcon::Question) == System::Windows::Forms::DialogResult::Yes)
 | 
        
           | 183 | cycrow | 328 | 				packages.removeUnusedSharedFiles();
 | 
        
           | 1 | cycrow | 329 | 		}
 | 
        
           | 183 | cycrow | 330 | 		packages.closeDir(0, 0, true);
 | 
        
           | 1 | cycrow | 331 | 	}
 | 
        
           |  |  | 332 |   | 
        
           | 196 | cycrow | 333 | 	Utils::WStringList restoreModified;
 | 
        
           | 1 | cycrow | 334 | 	if ( gui->GetDownloadFile() )
 | 
        
           |  |  | 335 | 	{
 | 
        
           |  |  | 336 | 		if ( System::IO::File::Exists(".\\AutoUpdater.exe") )
 | 
        
           |  |  | 337 | 		{
 | 
        
           |  |  | 338 | 			// rename the autoupdater
 | 
        
           |  |  | 339 | 			System::String ^dir = System::IO::FileInfo(System::Windows::Forms::Application::ExecutablePath).DirectoryName;
 | 
        
           |  |  | 340 | 			if ( System::IO::File::Exists(tempDir + "\\AutoUpdater_old.exe") )
 | 
        
           |  |  | 341 | 				System::IO::File::Delete(tempDir + "\\AutoUpdater_old.exe");
 | 
        
           |  |  | 342 | 			System::IO::File::Copy(dir + "\\AutoUpdater.exe", tempDir + "\\AutoUpdater_old.exe");
 | 
        
           |  |  | 343 |   | 
        
           |  |  | 344 | 			System::Diagnostics::ProcessStartInfo ^info = nullptr;
 | 
        
           |  |  | 345 | 			if ( System::IO::File::Exists(tempDir + "\\AutoUpdater_old.exe") )
 | 
        
           |  |  | 346 | 				info = gcnew System::Diagnostics::ProcessStartInfo(tempDir + "\\AutoUpdater_old.exe");
 | 
        
           |  |  | 347 | 			else 
 | 
        
           |  |  | 348 | 			{
 | 
        
           |  |  | 349 | 				MessageBox::Show("Error trying to update the Plugin Manager\nUnable to load AutoUpdater", "AutoUpdate", MessageBoxButtons::OK, MessageBoxIcon::Warning);
 | 
        
           |  |  | 350 | 				System::Windows::Forms::Application::Restart();
 | 
        
           |  |  | 351 | 				return 0;
 | 
        
           |  |  | 352 | 			}
 | 
        
           |  |  | 353 |   | 
        
           |  |  | 354 | 			if ( info )
 | 
        
           |  |  | 355 | 			{
 | 
        
           |  |  | 356 | 				info->WorkingDirectory = dir;
 | 
        
           |  |  | 357 | 				info->Arguments = "\"" + gui->GetDownloadFile() + "\" \"" + System::Windows::Forms::Application::ExecutablePath + "\"";
 | 
        
           |  |  | 358 | 				info->UseShellExecute = false;
 | 
        
           |  |  | 359 | 				info->WindowStyle = System::Diagnostics::ProcessWindowStyle::Normal;
 | 
        
           |  |  | 360 | 				System::Diagnostics::Process ^process = System::Diagnostics::Process::Start(info);
 | 
        
           |  |  | 361 | 			}
 | 
        
           |  |  | 362 | 		}
 | 
        
           |  |  | 363 | 		else
 | 
        
           |  |  | 364 | 		{
 | 
        
           |  |  | 365 | 			MessageBox::Show("Error trying to update the Plugin Manager\nUnable to load AutoUpdater", "AutoUpdate", MessageBoxButtons::OK, MessageBoxIcon::Warning);
 | 
        
           |  |  | 366 | 			System::Windows::Forms::Application::Restart();
 | 
        
           |  |  | 367 | 		}
 | 
        
           |  |  | 368 | 	}
 | 
        
           |  |  | 369 | 	else if ( gui->GetRunFile() )
 | 
        
           |  |  | 370 | 	{
 | 
        
           |  |  | 371 | 		System::String ^dir = System::IO::FileInfo(System::Windows::Forms::Application::ExecutablePath).DirectoryName;
 | 
        
           |  |  | 372 |   | 
        
           |  |  | 373 | 		// manager was run from the launcher, ie the launcher is still running, send a message to run the game instead of loading another one
 | 
        
           |  |  | 374 | 		if ( fromLauncher )
 | 
        
           |  |  | 375 | 		{
 | 
        
           |  |  | 376 | 			StreamWriter ^sw = File::CreateText(mydoc + "\\Egosoft\\launchgame.dat");
 | 
        
           |  |  | 377 | 			try 
 | 
        
           |  |  | 378 | 			{
 | 
        
           |  |  | 379 | 				sw->WriteLine("File:" + gui->GetRunFile());
 | 
        
           |  |  | 380 | 				if ( gui->GetGameArgs() && gui->GetGameArgs()->Length )
 | 
        
           |  |  | 381 | 					sw->WriteLine("Args:" + gui->GetGameArgs());
 | 
        
           |  |  | 382 | 			}
 | 
        
           |  |  | 383 | 			finally
 | 
        
           |  |  | 384 | 			{
 | 
        
           |  |  | 385 | 				if ( sw )
 | 
        
           |  |  | 386 | 					delete (IDisposable ^)sw;
 | 
        
           |  |  | 387 | 			}
 | 
        
           |  |  | 388 | 		}
 | 
        
           |  |  | 389 | 		else
 | 
        
           |  |  | 390 | 		{
 | 
        
           |  |  | 391 | 			if ( System::IO::File::Exists(dir + "\\GameLauncher.exe") )
 | 
        
           |  |  | 392 | 			{
 | 
        
           |  |  | 393 | 				System::Diagnostics::ProcessStartInfo ^info = gcnew System::Diagnostics::ProcessStartInfo(dir + "\\GameLauncher.exe");
 | 
        
           |  |  | 394 | 				if ( info )
 | 
        
           |  |  | 395 | 				{
 | 
        
           |  |  | 396 | 					if ( packages.GetCurrentGameFlags() & EXEFLAG_ADDON ) {
 | 
        
           |  |  | 397 | 						CPackages p;
 | 
        
           | 158 | cycrow | 398 | 						p.startup(".", _S(tempDir), _S(mydoc), "");
 | 
        
           | 196 | cycrow | 399 | 						Utils::WString baseDir = CFileIO(_S(gui->GetRunFile())).dir();
 | 
        
           |  |  | 400 | 						if ( p.read(baseDir.toString()) ) {
 | 
        
           | 1 | cycrow | 401 | 							if ( !p.IsVanilla() ) {
 | 
        
           |  |  | 402 | 								p.SetVanilla(true);
 | 
        
           |  |  | 403 | 								p.PrepareDisableForVanilla();
 | 
        
           | 183 | cycrow | 404 | 								p.enablePreparedPackages(0, 0, 0);
 | 
        
           | 158 | cycrow | 405 | 								restoreModified.pushBack(baseDir);
 | 
        
           | 1 | cycrow | 406 | 							}
 | 
        
           | 183 | cycrow | 407 | 							p.closeDir();							
 | 
        
           | 1 | cycrow | 408 | 						}
 | 
        
           |  |  | 409 | 					}
 | 
        
           |  |  | 410 |   | 
        
           |  |  | 411 | 					info->WorkingDirectory = dir;
 | 
        
           | 105 | cycrow | 412 | 					info->Arguments = "";
 | 
        
           |  |  | 413 | 					if ( Advanced ) info->Arguments = "--advanced ";
 | 
        
           | 1 | cycrow | 414 | 					if ( gui->GetGameArgs() && gui->GetGameArgs()->Length )
 | 
        
           | 105 | cycrow | 415 | 						info->Arguments += "\"" + gui->GetRunFile() + "\" \"" + System::Windows::Forms::Application::ExecutablePath + "\" \"" + gui->GetGameArgs() + "\"";
 | 
        
           | 1 | cycrow | 416 | 					else
 | 
        
           | 105 | cycrow | 417 | 						info->Arguments += "\"" + gui->GetRunFile() + "\" \"" + System::Windows::Forms::Application::ExecutablePath + "\"";
 | 
        
           | 1 | cycrow | 418 | 					info->UseShellExecute = false;
 | 
        
           |  |  | 419 | 					info->WindowStyle = System::Diagnostics::ProcessWindowStyle::Normal;
 | 
        
           |  |  | 420 | 					System::Diagnostics::Process ^process = System::Diagnostics::Process::Start(info);
 | 
        
           |  |  | 421 | 				}
 | 
        
           |  |  | 422 | 			}
 | 
        
           |  |  | 423 | 		}
 | 
        
           |  |  | 424 | 	}
 | 
        
           |  |  | 425 |   | 
        
           |  |  | 426 | 	// write config
 | 
        
           | 197 | cycrow | 427 | 	std::vector<Utils::WString> writeLines;
 | 
        
           | 121 | cycrow | 428 | 	for(auto itr = dirList.begin(); itr != dirList.end(); itr++)
 | 
        
           | 1 | cycrow | 429 | 	{
 | 
        
           | 197 | cycrow | 430 | 		writeLines.push_back(L"Dir:" + (*itr)->str);
 | 
        
           | 196 | cycrow | 431 | 		Utils::WString data;
 | 
        
           | 197 | cycrow | 432 | 		if ((*itr)->data.isin(L"|") )
 | 
        
           | 1 | cycrow | 433 | 		{
 | 
        
           | 220 | cycrow | 434 | 			data = CPackages::ConvertLanguage((*itr)->data.token(L"|", 1).toInt()) + L"|";
 | 
        
           | 196 | cycrow | 435 | 			data += (*itr)->data.tokens(L"|", 2);
 | 
        
           | 1 | cycrow | 436 | 		}
 | 
        
           |  |  | 437 | 		else
 | 
        
           | 121 | cycrow | 438 | 			data = (*itr)->data;
 | 
        
           | 1 | cycrow | 439 |   | 
        
           | 197 | cycrow | 440 | 		Utils::WString exe = CFileIO(packages.GetGameExe()->gameRunExe((*itr)->str)).fullFilename();
 | 
        
           |  |  | 441 | 		writeLines.push_back(L"DirExe:" + data + L"|" + exe);
 | 
        
           | 1 | cycrow | 442 |   | 
        
           |  |  | 443 | 		// do the log files
 | 
        
           | 197 | cycrow | 444 | 		writeLines.push_back(L"GameLog:" + packages.logDirectory(exe.toString()) + "|" + exe);
 | 
        
           | 1 | cycrow | 445 |   | 
        
           |  |  | 446 | 	}
 | 
        
           | 121 | cycrow | 447 | 	for (auto itr = remDirList.begin(); itr != remDirList.end(); itr++)
 | 
        
           | 197 | cycrow | 448 | 		writeLines.push_back(L"RemDir:" + (*itr)->str);
 | 
        
           | 1 | cycrow | 449 | 	if ( gui->IsExperimental() )
 | 
        
           | 197 | cycrow | 450 | 		writeLines.push_back(L"Experimental:");
 | 
        
           | 1 | cycrow | 451 | 	if ( gui->IsShips() )
 | 
        
           | 197 | cycrow | 452 | 		writeLines.push_back(L"FilterShips:");
 | 
        
           | 1 | cycrow | 453 | 	if ( gui->IsOnlySigned() )
 | 
        
           | 197 | cycrow | 454 | 		writeLines.push_back(L"FilterSigned:");
 | 
        
           | 1 | cycrow | 455 | 	if ( gui->IsCheat() )
 | 
        
           | 197 | cycrow | 456 | 		writeLines.push_back(L"Cheat:");
 | 
        
           |  |  | 457 | 	writeLines.push_back(L"SaveGameManager:" + Utils::WString::Number(gui->GetSaveGameManager()));
 | 
        
           | 1 | cycrow | 458 | 	if ( gui->IsDownloadable() )
 | 
        
           | 197 | cycrow | 459 | 		writeLines.push_back(L"Downloadable:");
 | 
        
           | 1 | cycrow | 460 | 	if ( gui->IsModSelectorDetailsShowing() )
 | 
        
           | 197 | cycrow | 461 | 		writeLines.push_back(L"ModSelectorDetails:");
 | 
        
           | 1 | cycrow | 462 | 	if ( !gui->IsAutoUpdate() )
 | 
        
           | 197 | cycrow | 463 | 		writeLines.push_back(L"NoAutoUpdate:");
 | 
        
           | 1 | cycrow | 464 | 	if ( gui->WindowState == FormWindowState::Normal )
 | 
        
           |  |  | 465 | 	{
 | 
        
           | 197 | cycrow | 466 | 		writeLines.push_back(L"ManagerSize:" + Utils::WString::Number(gui->Size.Height) + L" " + Utils::WString::Number(gui->Size.Width));
 | 
        
           |  |  | 467 | 		writeLines.push_back(L"ManagerPos:" + Utils::WString::Number(gui->Location.X) + L" " + Utils::WString::Number(gui->Location.Y));
 | 
        
           | 1 | cycrow | 468 | 	}
 | 
        
           |  |  | 469 | 	else
 | 
        
           |  |  | 470 | 	{
 | 
        
           | 197 | cycrow | 471 | 		writeLines.push_back(L"ManagerPos:" + Utils::WString::Number(gui->RestoreBounds.Location.X) + L" " + Utils::WString::Number(gui->RestoreBounds.Location.Y));
 | 
        
           |  |  | 472 | 		writeLines.push_back(L"ManagerSize:" + Utils::WString::Number(gui->RestoreBounds.Size.Height) + L" " + Utils::WString::Number(gui->RestoreBounds.Size.Width));
 | 
        
           | 1 | cycrow | 473 | 	}
 | 
        
           |  |  | 474 |   | 
        
           |  |  | 475 | 	if ( gui->WindowState == FormWindowState::Maximized )
 | 
        
           | 197 | cycrow | 476 | 		writeLines.push_back(L"ManagerMax:");
 | 
        
           | 1 | cycrow | 477 | 	if ( gui->GetIgnoreJoy() )
 | 
        
           | 197 | cycrow | 478 | 		writeLines.push_back(L"IgnoreJoy:" + Utils::WString::Number(gui->GetIgnoreJoy()));
 | 
        
           | 1 | cycrow | 479 |   | 
        
           |  |  | 480 | 	for ( int i = 0; i < gui->GetMaxTips(); i++ )
 | 
        
           |  |  | 481 | 	{
 | 
        
           |  |  | 482 | 		int tips = gui->GetTips(i);
 | 
        
           |  |  | 483 | 		if ( tips == -1 )
 | 
        
           |  |  | 484 | 			continue;
 | 
        
           | 197 | cycrow | 485 | 		writeLines.push_back(L"Tips: " + Utils::WString::Number(i) + L" " + Utils::WString::Number(tips));
 | 
        
           | 1 | cycrow | 486 | 	}
 | 
        
           |  |  | 487 |   | 
        
           | 158 | cycrow | 488 | 	for (auto rm = restoreModified.begin(); rm != restoreModified.end(); rm++) {
 | 
        
           | 197 | cycrow | 489 | 		writeLines.push_back(L"RestoreModified: " + (*rm)->str);
 | 
        
           | 1 | cycrow | 490 | 	}
 | 
        
           |  |  | 491 |   | 
        
           |  |  | 492 | 	// write settings
 | 
        
           | 197 | cycrow | 493 | 	configFile.writeFile(writeLines);
 | 
        
           | 1 | cycrow | 494 |   | 
        
           |  |  | 495 | 	return 0;
 | 
        
           |  |  | 496 | }
 |