Subversion Repositories spk

Rev

Rev 242 | Blame | Compare with Previous | Last modification | View Log | RSS feed

#pragma once

#include "../X3Data.h"

#include "ViewData.h"
#include "EZ_LCD.h"
#include "../LCDDisplay.h"

#define LOGFILE         902
#define VERSION         "1.32"
#define DATE            "08/08/2015"

#include "../../Direct3D-Hook/src/Hook/Direct3D-Hook.h"

using namespace System;

namespace GameLauncher {

        using namespace System;
        using namespace System::ComponentModel;
        using namespace System::Collections;
        using namespace System::Windows::Forms;
        using namespace System::Data;
        using namespace System::Drawing;

        using namespace Microsoft::Win32;
        /// <summary>
        /// Summary for Form1
        ///
        /// WARNING: If you change the name of this class, you will need to change the
        ///          'Resource File Name' property for the managed resource compiler tool
        ///          associated with all .resx files this class depends on.  Otherwise,
        ///          the designers will not be able to interact properly with localized
        ///          resources associated with this form.
        /// </summary>
        public ref class Form1 : public System::Windows::Forms::Form
        {
        public:
                Form1(System::String ^runGame, System::String ^arguments, System::String ^runManager);

                void SetGameLogDisplay()
                {
                        Utils::WString display = L"Game Log: ";
                        display += Utils::WString::PadNumber(m_iGameLog, 5);
                        System::String ^Str = gcnew System::String(display);
                        this->gameLogToolStripMenuItem->Text = Str;
                }

                bool Resume() 
                { 
                        if ( m_bResume )
                                return true;
                        return m_bAutoResume;
                }

                void AddGame(String ^dir, String ^name, String ^language)
                {
                        if ( language )
                                name = name + " (" + language + ")";

                        dir = dir->Replace(L'/', L'\\');
                        String ^exe = dir->Substring(dir->LastIndexOf('\\') + 1);
                        String ^baseDir = dir->Substring(0, dir->LastIndexOf('\\'));
                        ToolStripMenuItem ^foundItem;
                        for ( int i = 0; i < this->ContextGames->DropDownItems->Count; i++ )
                        {
                                if ( !String::Compare(this->ContextGames->DropDownItems[i]->Text, name) )
                                {
                                        foundItem = cli::safe_cast<ToolStripMenuItem ^>(this->ContextGames->DropDownItems[i]);
                                        break;
                                }
                        }


                        if ( foundItem )
                        {
                                if ( foundItem->Tag )
                                {
                                        String ^foundDir = cli::safe_cast<String ^>(foundItem->Tag);
                                        int imagePos = this->imageList1->Images->IndexOfKey(exe);
                                        ToolStripMenuItem ^item = gcnew ToolStripMenuItem(foundDir->Substring(0, foundDir->LastIndexOf('\\')), (imagePos == -1) ? nullptr : this->imageList1->Images[imagePos], gcnew EventHandler(this, &Form1::LaunchGameEvent));
                                        item->Tag = foundItem->Tag;
                                        foundItem->DropDownItems->Add(item);
                                        foundItem->Tag = nullptr;
                                }
                                int imagePos = this->imageList1->Images->IndexOfKey(exe);
                                ToolStripMenuItem ^item = gcnew ToolStripMenuItem(baseDir, (imagePos == -1) ? nullptr : this->imageList1->Images[imagePos], gcnew EventHandler(this, &Form1::LaunchGameEvent));
                                item->Tag = dir;
                                foundItem->DropDownItems->Add(item);
                        }
                        else
                        {
                                int imagePos = this->imageList1->Images->IndexOfKey(exe);
                                ToolStripMenuItem ^item = gcnew ToolStripMenuItem(name, (imagePos == -1) ? nullptr : this->imageList1->Images[imagePos], gcnew EventHandler(this, &Form1::LaunchGameEvent));
                                item->Tag = dir;
                                this->ContextGames->DropDownItems->Add(item);
                        }
                }

                void SetLogDirForGame(System::String ^gameExe)
                {
                        gameExe = System::IO::FileInfo(gameExe).Name;

                        System::String ^mydoc = Environment::GetFolderPath(Environment::SpecialFolder::Personal );
                        if ( IO::File::Exists(mydoc + "\\Egosoft\\pluginmanager.dat") )
                        {
                                try {
                                        cli::array<String ^> ^lines = IO::File::ReadAllLines(mydoc + "\\Egosoft\\pluginmanager.dat");
                                        if ( lines && lines->Length )
                                        {
                                                for ( int i = 0; i < lines->Length; i++ )
                                                {
                                                        int pos = lines[i]->IndexOf(":");
                                                        if ( pos == -1 )
                                                                continue;
                                                        if ( String::Compare(lines[i]->Substring(0, pos), "GameLog") )
                                                                continue;
                                                        String ^dir = lines[i]->Substring(pos + 1);
                                                        cli::array<String ^> ^parts = dir->Split('|');
                                                        if ( parts )
                                                        {
                                                                // no language
                                                                String ^name;
                                                                if ( parts->Length >= 2 )
                                                                {
                                                                        name = System::IO::FileInfo(parts[1]).Name;
                                                                        if ( name == gameExe )
                                                                        {
                                                                                m_sLogDir = parts[0];
                                                                                break;
                                                                        }
                                                                }
                                                                else
                                                                        continue;
                                                        }
                                                }
                                        }
                                }
                                catch (IO::IOException ^) { }
                                catch (System::Exception ^) {}
                        }
                }

                String ^GetGameName(String ^exe)
                {
                        // read the plugin manager file
                        System::String ^mydoc = Environment::GetFolderPath(Environment::SpecialFolder::Personal );
                        if ( IO::File::Exists(mydoc + "\\Egosoft\\pluginmanager.dat") )
                        {
                                try {
                                        cli::array<String ^> ^lines = IO::File::ReadAllLines(mydoc + "\\Egosoft\\pluginmanager.dat");
                                        if ( lines && lines->Length )
                                        {
                                                for ( int i = 0; i < lines->Length; i++ )
                                                {
                                                        int pos = lines[i]->IndexOf(":");
                                                        if ( pos == -1 )
                                                                continue;
                                                        if ( String::Compare(lines[i]->Substring(0, pos), "DirExe") )
                                                                continue;
                                                        String ^dir = lines[i]->Substring(pos + 1);
                                                        cli::array<String ^> ^parts = dir->Split('|');
                                                        if ( parts )
                                                        {
                                                                // no language
                                                                String ^language;
                                                                String ^dir;
                                                                String ^name;
                                                                if ( parts->Length == 2 )
                                                                {
                                                                        dir = parts[1];
                                                                        name = parts[0];
                                                                }
                                                                else if ( parts->Length > 2 )
                                                                {
                                                                        language = parts[0];
                                                                        name = parts[1];
                                                                        dir = parts[2];
                                                                }
                                                                else
                                                                        continue;

                                                                if ( String::Compare(IO::FileInfo(dir).FullName, IO::FileInfo(exe).FullName, true) == 0 )
                                                                {
                                                                        if ( language ) return name + " (" + language + ")";
                                                                        return name;
                                                                }
                                                        }
                                                }
                                        }
                                }
                                catch (IO::IOException ^) { }
                                catch (System::Exception ^) {}
                        }

                        return "";
                }

                void AddGames()
                {
                        // read the plugin manager file
                        System::String ^mydoc = Environment::GetFolderPath(Environment::SpecialFolder::Personal );
                        if ( IO::File::Exists(mydoc + "\\Egosoft\\pluginmanager.dat") )
                        {
                                try {
                                        cli::array<String ^> ^lines = IO::File::ReadAllLines(mydoc + "\\Egosoft\\pluginmanager.dat");
                                        if ( lines && lines->Length )
                                        {
                                                for ( int i = 0; i < lines->Length; i++ )
                                                {
                                                        int pos = lines[i]->IndexOf(":");
                                                        if ( pos == -1 )
                                                                continue;
                                                        if ( String::Compare(lines[i]->Substring(0, pos), "DirExe") )
                                                                continue;
                                                        String ^dir = lines[i]->Substring(pos + 1);
                                                        cli::array<String ^> ^parts = dir->Split('|');
                                                        if ( parts )
                                                        {
                                                                // no language
                                                                String ^language;
                                                                String ^dir;
                                                                String ^name;
                                                                if ( parts->Length == 2 )
                                                                {
                                                                        dir = parts[1];
                                                                        name = parts[0];
                                                                }
                                                                else if ( parts->Length > 2 )
                                                                {
                                                                        language = parts[0];
                                                                        name = parts[1];
                                                                        dir = parts[2];
                                                                }
                                                                else
                                                                        continue;

                                                                this->AddGame(dir, name, language);
                                                        }
                                                }
                                        }
                                }
                                catch (IO::IOException ^) { }
                                catch (System::Exception ^) {}
                        }
                }

        protected:
                void _launchManager(bool bAdvanced);


        private: System::Windows::Forms::ToolStripMenuItem^  resumeManagerToolStripMenuItem;
        public: 
        private: System::Windows::Forms::ToolStripSeparator^  toolStripSeparator1;

        protected:
private: System::Windows::Forms::ToolStripMenuItem^  ContextGames;
protected: 
private: System::Windows::Forms::ToolStripSeparator^  toolStripSeparator2;
private: System::Windows::Forms::ToolStripMenuItem^  settingsToolStripMenuItem;
private: System::Windows::Forms::ToolStripMenuItem^  ContextResume;
private: System::Windows::Forms::ToolStripMenuItem^  ContextAutoClose;
private: System::Windows::Forms::Timer^  timer1;
private: System::Windows::Forms::ImageList^  imageList1;
private: System::Windows::Forms::Timer^  timerGameData;

                bool    m_bResume;
                bool    m_bClose;
                bool    m_bAutoResume;
                bool    m_bCheckProcess;
                bool    m_bAutoClose;
                bool    m_bGameClosed;
                bool    m_bUpdateLCD;
                bool    m_bCustomGui;
                bool    m_bGuiHooked;
private: System::Windows::Forms::ToolStripSeparator^  toolStripSeparator3;
private: System::Windows::Forms::ToolStripMenuItem^  gameLogToolStripMenuItem;
private: System::Windows::Forms::ToolStripMenuItem^  gameDataToolStripMenuItem;
private: System::Windows::Forms::ToolStripMenuItem^  updateLCDToolStripMenuItem;
private: System::Windows::Forms::ToolStripMenuItem^  aboutToolStripMenuItem;
private: System::Windows::Forms::ToolStripSeparator^  toolStripSeparator4;
private: System::Windows::Forms::Label^  label1;
private: System::Windows::Forms::Label^  label2;
private: System::Windows::Forms::Label^  label3;
private: System::Windows::Forms::LinkLabel^  linkLabel1;
private: System::Windows::Forms::Timer^  timerCheckGame;
private: System::Windows::Forms::ToolStripMenuItem^  gUIOverlayToolStripMenuItem;
private: System::Windows::Forms::ToolStripMenuItem^  launchManagerAdvancedToolStripMenuItem;
                 bool   m_bNoLCD;

                void ParseNewData(bool updated)
                {
                        if ( m_bUpdateLCD && m_pLCD )
                        {
                                m_pLCD->UpdateDisplay(updated);
                        }
                }

                void StartGame(String ^originalGame, String ^args, String ^name)
                {
                        System::String ^game = originalGame;
                        if ( !game )
                                return;

                        String ^noSteamExe = System::IO::FileInfo(game).DirectoryName + "\\" + System::IO::Path::GetFileNameWithoutExtension(game) + "_n.exe";
                        if ( System::IO::File::Exists(noSteamExe) ) {
                                game = noSteamExe;
                        }

                        System::Diagnostics::ProcessStartInfo ^info = gcnew System::Diagnostics::ProcessStartInfo(game);
                        info->WorkingDirectory = System::IO::FileInfo(game).DirectoryName;
                        
                        m_bRunSteam = game->Contains("steamapps");
                        m_sGameRunExe = System::IO::FileInfo(game).Name;
                        m_sGameName = name;
                        m_bWaitingSteam = m_bRunSteam;

                        info->Arguments = args;
                        info->UseShellExecute = false;
                        info->WindowStyle = System::Diagnostics::ProcessWindowStyle::Normal;
                        System::Diagnostics::Process ^process = gcnew System::Diagnostics::Process;
                        process->StartInfo = info;
                        process->StartInfo->CreateNoWindow = true;
                        process->EnableRaisingEvents = true;
                        process->Exited += gcnew EventHandler(this, &Form1::ProgramClosedEvent);

                        // setup game to read log files
                        SetLogDirForGame(originalGame);
                        m_pGameData->Reset();
                        m_pGameData->setGameName(_WS(name));
                        m_pGameData->setGameDirectory(_WS(System::IO::FileInfo(game).DirectoryName));
                        m_bGameClosed = false;

                        m_bGuiHooked = false;
                        if ( m_bCustomGui )
                        {
                                if ( IO::File::Exists(info->WorkingDirectory + "\\X-Gui.dll") || IO::File::Exists(IO::FileInfo(System::Windows::Forms::Application::ExecutablePath).DirectoryName + "\\X-Gui.dll") )
                                {
                                        RegistryKey ^searchKey = Registry::CurrentUser->CreateSubKey("Software\\Egosoft\\XUniverseGame-Hook");
                                        if ( searchKey )
                                        {
                                                searchKey->SetValue("", System::IO::FileInfo(game).Name);
                                                searchKey->SetValue("LogDir", m_sLogDir);
                                                searchKey->SetValue("GameDir", System::IO::FileInfo(game).DirectoryName);
                                                InstallHook();
                                                m_bGuiHooked = true;
                                        }
                                }
                        }

                        // start the game
                        process->Start();
                        this->ContextGames->Visible = false;
                        this->gameDataToolStripMenuItem->Visible = true;

                        // check for LCD
                    CEzLcd* pEzlcd = new CEzLcd();
                    // Have it initialize itself
                        if ( pEzlcd->InitYourself(_T("X-Universe LCD Display"), false, false) == S_OK )
                        {
                                if ( m_pLCD ) delete m_pLCD;
                                m_pLCD = new CLCDDisplay(pEzlcd, m_pGameData);
                        }
                        else
                        {
                                this->updateLCDToolStripMenuItem->Visible = false;
                                delete pEzlcd;
                        }

                        timerGameData->Start();
                }

                void EndGame()
                {
                        timerGameData->Stop();
                        this->gameDataToolStripMenuItem->Visible = false;
                        this->ContextGames->Visible = true;

                        if ( m_pLCD ) delete m_pLCD;
                        m_pLCD = NULL;

                        Utils::WString logfile = _WS(m_sLogDir);
                        logfile += L"/log";
                        logfile += Utils::WString((long)m_iGameLog).padNumber(5);
                        logfile += L".txt";
                        String ^sLog = _US(logfile);
                        System::IO::File::Delete(sLog);

                        // unhook the gui
                        if ( m_bGuiHooked )
                        {
                                RemoveHook();
                                m_bGuiHooked = false;
                        }

                        if ( m_bAutoClose )
                        {
                                m_bClosing = true;
                                this->Close();
                        }
                }

                void LaunchManager(bool advanced)
                {
                         if ( !m_sManager || !m_sManager->Length )
                                 MessageBox::Show(this, "Unable to run the Plugin Manager, cant find exe", "Unable to Run", MessageBoxButtons::OK, MessageBoxIcon::Error);
                         else
                         {
                                System::Diagnostics::ProcessStartInfo ^info = gcnew System::Diagnostics::ProcessStartInfo(m_sManager);
                                info->WorkingDirectory = System::IO::FileInfo(m_sManager).DirectoryName;
                                info->UseShellExecute = false;
                                info->WindowStyle = System::Diagnostics::ProcessWindowStyle::Normal;
                                info->Arguments = "\"--fromlauncher\"";
                                if ( advanced )
                                        info->Arguments += " \"--advanced\"";
                                System::Diagnostics::Process ^process = System::Diagnostics::Process::Start(info);
                         }
                }

                /// <summary>
                /// Clean up any resources being used.
                /// </summary>
                ~Form1()
                {
                        if (components)
                        {
                                delete components;
                        }
                        delete m_pGameData;
                        if ( m_pLCD ) delete m_pLCD;

                        if ( m_bGuiHooked )
                        {
                                RemoveHook();
                                m_bGuiHooked = false;
                        }

                }
        private: System::Windows::Forms::NotifyIcon^  notifyIcon1;
        protected: 
                bool    m_bWaitingSteam;
                bool    m_bRunSteam;
                int             m_iGameLog;
                String ^m_sGameRunExe;
                System::String ^m_sGameName;
                System::String ^m_sGame;
                System::String ^m_sManager;
                System::String ^m_sArgs;
                System::String ^m_sLogDir;
                CLCDDisplay *m_pLCD;
                CX3Data *m_pGameData;
                bool    m_bClosing;
        private: System::Windows::Forms::ContextMenuStrip^  contextMenuStrip1;
        protected: 
        private: System::Windows::Forms::ToolStripMenuItem^  closeToolStripMenuItem;
        private: System::ComponentModel::IContainer^  components;

        private:
                /// <summary>
                /// Required designer variable.
                /// </summary>


#pragma region Windows Form Designer generated code
                /// <summary>
                /// Required method for Designer support - do not modify
                /// the contents of this method with the code editor.
                /// </summary>
                void InitializeComponent(void)
                {
                        this->components = (gcnew System::ComponentModel::Container());
                        System::ComponentModel::ComponentResourceManager^  resources = (gcnew System::ComponentModel::ComponentResourceManager(Form1::typeid));
                        this->notifyIcon1 = (gcnew System::Windows::Forms::NotifyIcon(this->components));
                        this->contextMenuStrip1 = (gcnew System::Windows::Forms::ContextMenuStrip(this->components));
                        this->aboutToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
                        this->toolStripSeparator4 = (gcnew System::Windows::Forms::ToolStripSeparator());
                        this->settingsToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
                        this->ContextResume = (gcnew System::Windows::Forms::ToolStripMenuItem());
                        this->ContextAutoClose = (gcnew System::Windows::Forms::ToolStripMenuItem());
                        this->toolStripSeparator3 = (gcnew System::Windows::Forms::ToolStripSeparator());
                        this->gameLogToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
                        this->updateLCDToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
                        this->gUIOverlayToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
                        this->resumeManagerToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
                        this->toolStripSeparator1 = (gcnew System::Windows::Forms::ToolStripSeparator());
                        this->ContextGames = (gcnew System::Windows::Forms::ToolStripMenuItem());
                        this->gameDataToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
                        this->toolStripSeparator2 = (gcnew System::Windows::Forms::ToolStripSeparator());
                        this->closeToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
                        this->timer1 = (gcnew System::Windows::Forms::Timer(this->components));
                        this->imageList1 = (gcnew System::Windows::Forms::ImageList(this->components));
                        this->timerGameData = (gcnew System::Windows::Forms::Timer(this->components));
                        this->label1 = (gcnew System::Windows::Forms::Label());
                        this->label2 = (gcnew System::Windows::Forms::Label());
                        this->label3 = (gcnew System::Windows::Forms::Label());
                        this->linkLabel1 = (gcnew System::Windows::Forms::LinkLabel());
                        this->timerCheckGame = (gcnew System::Windows::Forms::Timer(this->components));
                        this->launchManagerAdvancedToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
                        this->contextMenuStrip1->SuspendLayout();
                        this->SuspendLayout();
                        // 
                        // notifyIcon1
                        // 
                        this->notifyIcon1->ContextMenuStrip = this->contextMenuStrip1;
                        this->notifyIcon1->Icon = (cli::safe_cast<System::Drawing::Icon^  >(resources->GetObject(L"notifyIcon1.Icon")));
                        this->notifyIcon1->Text = L"X-Universe Game Launcher";
                        this->notifyIcon1->Visible = true;
                        this->notifyIcon1->DoubleClick += gcnew System::EventHandler(this, &Form1::notifyIcon1_DoubleClick);
                        // 
                        // contextMenuStrip1
                        // 
                        this->contextMenuStrip1->Items->AddRange(gcnew cli::array< System::Windows::Forms::ToolStripItem^  >(10) {this->aboutToolStripMenuItem, 
                                this->toolStripSeparator4, this->settingsToolStripMenuItem, this->resumeManagerToolStripMenuItem, this->launchManagerAdvancedToolStripMenuItem, 
                                this->toolStripSeparator1, this->ContextGames, this->gameDataToolStripMenuItem, this->toolStripSeparator2, this->closeToolStripMenuItem});
                        this->contextMenuStrip1->Name = L"contextMenuStrip1";
                        this->contextMenuStrip1->Size = System::Drawing::Size(228, 198);
                        // 
                        // aboutToolStripMenuItem
                        // 
                        this->aboutToolStripMenuItem->Name = L"aboutToolStripMenuItem";
                        this->aboutToolStripMenuItem->Size = System::Drawing::Size(227, 22);
                        this->aboutToolStripMenuItem->Text = L"About";
                        this->aboutToolStripMenuItem->Click += gcnew System::EventHandler(this, &Form1::aboutToolStripMenuItem_Click);
                        // 
                        // toolStripSeparator4
                        // 
                        this->toolStripSeparator4->Name = L"toolStripSeparator4";
                        this->toolStripSeparator4->Size = System::Drawing::Size(224, 6);
                        // 
                        // settingsToolStripMenuItem
                        // 
                        this->settingsToolStripMenuItem->DropDownItems->AddRange(gcnew cli::array< System::Windows::Forms::ToolStripItem^  >(6) {this->ContextResume, 
                                this->ContextAutoClose, this->toolStripSeparator3, this->gameLogToolStripMenuItem, this->updateLCDToolStripMenuItem, this->gUIOverlayToolStripMenuItem});
                        this->settingsToolStripMenuItem->Name = L"settingsToolStripMenuItem";
                        this->settingsToolStripMenuItem->Size = System::Drawing::Size(227, 22);
                        this->settingsToolStripMenuItem->Text = L"Settings";
                        // 
                        // ContextResume
                        // 
                        this->ContextResume->Checked = true;
                        this->ContextResume->CheckOnClick = true;
                        this->ContextResume->CheckState = System::Windows::Forms::CheckState::Checked;
                        this->ContextResume->Name = L"ContextResume";
                        this->ContextResume->Size = System::Drawing::Size(145, 22);
                        this->ContextResume->Text = L"Auto Resume";
                        this->ContextResume->CheckedChanged += gcnew System::EventHandler(this, &Form1::ContextResume_CheckedChanged);
                        // 
                        // ContextAutoClose
                        // 
                        this->ContextAutoClose->Checked = true;
                        this->ContextAutoClose->CheckOnClick = true;
                        this->ContextAutoClose->CheckState = System::Windows::Forms::CheckState::Checked;
                        this->ContextAutoClose->Name = L"ContextAutoClose";
                        this->ContextAutoClose->Size = System::Drawing::Size(145, 22);
                        this->ContextAutoClose->Text = L"Auto Close";
                        this->ContextAutoClose->Click += gcnew System::EventHandler(this, &Form1::ContextAutoClose_Click);
                        // 
                        // toolStripSeparator3
                        // 
                        this->toolStripSeparator3->Name = L"toolStripSeparator3";
                        this->toolStripSeparator3->Size = System::Drawing::Size(142, 6);
                        // 
                        // gameLogToolStripMenuItem
                        // 
                        this->gameLogToolStripMenuItem->Name = L"gameLogToolStripMenuItem";
                        this->gameLogToolStripMenuItem->Size = System::Drawing::Size(145, 22);
                        this->gameLogToolStripMenuItem->Text = L"Game Log";
                        this->gameLogToolStripMenuItem->Click += gcnew System::EventHandler(this, &Form1::gameLogToolStripMenuItem_Click);
                        // 
                        // updateLCDToolStripMenuItem
                        // 
                        this->updateLCDToolStripMenuItem->Checked = true;
                        this->updateLCDToolStripMenuItem->CheckOnClick = true;
                        this->updateLCDToolStripMenuItem->CheckState = System::Windows::Forms::CheckState::Checked;
                        this->updateLCDToolStripMenuItem->Name = L"updateLCDToolStripMenuItem";
                        this->updateLCDToolStripMenuItem->Size = System::Drawing::Size(145, 22);
                        this->updateLCDToolStripMenuItem->Text = L"Update LCD";
                        this->updateLCDToolStripMenuItem->Click += gcnew System::EventHandler(this, &Form1::updateLCDToolStripMenuItem_Click);
                        // 
                        // gUIOverlayToolStripMenuItem
                        // 
                        this->gUIOverlayToolStripMenuItem->Checked = true;
                        this->gUIOverlayToolStripMenuItem->CheckOnClick = true;
                        this->gUIOverlayToolStripMenuItem->CheckState = System::Windows::Forms::CheckState::Checked;
                        this->gUIOverlayToolStripMenuItem->Name = L"gUIOverlayToolStripMenuItem";
                        this->gUIOverlayToolStripMenuItem->Size = System::Drawing::Size(145, 22);
                        this->gUIOverlayToolStripMenuItem->Text = L"GUI Overlay";
                        this->gUIOverlayToolStripMenuItem->Click += gcnew System::EventHandler(this, &Form1::gUIOverlayToolStripMenuItem_Click);
                        // 
                        // resumeManagerToolStripMenuItem
                        // 
                        this->resumeManagerToolStripMenuItem->Name = L"resumeManagerToolStripMenuItem";
                        this->resumeManagerToolStripMenuItem->Size = System::Drawing::Size(227, 22);
                        this->resumeManagerToolStripMenuItem->Text = L"Launch Manager (Lite)";
                        this->resumeManagerToolStripMenuItem->Click += gcnew System::EventHandler(this, &Form1::resumeManagerToolStripMenuItem_Click);
                        // 
                        // toolStripSeparator1
                        // 
                        this->toolStripSeparator1->Name = L"toolStripSeparator1";
                        this->toolStripSeparator1->Size = System::Drawing::Size(224, 6);
                        // 
                        // ContextGames
                        // 
                        this->ContextGames->Name = L"ContextGames";
                        this->ContextGames->Size = System::Drawing::Size(227, 22);
                        this->ContextGames->Text = L"Launch Game";
                        // 
                        // gameDataToolStripMenuItem
                        // 
                        this->gameDataToolStripMenuItem->Name = L"gameDataToolStripMenuItem";
                        this->gameDataToolStripMenuItem->Size = System::Drawing::Size(227, 22);
                        this->gameDataToolStripMenuItem->Text = L"View Game Data";
                        this->gameDataToolStripMenuItem->Click += gcnew System::EventHandler(this, &Form1::gameDataToolStripMenuItem_Click);
                        // 
                        // toolStripSeparator2
                        // 
                        this->toolStripSeparator2->Name = L"toolStripSeparator2";
                        this->toolStripSeparator2->Size = System::Drawing::Size(224, 6);
                        // 
                        // closeToolStripMenuItem
                        // 
                        this->closeToolStripMenuItem->Name = L"closeToolStripMenuItem";
                        this->closeToolStripMenuItem->Size = System::Drawing::Size(227, 22);
                        this->closeToolStripMenuItem->Text = L"Close";
                        this->closeToolStripMenuItem->Click += gcnew System::EventHandler(this, &Form1::closeToolStripMenuItem_Click);
                        // 
                        // timer1
                        // 
                        this->timer1->Enabled = true;
                        this->timer1->Interval = 1000;
                        this->timer1->Tick += gcnew System::EventHandler(this, &Form1::timer1_Tick);
                        // 
                        // imageList1
                        // 
                        this->imageList1->ImageStream = (cli::safe_cast<System::Windows::Forms::ImageListStreamer^  >(resources->GetObject(L"imageList1.ImageStream")));
                        this->imageList1->TransparentColor = System::Drawing::Color::Transparent;
                        this->imageList1->Images->SetKeyName(0, L"x3.exe");
                        this->imageList1->Images->SetKeyName(1, L"x3tc.exe");
                        this->imageList1->Images->SetKeyName(2, L"x2.exe");
                        // 
                        // timerGameData
                        // 
                        this->timerGameData->Tick += gcnew System::EventHandler(this, &Form1::timerGameData_Tick);
                        // 
                        // label1
                        // 
                        this->label1->Dock = System::Windows::Forms::DockStyle::Top;
                        this->label1->Font = (gcnew System::Drawing::Font(L"Segoe Print", 14.25F, System::Drawing::FontStyle::Bold, System::Drawing::GraphicsUnit::Point, 
                                static_cast<System::Byte>(0)));
                        this->label1->Location = System::Drawing::Point(0, 0);
                        this->label1->Name = L"label1";
                        this->label1->Size = System::Drawing::Size(328, 49);
                        this->label1->TabIndex = 1;
                        this->label1->Text = L"X-Universe Game Launcher";
                        this->label1->TextAlign = System::Drawing::ContentAlignment::MiddleCenter;
                        // 
                        // label2
                        // 
                        this->label2->Dock = System::Windows::Forms::DockStyle::Top;
                        this->label2->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 12, System::Drawing::FontStyle::Italic, System::Drawing::GraphicsUnit::Point, 
                                static_cast<System::Byte>(0)));
                        this->label2->Location = System::Drawing::Point(0, 49);
                        this->label2->Name = L"label2";
                        this->label2->Size = System::Drawing::Size(328, 30);
                        this->label2->TabIndex = 2;
                        this->label2->Text = L"By Cycrow";
                        this->label2->TextAlign = System::Drawing::ContentAlignment::MiddleCenter;
                        // 
                        // label3
                        // 
                        this->label3->Dock = System::Windows::Forms::DockStyle::Top;
                        this->label3->Location = System::Drawing::Point(0, 79);
                        this->label3->Name = L"label3";
                        this->label3->Size = System::Drawing::Size(328, 30);
                        this->label3->TabIndex = 3;
                        this->label3->Text = L"Version: 1.00";
                        this->label3->TextAlign = System::Drawing::ContentAlignment::MiddleCenter;
                        // 
                        // linkLabel1
                        // 
                        this->linkLabel1->Dock = System::Windows::Forms::DockStyle::Bottom;
                        this->linkLabel1->Location = System::Drawing::Point(0, 109);
                        this->linkLabel1->Name = L"linkLabel1";
                        this->linkLabel1->Size = System::Drawing::Size(328, 34);
                        this->linkLabel1->TabIndex = 4;
                        this->linkLabel1->TabStop = true;
                        this->linkLabel1->Text = L"http://cycrow.thexuniverse.us";
                        this->linkLabel1->TextAlign = System::Drawing::ContentAlignment::MiddleCenter;
                        this->linkLabel1->LinkClicked += gcnew System::Windows::Forms::LinkLabelLinkClickedEventHandler(this, &Form1::linkLabel1_LinkClicked);
                        // 
                        // timerCheckGame
                        // 
                        this->timerCheckGame->Enabled = true;
                        this->timerCheckGame->Interval = 1000;
                        this->timerCheckGame->Tick += gcnew System::EventHandler(this, &Form1::timerCheckGame_Tick);
                        // 
                        // launchManagerAdvancedToolStripMenuItem
                        // 
                        this->launchManagerAdvancedToolStripMenuItem->Name = L"launchManagerAdvancedToolStripMenuItem";
                        this->launchManagerAdvancedToolStripMenuItem->Size = System::Drawing::Size(227, 22);
                        this->launchManagerAdvancedToolStripMenuItem->Text = L"Launch Manager (Advanced)";
                        this->launchManagerAdvancedToolStripMenuItem->Click += gcnew System::EventHandler(this, &Form1::launchManagerAdvancedToolStripMenuItem_Click);
                        // 
                        // Form1
                        // 
                        this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
                        this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
                        this->ClientSize = System::Drawing::Size(328, 143);
                        this->Controls->Add(this->linkLabel1);
                        this->Controls->Add(this->label3);
                        this->Controls->Add(this->label2);
                        this->Controls->Add(this->label1);
                        this->Icon = (cli::safe_cast<System::Drawing::Icon^  >(resources->GetObject(L"$this.Icon")));
                        this->MaximizeBox = false;
                        this->MinimizeBox = false;
                        this->Name = L"Form1";
                        this->Opacity = 0;
                        this->ShowInTaskbar = false;
                        this->SizeGripStyle = System::Windows::Forms::SizeGripStyle::Hide;
                        this->Text = L"Game Launcher";
                        this->WindowState = System::Windows::Forms::FormWindowState::Minimized;
                        this->Load += gcnew System::EventHandler(this, &Form1::Form1_Load);
                        this->FormClosing += gcnew System::Windows::Forms::FormClosingEventHandler(this, &Form1::Form1_FormClosing);
                        this->contextMenuStrip1->ResumeLayout(false);
                        this->ResumeLayout(false);

                }
