示例#1
0
        private void LaunchThreadStart()
        {
            Logging.Log.Debug("Launch thread started.");

            m_stateBecameNoneEvent.Reset();

            try
            {
                m_launcher.Launch();
            }
            catch (Exception ex)
            {
                if (ex is System.Security.SecurityException ||
                    ex is System.Net.WebException ||
                    ex is DfoAuthenticationException ||
                    ex is DfoLaunchException)
                {
                    DisplayError(ex.Message, "Launch Error");
                }
                else
                {
                    throw;
                }
            }

            // Wait for the launcher state to become None or a cancel request. Then we can enable the button again.
            if (m_launcher.State != LaunchState.None)
            {
                Logging.Log.Debug("Waiting for state to become None or a cancel request.");
                int conditionIndex = WaitHandle.WaitAny(
                    new WaitHandle[] { m_stateBecameNoneEvent, m_launcherThreadCanceledEvent });
                if (conditionIndex == 0)
                {
                    Logging.Log.Debug("State became None, done waiting.");
                }
                else
                {
                    Logging.Log.Debug("Canceled, done waiting.");
                }

                m_launcher.Reset();
                Logging.Log.Debug("Launcher object reset.");
            }

            PreventLaunch = false;

            lock ( m_syncHandle )
            {
                if (m_closeWhenDone)
                {
                    // This has to be an async invoke because the form closing handler waits for this thread to finish!
                    this.BeginInvoke(() => this.Close());
                }
            }

            Logging.Log.Debug("End of launch thread.");
        }
示例#2
0
        public int Run()
        {
            if (m_parsedArgs.ShowVersion)
            {
                Console.WriteLine("{0} version {1}", VersionInfo.AssemblyTitle, VersionInfo.AssemblyVersion);
                Console.WriteLine(VersionInfo.AssemblyCopyright);
                Console.WriteLine(VersionInfo.LicenseStatement);
            }
            if (m_parsedArgs.ShowHelp)
            {
                CommandLineArgs.DisplayHelp(Console.Out);
            }

            if (m_parsedArgs.ShowVersion || m_parsedArgs.ShowHelp)
            {
                return(0);
            }

            bool invalidArgs = false;

            if (m_parsedArgs.Settings.Username == null)
            {
                Logging.Log.FatalFormat("You must supply a username.");
                invalidArgs = true;
            }

            if (m_parsedArgs.Settings.Password == null)
            {
                Logging.Log.FatalFormat("You must supply a password.");
                invalidArgs = true;
            }

            if (invalidArgs)
            {
                Console.WriteLine("Try {0} --help for usage information.", CommandLineArgs.GetProgramName());
                return(1);
            }

            if (m_parsedArgs.Settings.ClosePopup != null)
            {
                m_launcher.Params.ClosePopup = m_parsedArgs.Settings.ClosePopup.Value;
            }
            if (m_parsedArgs.Settings.DfoDir != null)
            {
                m_launcher.Params.GameDir = m_parsedArgs.Settings.DfoDir;
            }
            if (m_parsedArgs.Settings.LaunchWindowed != null)
            {
                m_launcher.Params.LaunchInWindowed = m_parsedArgs.Settings.LaunchWindowed.Value;
            }
            if (m_parsedArgs.Settings.GameWindowWidth != null)
            {
                m_launcher.Params.WindowWidth = m_parsedArgs.Settings.GameWindowWidth;
            }
            if (m_parsedArgs.Settings.GameWindowHeight != null)
            {
                m_launcher.Params.WindowHeight = m_parsedArgs.Settings.GameWindowHeight;
            }
            if (m_parsedArgs.Settings.Password != null)
            {
                m_launcher.Params.Password = m_parsedArgs.Settings.Password;
            }
            if (m_parsedArgs.Settings.Username != null)
            {
                m_launcher.Params.Username = m_parsedArgs.Settings.Username;
            }

            if (m_parsedArgs.Settings.DfoDir == null)
            {
                try
                {
                    m_launcher.Params.AutoDetectGameDir();
                }
                catch (IOException ex)
                {
                    Logging.Log.ErrorFormat("Could not autodetect the DFO directory. {0}", ex.Message);
                }
            }

            foreach (SwitchableFile switchableFile in m_parsedArgs.Settings.SwitchableFiles.Values)
            {
                switchableFile.RelativeRoot = m_launcher.Params.GameDir;
                switchableFile.ApplyDefaults();

                if (m_parsedArgs.Settings.SwitchFile[switchableFile.Name].HasValue &&
                    m_parsedArgs.Settings.SwitchFile[switchableFile.Name].Value)
                {
                    FileSwitcher fileToSwitch = switchableFile.AsFileSwitcher();
                    m_launcher.Params.FilesToSwitch.Add(fileToSwitch);
                }
            }

            try
            {
                FixSwitchableFilesIfNeeded(m_parsedArgs.Settings.SwitchableFiles.Values);
            }
            catch (IOException ex)
            {
                Logging.Log.FatalFormat(
                    "Error while trying to fix switchable file. {0} I guess you'll have to fix it yourself.",
                    ex.Message);

                return(2);
            }

            m_launcher.LaunchStateChanged += StateChangedHandler;
            m_launcher.FileSwitchFailed   += FileSwitchFailHandler;
            m_launcher.WindowModeFailed   += WindowFailHandler;
            m_launcher.PopupKillFailed    += PopupKillFailHandler;

            Console.WriteLine("You must leave this program running. It will automatically stop when the game is closed.");

            try
            {
                Logging.Log.InfoFormat("Launching.");
                m_launcher.Launch();

                Logging.Log.DebugFormat("Waiting for state to become None.");
                m_stateBecameNoneEvent.WaitOne();

                Logging.Log.DebugFormat("Done.");
                Console.WriteLine("Done.");
            }
            catch (Exception ex)
            {
                if (ex is System.Security.SecurityException ||
                    ex is System.Net.WebException ||
                    ex is DfoAuthenticationException ||
                    ex is DfoLaunchException)
                {
                    Logging.Log.FatalFormat("There was a problem while trying to start the game. {0}", ex.Message);
                    return(2);
                }
                else
                {
                    throw;
                }
            }

            return(0);
        }