Example #1
0
        /// <summary>
        /// Initializes a new instance of the MainViewModel class.
        /// </summary>
        public MainViewModel(IDialogCoordinator dialogCoordinator)
        {
            Release razor = GitHubHelper.GetLatestRazorVersion(false);
            Release cuo   = GitHubHelper.GetLatestClassicUOVersion(false);

            RazorVersion = $"Razor {razor.TagName} ({razor.PublishedAt:g})";
            CUOVersion   = $"ClassicUO {cuo.TagName} ({cuo.PublishedAt:g})";

            InstallUpdateCommand     = new RelayCommand(DoConfirmInstallUpdate);
            BrowseInstallPathCommand = new RelayCommand(DoSetInstallPath);
            BrowseUOPathCommand      = new RelayCommand(DoSetUODataPath);
            WebsiteCommand           = new RelayCommand(DoWebsite);

            _dialogCoordinator = dialogCoordinator;

            IsButtonEnabled = true;
            InstallCUO      = true;

            InstallPath   = ConfigurationManager.AppSettings["InstallPath"];
            UODataPath    = ConfigurationManager.AppSettings["UODataPath"];
            ServerHost    = ConfigurationManager.AppSettings["ServerHost"];
            ServerPort    = ConfigurationManager.AppSettings["ServerPort"];
            ClientVersion = ConfigurationManager.AppSettings["ClientVersion"];
        }
Example #2
0
        private void InstallUpdateBackgroundWorkerDoWork(object sender, DoWorkEventArgs e)
        {
            try
            {
                IsButtonEnabled = false;

                if (string.IsNullOrEmpty(UODataPath) || !InstallerHelper.CheckUoPath(UODataPath))
                {
                    MessageBox.Show($"'{UODataPath}' doesn't appear to be a valid UO installation path.");
                    return;
                }

                InstallerHelper.ValidatePath(InstallPath);

                ReleaseAsset razor = GitHubHelper.GetLatestRazorVersion(UseRazorPreview).Assets[0];
                ReleaseAsset cuo   = GitHubHelper.GetLatestClassicUOVersion(UseCUOPreview).Assets[0];

                DownloadFile(razor.BrowserDownloadUrl, Path.Combine(InstallPath, razor.Name));
                DownloadFile(cuo.BrowserDownloadUrl, Path.Combine(InstallPath, cuo.Name));

                ZipArchive razorZip = ZipFile.OpenRead(Path.Combine(InstallPath, razor.Name));
                foreach (ZipArchiveEntry entry in razorZip.Entries)
                {
                    string full    = Path.Combine(InstallPath, "Razor", entry.FullName);
                    string dirName = Path.GetDirectoryName(full);

                    if (!Directory.Exists(dirName))
                    {
                        Directory.CreateDirectory(dirName);
                    }

                    if (!string.IsNullOrEmpty(Path.GetFileName(full)))
                    {
                        entry.ExtractToFile(full, true);
                    }
                }

                if (InstallCUO)
                {
                    ZipArchive cuoZip = ZipFile.OpenRead(Path.Combine(InstallPath, cuo.Name));
                    foreach (ZipArchiveEntry entry in cuoZip.Entries)
                    {
                        string full    = Path.Combine(InstallPath, entry.FullName);
                        string dirName = Path.GetDirectoryName(full);

                        if (!Directory.Exists(dirName))
                        {
                            Directory.CreateDirectory(dirName);
                        }

                        if (!string.IsNullOrEmpty(Path.GetFileName(full)))
                        {
                            entry.ExtractToFile(full, true);
                        }
                    }

                    ClassicUoModel settings = new ClassicUoModel
                    {
                        UltimaOnlineDirectory = UODataPath,
                        IP            = ServerHost,
                        Port          = Convert.ToInt32(ServerPort),
                        ClientVersion = ClientVersion,
                        Plugins       = new[] { Path.Combine(InstallPath, "Razor", "Razor.exe") }
                    };

                    File.WriteAllText(Path.Combine(InstallPath, "settings.json"), JsonConvert.SerializeObject(settings));
                }

                InstallerHelper.UpdateSetting("InstallPath", InstallPath);
                InstallerHelper.UpdateSetting("UODataPath", UODataPath);
                InstallerHelper.UpdateSetting("ServerHost", ServerHost);
                InstallerHelper.UpdateSetting("ServerPort", ServerPort);
                InstallerHelper.UpdateSetting("ClientVersion", ClientVersion);

                if (ShowLaunchDialogCommand.CanExecute(null))
                {
                    ShowLaunchDialogCommand.Execute(null);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show($"Unexpected error. {ex.Message}");
            }
        }