#pragma endregion
        private: System::Void Form1_Load(System::Object^  sender, System::EventArgs^  e) {
                                 this->StartGame(m_sGame, m_sArgs, GetGameName(m_sGame));
                         }
                         void ProgramClosedEvent(System::Object^  sender, System::EventArgs^  e) {
                                 System::Diagnostics::Process ^process = cli::safe_cast<Diagnostics::Process ^>(sender);
                                 process->WaitForExit();

                                 m_bGameClosed = true;
                                 if ( m_bRunSteam )
                                 {
                                         m_bCheckProcess = true;
                                         m_bWaitingSteam = true;
                                         m_bGameClosed = false;
                                 }
                                 else if ( m_bAutoClose )
                                 {
                                         m_bClose = true;
                                         m_bWaitingSteam = false;
                                 }
                         }
        private: System::Void closeToolStripMenuItem_Click(System::Object^  sender, System::EventArgs^  e) {
                                 m_bClosing = true;
                                 this->Close();
                         }
private: System::Void ContextResume_CheckedChanged(System::Object^  sender, System::EventArgs^  e) {
                        m_bAutoResume = this->ContextResume->Checked;
                        RegistryKey ^searchKey = Registry::CurrentUser->CreateSubKey("Software\\Egosoft\\PluginManagerSettings");
                        if ( searchKey )
                                searchKey->SetValue("DontAutoResume", (m_bAutoResume) ? 0 : 1);
                 }
