/***** 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();
        }
        /***** 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);
                }
            }
        }
        /// <summary>
        /// Check current version of addon list against remote repo for changes and fetch them
        /// </summary>
        /// <param name="cfg">User's application configuration found in config.yaml</param>
        public static void FetchListFromRepo(UserConfig cfg)
        {
            const string tempFileName = "addonlist";
            var          client       = new WebClient();

            client.Headers.Add("User-Agent", "Gw2 Addon Manager");

            var    raw    = client.DownloadString(RepoUrl + "/branches");
            var    result = JsonConvert.DeserializeObject <BranchInfo[]>(raw);
            string master = null;

            //checking for changes
            foreach (var info in result)
            {
                if (info.Name != "master")
                {
                    continue;
                }

                if (info.Commit.Sha == cfg.current_addon_list)
                {
                    return;
                }

                master = info.Commit.Sha;
                break;
            }

            //deleting old version
            try
            {
                Directory.Delete(AddonFolder, true);
                File.Delete(tempFileName);
            }
            catch (Exception)
            {
                // ignored
            }

            //fetching new version
            client = new WebClient();
            client.Headers.Add("User-Agent", "Gw2 Addon Manager");
            client.DownloadFile(RepoUrl + "/zipball", tempFileName);
            ZipFile.ExtractToDirectory(tempFileName, AddonFolder);
            var downloaded = Directory.EnumerateDirectories(AddonFolder).First();

            foreach (var entry in Directory.EnumerateFileSystemEntries(downloaded))
            {
                Directory.Move(entry, AddonFolder + "\\" + Path.GetFileName(entry));
            }

            //updating version in config file
            cfg.current_addon_list = master;
            Configuration.setConfigAsYAML(cfg);

            //cleanup
            Directory.Delete(downloaded, true);
            File.Delete(tempFileName);
        }
        /***** 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>
        /// 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);
        }
示例#7
0
        private void Install()
        {
            viewModel.ProgBarLabel = "Installing Addon Loader";

            if (File.Exists(loader_destination))
            {
                File.Delete(loader_destination);
            }

            ZipFile.ExtractToDirectory(fileName, loader_game_path);

            userConfig.loader_version = latestLoaderVersion;

            Configuration.setConfigAsYAML(userConfig);
        }
        /***** 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);
                }
            }
        }
        /***** 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);
                }
            }
        }
        /***** 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);
                }
            }
        }
        /***** 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);
            }

            //set config.yaml
            Configuration.setConfigAsYAML(userConfig);
        }