Exemple #1
0
        private bool LoadVersionsFile()
        {
            try
            {
                versionService.AllVersions = JsonConverterService <List <GodotVersion> > .Deserialize("config\\versions.json");

                string installedManifest = $"{config.GodotInstallLocation}\\manifest.json";
                if (config.GodotInstallLocation != String.Empty && File.Exists(installedManifest))
                {
                    versionService.InstalledVersions = JsonConverterService <List <GodotVersionInstalled> > .Deserialize(installedManifest);
                }
                else
                {
                    versionService.InstalledVersions = new List <GodotVersionInstalled>();
                }
            }
            catch (Exception ex)
            {
                logger.Error(ex);
                CommonUtilsService.PopupExceptionMessage("Error loading versions", ex);

                return(false);
            }

            versionService.AllVersions.Reverse();

            return(true);
        }
Exemple #2
0
        private bool TryToDownloadOrUpdateVersionsFile()
        {
            string url;

            if (File.Exists("config\\versions.json") && (DateTime.Now - config.LastUpdateChecked).TotalDays < 1)
            {
                return(true);
            }

            try
            {
                url = FindResource("VersionsFileUrl").ToString();

                if (config.UseProxy)
                {
                    DownloadManagerService.DownloadFileSyncWithProxy(url, "config\\versions.json", config.ProxyUrl, config.ProxyPort);
                }
                else
                {
                    DownloadManagerService.DownloadFileSync(url, "config\\versions.json");
                }
            }
            catch (Exception ex)
            {
                logger.Error(ex);
                CommonUtilsService.PopupExceptionMessage("Error while downloading versions", ex);
            }

            config.LastUpdateChecked = DateTime.Now;

            return(true);
        }
        private void InstallButton_Click(object sender, RoutedEventArgs e)
        {
            if (config.GodotInstallLocation == String.Empty)
            {
                CommonUtilsService.PopupWarningMessage("No install location", "Please specify a Godot install location");
                return;
            }

            BusyIndicator.IsBusy = true;

            var temp = (KeyValuePair <int, string>)GodotVersionsTree.SelectedItem;

            var selectedVersion = versionService.AllVersions.FirstOrDefault(x => x.VersionId == temp.Key);

            var worker = new BackgroundWorker();

            worker.DoWork             += (s, ev) => DownloadAndExtractVersion(selectedVersion);
            worker.RunWorkerCompleted += (s, ev) =>
            {
                if (ev.Error != null)
                {
                    logger.Error(ev.Error);
                    CommonUtilsService.PopupExceptionMessage("Error while downloading Godot", ev.Error);
                }

                BusyIndicator.IsBusy = false;
            };
            worker.RunWorkerAsync();
        }
Exemple #4
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);
        }
Exemple #5
0
        private void App_OnDispatcherUnhandledException(object sender, DispatcherUnhandledExceptionEventArgs e)
        {
            // log the unhandled exception
            logger.Error(e.Exception, "An unhandled exception occurred");

            // also show a popup informing the user of the exception
            CommonUtilsService.PopupExceptionMessage("Unhandled exception", e.Exception);

            // mark it as handled
            //e.Handled = true;
        }
Exemple #6
0
        private bool CheckIfCurrentDirectoryIsWritable()
        {
            try
            {
                using (var file = File.Create("tmp"))
                { }

                File.Delete("tmp");
            }
            catch (Exception ex)
            {
                logger.Error(ex);
                CommonUtilsService.PopupExceptionMessage("I/O error", ex);

                return(false);
            }

            return(true);
        }
        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!")));
        }
Exemple #10
0
        private bool TryToCreateDirectories()
        {
            try
            {
                if (!Directory.Exists("config"))
                {
                    Directory.CreateDirectory("config");
                }

                if (!Directory.Exists("temp"))
                {
                    Directory.CreateDirectory("temp");
                }
            }
            catch (Exception ex)
            {
                logger.Error(ex);
                CommonUtilsService.PopupExceptionMessage("I/O error", ex);

                return(false);
            }

            return(true);
        }