Subversion Repositories spk

Rev

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

Rev 105 Rev 121
Line 24... Line 24...
24
 
24
 
25
	System::String ^tempDir = System::IO::Path::GetTempPath();
25
	System::String ^tempDir = System::IO::Path::GetTempPath();
26
	System::String ^mydoc = Environment::GetFolderPath(Environment::SpecialFolder::Personal );
26
	System::String ^mydoc = Environment::GetFolderPath(Environment::SpecialFolder::Personal );
27
	System::String ^progfile = Environment::GetFolderPath(Environment::SpecialFolder::ProgramFiles );
27
	System::String ^progfile = Environment::GetFolderPath(Environment::SpecialFolder::ProgramFiles );
28
 
28
 
29
	CyStringList dirList;
29
	Utils::CStringList dirList;
30
	CyStringList remDirList;
30
	Utils::CStringList remDirList;
31
	System::String ^gameArgs;
31
	System::String ^gameArgs;
32
	System::String ^openPackage;
32
	System::String ^openPackage;
33
 
33
 
34
	CLanguages::Instance()->SetLanguage(44);
34
	CLanguages::Instance()->SetLanguage(44);
35
 
35
 
Line 65... Line 65...
65
			if ( rest.Right(1) == "\"" )
65
			if ( rest.Right(1) == "\"" )
66
				rest.Truncate(rest.Length() - 1);
66
				rest.Truncate(rest.Length() - 1);
67
 
67
 
68
			if ( argSwitch == "--dir" && !rest.Empty() )
68
			if ( argSwitch == "--dir" && !rest.Empty() )
69
			{
69
			{
70
				CyString gameName = packages.GetGameName(rest);
70
				Utils::String gameName = packages.getGameName(rest.ToString());
71
				if ( !gameName.Empty() )
71
				if ( !gameName.empty() )
72
					dirList.PushBack(rest, gameName);
72
					dirList.pushBack(rest.ToString(), gameName);
73
			}
73
			}
74
 
74
 
75
			if ( argSwitch == "--advanced" )
75
			if ( argSwitch == "--advanced" )
76
				Advanced = true;
76
				Advanced = true;
77
			else if ( argSwitch == "--fromlauncher" )
77
			else if ( argSwitch == "--fromlauncher" )
Line 197... Line 197...
197
	MainGui ^gui = gcnew MainGui(&packages, &dirList, &remDirList, Advanced);
197
	MainGui ^gui = gcnew MainGui(&packages, &dirList, &remDirList, Advanced);
198
	gui->AddGameArgs(gameArgs);
198
	gui->AddGameArgs(gameArgs);
199
 
199
 
200
 
200
 
201
	// load in the config file
201
	// load in the config file
202
	CFileIO configFile(CyStringFromSystemString(mydoc) + "/Egosoft/pluginmanager.dat");
202
	CFileIO configFile(_S(mydoc) + "/Egosoft/pluginmanager.dat");
203
	bool anyDirs = false;
203
	bool anyDirs = false;
204
	if ( configFile.exists() )
204
	if ( configFile.exists() )
