Subversion Repositories spk

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
1 cycrow 1
#pragma once
2
 
3
#include "X3Data.h"
4
 
5
#include "ViewData.h"
6
#include "EZ_LCD.h"
7
#include "LCDDisplay.h"
8
 
9
#define LOGFILE		902
10
#define VERSION		"1.30"
11
#define DATE		"01/01/2012"
12
 
15 cycrow 13
#include "../../Direct3D-Hook/src/Hook/Direct3D-Hook.h"
1 cycrow 14
 
15
using namespace System;
16
 
17
namespace GameLauncher {
18
 
19
	using namespace System;
20
	using namespace System::ComponentModel;
21
	using namespace System::Collections;
22
	using namespace System::Windows::Forms;
23
	using namespace System::Data;
24
	using namespace System::Drawing;
25
 
26
	using namespace Microsoft::Win32;
27
	/// <summary>
28
	/// Summary for Form1
29
	///
30
	/// WARNING: If you change the name of this class, you will need to change the
31
	///          'Resource File Name' property for the managed resource compiler tool
32
	///          associated with all .resx files this class depends on.  Otherwise,
33
	///          the designers will not be able to interact properly with localized
34
	///          resources associated with this form.
35
	/// </summary>
36
	public ref class Form1 : public System::Windows::Forms::Form
37
	{
38
	public:
39
		Form1(System::String ^runGame, System::String ^arguments, System::String ^runManager)
40
		{
41
			InitializeComponent();
42
 
43
			m_sGame = runGame;
44
			m_sArgs = arguments;
45
			m_sManager = runManager;
46
 
47
			this->label3->Text = "Version: V" + VERSION + " (" + DATE + ")";
48
 
49
			this->gameDataToolStripMenuItem->Visible = false;
50
			m_bClosing = false;
51
			m_bGameClosed = true;
52
			m_bWaitingSteam = false;
53
			m_bRunSteam = false;
54
			m_bCheckProcess = false;
55
			m_bAutoClose = true;
56
			m_bAutoResume = true;
57
			m_bNoLCD = false;
58
			m_bResume = false;
59
			m_bClose = false;
60
			m_bUpdateLCD = true;
61
			m_bCustomGui = true;
62
			m_bGuiHooked = false;
63
			m_iGameLog = LOGFILE;
64
 
65
			// create the game data container
66
			m_pGameData = new CX3Data(CyStringFromSystemString(System::IO::FileInfo(System::Windows::Forms::Application::ExecutablePath).DirectoryName));
67
 
68
			// read the launchers settings
69
			RegistryKey ^searchKey = Registry::CurrentUser->OpenSubKey("Software\\Egosoft\\PluginManagerSettings");
70
			if ( searchKey )
71
			{
72
				if ( System::Convert::ToInt32(searchKey->GetValue("DontAutoResume")) )
73
					m_bAutoResume = false;
74
				if ( System::Convert::ToInt32(searchKey->GetValue("DontAutoClose")) )
75
					m_bAutoClose = false;
76
				if ( System::Convert::ToInt32(searchKey->GetValue("DontUpdateLCD")) )
77
					m_bUpdateLCD = false;
78
				if ( System::Convert::ToInt32(searchKey->GetValue("DontDoGUI")) )
79
					m_bCustomGui = false;
80
				if ( System::Convert::ToInt32(searchKey->GetValue("GameDataLog")) )
81
					m_iGameLog = System::Convert::ToInt32(searchKey->GetValue("GameDataLog"));
82
			}
83
 
84
			// update the UI
85
			this->ContextResume->Checked = m_bAutoResume;
86
			this->ContextAutoClose->Checked = m_bAutoClose;
87
			this->updateLCDToolStripMenuItem->Checked = m_bUpdateLCD;
88
			this->gUIOverlayToolStripMenuItem->Checked = m_bCustomGui;
89
			SetGameLogDisplay();
90
 
91
			this->AddGames();
92
 
93
			m_pLCD = NULL;
94
		}
95
 
96
		void SetGameLogDisplay()
97
		{
98
			CyString display = "Game Log: ";
99
			display += CyString((long)m_iGameLog).PadNumber(5);
100
			System::String ^Str = gcnew System::String(display.c_str());
101
			this->gameLogToolStripMenuItem->Text = Str;
102
		}
103
 
104
		bool Resume() 
105
		{ 
106
			if ( m_bResume )
107
				return true;
108
			return m_bAutoResume;
109
		}
110
 
111
		void AddGame(String ^dir, String ^name, String ^language)
112
		{
113
			if ( language )
114
				name = name + " (" + language + ")";
115
 
116
			dir = dir->Replace('/', '\\');
117
			String ^exe = dir->Substring(dir->LastIndexOf('\\') + 1);
118
			String ^baseDir = dir->Substring(0, dir->LastIndexOf('\\'));
119
			ToolStripMenuItem ^foundItem;
120
			for ( int i = 0; i < this->ContextGames->DropDownItems->Count; i++ )
121
			{
122
				if ( !String::Compare(this->ContextGames->DropDownItems[i]->Text, name) )
123
				{
124
					foundItem = cli::safe_cast<ToolStripMenuItem ^>(this->ContextGames->DropDownItems[i]);
125
					break;
126
				}
127
			}
128
 
129
 
130
			if ( foundItem )
131
			{
132
				if ( foundItem->Tag )
133
				{
134
					String ^foundDir = cli::safe_cast<String ^>(foundItem->Tag);
135
					int imagePos = this->imageList1->Images->IndexOfKey(exe);
136
					ToolStripMenuItem ^item = gcnew ToolStripMenuItem(foundDir->Substring(0, foundDir->LastIndexOf('\\')), (imagePos == -1) ? nullptr : this->imageList1->Images[imagePos], gcnew EventHandler(this, &Form1::LaunchGameEvent));
137
					item->Tag = foundItem->Tag;
138
					foundItem->DropDownItems->Add(item);
139
					foundItem->Tag = nullptr;
140
				}
141
				int imagePos = this->imageList1->Images->IndexOfKey(exe);
142
				ToolStripMenuItem ^item = gcnew ToolStripMenuItem(baseDir, (imagePos == -1) ? nullptr : this->imageList1->Images[imagePos], gcnew EventHandler(this, &Form1::LaunchGameEvent));
143
				item->Tag = dir;
144
				foundItem->DropDownItems->Add(item);
145
			}
146
			else
147
			{
148
				int imagePos = this->imageList1->Images->IndexOfKey(exe);
149
				ToolStripMenuItem ^item = gcnew ToolStripMenuItem(name, (imagePos == -1) ? nullptr : this->imageList1->Images[imagePos], gcnew EventHandler(this, &Form1::LaunchGameEvent));
150
				item->Tag = dir;
151
				this->ContextGames->DropDownItems->Add(item);
152
			}
153
		}
154
 
155
		void SetLogDirForGame(System::String ^gameExe)
156
		{
157
			gameExe = System::IO::FileInfo(gameExe).Name;
158
 
159
			System::String ^mydoc = Environment::GetFolderPath(Environment::SpecialFolder::Personal );
160
			if ( IO::File::Exists(mydoc + "\\Egosoft\\pluginmanager.dat") )
161
			{
162
				try {
163
					cli::array<String ^> ^lines = IO::File::ReadAllLines(mydoc + "\\Egosoft\\pluginmanager.dat");
164
					if ( lines && lines->Length )
165
					{
166
						for ( int i = 0; i < lines->Length; i++ )
167
						{
168
							int pos = lines[i]->IndexOf(":");
169
							if ( pos == -1 )
170
								continue;
171
							if ( String::Compare(lines[i]->Substring(0, pos), "GameLog") )
172
								continue;
173
							String ^dir = lines[i]->Substring(pos + 1);
174
							cli::array<String ^> ^parts = dir->Split('|');
175
							if ( parts )
176
							{
177
								// no language
178
								String ^name;
179
								if ( parts->Length >= 2 )
180
								{
181
									name = System::IO::FileInfo(parts[1]).Name;
182
									if ( name == gameExe )
183
									{
184
										m_sLogDir = parts[0];
185
										break;
186
									}
187
								}
188
								else
189
									continue;
190
							}
191
						}
192
					}
193
				}
194
				catch (IO::IOException ^) { }
195
				catch (System::Exception ^) {}
196
			}
197
		}
198
 
199
		String ^GetGameName(String ^exe)
200
		{
201
			// read the plugin manager file
202
			System::String ^mydoc = Environment::GetFolderPath(Environment::SpecialFolder::Personal );
203
			if ( IO::File::Exists(mydoc + "\\Egosoft\\pluginmanager.dat") )
204
			{
205
				try {
206
					cli::array<String ^> ^lines = IO::File::ReadAllLines(mydoc + "\\Egosoft\\pluginmanager.dat");
207
					if ( lines && lines->Length )
208
					{
209
						for ( int i = 0; i < lines->Length; i++ )
210
						{
211
							int pos = lines[i]->IndexOf(":");
212
							if ( pos == -1 )
213
								continue;
214
							if ( String::Compare(lines[i]->Substring(0, pos), "DirExe") )
215
								continue;
216
							String ^dir = lines[i]->Substring(pos + 1);
217
							cli::array<String ^> ^parts = dir->Split('|');
218
							if ( parts )
219
							{
220
								// no language
221
								String ^language;
222
								String ^dir;
223
								String ^name;
224
								if ( parts->Length == 2 )
225
								{
226
									dir = parts[1];
227
									name = parts[0];
228
								}
229
								else if ( parts->Length > 2 )
230
								{
231
									language = parts[0];
232
									name = parts[1];
233
									dir = parts[2];
234
								}
235
								else
236
									continue;
237
 
238
								if ( String::Compare(IO::FileInfo(dir).FullName, IO::FileInfo(exe).FullName, true) == 0 )
239
								{
240
									if ( language ) return name + " (" + language + ")";
241
									return name;
242
								}
243
							}
244
						}
245
					}
246
				}
247
				catch (IO::IOException ^) { }
248
				catch (System::Exception ^) {}
249
			}
250
 
251
			return "";
252
		}
253
 
254
		void AddGames()
255
		{
256
			// read the plugin manager file
257
			System::String ^mydoc = Environment::GetFolderPath(Environment::SpecialFolder::Personal );
258
			if ( IO::File::Exists(mydoc + "\\Egosoft\\pluginmanager.dat") )
259
			{
260
				try {
261
					cli::array<String ^> ^lines = IO::File::ReadAllLines(mydoc + "\\Egosoft\\pluginmanager.dat");
262
					if ( lines && lines->Length )
263
					{
264
						for ( int i = 0; i < lines->Length; i++ )
265
						{
266
							int pos = lines[i]->IndexOf(":");
267
							if ( pos == -1 )
268
								continue;
269
							if ( String::Compare(lines[i]->Substring(0, pos), "DirExe") )
270
								continue;
271
							String ^dir = lines[i]->Substring(pos + 1);
272
							cli::array<String ^> ^parts = dir->Split('|');
273
							if ( parts )
274
							{
275
								// no language
276
								String ^language;
277
								String ^dir;
278
								String ^name;
279
								if ( parts->Length == 2 )
280
								{
281
									dir = parts[1];
282
									name = parts[0];
283
								}
284
								else if ( parts->Length > 2 )
285
								{
286
									language = parts[0];
287
									name = parts[1];
288
									dir = parts[2];
289
								}
290
								else
291
									continue;
292
 
293
								this->AddGame(dir, name, language);
294
							}
295
						}
296
					}
297
				}
298
				catch (IO::IOException ^) { }
299
				catch (System::Exception ^) {}
300
			}
301
		}
302
 
303
	private: System::Windows::Forms::ToolStripMenuItem^  resumeManagerToolStripMenuItem;
304
	public: 
305
	private: System::Windows::Forms::ToolStripSeparator^  toolStripSeparator1;
306
 
307
	protected:
308
private: System::Windows::Forms::ToolStripMenuItem^  ContextGames;
309
protected: 
310
private: System::Windows::Forms::ToolStripSeparator^  toolStripSeparator2;
311
private: System::Windows::Forms::ToolStripMenuItem^  settingsToolStripMenuItem;
312
private: System::Windows::Forms::ToolStripMenuItem^  ContextResume;
313
private: System::Windows::Forms::ToolStripMenuItem^  ContextAutoClose;
314
private: System::Windows::Forms::Timer^  timer1;
315
private: System::Windows::Forms::ImageList^  imageList1;
316
private: System::Windows::Forms::Timer^  timerGameData;
317
 
318
		bool	m_bResume;
319
		bool	m_bClose;
320
		bool	m_bAutoResume;
321
		bool	m_bCheckProcess;
322
		bool	m_bAutoClose;
323
		bool	m_bGameClosed;
324
		bool	m_bUpdateLCD;
325
		bool	m_bCustomGui;
326
		bool	m_bGuiHooked;
327
private: System::Windows::Forms::ToolStripSeparator^  toolStripSeparator3;
328
private: System::Windows::Forms::ToolStripMenuItem^  gameLogToolStripMenuItem;
329
private: System::Windows::Forms::ToolStripMenuItem^  gameDataToolStripMenuItem;
330
private: System::Windows::Forms::ToolStripMenuItem^  updateLCDToolStripMenuItem;
331
private: System::Windows::Forms::ToolStripMenuItem^  aboutToolStripMenuItem;
332
private: System::Windows::Forms::ToolStripSeparator^  toolStripSeparator4;
333
private: System::Windows::Forms::Label^  label1;
334
private: System::Windows::Forms::Label^  label2;
335
private: System::Windows::Forms::Label^  label3;
336
private: System::Windows::Forms::LinkLabel^  linkLabel1;
337
private: System::Windows::Forms::Timer^  timerCheckGame;
338
private: System::Windows::Forms::ToolStripMenuItem^  gUIOverlayToolStripMenuItem;
339
		 bool	m_bNoLCD;
340
 
341
		void ParseNewData(bool updated)
342
		{
343
			if ( m_bUpdateLCD && m_pLCD )
344
			{
345
				m_pLCD->UpdateDisplay(updated);
346
			}
347
		}
348
 
349
		void StartGame(String ^game, String ^args, String ^name)
350
		{
351
			if ( !game )
352
				return;
353
			System::Diagnostics::ProcessStartInfo ^info = gcnew System::Diagnostics::ProcessStartInfo(game);
354
			info->WorkingDirectory = System::IO::FileInfo(game).DirectoryName;
355
			m_bRunSteam = game->Contains("steamapps");
356
			m_sGameRunExe = System::IO::FileInfo(game).Name;
357
			m_sGameName = name;
358
			m_bWaitingSteam = m_bRunSteam;
359
			info->Arguments = args;
360
			info->UseShellExecute = false;
361
			info->WindowStyle = System::Diagnostics::ProcessWindowStyle::Normal;
362
			System::Diagnostics::Process ^process = gcnew System::Diagnostics::Process;
363
			process->StartInfo = info;
364
			process->StartInfo->CreateNoWindow = true;
365
			process->EnableRaisingEvents = true;
366
			process->Exited += gcnew EventHandler(this, &Form1::ProgramClosedEvent);
367
 
368
			// setup game to read log files
369
			SetLogDirForGame(game);
370
			m_pGameData->Reset();
371
			m_pGameData->SetGameName(CyStringFromSystemString(name));
372
			m_pGameData->SetGameDirectory(CyStringFromSystemString(System::IO::FileInfo(game).DirectoryName));
373
			m_bGameClosed = false;
374
 
375
			m_bGuiHooked = false;
376
			if ( m_bCustomGui )
377
			{
378
				if ( IO::File::Exists(info->WorkingDirectory + "\\X-Gui.dll") || IO::File::Exists(IO::FileInfo(System::Windows::Forms::Application::ExecutablePath).DirectoryName + "\\X-Gui.dll") )
379
				{
380
					RegistryKey ^searchKey = Registry::CurrentUser->CreateSubKey("Software\\Egosoft\\XUniverseGame-Hook");
381
					if ( searchKey )
382
					{
383
						searchKey->SetValue("", System::IO::FileInfo(game).Name);
384
						searchKey->SetValue("LogDir", m_sLogDir);
385
						searchKey->SetValue("GameDir", System::IO::FileInfo(game).DirectoryName);
386
						InstallHook();
387
						m_bGuiHooked = true;
388
					}
389
				}
390
			}
391
 
392
			// start the game
393
			process->Start();
394
			this->ContextGames->Visible = false;
395
			this->gameDataToolStripMenuItem->Visible = true;
396
 
397
			// check for LCD
398
		    CEzLcd* pEzlcd = new CEzLcd();
399
		    // Have it initialize itself
400
			if ( pEzlcd->InitYourself(_T("X-Universe LCD Display"), false, false) == S_OK )
401
			{
402
				if ( m_pLCD ) delete m_pLCD;
403
				m_pLCD = new CLCDDisplay(pEzlcd, m_pGameData);
404
			}
405
			else
406
			{
407
				this->updateLCDToolStripMenuItem->Visible = false;
408
				delete pEzlcd;
409
			}
410
 
411
			timerGameData->Start();
412
		}
413
 
414
		void EndGame()
415
		{
416
			timerGameData->Stop();
417
			this->gameDataToolStripMenuItem->Visible = false;
418
			this->ContextGames->Visible = true;
419
 
420
			if ( m_pLCD ) delete m_pLCD;
421
			m_pLCD = NULL;
422
 
423
			CyString logfile = CyStringFromSystemString(m_sLogDir);
424
			logfile += "/log";
425
			logfile += CyString((long)m_iGameLog).PadNumber(5);
426
			logfile += ".txt";
427
			String ^sLog = SystemStringFromCyString(logfile);
428
			System::IO::File::Delete(sLog);
429
 
430
			// unhook the gui
431
			if ( m_bGuiHooked )
432
			{
433
				RemoveHook();
434
				m_bGuiHooked = false;
435
			}
436
 
437
			if ( m_bAutoClose )
438
			{
439
				m_bClosing = true;
440
				this->Close();
441
			}
442
		}
443
 
444
		void LaunchManager(bool advanced)
445
		{
446
			 if ( !m_sManager || !m_sManager->Length )
447
				 MessageBox::Show(this, "Unable to run the Plugin Manager, cant find exe", "Unable to Run", MessageBoxButtons::OK, MessageBoxIcon::Error);
448
			 else
449
			 {
450
				System::Diagnostics::ProcessStartInfo ^info = gcnew System::Diagnostics::ProcessStartInfo(m_sManager);
451
				info->WorkingDirectory = System::IO::FileInfo(m_sManager).DirectoryName;
452
				info->UseShellExecute = false;
453
				info->WindowStyle = System::Diagnostics::ProcessWindowStyle::Normal;
454
				info->Arguments = "\"--fromlauncher\"";
455
				if ( advanced )
456
					info->Arguments += " \"--advanced\"";
457
				System::Diagnostics::Process ^process = System::Diagnostics::Process::Start(info);
458
			 }
459
		}
460
 
461
		/// <summary>
462
		/// Clean up any resources being used.
463
		/// </summary>
464
		~Form1()
465
		{
466
			if (components)
467
			{
468
				delete components;
469
			}
470
			delete m_pGameData;
471
			if ( m_pLCD ) delete m_pLCD;
472
 
473
			if ( m_bGuiHooked )
474
			{
475
				RemoveHook();
476
				m_bGuiHooked = false;
477
			}
478
 
479
		}
480
	private: System::Windows::Forms::NotifyIcon^  notifyIcon1;
481
	protected: 
482
		bool	m_bWaitingSteam;
483
		bool	m_bRunSteam;
484
		int		m_iGameLog;
485
		String ^m_sGameRunExe;
486
		System::String ^m_sGameName;
487
		System::String ^m_sGame;
488
		System::String ^m_sManager;
489
		System::String ^m_sArgs;
490
		System::String ^m_sLogDir;
491
		CLCDDisplay *m_pLCD;
492
		CX3Data *m_pGameData;
493
		bool	m_bClosing;
494
	private: System::Windows::Forms::ContextMenuStrip^  contextMenuStrip1;
495
	protected: 
496
	private: System::Windows::Forms::ToolStripMenuItem^  closeToolStripMenuItem;
497
	private: System::ComponentModel::IContainer^  components;
498
 
499
	private:
500
		/// <summary>
501
		/// Required designer variable.
502
		/// </summary>
503
 
504
 
505
#pragma region Windows Form Designer generated code
506
		/// <summary>
507
		/// Required method for Designer support - do not modify
508
		/// the contents of this method with the code editor.
509
		/// </summary>
510
		void InitializeComponent(void)
511
		{
512
			this->components = (gcnew System::ComponentModel::Container());
513
			System::ComponentModel::ComponentResourceManager^  resources = (gcnew System::ComponentModel::ComponentResourceManager(Form1::typeid));
514
			this->notifyIcon1 = (gcnew System::Windows::Forms::NotifyIcon(this->components));
515
			this->contextMenuStrip1 = (gcnew System::Windows::Forms::ContextMenuStrip(this->components));
516
			this->aboutToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
517
			this->toolStripSeparator4 = (gcnew System::Windows::Forms::ToolStripSeparator());
518
			this->settingsToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
519
			this->ContextResume = (gcnew System::Windows::Forms::ToolStripMenuItem());
520
			this->ContextAutoClose = (gcnew System::Windows::Forms::ToolStripMenuItem());
521
			this->toolStripSeparator3 = (gcnew System::Windows::Forms::ToolStripSeparator());
522
			this->gameLogToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
523
			this->updateLCDToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
524
			this->resumeManagerToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
525
			this->toolStripSeparator1 = (gcnew System::Windows::Forms::ToolStripSeparator());
526
			this->ContextGames = (gcnew System::Windows::Forms::ToolStripMenuItem());
527
			this->gameDataToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
528
			this->toolStripSeparator2 = (gcnew System::Windows::Forms::ToolStripSeparator());
529
			this->closeToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
530
			this->timer1 = (gcnew System::Windows::Forms::Timer(this->components));
531
			this->imageList1 = (gcnew System::Windows::Forms::ImageList(this->components));
532
			this->timerGameData = (gcnew System::Windows::Forms::Timer(this->components));
533
			this->label1 = (gcnew System::Windows::Forms::Label());
534
			this->label2 = (gcnew System::Windows::Forms::Label());
535
			this->label3 = (gcnew System::Windows::Forms::Label());
536
			this->linkLabel1 = (gcnew System::Windows::Forms::LinkLabel());
537
			this->timerCheckGame = (gcnew System::Windows::Forms::Timer(this->components));
538
			this->gUIOverlayToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
539
			this->contextMenuStrip1->SuspendLayout();
540
			this->SuspendLayout();
541
			// 
542
			// notifyIcon1
543
			// 
544
			this->notifyIcon1->ContextMenuStrip = this->contextMenuStrip1;
545
			this->notifyIcon1->Icon = (cli::safe_cast<System::Drawing::Icon^  >(resources->GetObject(L"notifyIcon1.Icon")));
546
			this->notifyIcon1->Text = L"X-Universe Game Launcher";
547
			this->notifyIcon1->Visible = true;
548
			this->notifyIcon1->DoubleClick += gcnew System::EventHandler(this, &Form1::notifyIcon1_DoubleClick);
549
			// 
550
			// contextMenuStrip1
551
			// 
552
			this->contextMenuStrip1->Items->AddRange(gcnew cli::array< System::Windows::Forms::ToolStripItem^  >(9) {this->aboutToolStripMenuItem, 
553
				this->toolStripSeparator4, this->settingsToolStripMenuItem, this->resumeManagerToolStripMenuItem, this->toolStripSeparator1, 
554
				this->ContextGames, this->gameDataToolStripMenuItem, this->toolStripSeparator2, this->closeToolStripMenuItem});
555
			this->contextMenuStrip1->Name = L"contextMenuStrip1";
556
			this->contextMenuStrip1->Size = System::Drawing::Size(164, 176);
557
			// 
558
			// aboutToolStripMenuItem
559
			// 
560
			this->aboutToolStripMenuItem->Name = L"aboutToolStripMenuItem";
561
			this->aboutToolStripMenuItem->Size = System::Drawing::Size(163, 22);
562
			this->aboutToolStripMenuItem->Text = L"About";
563
			this->aboutToolStripMenuItem->Click += gcnew System::EventHandler(this, &Form1::aboutToolStripMenuItem_Click);
564
			// 
565
			// toolStripSeparator4
566
			// 
567
			this->toolStripSeparator4->Name = L"toolStripSeparator4";
568
			this->toolStripSeparator4->Size = System::Drawing::Size(160, 6);
569
			// 
570
			// settingsToolStripMenuItem
571
			// 
572
			this->settingsToolStripMenuItem->DropDownItems->AddRange(gcnew cli::array< System::Windows::Forms::ToolStripItem^  >(6) {this->ContextResume, 
573
				this->ContextAutoClose, this->toolStripSeparator3, this->gameLogToolStripMenuItem, this->updateLCDToolStripMenuItem, this->gUIOverlayToolStripMenuItem});
574
			this->settingsToolStripMenuItem->Name = L"settingsToolStripMenuItem";
575
			this->settingsToolStripMenuItem->Size = System::Drawing::Size(163, 22);
576
			this->settingsToolStripMenuItem->Text = L"Settings";
577
			// 
578
			// ContextResume
579
			// 
580
			this->ContextResume->Checked = true;
581
			this->ContextResume->CheckOnClick = true;
582
			this->ContextResume->CheckState = System::Windows::Forms::CheckState::Checked;
583
			this->ContextResume->Name = L"ContextResume";
584
			this->ContextResume->Size = System::Drawing::Size(152, 22);
585
			this->ContextResume->Text = L"Auto Resume";
586
			this->ContextResume->CheckedChanged += gcnew System::EventHandler(this, &Form1::ContextResume_CheckedChanged);
587
			// 
588
			// ContextAutoClose
589
			// 
590
			this->ContextAutoClose->Checked = true;
591
			this->ContextAutoClose->CheckOnClick = true;
592
			this->ContextAutoClose->CheckState = System::Windows::Forms::CheckState::Checked;
593
			this->ContextAutoClose->Name = L"ContextAutoClose";
594
			this->ContextAutoClose->Size = System::Drawing::Size(152, 22);
595
			this->ContextAutoClose->Text = L"Auto Close";
596
			this->ContextAutoClose->Click += gcnew System::EventHandler(this, &Form1::ContextAutoClose_Click);
597
			// 
598
			// toolStripSeparator3
599
			// 
600
			this->toolStripSeparator3->Name = L"toolStripSeparator3";
601
			this->toolStripSeparator3->Size = System::Drawing::Size(149, 6);
602
			// 
603
			// gameLogToolStripMenuItem
604
			// 
605
			this->gameLogToolStripMenuItem->Name = L"gameLogToolStripMenuItem";
606
			this->gameLogToolStripMenuItem->Size = System::Drawing::Size(152, 22);
607
			this->gameLogToolStripMenuItem->Text = L"Game Log";
608
			this->gameLogToolStripMenuItem->Click += gcnew System::EventHandler(this, &Form1::gameLogToolStripMenuItem_Click);
609
			// 
610
			// updateLCDToolStripMenuItem
611
			// 
612
			this->updateLCDToolStripMenuItem->Checked = true;
613
			this->updateLCDToolStripMenuItem->CheckOnClick = true;
614
			this->updateLCDToolStripMenuItem->CheckState = System::Windows::Forms::CheckState::Checked;
615
			this->updateLCDToolStripMenuItem->Name = L"updateLCDToolStripMenuItem";
616
			this->updateLCDToolStripMenuItem->Size = System::Drawing::Size(152, 22);
617
			this->updateLCDToolStripMenuItem->Text = L"Update LCD";
618
			this->updateLCDToolStripMenuItem->Click += gcnew System::EventHandler(this, &Form1::updateLCDToolStripMenuItem_Click);
619
			// 
620
			// resumeManagerToolStripMenuItem
621
			// 
622
			this->resumeManagerToolStripMenuItem->Name = L"resumeManagerToolStripMenuItem";
623
			this->resumeManagerToolStripMenuItem->Size = System::Drawing::Size(163, 22);
624
			this->resumeManagerToolStripMenuItem->Text = L"Launch Manager";
625
			this->resumeManagerToolStripMenuItem->Click += gcnew System::EventHandler(this, &Form1::resumeManagerToolStripMenuItem_Click);
626
			// 
627
			// toolStripSeparator1
628
			// 
629
			this->toolStripSeparator1->Name = L"toolStripSeparator1";
630
			this->toolStripSeparator1->Size = System::Drawing::Size(160, 6);
631
			// 
632
			// ContextGames
633
			// 
634
			this->ContextGames->Name = L"ContextGames";
635
			this->ContextGames->Size = System::Drawing::Size(163, 22);
636
			this->ContextGames->Text = L"Launch Game";
637
			// 
638
			// gameDataToolStripMenuItem
639
			// 
640
			this->gameDataToolStripMenuItem->Name = L"gameDataToolStripMenuItem";
641
			this->gameDataToolStripMenuItem->Size = System::Drawing::Size(163, 22);
642
			this->gameDataToolStripMenuItem->Text = L"View Game Data";
643
			this->gameDataToolStripMenuItem->Click += gcnew System::EventHandler(this, &Form1::gameDataToolStripMenuItem_Click);
644
			// 
645
			// toolStripSeparator2
646
			// 
647
			this->toolStripSeparator2->Name = L"toolStripSeparator2";
648
			this->toolStripSeparator2->Size = System::Drawing::Size(160, 6);
649
			// 
650
			// closeToolStripMenuItem
651
			// 
652
			this->closeToolStripMenuItem->Name = L"closeToolStripMenuItem";
653
			this->closeToolStripMenuItem->Size = System::Drawing::Size(163, 22);
654
			this->closeToolStripMenuItem->Text = L"Close";
655
			this->closeToolStripMenuItem->Click += gcnew System::EventHandler(this, &Form1::closeToolStripMenuItem_Click);
656
			// 
657
			// timer1
658
			// 
659
			this->timer1->Enabled = true;
660
			this->timer1->Interval = 1000;
661
			this->timer1->Tick += gcnew System::EventHandler(this, &Form1::timer1_Tick);
662
			// 
663
			// imageList1
664
			// 
665
			this->imageList1->ImageStream = (cli::safe_cast<System::Windows::Forms::ImageListStreamer^  >(resources->GetObject(L"imageList1.ImageStream")));
666
			this->imageList1->TransparentColor = System::Drawing::Color::Transparent;
667
			this->imageList1->Images->SetKeyName(0, L"x3.exe");
668
			this->imageList1->Images->SetKeyName(1, L"x3tc.exe");
669
			this->imageList1->Images->SetKeyName(2, L"x2.exe");
670
			// 
671
			// timerGameData
672
			// 
673
			this->timerGameData->Tick += gcnew System::EventHandler(this, &Form1::timerGameData_Tick);
674
			// 
675
			// label1
676
			// 
677
			this->label1->Dock = System::Windows::Forms::DockStyle::Top;
678
			this->label1->Font = (gcnew System::Drawing::Font(L"Segoe Print", 14.25F, System::Drawing::FontStyle::Bold, System::Drawing::GraphicsUnit::Point, 
679
				static_cast<System::Byte>(0)));
680
			this->label1->Location = System::Drawing::Point(0, 0);
681
			this->label1->Name = L"label1";
682
			this->label1->Size = System::Drawing::Size(328, 49);
683
			this->label1->TabIndex = 1;
684
			this->label1->Text = L"X-Universe Game Launcher";
685
			this->label1->TextAlign = System::Drawing::ContentAlignment::MiddleCenter;
686
			// 
687
			// label2
688
			// 
689
			this->label2->Dock = System::Windows::Forms::DockStyle::Top;
690
			this->label2->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 12, System::Drawing::FontStyle::Italic, System::Drawing::GraphicsUnit::Point, 
691
				static_cast<System::Byte>(0)));
692
			this->label2->Location = System::Drawing::Point(0, 49);
693
			this->label2->Name = L"label2";
694
			this->label2->Size = System::Drawing::Size(328, 30);
695
			this->label2->TabIndex = 2;
696
			this->label2->Text = L"By Cycrow";
697
			this->label2->TextAlign = System::Drawing::ContentAlignment::MiddleCenter;
698
			// 
699
			// label3
700
			// 
701
			this->label3->Dock = System::Windows::Forms::DockStyle::Top;
702
			this->label3->Location = System::Drawing::Point(0, 79);
703
			this->label3->Name = L"label3";
704
			this->label3->Size = System::Drawing::Size(328, 30);
705
			this->label3->TabIndex = 3;
706
			this->label3->Text = L"Version: 1.00";
707
			this->label3->TextAlign = System::Drawing::ContentAlignment::MiddleCenter;
708
			// 
709
			// linkLabel1
710
			// 
711
			this->linkLabel1->Dock = System::Windows::Forms::DockStyle::Bottom;
712
			this->linkLabel1->Location = System::Drawing::Point(0, 109);
713
			this->linkLabel1->Name = L"linkLabel1";
714
			this->linkLabel1->Size = System::Drawing::Size(328, 34);
715
			this->linkLabel1->TabIndex = 4;
716
			this->linkLabel1->TabStop = true;
717
			this->linkLabel1->Text = L"http://cycrow.thexuniverse.us";
718
			this->linkLabel1->TextAlign = System::Drawing::ContentAlignment::MiddleCenter;
719
			this->linkLabel1->LinkClicked += gcnew System::Windows::Forms::LinkLabelLinkClickedEventHandler(this, &Form1::linkLabel1_LinkClicked);
720
			// 
721
			// timerCheckGame
722
			// 
723
			this->timerCheckGame->Enabled = true;
724
			this->timerCheckGame->Interval = 1000;
725
			this->timerCheckGame->Tick += gcnew System::EventHandler(this, &Form1::timerCheckGame_Tick);
726
			// 
727
			// gUIOverlayToolStripMenuItem
728
			// 
729
			this->gUIOverlayToolStripMenuItem->Checked = true;
730
			this->gUIOverlayToolStripMenuItem->CheckOnClick = true;
731
			this->gUIOverlayToolStripMenuItem->CheckState = System::Windows::Forms::CheckState::Checked;
732
			this->gUIOverlayToolStripMenuItem->Name = L"gUIOverlayToolStripMenuItem";
733
			this->gUIOverlayToolStripMenuItem->Size = System::Drawing::Size(152, 22);
734
			this->gUIOverlayToolStripMenuItem->Text = L"GUI Overlay";
735
			this->gUIOverlayToolStripMenuItem->Click += gcnew System::EventHandler(this, &Form1::gUIOverlayToolStripMenuItem_Click);
736
			// 
737
			// Form1
738
			// 
739
			this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
740
			this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
741
			this->ClientSize = System::Drawing::Size(328, 143);
742
			this->Controls->Add(this->linkLabel1);
743
			this->Controls->Add(this->label3);
744
			this->Controls->Add(this->label2);
745
			this->Controls->Add(this->label1);
746
			this->Icon = (cli::safe_cast<System::Drawing::Icon^  >(resources->GetObject(L"$this.Icon")));
747
			this->MaximizeBox = false;
748
			this->MinimizeBox = false;
749
			this->Name = L"Form1";
750
			this->Opacity = 0;
751
			this->ShowInTaskbar = false;
752
			this->SizeGripStyle = System::Windows::Forms::SizeGripStyle::Hide;
753
			this->Text = L"Game Launcher";
754
			this->WindowState = System::Windows::Forms::FormWindowState::Minimized;
755
			this->Load += gcnew System::EventHandler(this, &Form1::Form1_Load);
756
			this->FormClosing += gcnew System::Windows::Forms::FormClosingEventHandler(this, &Form1::Form1_FormClosing);
757
			this->contextMenuStrip1->ResumeLayout(false);
758
			this->ResumeLayout(false);
759
 
760
		}
