Пример #1
0
        public static async Task Load(UIReplayLoader loader)
        {
            if (!Dispatcher.UIThread.CheckAccess())
            {
                await Dispatcher.UIThread.InvokeAsync(() => Load(loader));

                return;
            }
            string errorMessage, result = null;

            do
            {
                try
                {
                    if ((errorMessage = await loader.Load()) == null)
                    {
                        Window.DataContext = new MissWindowViewModel(loader);
                        return;
                    }

                    if (loader.Options.WatchDogMode)
                    {
                        return;
                    }
                }
                catch (Exception e)
                {
                    errorMessage = e.Message;
                    File.WriteAllText("exception.log", e.ToString());
                }
                if (errorMessage != null)
                {
                    result = await ShowMessageBox($"An error has occurred.\n{errorMessage}", "OK", "Reload");

                    if (result != "Reload")
                    {
                        Window.Close();
                        return;
                    }
                    else
                    {
                        loader = new UIReplayLoader {
                            Options = loader.Options
                        };
                    }
                }
            } while (result == "Reload");
        }
Пример #2
0
        public static void Main(string[] args)
        {
            MissAnalyzer         missAnalyzer;
            MissWindowController controller;
            MissWindow           window;

            Debug.Print("Starting MissAnalyser... ");
            Directory.SetCurrentDirectory(AppDomain.CurrentDomain.BaseDirectory);
            string        replay = null, beatmap = null;
            List <string> extras;
            Dictionary <string, string> optList = new Dictionary <string, string>();
            bool   help        = false;
            int    getMiss     = -1;
            string optionsFile = "options.cfg";

            var opts = new OptionSet()
            {
                { "o|osudir=", "Set osu! directory", o => optList["osudir"] = o },
                { "c|config=", "Set options.cfg", f => optionsFile = f },
                { "s|songsdir=", "Set songs directory", s => optList["songsdir"] = s },
                { "d|daemon", "Run without dialogs", d => headless = d != null },
                { "h|help", "Displays help", h => help = h != null },
                { "m|miss=", "Export miss #", (int m) => getMiss = m }
            };

            extras = opts.Parse(args);
            foreach (var arg in extras)
            {
                if (arg.EndsWith(".osu") && File.Exists(arg))
                {
                    beatmap = arg;
                }
                if (arg.EndsWith(".osr") && File.Exists(arg))
                {
                    replay = arg;
                }
            }
            if (!File.Exists(optionsFile))
            {
                File.Create(optionsFile).Close();
                Debug.Print("\nCreating options.cfg... ");
                Debug.Print("- In options.cfg, you can define various settings that impact the program. ");
                Debug.Print("- To add these to options.cfg, add a new line formatted <Setting Name>=<Value> ");
                Debug.Print("- Available settings : SongsDir | Value = Specify osu!'s songs dir.");
                Debug.Print("-                       APIKey  | Value = Your osu! API key (https://osu.ppy.sh/api/");
                Debug.Print("-                       OsuDir  | Value = Your osu! directory");
            }
            if (help)
            {
                Console.WriteLine("osu! Miss Analyzer");
                opts.WriteOptionDescriptions(Console.Out);
                return;
            }

            try
            {
                Options        options      = new Options("options.cfg", optList);
                UIReplayLoader replayLoader = new UIReplayLoader(options);
                if (!replayLoader.Load(replay, beatmap))
                {
                    return;
                }
                if (replayLoader.Replay == null || replayLoader.Beatmap == null)
                {
                    ShowErrorDialog("Couldn't find " + (replayLoader.Replay == null ? "replay" : "beatmap"));
                    return;
                }

                missAnalyzer = new MissAnalyzer(replayLoader);
                controller   = new MissWindowController(missAnalyzer, replayLoader);
                window       = new MissWindow(controller);
                Application.Run(window);
            } catch (Exception e)
            {
                ShowErrorDialog(e.Message);
                File.WriteAllText("exception.log", e.ToString());
            }
        }