Subversion Repositories spk

Rev

Rev 15 | Rev 105 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

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