205
	{
205
	{
206
		std::vector<CyString> *readFile = configFile.ReadLines();
206
		std::vector<Utils::String> *readFile = configFile.readLines();
207
		if ( readFile )
207
		if ( readFile )
208
		{
208
		{
209
			for ( int i = 0; i < (int)readFile->size(); i++ )
209
			for ( int i = 0; i < (int)readFile->size(); i++ )
210
			{
210
			{
211
				CyString line(readFile->at(i));
211
				Utils::String line(readFile->at(i));
212
				CyString cmd = line.GetToken(":", 1, 1).lower();
212
				Utils::String cmd = line.token(":", 1).lower();
213
				CyString rest = line.GetToken(":", 2).RemoveFirstSpace();
213
				Utils::String rest = line.tokens(":", 2).removeFirstSpace();
214
 
214
 
215
				if ( cmd == "dir" )
215
				if ( cmd == "dir" )
216
				{
216
				{
217
					// first check its on the list
217
					// first check its on the list
218
					if ( !dirList.FindString(rest) )
218
					if ( !dirList.findString(rest) )
219
					{
219
					{
220
						CyString gameName = packages.GetGameName(rest);
220
						Utils::String gameName = packages.GetGameName(rest).ToString();
221
						if ( !gameName.Empty() )
221
						if ( !gameName.empty() )
222
						{
222
						{
223
							int lang = packages.GetGameLanguage(rest);
223
							int lang = packages.GetGameLanguage(rest);
224
							if ( lang )
224
							if ( lang )
225
								dirList.PushBack(rest, CyString::Number(lang) + "|" + gameName);
225
								dirList.pushBack(rest, Utils::String::Number(lang) + "|" + gameName);
226
							else
226
							else
227
								dirList.PushBack(rest, gameName);
227
								dirList.pushBack(rest, gameName);
228
							anyDirs = true;
228
							anyDirs = true;
229
						}
229
						}
230
					}
230
					}
231
				}
231
				}
232
				else if ( cmd == "remdir" )
232
				else if ( cmd == "remdir" )
233
				{
233
				{
234
					// first check its on the list
234
					// first check its on the list
235
					if ( !remDirList.FindString(rest) )
235
					if ( !remDirList.findString(rest) )
236
					{
236
					{
237
						remDirList.PushBack(rest);
237
						remDirList.pushBack(rest);
238
						anyDirs = true;
238
						anyDirs = true;
239
					}
239
					}
240
				}
240
				}
241
				else if ( cmd == "experimental" )
241
				else if ( cmd == "experimental" )
242
					gui->SetExperimental(true);
242
					gui->SetExperimental(true);
Line 251... Line 251...
251
				else if ( cmd == "downloadable" )
251
				else if ( cmd == "downloadable" )
252
					gui->SetDownloadable(true);
252
					gui->SetDownloadable(true);
253
				else if ( cmd == "noautoupdate" )
253
				else if ( cmd == "noautoupdate" )
254
					gui->SetAutoUpdate(false);
254
					gui->SetAutoUpdate(false);
255
				else if ( cmd == "managersize" )
255
				else if ( cmd == "managersize" )
256
					gui->SetSize(rest.GetToken(" ", 2, 2).ToInt(), rest.GetToken(" ", 1, 1).ToInt());
256
					gui->SetSize(rest.token(" ", 2).toLong(), rest.token(" ", 1).toLong());
257
				else if ( cmd == "managerpos" )
257
				else if ( cmd == "managerpos" )
258
					gui->Location = System::Drawing::Point(rest.GetToken(" ", 1, 1).ToInt(), rest.GetToken(" ", 2, 2).ToInt());
258
					gui->Location = System::Drawing::Point(rest.token(" ", 1).toLong(), rest.token(" ", 2).toLong());
259
				else if ( cmd == "managermax" )
259
				else if ( cmd == "managermax" )
260
					gui->WindowState = FormWindowState::Maximized;
260
					gui->WindowState = FormWindowState::Maximized;
261
				else if ( cmd == "tips" )
261
				else if ( cmd == "tips" )
262
					gui->SetTips(rest.GetToken(" ", 1, 1).ToInt(), rest.GetToken(" ", 2, 2).ToInt());
262
					gui->SetTips(rest.token(" ", 1).toInt(), rest.token(" ", 2).toInt());
263
				else if ( cmd == "ignorejoy" )
263
				else if ( cmd == "ignorejoy" )
264
					gui->SetIgnoreJoy(rest.ToInt());
264
					gui->SetIgnoreJoy(rest.toInt());
265
				else if ( cmd == "savegamemanager" )
265
				else if ( cmd == "savegamemanager" )
266
					gui->SetSaveGameManager(rest.ToInt());
266
					gui->SetSaveGameManager(rest.toInt());
267
				else if ( cmd == "restoremodified" ) {
267
				else if ( cmd == "restoremodified" ) {
268
					CPackages p;
268
					CPackages p;
269
					p.Startup(".", CyStringFromSystemString(tempDir), CyStringFromSystemString(mydoc), "");
269
					p.Startup(".", CyStringFromSystemString(tempDir), CyStringFromSystemString(mydoc), "");
270
					if ( p.Read(rest) ) {
270
					if ( p.Read(rest) ) {
271
						p.SetVanilla(false);
271
						p.SetVanilla(false);
Line 275... Line 275...
275
					}
275
					}
276
				}
276
				}
277
			}
277
			}
278
 
278
 
279
			delete readFile;
279
			delete readFile;
280
		}
-
 
281
	}
-
 
282
 
-
 
283
	CyStringList gameDirs;
-
 
284
	gameDirs.PushBack("HKCU\\Software\\Deepsilver\\X2 The Threat", "INSTALL_DIR");
-
 
285
	gameDirs.PushBack("HKCU\\Software\\Deepsilver\\X3 Reunion", "INSTALL_DIR");
-
 
286
	gameDirs.PushBack("HKCU\\Software\\Egosoft\\X3TC", "INSTALL_DIR");
-
 
287
	gameDirs.PushBack("Steam\\x2 - the threat");
-
 
288
	gameDirs.PushBack("Steam\\x3 - reunion");
-
 
289
	gameDirs.PushBack("Steam\\x3 terran conflict");
-
 
290
	// some custom directories to look for
-
 
291
	gameDirs.PushBack("%PROGRAMFILES%\\Egosoft\\X2 The Threat");
-
 
292
	gameDirs.PushBack("%PROGRAMFILES%\\Egosoft\\X3 Reunion");
-
 
293
	gameDirs.PushBack("%PROGRAMFILES%\\Egosoft\\X3 Terran Conflict");
-
 
294
	gameDirs.PushBack("C:\\Games\\X2");
-
 
295
	gameDirs.PushBack("C:\\Games\\X3");
-
 
296
	gameDirs.PushBack("C:\\Games\\X3TC");
-
 
297
	gameDirs.PushBack("D:\\Games\\X2");
-
 
298
	gameDirs.PushBack("D:\\Games\\X3");
-
 
299
	gameDirs.PushBack("D:\\Games\\X3TC");
-
 
300
 
-
 
301
	for ( SStringList *strNode = gameDirs.Head(); strNode; strNode = strNode->next )
-
 
302
	{
-
 
303
		CyString sFirst = strNode->str.GetToken("\\", 1, 1);
-
 
304
		CyString sRest = strNode->str.GetToken("\\", 2);
-
 
305
 
-
 
306
		if ( sFirst.Compare("HKCU") || sFirst.Compare("HKLM") )
-
 
307
		{
-
 
308
			RegistryKey ^searchKey = nullptr;
-
 
309
			if ( sFirst.Compare("HKCU") )
-
 
310
				searchKey = Registry::CurrentUser->OpenSubKey(SystemStringFromCyString(sRest));
-
 
311
			else if ( sFirst.Compare("HKLM") )
-
 
312
				searchKey = Registry::LocalMachine->OpenSubKey(SystemStringFromCyString(sRest));
-
 
313
 
-
 
314
			if ( searchKey )
-
 
315
			{
-
 
316
				System::String ^regRead = System::Convert::ToString(searchKey->GetValue(SystemStringFromCyString(strNode->data)));
-
 
317
				if ( regRead )
-
 
318
				{
-
 
319
					CyString dir = CyStringFromSystemString(regRead);
-
 
320
					gui->GetGameDirs(dir, anyDirs, anyDirs);
-
 
321
				}
-
 
322
			}
-
 
323
		}
-
 
324
		else if ( sFirst.Compare("Steam") )
-
 
325
		{
-
 
326
			RegistryKey ^steamKey = Registry::CurrentUser->OpenSubKey("Software\\Valve\\Steam");
-
 
327
			if ( steamKey )
-
 
328
			{
-
 
329
				System::String ^regRead = System::Convert::ToString(steamKey->GetValue("SteamPath"));
-
 
330
				if ( regRead )
-
 
331
				{
-
 
332
					CyString steamDir = CyStringFromSystemString(regRead);
-
 
333
					CyString dir = steamDir + "\\steamapps\\common\\" + sRest;
-
 
334
					dir = dir.FindReplace("/","\\");
-
 
335
					dir = dir.FindReplace("\\\\", "\\");
-
 
336
					gui->GetGameDirs(dir, anyDirs, anyDirs);
-
 
337
				}
-
 
338
			}
-
 
339
		}
-
 
340
		else
-
 
341
		{
-
 
342
			CyString dir = strNode->str;
-
 
343
			dir = dir.FindReplace("/","\\");
-
 
344
			dir = dir.FindReplace("\\\\", "\\");
-
 
345
			dir = dir.FindReplace("%PROGRAMFILES%", CyStringFromSystemString(progfile));
-
 
346
			gui->GetGameDirs(dir, anyDirs, anyDirs);
-
 
347
		}
-
 
348
	}
-
 
349
 
-
 
350
	// no directories?
-
 
351
	if ( dirList.Empty() )
-
 
352
	{
-
 
353
		OpenFileDialog ^ofd = gcnew OpenFileDialog();
-
 
354
		ofd->Filter = "X-Universe Executable|";
-
 
355
		String ^games = "";
-
 
356
		for ( int i = 0; i < packages.GetGameExe()->GetNumGames(); i++ )
-
 
357
		{
-
 
358
			SGameExe *exe = packages.GetGameExe()->GetGame(i);
-
 
359
			if ( i ) ofd->Filter += ";";
-
 
360
			ofd->Filter += SystemStringFromCyString(exe->sExe);
-
 
361
			games += "|" + SystemStringFromCyString(exe->sName) + "|" + SystemStringFromCyString(exe->sExe);
-
 
362
		}
-
 
363
		ofd->Filter += games;
-
 
364
		ofd->FilterIndex = 1;
-
 
365
		ofd->RestoreDirectory = true;
-
 
366
		if ( ofd->ShowDialog() == System::Windows::Forms::DialogResult::OK )
-
 
367
		{
-
 
368
			CyString dir = CyStringFromSystemString(IO::FileInfo(ofd->FileName).DirectoryName);
-
 
369
			if ( !dir.Empty() )
-
 
370
			{
-
 
371
				CyString gameName = packages.GetGameName(dir);
-
 
372
				if ( !gameName.Empty() )
-
 
373
				{
-
 
374
					remDirList.Remove(dir);
-
 
375
					gui->GetGameDirs(dir, false, true);
-
 
376
				}
-
 
377
			}
-
 
378
		}
280
		}
379
	}
281
	}
