예제 #1
0
        /// <summary>
        /// Creates the app as specified by the command line.
        /// </summary>
        /// <param name="commandLine">The programs command line.</param>
        private static App CreateApp(CommandLine commandLine)
        {
            // Do not create crash logs when debugging.
            bool createCrashLog = !commandLine.IsSet('l', "no-logs");

            // Do not register fily type associations when debugging.
            bool registerFileTypes = !commandLine.IsSet('t', "no-register-filetype");

            // Custom AppData path for debugging purposes only.
            string appDataPath;
            bool   hasCustomAppDataPath = commandLine.TryGetArgument('a', "appdata-path", out appDataPath);


            if (hasCustomAppDataPath)
            {
                return(new App(createCrashLog, registerFileTypes, appDataPath));
            }
            else
            {
                return(new App(createCrashLog, registerFileTypes));
            }
        }
예제 #2
0
        /// <summary>
        /// Creates the app as specified by the command line.
        /// </summary>
        /// <param name="commandLine">The programs command line.</param>
        private static App CreateApp(CommandLine commandLine)
        {
            // Do not create crash logs when debugging.
            bool createCrashLog = !commandLine.IsSet('l', "no-logs");

            // Custom AppData path for debugging purposes only.
            string appDataPath;
            bool   hasCustomAppDataPath = commandLine.TryGetArgument('a', "appdata-path", out appDataPath);


            if (hasCustomAppDataPath)
            {
                return(new App(createCrashLog, appDataPath));
            }
            else
            {
                return(new App(createCrashLog));
            }
        }
예제 #3
0
        /// <summary>
        /// Runs the program.
        /// </summary>
        /// <param name="commandLine">The programs command line.</param>
        /// <param name="app">The app to run.</param>
        /// <returns>The programs exit code.</returns>
        private static int Run(CommandLine commandLine, App app)
        {
            // Prevent update search on startup
            UpdateCheckOnStartup = !commandLine.IsSet('u', "no-update");


            var fileList = new List <FileInfo>();

            foreach (string argument in commandLine.Arguments)
            {
                if (argument.EndsWith(".fmp") && File.Exists(argument))
                {
                    var file = new FileInfo(argument);
                    fileList.Add(file);
                }
            }
            ImportFileList = fileList;


            app.InitializeComponent();
            return(app.Run());
        }
예제 #4
0
        public static int Main(string[] args)
        {
            var commandLine = new CommandLine(args);

            // Only display help.
            if (commandLine.IsSet('h', "help"))
            {
                Program.DisplayHelp();
                return(0);
            }


            string appGuid = Program.Guid.ToString();
            string mutexId = $"{{{appGuid}}}";

            bool createdNew;

            using (var mutex = new Mutex(false, mutexId, out createdNew))
            {
                var hasHandle = false;
                try
                {
                    try
                    {
                        hasHandle = mutex.WaitOne(100, false);
                        if (!hasHandle)
                        {
                            // App already running.
                            if (StartGameIfSpecified(commandLine, true))
                            {
                                return(0);
                            }

                            SendNewInstanceStartedMessage(args);
                            return(0);
                        }
                    }
                    catch (AbandonedMutexException)
                    {
                        hasHandle = true;
                    }


                    // App not running.
                    App app = CreateApp(commandLine);

                    if (StartGameIfSpecified(commandLine, false))
                    {
                        return(0);
                    }


                    var  cancellationSource = new CancellationTokenSource();
                    Task listenTask         = ListenForNewInstanceStarted(cancellationSource.Token);

                    int result = Program.Run(commandLine, app);

                    cancellationSource.Cancel();
                    listenTask.Wait();

                    return(result);
                }
                finally
                {
                    if (hasHandle)
                    {
                        mutex.ReleaseMutex();
                    }
                }
            }
        }
예제 #5
0
        public static int Main(string[] args)
        {
            var commandLine = new CommandLine(args, 'a', 'n', 'f', 'p', 's', 'c');

            // Only display help.
            if (commandLine.IsSet('h', "help"))
            {
                Program.DisplayHelp();
                return(0);
            }

            // Wait for updater to exit.
            if (commandLine.TryGetArgument(null, "update-complete", out string pidStr))
            {
                if (int.TryParse(pidStr, out int pid))
                {
                    try
                    {
                        var updaterProcess = Process.GetProcessById(pid);
                        updaterProcess.WaitForExit();
                    }
                    catch
                    { }
                }
            }


            string appGuid = Program.Guid.ToString();
            string mutexId = $"{{{appGuid}}}";

            bool createdNew;

            using (var mutex = new Mutex(false, mutexId, out createdNew))
            {
                var hasHandle = false;
                try
                {
                    try
                    {
                        hasHandle = mutex.WaitOne(100, false);
                        if (!hasHandle) // App already running.
                        {
                            bool gameStarted = StartGameIfSpecified(commandLine, true);

                            var sendArgs = args;
                            if (gameStarted)
                            {
                                sendArgs = sendArgs.Append(NewInstanceGameStartedSpecifier).ToArray();
                            }
                            SendNewInstanceStartedMessage(sendArgs);

                            return(0);
                        }
                    }
                    catch (AbandonedMutexException)
                    {
                        hasHandle = true;
                    }


                    // App not running.
                    App app = CreateApp(commandLine);

                    if (StartGameIfSpecified(commandLine, false))
                    {
                        return(0);
                    }


                    var  cancellationSource = new CancellationTokenSource();
                    Task listenTask         = ListenForNewInstanceStarted(cancellationSource.Token);

                    int result = Program.Run(commandLine, app);

                    cancellationSource.Cancel();
                    listenTask.Wait();

                    return(result);
                }
                finally
                {
                    if (hasHandle)
                    {
                        mutex.ReleaseMutex();
                    }
                }
            }
        }