Example #1
0
        private static async void Watcher_FileCreated(object sender, FileSystemEventArgs e)
        {
            if (e.Name == FileLocations.OpenFileName)
            {
                await Application.Current.Dispatcher.InvokeAsync(async() =>
                {
                    await Application.Current.MainWindow.Dispatcher.InvokeAsync(async() =>
                    {
                        await Task.Delay(1000);
                        string[] text;
                        using (var reader = File.OpenText(FileLocations.OpenFileLocalLocation))
                        {
                            text = (await reader.ReadToEndAsync()).Split('\r', '\n');
                        }

                        if (text[0] == "LOADCUSTOM") //Load a custom profile
                        {
                            CustomPage.StartCustomProfileLogic(text[2]);
                        }
                        else
                        {
                            Application.Current.MainWindow.WindowState = WindowState.Normal;
                            Application.Current.MainWindow.Activate();
                        }

                        try
                        {
                            File.Delete(FileLocations.OpenFileLocalLocation);
                        }
                        catch
                        {
                            App.Logging.Application($"{App.Text.CouldntDelete} {FileLocations.OpenFileLocalLocation}");
                        }
                    });
                });
            }
        }
Example #2
0
        private void App_Startup(object sender, StartupEventArgs e)
        {
            #if !DEBUG
            var args = e.Args?.ToList() ?? System.Extra.Uri.GetQueryStringParameters() ?? new List <string>();
            if (Process.GetProcessesByName("MultiRPC").Length > 1)
            {
                if (File.Exists(FileLocations.OpenFileLocalLocation))
                {
                    try
                    {
                        File.Delete(FileLocations.OpenFileLocalLocation);
                    }
                    catch
                    {
                        Logging.Application(Text.CouldntDelete + " " + FileLocations.OpenFileLocalLocation);
                    }
                }

                if (args.Contains("-custom") && args.IndexOf("-custom") + 1 >= args.Count)
                {
                    File.WriteAllLines(FileLocations.OpenFileLocalLocation,
                                       new List <string> {
                        "LOADCUSTOM", args.ElementAt(args.IndexOf("-custom") + 1)
                    });
                }
                else
                {
                    File.Create(FileLocations.OpenFileLocalLocation);
                }

                if (!args.Contains("--fromupdate"))
                {
                    Current.Shutdown();
                }
            }
            else if (args.Contains("-custom") && args.IndexOf("-custom") + 1 >= args.Count)
            {
                StartedWithJumpListLogic = true;
                _ = CustomPage.StartCustomProfileLogic(args.ElementAt(args.IndexOf("-custom") + 1), true);
            }
            #endif

            FileWatch.Create();
            SettingsPage.UIText = new List <UIText>();
            GetLangFiles();
            Config = Config.Load();
            if (Config.Debug)
            {
                try
                {
                    UITextUpdate();
                    Logging = new Logging();
                    File.AppendAllText(FileLocations.ErrorFileLocalLocation,
                                       $"\r\n------------------------------------------------------------------------------------------------\r\n{Text.ErrorsFrom} {DateTime.Now.ToLongDateString()} {DateTime.Now.ToLongTimeString()}");
                    DispatcherUnhandledException += App_DispatcherUnhandledException;
                    Application.Current.DispatcherUnhandledException += Current_DispatcherUnhandledException;
                    AppDomain.CurrentDomain.UnhandledException       += CurrentDomain_UnhandledException;
                    TaskScheduler.UnobservedTaskException            += TaskScheduler_UnobservedTaskException;
                    Dispatcher.UnhandledException += Dispatcher_UnhandledException;
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.ToString(), "Startup error", MessageBoxButton.OK, MessageBoxImage.Error);
                }
            }
            else
            {
                UITextUpdate();
                Logging = new Logging();
                File.AppendAllText(FileLocations.ErrorFileLocalLocation,
                                   $"\r\n------------------------------------------------------------------------------------------------\r\n{Text.ErrorsFrom} {DateTime.Now.ToLongDateString()} {DateTime.Now.ToLongTimeString()}");
                DispatcherUnhandledException += App_DispatcherUnhandledException;
            }
        }