380
 
282
 
381
	// still no directories, quit
283
	// still no directories, quit
382
	if ( dirList.Empty() )
284
	if (dirList.empty() && openPackage)
-
 
285
	{
-
 
286
		MessageBox::Show("You dont currently have any controlled directories", "Open Package", MessageBoxButtons::OK, MessageBoxIcon::Error);
383
		return 1;
287
		return 1;
-
 
288
	}
384
 
289
 
385
	CyString dir = dirList.First();
290
	Utils::String dir = dirList.empty() ? "" : dirList.first()->str;
386
 
291
 
387
	StartUp ^startup = gcnew StartUp(&packages, &dir, (openPackage) ? true : false, Advanced);
292
	StartUp ^startup = gcnew StartUp(&packages, &dir, (openPackage) ? true : false, Advanced);
388
	Application::Run(startup);
293
	Application::Run(startup);
389
	if ( packages.IsOldPluginManager() )
-
 
390
	{
-
 
391
		if ( MessageBox::Show("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?", "Update Game Directory", MessageBoxButtons::YesNo, MessageBoxIcon::Question) != System::Windows::Forms::DialogResult::Yes )
-
 
392
			return 0;
-
 
393
	}
-
 
394
 
294
 
395
	// opening a package from command line
295
	// opening a package from command line
