Пример #1
0
        private bool ReadOrCreateConfigFile()
        {
            string configFile = "config\\config.json";

            try
            {
                if (!File.Exists(configFile))
                {
                    config = new ApplicationConfig
                    {
                        GodotInstallLocation     = String.Empty,
                        Show32BitVersions        = true,
                        Show64BitVersions        = true,
                        ShowMonoVersions         = false,
                        ShowUnstableVersions     = false,
                        ShowInstalledVersions    = true,
                        ShowNotInstalledVersions = true,
                        ShowStableVersions       = true,
                        ShowStandardVersions     = true,
                        LastUpdateChecked        = DateTime.Now,
                        LastSelectedVersion      = -1,
                        OnGodotLaunch            = Constants.DO_NOTHING_ON_LAUNCH,
                        UseProxy  = false,
                        ProxyUrl  = String.Empty,
                        ProxyPort = 0,
                    };

                    JsonConverterService <ApplicationConfig> .Serialize(config, configFile);
                }

                config = JsonConverterService <ApplicationConfig> .Deserialize(configFile);

                if (config.UseProxy && (config.ProxyPort == 0 || config.ProxyUrl == String.Empty))
                {
                    config.UseProxy = false;

                    JsonConverterService <ApplicationConfig> .Serialize(config, configFile);
                }

                if (config.GodotInstallLocation != String.Empty && !Directory.Exists(config.GodotInstallLocation))
                {
                    Directory.CreateDirectory(config.GodotInstallLocation);

                    using (var file = File.CreateText($"{config.GodotInstallLocation}\\manifest.json"))
                    {
                        file.Write("[]");
                    }
                }
            }
            catch (Exception ex)
            {
                logger.Error(ex);
                CommonUtilsService.PopupExceptionMessage("Error reading config", ex);

                return(false);
            }

            return(true);
        }
Пример #2
0
        public void Serialize_JsonData_IsSerialized()
        {
            // Given: A JSON metadata value
            JsonConverterService jsonConverterService = new JsonConverterService();
            PaymentRequest       paymentRequest       = new PaymentRequest()
            {
                Amount      = new Amount(Currency.EUR, "100.00"),
                Description = "Description",
                RedirectUrl = "http://www.mollie.com",
                Metadata    = "{\"firstName\":\"John\",\"lastName\":\"Doe\"}",
            };
            string expectedJsonValue = "{\"amount\":{\"currency\":\"EUR\",\"value\":\"100.00\"},\"description\":\"Description\",\"redirectUrl\":\"http://www.mollie.com\",\"metadata\":{\"firstName\":\"John\",\"lastName\":\"Doe\"}}";

            // When: We serialize the JSON
            string jsonValue = jsonConverterService.Serialize(paymentRequest);

            // Then:
            Assert.AreEqual(expectedJsonValue, jsonValue);
        }