761
#pragma endregion
762
	private: System::Void Form1_Load(System::Object^  sender, System::EventArgs^  e) {
763
				 this->StartGame(m_sGame, m_sArgs, GetGameName(m_sGame));
764
			 }
765
			 void ProgramClosedEvent(System::Object^  sender, System::EventArgs^  e) {
766
				 System::Diagnostics::Process ^process = cli::safe_cast<Diagnostics::Process ^>(sender);
767
				 process->WaitForExit();
768
 
769
				 m_bGameClosed = true;
770
				 if ( m_bRunSteam )
771
				 {
772
					 m_bCheckProcess = true;
773
					 m_bWaitingSteam = true;
774
					 m_bGameClosed = false;
775
				 }
776
				 else if ( m_bAutoClose )
777
				 {
778
					 m_bClose = true;
779
					 m_bWaitingSteam = false;
780
				 }
781
			 }
782
	private: System::Void closeToolStripMenuItem_Click(System::Object^  sender, System::EventArgs^  e) {
783
				 m_bClosing = true;
784
				 this->Close();
785
			 }
786
private: System::Void ContextResume_CheckedChanged(System::Object^  sender, System::EventArgs^  e) {
787
			m_bAutoResume = this->ContextResume->Checked;
788
			RegistryKey ^searchKey = Registry::CurrentUser->CreateSubKey("Software\\Egosoft\\PluginManagerSettings");
789
			if ( searchKey )
790
				searchKey->SetValue("DontAutoResume", (m_bAutoResume) ? 0 : 1);
791
		 }