396
	if ( openPackage )
296
	if ( openPackage )
397
	{
297
	{
398
		if ( gui->InstallPackage(openPackage, true, false, false) )
298
		if ( gui->InstallPackage(openPackage, true, false, false) )
Line 403... Line 303...
403
			return 0;
303
			return 0;
404
		}
304
		}
405
		return 1;
305
		return 1;
406
	}
306
	}
407
 
307
 
408
	gui->UpdateDirList();
308
	gui->UpdateDirList("");
409
	gui->UpdateControls();
309
	gui->UpdateControls();
410
	gui->UpdatePackages();
310
	gui->UpdatePackages();
411
	gui->StartCheckTimer();
311
	gui->StartCheckTimer();
412
 
312
 
413
	System::String ^mod = PluginManager::ReadRegistryValue(packages.GetModKey());
313
	System::String ^mod = PluginManager::ReadRegistryValue(packages.GetModKey());
Line 521... Line 421...
521
			}
421
			}
522
		}
422
		}
523
	}
423
	}
524
 
424
 
525
	// write config
425
	// write config
526
	std::vector<CyString> writeLines;
426
	std::vector<Utils::String> writeLines;
527
	for ( SStringList *strNode = dirList.Head(); strNode; strNode = strNode->;next )
427
	for(auto itr = dirList.begin(); itr != dirList.end(); itr++)
