Subversion Repositories spk

Rev

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

Rev 15 Rev 85
Line 1... Line 1...
1
#pragma once
1
#pragma once
2
 
2
 
3
#include "X3Data.h"
3
#include "../X3Data.h"
4
 
4
 
5
#include "ViewData.h"
5
#include "ViewData.h"
6
#include "EZ_LCD.h"
6
#include "EZ_LCD.h"
7
#include "LCDDisplay.h"
7
#include "../LCDDisplay.h"
8
 
8
 
9
#define LOGFILE		902
9
#define LOGFILE		902
10
#define VERSION		"1.30"
10
#define VERSION		"1.30"
11
#define DATE		"01/01/2012"
11
#define DATE		"01/01/2012"
12
 
12
 
Line 34... Line 34...
34
	///          resources associated with this form.
34
	///          resources associated with this form.
35
	/// </summary>
35
	/// </summary>
36
	public ref class Form1 : public System::Windows::Forms::Form
36
	public ref class Form1 : public System::Windows::Forms::Form
37
	{
37
	{
38
	public:
38
	public:
39
		Form1(System::String ^runGame, System::String ^arguments, System::String ^runManager)
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
 
40
 
96
		void SetGameLogDisplay()
41
		void SetGameLogDisplay()
97
		{
42
		{
98
			CyString display = "Game Log: ";
43
			CyString display = "Game Log: ";
99
			display += CyString((long)m_iGameLog).PadNumber(5);
44
			display += CyString((long)m_iGameLog).PadNumber(5);
100
			System::String ^Str = gcnew System::String(display.c_str());
45
			System::String ^Str = gcnew System::String(display.c_str());
101
			this->gameLogToolStripMenuItem->Text = Str;
46
			this->gameLogToolStripMenuItem->Text = Str;
102
		}
47
		}
103
 
48
 
104
		bool Resume() 
49
		bool Resume() 
105
		{ 
50
		{ 
106
			if ( m_bResume )
51
			if ( m_bResume )
107
				return true;
52
				return true;
108
			return m_bAutoResume;
53
			return m_bAutoResume;
Line 121... Line 66...
121
			{
66
			{
122
				if ( !String::Compare(this->ContextGames->DropDownItems[i]->Text, name) )
67
				if ( !String::Compare(this->ContextGames->DropDownItems[i]->Text, name) )
123
				{
68
				{
124
					foundItem = cli::safe_cast<ToolStripMenuItem ^>(this->ContextGames->DropDownItems[i]);
69
					foundItem = cli::safe_cast<ToolStripMenuItem ^>(this->ContextGames->DropDownItems[i]);
125
					break;
70
					break;
126
				}
71
				}
127
			}
72
			}
128
 
73
 
129
 
74
 
130
			if ( foundItem )
75
			if ( foundItem )
131
			{
76
			{
132
				if ( foundItem->Tag )
77
				if ( foundItem->Tag )
133
				{
78
				{
134
					String ^foundDir = cli::safe_cast<String ^>(foundItem->Tag);
79
					String ^foundDir = cli::safe_cast<String ^>(foundItem->Tag);
Line 151... Line 96...
151
				this->ContextGames->DropDownItems->Add(item);
96
				this->ContextGames->DropDownItems->Add(item);
152
			}
97
			}
153
		}
98
		}
154
 
99
 
155
		void SetLogDirForGame(System::String ^gameExe)
100
		void SetLogDirForGame(System::String ^gameExe)
156
		{
101
		{
157
			gameExe = System::IO::FileInfo(gameExe).Name;
102
			gameExe = System::IO::FileInfo(gameExe).Name;
158
 
103
 
159
			System::String ^mydoc = Environment::GetFolderPath(Environment::SpecialFolder::Personal );
104
			System::String ^mydoc = Environment::GetFolderPath(Environment::SpecialFolder::Personal );
160
			if ( IO::File::Exists(mydoc + "\\Egosoft\\pluginmanager.dat") )
105
			if ( IO::File::Exists(mydoc + "\\Egosoft\\pluginmanager.dat") )
161
			{
106
			{
162
				try {
107
				try {
163
					cli::array<String ^> ^lines = IO::File::ReadAllLines(mydoc + "\\Egosoft\\pluginmanager.dat");
108
					cli::array<String ^> ^lines = IO::File::ReadAllLines(mydoc + "\\Egosoft\\pluginmanager.dat");
164
					if ( lines && lines->Length )
109
					if ( lines && lines->Length )
165
					{
110
					{
166
						for ( int i = 0; i < lines->Length; i++ )
111
						for ( int i = 0; i < lines->Length; i++ )
Line 182... Line 127...
182
									if ( name == gameExe )
127
									if ( name == gameExe )
183
									{
128
									{
184
										m_sLogDir = parts[0];
129
										m_sLogDir = parts[0];
185
										break;
130
										break;
186
									}
131
									}
187
								}
132
								}
188
								else
133
								else
189
									continue;
134
									continue;
190
							}
135
							}
191
						}
136
						}
192
					}
137
					}
193
				}
138
				}
194
				catch (IO::IOException ^) { }
139
				catch (IO::IOException ^) { }
195
				catch (System::Exception ^) {}
140
				catch (System::Exception ^) {}
196
			}
141
			}
197
		}
142
		}
198
 
143
 
199
		String ^GetGameName(String ^exe)
144
		String ^GetGameName(String ^exe)