792
private: System::Void resumeManagerToolStripMenuItem_Click(System::Object^  sender, System::EventArgs^  e) {
793
			 if ( m_bAutoClose )
794
			 {
795
				 m_bResume = true;
796
				this->Close();
797
			 }
798
			 else
799
				 LaunchManager(false);
800
		 }
801
private: System::Void notifyIcon1_DoubleClick(System::Object^  sender, System::EventArgs^  e) {
802
			 m_bResume = true;
803
			 if ( m_bAutoClose )
804
				this->Close();
805
		 }
806
private: System::Void LaunchGameEvent(System::Object^  sender, System::EventArgs^  e) {
807
			 ToolStripMenuItem ^item = cli::safe_cast<ToolStripMenuItem ^>(sender);
808
			 if ( item )
809
				 this->StartGame(cli::safe_cast<String ^>(item->Tag), "-noabout", item->Text);
810
		 }
811
private: System::Void ContextAutoClose_Click(System::Object^  sender, System::EventArgs^  e) {
812
			m_bAutoClose = this->ContextAutoClose->Checked;
813
			RegistryKey ^searchKey = Registry::CurrentUser->CreateSubKey("Software\\Egosoft\\PluginManagerSettings");
814
			if ( searchKey )
815
				searchKey->SetValue("DontAutoClose", (m_bAutoClose) ? 0 : 1);
816
		 }