private: System::Void resumeManagerToolStripMenuItem_Click(System::Object^  sender, System::EventArgs^  e) {
                         _launchManager(false);
                 }
private: System::Void notifyIcon1_DoubleClick(System::Object^  sender, System::EventArgs^  e) {
                         m_bResume = true;
                         if ( m_bAutoClose )
                                this->Close();
                 }
private: System::Void LaunchGameEvent(System::Object^  sender, System::EventArgs^  e) {
                         ToolStripMenuItem ^item = cli::safe_cast<ToolStripMenuItem ^>(sender);
                         if ( item )
                                 this->StartGame(cli::safe_cast<String ^>(item->Tag), "-noabout", item->Text);
                 }
private: System::Void ContextAutoClose_Click(System::Object^  sender, System::EventArgs^  e) {
                        m_bAutoClose = this->ContextAutoClose->Checked;
                        RegistryKey ^searchKey = Registry::CurrentUser->CreateSubKey("Software\\Egosoft\\PluginManagerSettings");
                        if ( searchKey )
                                searchKey->SetValue("DontAutoClose", (m_bAutoClose) ? 0 : 1);
                 }
private: System::Void timer1_Tick(System::Object^  sender, System::EventArgs^  e) {
                         if ( m_bClose )
                                 this->Close();
                         else if ( m_bCheckProcess )
                         {
                                 // check for the steam game
                                 if ( m_sGameRunExe )
                                 {
                                         String ^name = m_sGameRunExe->Substring(0, m_sGameRunExe->IndexOf('.'));
                                         cli::array<Diagnostics::Process ^> ^processes = Diagnostics::Process::GetProcessesByName(name);
                                         if ( !processes || !processes->Length )
                                         {
                                                 if ( !m_bWaitingSteam )
                                                 {
                                                         m_bCheckProcess = false;
                                                         this->EndGame();
                                                 }
                                         }
                                         // if steam, waiting for process to start before resuming
                                         else if ( m_bWaitingSteam )
                                                 m_bWaitingSteam = false;
                                 }
                         }
                 }

