Ejemplo n.º 1
0
        protected override void OnStartup(StartupEventArgs e)
        {
            base.OnStartup(e);

            DispatcherUnhandledException += (_, args) =>
            {
                MessageBoxUtils.ShowError($"Unhandled exception: `{args.Exception}`");
            };

            Task.Run(() =>
            {
                try
                {
                    int[] appVersion    = UpdateUtils.ConvertVersion(Assembly.GetExecutingAssembly().GetName().Version.ToString(4));
                    int[] latestVersion = UpdateUtils.ConvertVersion(UpdateUtils.GetLatestVersion());

                    for (int i = 0; i < 4; i++)
                    {
                        if (appVersion[i] > latestVersion[i])
                        {
                            break;
                        }
                        if (appVersion[i] == latestVersion[i])
                        {
                            continue;
                        }

                        Process.Start(
                            Path.Combine(ApplicationDataUtils.PathToRootFolder, "updater.exe"),
                            "disable_shortcut"
                            );
                        Environment.Exit(0);
                    }
                }
                catch (Exception ex)
                {
                    CrashUtils.HandleException(ex);
                }
            });

            SetCurrentLanguage();
            new PackStartupWindow().Show();
        }
Ejemplo n.º 2
0
        public static AppSettingsJson LoadAppSettings()
        {
            if (!File.Exists(Paths.AppSettingsFile))
            {
                return(new AppSettingsJson());
            }

            try
            {
                return(JsonUtils.Deserialize <AppSettingsJson>(
                           File.ReadAllText(Paths.AppSettingsFile)
                           ));
            }
            catch (Exception ex)
            {
                MessageBoxUtils.ShowError($"{StringResources.CantLoadAppSettings} {ex.Message}");
                return(new AppSettingsJson());
            }
        }
Ejemplo n.º 3
0
        public static void WriteToJSON(Object runData, String filePath = null)
        {
            // Write all of it into the current template path.
            RunTemplate runTemplate = new()
            {
                ApplicationMode = ApplicationSettings.Mode,
                RunsData        = new List <DraggableButtonDataContext>(runData as IEnumerable <DraggableButtonDataContext>)
            };

            String jsonString = GetJsonString(runTemplate);

            try
            {
                File.WriteAllText(filePath ?? _currentTemplatePath, jsonString);
            }
            catch (Exception ex)
            {
                MessageBoxUtils.ShowError(ex.InnerException?.Message ?? ex.Message);
                return;
            }
        }
        private void SwitchLanguageTo(string language)
        {
            if (Thread.CurrentThread.CurrentUICulture.Name == language)
            {
                return;
            }

            Thread.CurrentThread.CurrentUICulture = new CultureInfo(language);
            string oldLanguage = _appSettings.AppLanguage;

            _appSettings.AppLanguage = language;
            try
            {
                AppUtils.SaveAppSettings(_appSettings);
            }
            catch (Exception ex)
            {
                _appSettings.AppLanguage = oldLanguage;
                MessageBoxUtils.ShowError($"{StringResources.CantSaveAppSettings} {ex.Message}");
            }
            RecreateWindow?.Invoke();
        }
        private void ChooseExistingPackCommand_Execute()
        {
            string filters = $"{StringResources.ChoosePackDialogFilter}|*{PackUtils.PacksExtension};*{PackUtils.PacksActualExtension}";

            var dialog = new OpenFileDialog
            {
                Title           = StringResources.ChoosePackDialogTitle,
                Filter          = filters,
                CheckFileExists = true
            };

            if (dialog.ShowDialog() != true)
            {
                MessageBoxUtils.ShowError(StringResources.ChoosePackDialogFailed);
                return;
            }

            var mainWindow = new MainWindow();

            mainWindow.Show();
            mainWindow.ViewModel.PackProcessor.LoadPackFromFile(dialog.FileName);

            _attachedWindowManipulator.Close();
        }
Ejemplo n.º 6
0
        public Boolean TryLoadData(Boolean browseForFile = true)
        {
            OpenFileDialog fileBrowserDialog = null;

            if (browseForFile)
            {
                fileBrowserDialog = new OpenFileDialog()
                {
                    Filter           = PathUtils.MCROFilter,
                    DefaultExt       = PathUtils.Extension,
                    AddExtension     = true,
                    RestoreDirectory = true,
                };

                if (fileBrowserDialog.ShowDialog() != DialogResult.OK)
                {
                    return(false);
                }
            }

            // Update the path of the current template.
            if (fileBrowserDialog?.FileName != null)
            {
                _currentTemplatePath = fileBrowserDialog.FileName;
            }

            // Read the jsonString from the loaded file.
            String jsonString = String.Empty;

            try
            {
                jsonString = File.ReadAllText(_currentTemplatePath);
            }
            catch (FileNotFoundException)
            {
                return(false);
            }

            // Deserialize the template.
            RunTemplate runTemplate = null;

            try
            {
                runTemplate = JsonConvert.DeserializeObject <RunTemplate>(jsonString, new JsonSerializerSettings()
                {
                    TypeNameHandling = TypeNameHandling.Auto,
                    Formatting       = Formatting.Indented,
                    Converters       = new JsonConverter[] { new StringEnumConverter() }
                });
            }
            catch (Exception ex)
            {
                MessageBoxUtils.ShowError(ex.InnerException?.Message ?? ex.Message);
                return(false);
            }

            if (runTemplate.RunsData == null || runTemplate.RunsData.Count == 0)
            {
                MessageBoxUtils.ShowError("Loading the runs data failed.");
                return(false);
            }

            _managedControl.Runs.Clear();

            // Set the ApplicationMode.
            ApplicationSettings.Mode = runTemplate.ApplicationMode;

            // Create the runs.
            foreach (var runData in runTemplate.RunsData)
            {
                _managedControl.Runs.Add(new DraggableButton(_managedControl, runData));
            }

            return(true);
        }