817
private: System::Void timer1_Tick(System::Object^  sender, System::EventArgs^  e) {
818
			 if ( m_bClose )
819
				 this->Close();
820
			 else if ( m_bCheckProcess )
821
			 {
822
				 // check for the steam game
823
				 if ( m_sGameRunExe )
824
				 {
825
					 String ^name = m_sGameRunExe->Substring(0, m_sGameRunExe->IndexOf('.'));
826
					 cli::array<Diagnostics::Process ^> ^processes = Diagnostics::Process::GetProcessesByName(name);
827
					 if ( !processes || !processes->Length )
828
					 {
829
						 if ( !m_bWaitingSteam )
830
						 {
831
							 m_bCheckProcess = false;
832
							 this->EndGame();
833
						 }
834
					 }
835
					 // if steam, waiting for process to start before resuming
836
					 else if ( m_bWaitingSteam )
837
						 m_bWaitingSteam = false;
838
				 }
839
			 }
840
		 }
841
 
842
private: System::Void timerGameData_Tick(System::Object^  sender, System::EventArgs^  e) {
843
 
844
			 if ( m_bGameClosed )
845
			 {
846
				 this->EndGame();
847
				 return;
848
			 }
849
 
850
			 if ( m_pGameData->ReadFile(CyStringFromSystemString(m_sLogDir), CyString((long)m_iGameLog).PadNumber(5)) )
851
				 ParseNewData(true);
852
			 else
853
				 ParseNewData(false);
854
		 }