private: System::Void timerGameData_Tick(System::Object^  sender, System::EventArgs^  e) {

                         if ( m_bGameClosed )
                         {
                                 this->EndGame();
                                 return;
                         }

                         if ( m_pGameData->readFile(_WS(m_sLogDir), Utils::WString::PadNumber((long)m_iGameLog, 5)) )
                                 ParseNewData(true);
                         else
                                 ParseNewData(false);
                 }
private: System::Void gameLogToolStripMenuItem_Click(System::Object^  sender, System::EventArgs^  e) {
                         InputBox ^input = gcnew InputBox("Enter the log file number to extract game data from", Convert::ToString(m_iGameLog));
                         if ( input->ShowDialog(this) == Windows::Forms::DialogResult::OK )
                         {
                                 int log = System::Convert::ToInt32(input->GetInput());
                                 if ( log <= 0 )
                                 {
                                 }
                                 else
                                 {
                                        m_iGameLog = log;
                                        RegistryKey ^searchKey = Registry::CurrentUser->CreateSubKey("Software\\Egosoft\\PluginManagerSettings");
                                        if ( searchKey )
                                                searchKey->SetValue("GameDataLog", m_iGameLog);
                                        SetGameLogDisplay();
                                 }
                         }
                 }
private: System::Void gameDataToolStripMenuItem_Click(System::Object^  sender, System::EventArgs^  e) {
                         ViewData ^data = gcnew ViewData(m_pGameData, m_sGameName);
                         data->ShowDialog(this);
                 }