528
	{
428
	{
529
		writeLines.push_back(CyString("Dir:") + strNode->str);
429
		writeLines.push_back("Dir:" + (*itr)->str);
530
		CyString data;
430
		Utils::String data;
531
		if ( strNode->data.IsIn("|") )
431
		if ((*itr)->data.isin("|") )
532
		{
432
		{
533
			data = CPackages::ConvertLanguage(strNode-&gt;data.GetToken("|", 1, 1).ToInt()) + "|";
433
			data = CPackages::ConvertLanguage((*itr)-&gt;data.token("|", 1).toInt()) + "|";
534
			data += strNode->data.GetToken("|", 2);
434
			data += (*itr)->data.tokens("|", 2);
535
		}
435
		}
536
		else
436
		else
537
			data = strNode->data;
437
			data = (*itr)->data;
538
 
438
 
539
		CyString exe = CFileIO(packages.GetGameExe()->GetGameRunExe(strNode->str.ToString())).fullFilename();
439
		Utils::String exe = CFileIO(packages.GetGameExe()->GetGameRunExe((*itr)->str)).fullFilename();
540
		writeLines.push_back(CyString("DirExe:") + data + "|" + exe);
440
		writeLines.push_back("DirExe:" + data + "|" + exe);
541
 
441
 
542
		// do the log files
442
		// do the log files
543
		writeLines.push_back(CyString(";GameLog:") + packages.logDirectory(exe.ToString()) + "|" + exe);
443
		writeLines.push_back(";GameLog:" + packages.logDirectory(exe) + "|" + exe);
544
 
444
 
545
	}
445
	}
546
	for ( SStringList *strNode = remDirList.Head(); strNode; strNode = strNode->next )
446
	for (auto itr = remDirList.begin(); itr != remDirList.end(); itr++)
547
		writeLines.push_back(CyString("RemDir:") + strNode->str);
447
		writeLines.push_back("RemDir:" + (*itr)->str);
548
	if ( gui->IsExperimental() )
448
	if ( gui->IsExperimental() )
549
		writeLines.push_back("Experimental:");
449
		writeLines.push_back("Experimental:");
550
	if ( gui->IsShips() )
450
	if ( gui->IsShips() )
551
		writeLines.push_back("FilterShips:");
451
		writeLines.push_back("FilterShips:");
552
	if ( gui->IsOnlySigned() )
452
	if ( gui->IsOnlySigned() )
553
		writeLines.push_back("FilterSigned:");
453
		writeLines.push_back("FilterSigned:");
554
	if ( gui->IsCheat() )
454
	if ( gui->IsCheat() )
555
		writeLines.push_back("Cheat:");
455
		writeLines.push_back("Cheat:");
556
	writeLines.push_back(CyString("SaveGameManager:") + (long)gui->GetSaveGameManager());
456
	writeLines.push_back(Utils::String("SaveGameManager:") + (long)gui->GetSaveGameManager());