855
private: System::Void gameLogToolStripMenuItem_Click(System::Object^  sender, System::EventArgs^  e) {
856
			 InputBox ^input = gcnew InputBox("Enter the log file number to extract game data from", Convert::ToString(m_iGameLog));
857
			 if ( input->ShowDialog(this) == Windows::Forms::DialogResult::OK )
858
			 {
859
				 int log = System::Convert::ToInt32(input->GetInput());
860
				 if ( log <= 0 )
861
				 {
862
				 }
863
				 else
864
				 {
865
					m_iGameLog = log;
866
					RegistryKey ^searchKey = Registry::CurrentUser->CreateSubKey("Software\\Egosoft\\PluginManagerSettings");
867
					if ( searchKey )
868
						searchKey->SetValue("GameDataLog", m_iGameLog);
869
					SetGameLogDisplay();
870
				 }
871
			 }
872
		 }
873
private: System::Void gameDataToolStripMenuItem_Click(System::Object^  sender, System::EventArgs^  e) {
874
			 ViewData ^data = gcnew ViewData(m_pGameData, m_sGameName);
875
			 data->ShowDialog(this);
876
		 }
877
private: System::Void updateLCDToolStripMenuItem_Click(System::Object^  sender, System::EventArgs^  e) {
878
			m_bUpdateLCD = this->updateLCDToolStripMenuItem->Checked;
879
			RegistryKey ^searchKey = Registry::CurrentUser->CreateSubKey("Software\\Egosoft\\PluginManagerSettings");
880
			if ( searchKey )
881
				searchKey->SetValue("DontUpdateLCD", (m_bUpdateLCD) ? 0 : 1);
882
		 }