private: System::Void updateLCDToolStripMenuItem_Click(System::Object^  sender, System::EventArgs^  e) {
                        m_bUpdateLCD = this->updateLCDToolStripMenuItem->Checked;
                        RegistryKey ^searchKey = Registry::CurrentUser->CreateSubKey("Software\\Egosoft\\PluginManagerSettings");
                        if ( searchKey )
                                searchKey->SetValue("DontUpdateLCD", (m_bUpdateLCD) ? 0 : 1);
                 }
private: System::Void aboutToolStripMenuItem_Click(System::Object^  sender, System::EventArgs^  e) {
                         this->WindowState = Windows::Forms::FormWindowState::Normal;
                         this->Opacity = 1.0;
                 }
private: System::Void Form1_FormClosing(System::Object^  sender, System::Windows::Forms::FormClosingEventArgs^  e) {
                         if ( !m_bClosing )
                         {
                                 this->WindowState = Windows::Forms::FormWindowState::Minimized;
                                 this->Opacity = 0.0;
                                 e->Cancel = true;
                                 return;
                         }
                 }
private: System::Void linkLabel1_LinkClicked(System::Object^  sender, System::Windows::Forms::LinkLabelLinkClickedEventArgs^  e) {
                         Diagnostics::Process::Start(linkLabel1->Text);
                 }