557
	if ( gui->IsDownloadable() )
457
	if ( gui->IsDownloadable() )
558
		writeLines.push_back("Downloadable:");
458
		writeLines.push_back("Downloadable:");
559
	if ( gui->IsModSelectorDetailsShowing() )
459
	if ( gui->IsModSelectorDetailsShowing() )
560
		writeLines.push_back("ModSelectorDetails:");
460
		writeLines.push_back("ModSelectorDetails:");
561
	if ( !gui->IsAutoUpdate() )
461
	if ( !gui->IsAutoUpdate() )
562
		writeLines.push_back("NoAutoUpdate:");
462
		writeLines.push_back("NoAutoUpdate:");
563
	if ( gui->WindowState == FormWindowState::Normal )
463
	if ( gui->WindowState == FormWindowState::Normal )
564
	{
464
	{
565
		writeLines.push_back(CyString("ManagerSize:") + (long)gui->Size.Height + " " + (long)gui->Size.Width);
465
		writeLines.push_back(Utils::String("ManagerSize:") + (long)gui->Size.Height + " " + (long)gui->Size.Width);
566
		writeLines.push_back(CyString("ManagerPos:") + (long)gui->Location.X + " " + (long)gui->Location.Y);
466
		writeLines.push_back(Utils::String("ManagerPos:") + (long)gui->Location.X + " " + (long)gui->Location.Y);
567
	}
467
	}
568
	else
468
	else
569
	{
469
	{
570
		writeLines.push_back(CyString("ManagerPos:") + (long)gui->RestoreBounds.Location.X + " " + (long)gui->RestoreBounds.Location.Y);
470
		writeLines.push_back(Utils::String("ManagerPos:") + (long)gui->RestoreBounds.Location.X + " " + (long)gui->RestoreBounds.Location.Y);
571
		writeLines.push_back(CyString("ManagerSize:") + (long)gui->RestoreBounds.Size.Height + " " + (long)gui->RestoreBounds.Size.Width);
471
		writeLines.push_back(Utils::String("ManagerSize:") + (long)gui->RestoreBounds.Size.Height + " " + (long)gui->RestoreBounds.Size.Width);
572
	}
472
	}
573
 
473
 
574
	if ( gui->WindowState == FormWindowState::Maximized )
474
	if ( gui->WindowState == FormWindowState::Maximized )
575
		writeLines.push_back("ManagerMax:");
475
		writeLines.push_back("ManagerMax:");
576
	if ( gui->GetIgnoreJoy() )
476
	if ( gui->GetIgnoreJoy() )
577
		writeLines.push_back(CyString("IgnoreJoy:") + gui->GetIgnoreJoy());
477
		writeLines.push_back(Utils::String("IgnoreJoy:") + gui->GetIgnoreJoy());
578
 
478
 
579
	for ( int i = 0; i < gui->GetMaxTips(); i++ )
479
	for ( int i = 0; i < gui->GetMaxTips(); i++ )
580
	{
480
	{
581
		int tips = gui->GetTips(i);
481
		int tips = gui->GetTips(i);
582
		if ( tips == -1 )
482
		if ( tips == -1 )
583
			continue;
483
			continue;
584
		writeLines.push_back(CyString("Tips: ") + (long)i + " " + (long)tips);
484
		writeLines.push_back(Utils::String("Tips: ") + (long)i + " " + (long)tips);
585
	}
485
	}
586
 
486
 
587
	for ( SStringList *rm = restoreModified.Head(); rm; rm = rm->next ) {
487
	for ( SStringList *rm = restoreModified.Head(); rm; rm = rm->next ) {
588
		writeLines.push_back(CyString(";RestoreModified: &quot;) + rm->str);
488
		writeLines.push_back(";RestoreModified: &quot; + rm->str.ToString());
589
	}
489
	}
590
 
490
 
591
	// write settings
491
	// write settings
592
	configFile.WriteFile(&writeLines);
492
	configFile.writeFile(&writeLines);
593
 
493
 
594
	return 0;
494
	return 0;
595
}
495
}