/// <summary> /// Constructor; also sets some UI text to indicate that the addon loader is having an update check /// </summary> public LoaderSetup() { viewModel = UpdatingViewModel.GetInstance; viewModel.ProgBarLabel = "Checking for updates to Addon Loader"; userConfig = Configuration.getConfigAsYAML(); loader_game_path = Path.Combine(userConfig.game_path, userConfig.bin_folder); }
/***** UPDATE button *****/ private void update_button_clicked(object sender, RoutedEventArgs e) { //If bin folder doesn't exist then LoaderSetup intialization will fail. var userConfig = Configuration.getConfigAsYAML(); if (userConfig.bin_folder == null) { MessageBox.Show("Unable to locate Guild Wars 2 /bin/ or /bin64/ folder." + Environment.NewLine + "Please verify Game Path is correct.", "Unable to Update", MessageBoxButton.OK, MessageBoxImage.Warning); return; } List <AddonInfoFromYaml> selectedAddons = new List <AddonInfoFromYaml>(); //the d3d9 wrapper is installed by default and hidden from the list displayed to the user, so it has to be added to this list manually AddonInfoFromYaml wrapper = AddonYamlReader.getAddonInInfo("d3d9_wrapper"); wrapper.folder_name = "d3d9_wrapper"; selectedAddons.Add(wrapper); foreach (AddonInfoFromYaml addon in OpeningViewModel.GetInstance.AddonList.Where(add => add.IsSelected == true)) { selectedAddons.Add(addon); } Application.Current.Properties["Selected"] = selectedAddons; this.NavigationService.Navigate(new Uri("UI/UpdatingPage/UpdatingView.xaml", UriKind.Relative)); }
/***** ENABLE *****/ public static void enable(AddonInfo addon_info) { UserConfig info = Configuration.getConfigAsYAML(); if (info.installed.ContainsKey(addon_info.folder_name) && info.installed[addon_info.folder_name] != null) { if (info.disabled.ContainsKey(addon_info.folder_name) && info.disabled[addon_info.folder_name]) { if (addon_info.install_mode != "arc") { Directory.Move( Path.Combine("Disabled Plugins", addon_info.folder_name), Path.Combine(Path.Combine(info.game_path, "addons"), addon_info.folder_name) ); } else { if (!Directory.Exists(Path.Combine(Path.Combine(info.game_path, "addons"), "arcdps"))) { Directory.CreateDirectory(Path.Combine(Path.Combine(info.game_path, "addons"), "arcdps")); } File.Move( Path.Combine(Path.Combine("Disabled Plugins", addon_info.folder_name), addon_info.plugin_name), Path.Combine(Path.Combine(Path.Combine(info.game_path, "addons"), "arcdps"), addon_info.plugin_name) ); } info.disabled[addon_info.folder_name] = false; Configuration.setConfigAsYAML(info); } } }
/***************************** Button Controls *****************************/ private void close_clicked(object sender, RoutedEventArgs e) { SelfUpdate.startUpdater(); if ((bool)launchOnClose.IsChecked) { string exeLocation = Path.Combine(Configuration.getConfigAsYAML().game_path, Configuration.getConfigAsYAML().exe_name); try { Process.Start(exeLocation, "-autologin"); } catch (System.ComponentModel.Win32Exception) { MessageBox.Show($"Unable to launch game as {Configuration.getConfigAsYAML().exe_name} is missing.", "Unable to Launch Game", MessageBoxButton.OK, MessageBoxImage.Error); } } UserConfig config = Configuration.getConfigAsYAML(); if (config.launch_game != (bool)launchOnClose.IsChecked) { config.launch_game = (bool)launchOnClose.IsChecked; Configuration.setConfigAsYAML(config); } System.Windows.Application.Current.Shutdown(); }
/// <summary> /// Sets some UI text to indicate that the addon loader is having an update check /// </summary> /// <param name="aViewModel"></param> public LoaderSetup(UpdatingViewModel aViewModel) { viewModel = aViewModel; viewModel.label = "Checking for updates to Addon Loader"; userConfig = Configuration.getConfigAsYAML(); loader_game_path = Path.Combine(userConfig.game_path, userConfig.bin_folder); }
/***** ENABLE *****/ public static void enable(AddonInfoFromYaml addon_info) { UserConfig info = Configuration.getConfigAsYAML(); if (info.installed.ContainsKey(addon_info.folder_name) && info.installed[addon_info.folder_name] != null) { if (info.disabled.ContainsKey(addon_info.folder_name) && info.disabled[addon_info.folder_name]) { if (addon_info.install_mode != "arc") { //non-arc Directory.Move( Path.Combine("Disabled Plugins", addon_info.folder_name), Path.Combine(Path.Combine(info.game_path, "addons"), addon_info.folder_name) ); } else { //arc if (!Directory.Exists(Path.Combine(Path.Combine(info.game_path, "addons"), "arcdps"))) { Directory.CreateDirectory(Path.Combine(Path.Combine(info.game_path, "addons"), "arcdps")); } //buildpad compatibility check if (!addon_info.addon_name.Contains("BuildPad")) { //non-buildpad File.Move( Path.Combine(Path.Combine("Disabled Plugins", addon_info.folder_name), addon_info.plugin_name), Path.Combine(Path.Combine(Path.Combine(info.game_path, "addons"), "arcdps"), addon_info.plugin_name) ); } else { //buildpad string buildPadFileName = ""; string[] buildPadFiles = Directory.GetFiles(Path.Combine("Disabled Plugins", addon_info.folder_name)); foreach (string someFileName in buildPadFiles) { if (someFileName.Contains("buildpad")) { buildPadFileName = Path.GetFileName(someFileName); } } File.Move( Path.Combine(Path.Combine("Disabled Plugins", addon_info.folder_name), buildPadFileName), Path.Combine(Path.Combine(Path.Combine(info.game_path, "addons"), "arcdps"), buildPadFileName) ); } } info.disabled[addon_info.folder_name] = false; Configuration.setConfigAsYAML(info); } } }
/***** DELETE *****/ public static void delete(AddonInfo addon_info) { UserConfig info = Configuration.getConfigAsYAML(); if (info.installed.ContainsKey(addon_info.folder_name) && info.installed[addon_info.folder_name] != null) { if (info.disabled.ContainsKey(addon_info.folder_name) && info.disabled[addon_info.folder_name]) { Directory.Delete(Path.Combine("Disabled Plugins", addon_info.folder_name), true); info.disabled.Remove(addon_info.folder_name); info.installed.Remove(addon_info.folder_name); info.version.Remove(addon_info.folder_name); Configuration.setConfigAsYAML(info); } else { if (addon_info.install_mode != "arc") { Directory.Delete(Path.Combine(Path.Combine(info.game_path, "addons"), addon_info.folder_name), true); if (info.disabled.ContainsKey(addon_info.folder_name)) { info.disabled.Remove(addon_info.folder_name); } info.installed.Remove(addon_info.folder_name); info.version.Remove(addon_info.folder_name); //deleting arcdps will delete other addons as well if (addon_info.folder_name == "arcdps") { foreach (AddonInfo adj_info in ApprovedList.GenerateAddonList()) { if (adj_info.install_mode == "arc") { //if arc-dependent plugin is disabled, it won't get deleted since it's not in the /addons/arcdps folder if (info.disabled.ContainsKey(adj_info.folder_name) && !info.disabled[adj_info.folder_name]) { info.disabled.Remove(adj_info.folder_name); info.installed.Remove(adj_info.folder_name); info.version.Remove(adj_info.folder_name); } } } } } else { File.Delete(Path.Combine(Path.Combine(Path.Combine(info.game_path, "addons"), "arcdps"), addon_info.plugin_name)); if (info.disabled.ContainsKey(addon_info.folder_name)) { info.disabled.Remove(addon_info.folder_name); } info.installed.Remove(addon_info.folder_name); info.version.Remove(addon_info.folder_name); } Configuration.setConfigAsYAML(info); } } }
/// <summary> /// <c>SetGamePath</c> both sets the game path for the current application session to <paramref name="path"/> and records it in the configuration file. /// </summary> /// <param name="path">The game path.</param> public static void SetGamePath(string path) { Application.Current.Properties["game_path"] = path.Replace("\\", "\\\\"); UserConfig config_obj = Configuration.getConfigAsYAML(); config_obj.game_path = Application.Current.Properties["game_path"].ToString().Replace("\\\\", "\\"); setConfigAsYAML(config_obj); DetermineSystemType(); }
public GenericUpdater(AddonInfoFromYaml addon) { addon_name = addon.folder_name; addon_info = addon; viewModel = UpdatingViewModel.GetInstance; userConfig = Configuration.getConfigAsYAML(); addon_expanded_path = Path.Combine(Path.GetTempPath(), addon_name); addon_install_path = Path.Combine(Configuration.getConfigAsYAML().game_path, "addons\\"); }
/// <summary> /// Sets the page's DataContext, initializes it, and begins the update process. /// </summary> public UpdatingView() { DataContext = UpdatingViewModel.GetInstance; InitializeComponent(); LoaderSetup settingUp = new LoaderSetup(); Task.Run(() => UpdateHelpers.UpdateAll()); launchOnClose.IsChecked = Configuration.getConfigAsYAML().launch_game; }
/// <summary> /// This constructor initializes various default properties across the class and then /// applies any updated values to them using <c>ApplyDefaultConfig</c>. /// </summary> public OpeningViewModel() { AddonList = ApprovedList.GenerateAddonList(); DescriptionText = "Select an add-on to see more information about it."; DeveloperVisibility = Visibility.Hidden; UpdateLinkVisibility = Visibility.Hidden; UpdateProgressVisibility = Visibility.Hidden; GamePath = Configuration.getConfigAsYAML().game_path; }
/// <summary> /// Sets version fields of all installed and enabled addons to a dummy value so they are redownloaded, then starts update process. /// Intended for use if a user borks their install (probably by manually deleting something in the /addons/ folder). /// </summary> public static bool ForceRedownload() { string redownloadmsg = "This will forcibly redownload all installed addons regardless of their version. Do you wish to continue?"; if (MessageBox.Show(redownloadmsg, "Warning!", MessageBoxButton.YesNo, MessageBoxImage.Warning) == MessageBoxResult.Yes) { UserConfig config = Configuration.getConfigAsYAML(); config.version = config.version.ToDictionary(entry => entry.Key, entry => "dummy value"); Configuration.setConfigAsYAML(config); return(true); } return(false); }
/***** DISABLE *****/ public static void Disable(AddonInfoFromYaml addon_info) { UserConfig info = Configuration.getConfigAsYAML(); if (info.installed.ContainsKey(addon_info.folder_name) && info.installed[addon_info.folder_name] != null) { if (info.disabled.ContainsKey(addon_info.folder_name) && !info.disabled[addon_info.folder_name]) { if (addon_info.install_mode != "arc") { Directory.Move( Path.Combine(Path.Combine(info.game_path, "addons"), addon_info.folder_name), Path.Combine("Disabled Plugins", addon_info.folder_name) ); } else { //probably broken if (!Directory.Exists(Path.Combine("Disabled Plugins", addon_info.folder_name))) { Directory.CreateDirectory(Path.Combine("Disabled Plugins", addon_info.folder_name)); } if (addon_info.addon_name == "BuildPad (Installed)") { File.Move( Path.Combine(Path.Combine(Path.Combine(info.game_path, "addons"), "arcdps"), Configuration.getConfigAsYAML().version["buildPad"]), Path.Combine(Path.Combine("Disabled Plugins", addon_info.folder_name), Configuration.getConfigAsYAML().version["buildPad"]) ); } else { File.Move( Path.Combine(Path.Combine(Path.Combine(info.game_path, "addons"), "arcdps"), addon_info.plugin_name), Path.Combine(Path.Combine("Disabled Plugins", addon_info.folder_name), addon_info.plugin_name) ); } } info.disabled[addon_info.folder_name] = true; Configuration.setConfigAsYAML(info); } } }
/// <summary> /// /// </summary> /// <returns>A list of AddonInfo objects representing all approved add-ons.</returns> public static ObservableCollection <AddonInfo> GenerateAddonList() { ObservableCollection <AddonInfo> Addons = new ObservableCollection <AddonInfo>(); //List of AddonInfo objects string[] AddonDirectories = Directory.GetDirectories("resources\\addons"); //Names of addon subdirectories in /resources/addons UserConfig userConfig = Configuration.getConfigAsYAML(); foreach (string addonFolderName in AddonDirectories) { if (addonFolderName != "resources\\addons\\d3d9_wrapper") { AddonInfo temp = AddonYamlReader.getAddonInInfo(addonFolderName.Replace("resources\\addons\\", "")); temp.folder_name = addonFolderName.Replace("resources\\addons\\", ""); if (userConfig.default_configuration.ContainsKey(temp.folder_name) && userConfig.default_configuration[temp.folder_name]) { temp.IsSelected = true; } Addons.Add(temp); //retrieving info from each addon subdirectory's update.yaml file and adding it to the list } } return(Addons); }
/***** DELETE *****/ public static void delete(AddonInfoFromYaml addon_info) { UserConfig info = Configuration.getConfigAsYAML(); if (info.installed.ContainsKey(addon_info.folder_name) && info.installed[addon_info.folder_name] != null) { if (info.disabled.ContainsKey(addon_info.folder_name) && info.disabled[addon_info.folder_name]) { FileSystem.DeleteDirectory(Path.Combine("Disabled Plugins", addon_info.folder_name), UIOption.OnlyErrorDialogs, RecycleOption.SendToRecycleBin); info.disabled.Remove(addon_info.folder_name); info.installed.Remove(addon_info.folder_name); info.version.Remove(addon_info.folder_name); Configuration.setConfigAsYAML(info); } else { if (addon_info.install_mode != "arc") { FileSystem.DeleteDirectory(Path.Combine(Path.Combine(info.game_path, "addons"), addon_info.folder_name), UIOption.OnlyErrorDialogs, RecycleOption.SendToRecycleBin); if (info.disabled.ContainsKey(addon_info.folder_name)) { info.disabled.Remove(addon_info.folder_name); } info.installed.Remove(addon_info.folder_name); info.version.Remove(addon_info.folder_name); //deleting arcdps will delete other addons as well if (addon_info.folder_name == "arcdps") { foreach (AddonInfoFromYaml adj_info in ApprovedList.GenerateAddonList()) { if (adj_info.install_mode == "arc") { //if arc-dependent plugin is disabled, it won't get deleted since it's not in the /addons/arcdps folder if (info.disabled.ContainsKey(adj_info.folder_name) && !info.disabled[adj_info.folder_name]) { info.disabled.Remove(adj_info.folder_name); info.installed.Remove(adj_info.folder_name); info.version.Remove(adj_info.folder_name); } } } } } else { //buildpad check if (!addon_info.addon_name.Contains("BuildPad")) { FileSystem.DeleteFile(Path.Combine(Path.Combine(Path.Combine(info.game_path, "addons"), "arcdps"), addon_info.plugin_name), UIOption.OnlyErrorDialogs, RecycleOption.SendToRecycleBin); } else { string buildPadFileName = ""; string[] arcFiles = Directory.GetFiles(Path.Combine(Path.Combine(info.game_path, "addons"), "arcdps")); //search for plugin name in arc folder //TODO: Should break out of operation and give message if the plugin is not found. foreach (string arcFileName in arcFiles) { if (arcFileName.Contains("buildpad")) { buildPadFileName = Path.GetFileName(arcFileName); } } FileSystem.DeleteFile(Path.Combine(Path.Combine(Path.Combine(info.game_path, "addons"), "arcdps"), buildPadFileName), UIOption.OnlyErrorDialogs, RecycleOption.SendToRecycleBin); } if (info.disabled.ContainsKey(addon_info.folder_name)) { info.disabled.Remove(addon_info.folder_name); } info.installed.Remove(addon_info.folder_name); info.version.Remove(addon_info.folder_name); } Configuration.setConfigAsYAML(info); } } }
/***** INSTALL *****/ /// <summary> /// Performs archive extraction and file IO operations to install the downloaded addon. /// </summary> private void Install() { viewModel.ProgBarLabel = "Installing " + addon_info.addon_name; if (addon_info.download_type == "archive") { if (Directory.Exists(addon_expanded_path)) { Directory.Delete(addon_expanded_path, true); } ZipFile.ExtractToDirectory(fileName, addon_expanded_path); if (addon_info.install_mode != "arc") { FileSystem.CopyDirectory(addon_expanded_path, addon_install_path, true); } else { if (!Directory.Exists(Path.Combine(addon_install_path, "arcdps"))) { Directory.CreateDirectory(Path.Combine(addon_install_path, "arcdps")); } File.Copy(Path.Combine(addon_expanded_path, addon_info.plugin_name), Path.Combine(Path.Combine(addon_install_path, "arcdps"), addon_info.plugin_name), true); } } else { if (addon_info.install_mode != "arc") { if (!Directory.Exists(Path.Combine(addon_install_path, addon_info.folder_name))) { Directory.CreateDirectory(Path.Combine(addon_install_path, addon_info.folder_name)); } FileSystem.CopyFile(fileName, Path.Combine(Path.Combine(addon_install_path, addon_info.folder_name), Path.GetFileName(fileName)), true); } else { if (!Directory.Exists(Path.Combine(addon_install_path, "arcdps"))) { Directory.CreateDirectory(Path.Combine(addon_install_path, "arcdps")); } FileSystem.CopyFile(fileName, Path.Combine(Path.Combine(addon_install_path, "arcdps"), Path.GetFileName(fileName)), true); } } //removing download from temp folder to avoid naming clashes FileSystem.DeleteFile(fileName); if (userConfig.version.ContainsKey(addon_info.folder_name)) { userConfig.version[addon_info.folder_name] = latestVersion; } else { userConfig.version.Add(addon_info.folder_name, latestVersion); } if (userConfig.installed.ContainsKey(addon_info.folder_name)) { userConfig.installed[addon_info.folder_name] = addon_info.folder_name; } else { userConfig.installed.Add(addon_info.folder_name, addon_info.folder_name); } if (!userConfig.disabled.ContainsKey(addon_info.folder_name)) { userConfig.disabled.Add(addon_info.folder_name, false); } //deleting old buildpad dll (other plugins get overwritten instead so deletion not necessary) if (addon_name == "buildPad" && Configuration.getConfigAsYAML().version.ContainsKey(addon_name)) { File.Delete(Path.Combine(Path.Combine(addon_install_path, "arcdps"), Configuration.getConfigAsYAML().version[addon_name])); } //set config.yaml Configuration.setConfigAsYAML(userConfig); }
/***** DISABLE *****/ //TODO: Note to self May 1 2020: consider making some vanity methods to clean up all the Path.Combine()s in here; the code's a bit of a chore to read. public static void Disable(AddonInfoFromYaml addon_info) { UserConfig info = Configuration.getConfigAsYAML(); if (info.installed.ContainsKey(addon_info.folder_name) && info.installed[addon_info.folder_name] != null) { if (!Directory.Exists("Disabled Plugins")) { Directory.CreateDirectory("Disabled Plugins"); } if (info.disabled.ContainsKey(addon_info.folder_name) && !info.disabled[addon_info.folder_name]) { if (addon_info.install_mode != "arc") { Directory.Move( Path.Combine(Path.Combine(info.game_path, "addons"), addon_info.folder_name), Path.Combine("Disabled Plugins", addon_info.folder_name) ); } else { //probably broken if (!Directory.Exists(Path.Combine("Disabled Plugins", addon_info.folder_name))) { Directory.CreateDirectory(Path.Combine("Disabled Plugins", addon_info.folder_name)); } if (addon_info.addon_name.Contains("BuildPad")) { string buildPadFileName = ""; string[] arcFiles = Directory.GetFiles(Path.Combine(Path.Combine(info.game_path, "addons"), "arcdps")); //search for plugin name in arc folder //TODO: Should break out of operation and give message if the plugin is not found. foreach (string arcFileName in arcFiles) { if (arcFileName.Contains("buildpad")) { buildPadFileName = Path.GetFileName(arcFileName); } } File.Move( Path.Combine(Path.Combine(Path.Combine(info.game_path, "addons"), "arcdps"), buildPadFileName), Path.Combine(Path.Combine("Disabled Plugins", addon_info.folder_name), buildPadFileName) ); } else { File.Move( Path.Combine(Path.Combine(Path.Combine(info.game_path, "addons"), "arcdps"), addon_info.plugin_name), Path.Combine(Path.Combine("Disabled Plugins", addon_info.folder_name), addon_info.plugin_name) ); } } info.disabled[addon_info.folder_name] = true; Configuration.setConfigAsYAML(info); } } }
public static async void UpdateAll() { UpdatingViewModel viewModel = UpdatingViewModel.GetInstance; LoaderSetup settingUp = new LoaderSetup(); await settingUp.HandleLoaderUpdate(); List <AddonInfoFromYaml> addons = (List <AddonInfoFromYaml>)Application.Current.Properties["Selected"]; foreach (AddonInfoFromYaml addon in addons.Where(add => add != null)) { GenericUpdater updater = new GenericUpdater(addon); if (!(addon.additional_flags != null && addon.additional_flags.Contains("self-updating") && Configuration.getConfigAsYAML().installed.ContainsKey(addon.folder_name))) { await updater.Update(); } } viewModel.ProgBarLabel = "Updates Complete"; viewModel.DownloadProgress = 100; viewModel.CloseBtnEnabled = true; viewModel.BackBtnEnabled = true; }