private: System::Void timerCheckGame_Tick(System::Object^  sender, System::EventArgs^  e) {
                System::String ^mydoc = Environment::GetFolderPath(Environment::SpecialFolder::Personal );
                if ( System::IO::File::Exists(mydoc + "\\Egosoft\\launchgame.dat") )
                {
                        System::String ^lines = System::IO::File::ReadAllText(mydoc + "\\Egosoft\\launchgame.dat");
                        System::IO::File::Delete(mydoc + "\\Egosoft\\launchgame.dat");
                        if ( lines )
                        {
                                System::String ^gameFile;
                                System::String ^gameArgs;

                                Utils::WString strLines = _WS(lines);
                                std::vector<Utils::WString> lines;
                                strLines.tokenise(L"\n", lines);
                                for (auto it = lines.begin(); it != lines.end(); ++it)
                                {
                                        Utils::WString l = *it;
                                        l.removeChar('\r');

                                        Utils::WString first = l.token(L":", 1);
                                        Utils::WString rest = l.tokens(L":", 2);
                                        rest.removeFirstSpace();

                                        if (first.Compare(L"File"))
                                                gameFile = _US(rest);
                                        else if (first.Compare(L"Args") )
                                                gameArgs = _US(rest);                           
                                }

                                if ( gameFile && gameFile->Length )
                                        this->StartGame(gameFile, gameArgs, GetGameName(gameFile));
                        }
                }
                 }
private: System::Void gUIOverlayToolStripMenuItem_Click(System::Object^  sender, System::EventArgs^  e) {
                        m_bCustomGui = this->gUIOverlayToolStripMenuItem->Checked;
                        RegistryKey ^searchKey = Registry::CurrentUser->CreateSubKey("Software\\Egosoft\\PluginManagerSettings");
                        if ( searchKey )
                                searchKey->SetValue("DontDoGUI", (m_bCustomGui) ? 0 : 1);
                 }
private: System::Void launchManagerAdvancedToolStripMenuItem_Click(System::Object^  sender, System::EventArgs^  e) {
                         _launchManager(true);
                 }
};
}