示例#1
0
文件: Program.cs 项目: xxami/Pulsus
        static void Main()
        {
            // keep the console visible only when launched from command-line
            if (Process.GetCurrentProcess().MainWindowHandle != IntPtr.Zero)
            {
                Utility.HideConsole();
            }

            if (!Debugger.IsAttached)
            {
                // handle thrown exceptions when debugger is not present
                AppDomain.CurrentDomain.UnhandledException +=
                    (sender, e) => OnCaughtException(e.ExceptionObject as Exception);
            }

            // store program name and version number
            Assembly assembly = Assembly.GetExecutingAssembly();

            name               = assembly.GetName().Name;
            version            = assembly.GetName().Version;
            versionDisplay     = Utility.GetVersionString(version);
            versionLongDisplay = assembly.GetCustomAttribute <AssemblyInformationalVersionAttribute>().InformationalVersion;
            platform           = Utility.GetPlatform();
            platformVersion    = Utility.GetPlatformVersion();
            platformId         = (Environment.OSVersion.Platform == PlatformID.Win32NT ? "Win" : platform) + (Environment.Is64BitProcess ? "-x64" : "-x86");

            // setup logging file
            Log.SetLogFile(Path.Combine(basePath, name + ".log"));

            Log.Text("{0} {1} ({2})", name, versionDisplay, Environment.Is64BitProcess ? "64-bit" : "32-bit");
            Log.Text("{0} {1} ({2})", platform, platformVersion, Environment.Is64BitOperatingSystem ? "64-bit" : "32-bit");

            // locale independent date and number formatting
            CultureInfo.DefaultThreadCurrentCulture = CultureInfo.InvariantCulture;
            Thread.CurrentThread.CurrentCulture     = CultureInfo.InvariantCulture;

            if (!File.Exists(cachePath))
            {
                Directory.CreateDirectory(cachePath);
            }

            // close Eto on exit
            AppDomain.CurrentDomain.ProcessExit += OnProcessExit;

            //SettingsManager.LoadDefaults();
            SettingsManager.Load();
            SettingsManager.Save();             // refresh with new fields
            SettingsManager.ParseArgs(Environment.GetCommandLineArgs());

            Settings settings = SettingsManager.instance;

            // restore console window
            if (settings.outputMode != OutputMode.None || settings.debug)
            {
                Utility.ShowConsole();
            }

            // start Eto context when not doing any command-line processing
            if (settings.outputMode == OutputMode.None)
            {
                EtoStartup();
            }
            else
            {
                hideErrorDialog = true;
            }

            // clean up residual files from update
            Updater.CleanUpdateFiles();

            if (settings.checkUpdates)
            {
                UpdateInfo updateInfo = Updater.GetLatestUpdate();
                if (updateInfo.version > version)
                {
                    if (!string.IsNullOrEmpty(updateInfo.downloadUrl))
                    {
                        UpdateWindow.Show(updateInfo, out restart);
                        if (restart)
                        {
                            return;                             // exit early
                        }
                    }
                    else
                    {
                        Log.Warning("Update found, but no release files are available for this platform: " + platformId);
                    }
                }
                else
                {
                    Log.Info("No updates found");
                }
            }

            if (settings.showSettings)
            {
                if (!ShowSettings(false))
                {
                    return;                     // exit early
                }
            }

            using (Game game = new Game())
                game.Run();

            SettingsManager.Save();
        }