コード例 #1
0
ファイル: MainForm.cs プロジェクト: TeoTwawki/DFOCP
        internal ctlMainForm( CommandLineArgs parsedArgs )
        {
            Logging.Log.Debug( "Creating main window." );
            InitializeComponent();

            m_notifyIcon.Icon = this.Icon;
            m_notifyIcon.Text = "DFO Control Panel";
            m_notifyIcon.DoubleClick += ( object sender, EventArgs e ) =>
                {
                    this.ShowInTaskbar = true;
                    this.WindowState = m_stateToRestoreTo;
                };

            exportToolStripMenuItem.ToolTipText = s_exportDisabledTooltip;
            UpdateLaunchVisibility();

            m_parsedArgs = parsedArgs;

            m_launcher.WindowModeFailed += WindowModeFailedHandler;
            m_launcher.LaunchStateChanged += StateChangedHandler;
            m_launcher.FileSwitchFailed += FileSwitchFailedHandler;
            m_launcher.PopupKillFailed += PopupKillFailedHandler;

            ctlStatusLabel.Text = m_stateNoneText;

            Logging.Log.Debug( "Main window created." );
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: TeoTwawki/DFOCP
        private static int Run( string[] args )
        {
            if ( !RunningOn35Sp1OrBetter() )
            {
                EnsureConsoleExists();
                Logging.Log.FatalFormat( "Not running on .NET 3.5 SP1 or better. .NET 3.5 SP1 or better is required. Exiting." );
                Console.WriteLine( "Press enter to exit." );
                Console.ReadLine();
                return 1;
            }
            else
            {
                Logging.Log.DebugFormat( ".NET 3.5 SP1 or better detected." );
            }

            Logging.Log.Info( "Parsing command-line arguments." );

            CommandLineArgs parsedArgs = null;
            try
            {
                parsedArgs = new CommandLineArgs( args );
            }
            catch ( OptionException ex )
            {
                EnsureConsoleExists();
                Logging.Log.FatalFormat("Improper value for {0}: {1}", ex.OptionName, ex.Message );
                Logging.Log.FatalFormat( "Try {0} --help for more information.", CommandLineArgs.GetProgramName() );

                return 1;
            }

            Logging.Log.InfoFormat( "Command line parsed. Argument dump:{0}{1}", Environment.NewLine, parsedArgs );

            if ( !parsedArgs.Gui )
            {
                EnsureConsoleExists();
            }

            foreach ( string message in parsedArgs.Messages )
            {
                Logging.Log.Warn( message );
                // Doing the log in the arg handler and a Console.WriteLine here causes anything written
                // to the console to not show up, wtf?
            }

            if ( parsedArgs.Gui )
            {
                Logging.Log.Info( "Starting GUI." );
                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault( false );
                Application.Run( new ctlMainForm( parsedArgs ) );
                return Environment.ExitCode;
            }
            else
            {
                Logging.Log.Info( "Starting command-line launcher." );

                using ( CommandLineEntryPoint cmd = new CommandLineEntryPoint( parsedArgs ) )
                {
                    return cmd.Run();
                }
            }
        }
コード例 #3
0
ファイル: Program.cs プロジェクト: LHCGreg/DFOCP
        private static int Run(string[] args)
        {
            if (!RunningOn35Sp1OrBetter())
            {
                EnsureConsoleExists();
                Logging.Log.FatalFormat("Not running on .NET 3.5 SP1 or better. .NET 3.5 SP1 or better is required. Exiting.");
                Console.WriteLine("Press enter to exit.");
                Console.ReadLine();
                return(1);
            }
            else
            {
                Logging.Log.DebugFormat(".NET 3.5 SP1 or better detected.");
            }

            Logging.Log.Info("Parsing command-line arguments.");

            CommandLineArgs parsedArgs = null;

            try
            {
                parsedArgs = new CommandLineArgs(args);
            }
            catch (OptionException ex)
            {
                EnsureConsoleExists();
                Logging.Log.FatalFormat("Improper value for {0}: {1}", ex.OptionName, ex.Message);
                Logging.Log.FatalFormat("Try {0} --help for more information.", CommandLineArgs.GetProgramName());

                return(1);
            }

            Logging.Log.InfoFormat("Command line parsed. Argument dump:{0}{1}", Environment.NewLine, parsedArgs);

            if (!parsedArgs.Gui)
            {
                EnsureConsoleExists();
            }

            foreach (string message in parsedArgs.Messages)
            {
                Logging.Log.Warn(message);
                // Doing the log in the arg handler and a Console.WriteLine here causes anything written
                // to the console to not show up, wtf?
            }

            if (parsedArgs.Gui)
            {
                Logging.Log.Info("Starting GUI.");
                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);
                Application.Run(new ctlMainForm(parsedArgs));
                return(Environment.ExitCode);
            }
            else
            {
                Logging.Log.Info("Starting command-line launcher.");

                using (CommandLineEntryPoint cmd = new CommandLineEntryPoint(parsedArgs))
                {
                    return(cmd.Run());
                }
            }
        }
コード例 #4
0
ファイル: CommandLineArgs.cs プロジェクト: TeoTwawki/DFOCP
 public static void DisplayHelp( TextWriter writer )
 {
     CommandLineArgs emptyArgs = new CommandLineArgs( new string[] { } ); // This is a bit of a hack, but I can't think of a better way to do it
     writer.WriteLine( "Usage: {0} [OPTIONS]", GetProgramName() );
     writer.WriteLine();
     writer.WriteLine( "Parameters:" );
     emptyArgs.GetOptionSet().WriteOptionDescriptions( writer );
 }
コード例 #5
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);
        }
コード例 #6
0
 public CommandLineEntryPoint(CommandLineArgs parsedArgs)
 {
     m_parsedArgs = parsedArgs;
 }
コード例 #7
0
 public CommandLineEntryPoint( CommandLineArgs parsedArgs )
 {
     m_parsedArgs = parsedArgs;
 }