883
private: System::Void aboutToolStripMenuItem_Click(System::Object^  sender, System::EventArgs^  e) {
884
			 this->WindowState = Windows::Forms::FormWindowState::Normal;
885
			 this->Opacity = 1.0;
886
		 }
887
private: System::Void Form1_FormClosing(System::Object^  sender, System::Windows::Forms::FormClosingEventArgs^  e) {
888
			 if ( !m_bClosing )
889
			 {
890
				 this->WindowState = Windows::Forms::FormWindowState::Minimized;
891
				 this->Opacity = 0.0;
892
				 e->Cancel = true;
893
				 return;
894
			 }
895
		 }
896
private: System::Void linkLabel1_LinkClicked(System::Object^  sender, System::Windows::Forms::LinkLabelLinkClickedEventArgs^  e) {
897
			 Diagnostics::Process::Start(linkLabel1->Text);
898
		 }
899
private: System::Void timerCheckGame_Tick(System::Object^  sender, System::EventArgs^  e) {
900
		System::String ^mydoc = Environment::GetFolderPath(Environment::SpecialFolder::Personal );
901
		if ( System::IO::File::Exists(mydoc + "\\Egosoft\\launchgame.dat") )
902
		{
903
			System::String ^lines = System::IO::File::ReadAllText(mydoc + "\\Egosoft\\launchgame.dat");
904
			System::IO::File::Delete(mydoc + "\\Egosoft\\launchgame.dat");
905
			if ( lines )
906
			{
907
				System::String ^gameFile;
908
				System::String ^gameArgs;
909
 
910
				CyString strLines = CyStringFromSystemString(lines);
911
				int num;
912
				CyString *aLines = strLines.SplitToken("\n", &num);
913
				if ( num && aLines )
914
				{
915
					for ( int i = 0; i < num; i++ )
916
					{
917
						CyString l = aLines[i];
918
						l = l.Remove("\r");
919
						CyString first = l.GetToken(":", 1, 1);
920
						CyString rest = l.GetToken(":", 2);
921
						rest.RemoveFirstSpace();
922
 
923
						if ( first.Compare("File") )
924
							gameFile = SystemStringFromCyString(rest);
925
						else if ( first.Compare("Args") )
926
							gameArgs = SystemStringFromCyString(rest);
927
					}
928
 
929
					CLEANSPLIT(aLines, num);
930
				}
931
 
932
				if ( gameFile && gameFile->Length )
933
					this->StartGame(gameFile, gameArgs, GetGameName(gameFile));
934
			}
935
		}
936
		 }
937
private: System::Void gUIOverlayToolStripMenuItem_Click(System::Object^  sender, System::EventArgs^  e) {
938
			m_bCustomGui = this->gUIOverlayToolStripMenuItem->Checked;
939
			RegistryKey ^searchKey = Registry::CurrentUser->CreateSubKey("Software\\Egosoft\\PluginManagerSettings");
940
			if ( searchKey )
941
				searchKey->SetValue("DontDoGUI", (m_bCustomGui) ? 0 : 1);
942
		 }
943
};
944
}
945