Пример #3
0
        private void StartButton_Click(object sender, RoutedEventArgs e)
        {
            int selId = (int)InstalledVersionsCB.SelectedValue;

            config.LastSelectedVersion = selId;

            var selectedVersion = versionService.InstalledVersions.FirstOrDefault(x => x.VersionId == selId);

            Process.Start(selectedVersion.InstallPath);

            if (config.OnGodotLaunch == Constants.CLOSE_ON_LAUNCH)
            {
                Close();
            }
            else if (config.OnGodotLaunch == Constants.MINIMIZE_ON_LAUNCH)
            {
                WindowState = WindowState.Minimized;
            }

            JsonConverterService <ApplicationConfig> .Serialize(config, "config\\config.json");
        }
        private void ApplyButton_Click(object sender, RoutedEventArgs e)
        {
            config.GodotInstallLocation = GodotInstallLocationTextbox.Text;
            config.OnGodotLaunch        = (int)OnGodotLaunchComboBox.SelectedValue;
            bool proxy = UseProxyCheckBox.IsChecked.Value;

            if (proxy)
            {
                if (ProxyPortTextBox.Text == String.Empty || ProxyUrlTextBox.Text == String.Empty)
                {
                    CommonUtilsService.PopupWarningMessage("Invalid values", "Please input both an URL and a port number for the proxy.");
                    return;
                }

                if (Uri.TryCreate(ProxyUrlTextBox.Text, UriKind.Absolute, out Uri uriResult) && (uriResult.Scheme == Uri.UriSchemeHttp || uriResult.Scheme == Uri.UriSchemeHttps))
                {
                    config.ProxyUrl = ProxyUrlTextBox.Text;
                }
                else
                {
                    CommonUtilsService.PopupWarningMessage("Invalid values", "Please input a valid URL for the proxy.");
                    return;
                }

                if (Int32.TryParse(ProxyPortTextBox.Text, out int portNum))
                {
                    config.ProxyPort = portNum;
                }
                else
                {
                    CommonUtilsService.PopupWarningMessage("Invalid values", "Please input a valid port for the proxy.");
                    return;
                }
            }

            config.UseProxy = proxy;
            JsonConverterService <ApplicationConfig> .Serialize(config, "config\\config.json");

            Close();
        }
        private void UninstallButton_Click(object sender, RoutedEventArgs e)
        {
            var temp             = (KeyValuePair <int, string>)GodotVersionsTree.SelectedItem;
            var selectedVersion  = versionService.AllVersions.FirstOrDefault(x => x.VersionId == temp.Key);
            var installedVersion = versionService.InstalledVersions.FirstOrDefault(x => x.VersionId == selectedVersion.VersionId);

            if (File.Exists(installedVersion.InstallPath))
            {
                File.Delete(installedVersion.InstallPath);
            }
            string parentDir;

            if (installedVersion.IsMono)
            {
                string monoDirectory = Path.GetDirectoryName(installedVersion.InstallPath);
                parentDir = Path.GetDirectoryName(monoDirectory);

                Directory.Delete(monoDirectory, true);
            }
            else
            {
                parentDir = Path.GetDirectoryName(installedVersion.InstallPath);
            }

            if (CommonUtilsService.IsDirectoryEmpty(parentDir))
            {
                Directory.Delete(parentDir, true);
            }

            versionService.InstalledVersions.Remove(installedVersion);

            JsonConverterService <List <GodotVersionInstalled> > .Serialize(versionService.InstalledVersions, $"{config.GodotInstallLocation}\\manifest.json");

            BuildVersionsTree();

            CommonUtilsService.PopupInfoMessage("Info", "Godot version uninstalled successfully!");
        }
        private void DownloadAndExtractVersion(GodotVersion selectedVersion)
        {
            string fileName;

            try
            {
                fileName = config.UseProxy ? DownloadManagerService.DownloadFileSyncWithProxy(selectedVersion.VersionUrl, "temp", config.ProxyUrl, config.ProxyPort, true) :
                           DownloadManagerService.DownloadFileSync(selectedVersion.VersionUrl, "temp", true);
            }
            catch (Exception ex)
            {
                throw ex;
            }

            var extractedFiles = ZipService.UnzipFile(fileName, $"{config.GodotInstallLocation}\\{selectedVersion.VersionName}");

            File.Delete(fileName);

            foreach (var file in extractedFiles)
            {
                versionService.InstalledVersions.Add(new GodotVersionInstalled
                {
                    VersionId   = selectedVersion.VersionId,
                    VersionName = selectedVersion.VersionName,
                    BitNum      = selectedVersion.BitNum,
                    IsMono      = selectedVersion.IsMono,
                    IsStable    = selectedVersion.IsStable,
                    InstallPath = file.Replace(@"/", @"\\"),
                });
            }

            JsonConverterService <List <GodotVersionInstalled> > .Serialize(versionService.InstalledVersions, $"{config.GodotInstallLocation}\\manifest.json");

            Dispatcher.Invoke(new Action(() => BuildVersionsTree()));

            Dispatcher.Invoke(new Action(() => CommonUtilsService.PopupInfoMessage("Info", "Godot version installed successfully!")));
        }
 private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
 {
     JsonConverterService <ApplicationConfig> .Serialize(config, "config\\config.json");
 }