200
		{
145
		{
201
			// read the plugin manager file
146
			// read the plugin manager file
202
			System::String ^mydoc = Environment::GetFolderPath(Environment::SpecialFolder::Personal );
147
			System::String ^mydoc = Environment::GetFolderPath(Environment::SpecialFolder::Personal );
203
			if ( IO::File::Exists(mydoc + "\\Egosoft\\pluginmanager.dat") )
148
			if ( IO::File::Exists(mydoc + "\\Egosoft\\pluginmanager.dat") )
204
			{
149
			{
205
				try {
150
				try {
206
					cli::array<String ^> ^lines = IO::File::ReadAllLines(mydoc + "\\Egosoft\\pluginmanager.dat");
151
					cli::array<String ^> ^lines = IO::File::ReadAllLines(mydoc + "\\Egosoft\\pluginmanager.dat");
207
					if ( lines && lines->Length )
152
					if ( lines && lines->Length )
208
					{
153
					{
209
						for ( int i = 0; i < lines->Length; i++ )
154
						for ( int i = 0; i < lines->Length; i++ )
210
						{
155
						{
211
							int pos = lines[i]->IndexOf(":");
156
							int pos = lines[i]->IndexOf(":");
212
							if ( pos == -1 )
157
							if ( pos == -1 )
213
								continue;
158
								continue;
214
							if ( String::Compare(lines[i]->Substring(0, pos), "DirExe") )
159
							if ( String::Compare(lines[i]->Substring(0, pos), "DirExe") )
215
								continue;
160
								continue;
216
							String ^dir = lines[i]->Substring(pos + 1);
161
							String ^dir = lines[i]->Substring(pos + 1);
217
							cli::array<String ^> ^parts = dir->Split('|');
162
							cli::array<String ^> ^parts = dir->Split('|');
218
							if ( parts )
163
							if ( parts )
219
							{
164
							{
220
								// no language
165
								// no language
221
								String ^language;
166
								String ^language;
222
								String ^dir;
167
								String ^dir;
223
								String ^name;
168
								String ^name;
224
								if ( parts->Length == 2 )
169
								if ( parts->Length == 2 )
225
								{
170
								{
226
									dir = parts[1];
171
									dir = parts[1];
227
									name = parts[0];
172
									name = parts[0];
228
								}
173
								}
229
								else if ( parts->Length > 2 )
174
								else if ( parts->Length > 2 )
230
								{
175
								{
231
									language = parts[0];
176
									language = parts[0];
232
									name = parts[1];
177
									name = parts[1];
233
									dir = parts[2];
178
									dir = parts[2];
Line 344... Line 289...
344
			{
289
			{
345
				m_pLCD->UpdateDisplay(updated);
290
				m_pLCD->UpdateDisplay(updated);
346
			}
291
			}
347
		}
292
		}
348
 
293
 
349
		void StartGame(String ^game, String ^args, String ^name)
294
		void StartGame(String ^originalGame, String ^args, String ^name)
350
		{
295
		{
-
 
296
			System::String ^game = originalGame;
351
			if ( !game )
297
			if ( !game )
352
				return;
298
				return;
-
 
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
 
353
			System::Diagnostics::ProcessStartInfo ^info = gcnew System::Diagnostics::ProcessStartInfo(game);
305
			System::Diagnostics::ProcessStartInfo ^info = gcnew System::Diagnostics::ProcessStartInfo(game);
354
			info->WorkingDirectory = System::IO::FileInfo(game).DirectoryName;
306
			info->WorkingDirectory = System::IO::FileInfo(game).DirectoryName;
-
 
307
			
355
			m_bRunSteam = game->Contains("steamapps");
308
			m_bRunSteam = game->Contains("steamapps");
356
			m_sGameRunExe = System::IO::FileInfo(game).Name;
309
			m_sGameRunExe = System::IO::FileInfo(game).Name;
357
			m_sGameName = name;
310
			m_sGameName = name;
358
			m_bWaitingSteam = m_bRunSteam;
311
			m_bWaitingSteam = m_bRunSteam;
-
 
312
 
359
			info->Arguments = args;
313
			info->Arguments = args;
360
			info->UseShellExecute = false;
314
			info->UseShellExecute = false;
361
			info->WindowStyle = System::Diagnostics::ProcessWindowStyle::Normal;
315
			info->WindowStyle = System::Diagnostics::ProcessWindowStyle::Normal;
362
			System::Diagnostics::Process ^process = gcnew System::Diagnostics::Process;
316
			System::Diagnostics::Process ^process = gcnew System::Diagnostics::Process;
363
			process->StartInfo = info;
317
			process->StartInfo = info;
364
			process->StartInfo->CreateNoWindow = true;
318
			process->StartInfo->CreateNoWindow = true;
365
			process->EnableRaisingEvents = true;
319
			process->EnableRaisingEvents = true;
366
			process->Exited += gcnew EventHandler(this, &Form1::ProgramClosedEvent);
320
			process->Exited += gcnew EventHandler(this, &Form1::ProgramClosedEvent);
367
 
321
 
368
			// setup game to read log files
322
			// setup game to read log files
369
			SetLogDirForGame(game);
323
			SetLogDirForGame(originalGame);
370
			m_pGameData->Reset();
324
			m_pGameData->Reset();
371
			m_pGameData->SetGameName(CyStringFromSystemString(name));
325
			m_pGameData->SetGameName(CyStringFromSystemString(name));
372
			m_pGameData->SetGameDirectory(CyStringFromSystemString(System::IO::FileInfo(game).DirectoryName));
326
			m_pGameData->SetGameDirectory(CyStringFromSystemString(System::IO::FileInfo(game).DirectoryName));
373
			m_bGameClosed = false;
327
			m_bGameClosed = false;
374
 
328