Пример #1
0
        public void DetectManualModInstallOrUninstall(out List <Mod> wasManuallyInstalled, out List <InstalledMod> wasManuallyUninstalled, bool onlyDetectApproved = true)
        {
            wasManuallyInstalled   = new List <Mod>();
            wasManuallyUninstalled = new List <InstalledMod>();

            foreach (Mod m in beatMods.AllMods.OnlyKeepMostRecentMods())
            {
                Mod.Download.File pluginDll = m.GetPluginBinaryFile(BeatSaberType);

                if (string.IsNullOrEmpty(pluginDll.file))
                {
                    continue;
                }

                string pluginDllPath = Path.Combine(BeatSaberDirectory, pluginDll.file);
                bool   onDisk        = File.Exists(pluginDllPath);

                if (IsInstalledAnyVersion(m) && !onDisk)
                {
                    // Plugin was uninstalled from outside this application.

                    wasManuallyUninstalled.Add(GetInstalledModIgnoreVersion(m));
                    Console.WriteLine($"Plugin was uninstalled from outside this application (md5: { pluginDll.hash }): { pluginDllPath }");
                }
                else if (!IsInstalledAnyVersion(m) && onDisk)
                {
                    // Plugin was installed from outside this application.

                    string diskDllHash = Hashing.CalculateMD5(pluginDllPath);

                    Mod installedVersion = beatMods.GetModsWithName(m.Name, onlyDetectApproved).FirstOrDefault((e) =>
                                                                                                               string.Compare(e.GetPluginBinaryFile(BeatSaberType).hash, diskDllHash, StringComparison.OrdinalIgnoreCase) == 0);

                    if (onlyDetectApproved && m.Status != ModStatus.Approved)
                    {
                        Console.WriteLine($"Plugin was installed from outside this application, but it was not returned because it is unapproved: { m }");
                        continue;
                    }

                    if (installedVersion == null)
                    {
                        installedVersion = beatMods.GetModsWithName(m.Name).Last();
                        Console.WriteLine($"Plugin was installed from outside this application, but the version could not be found for { m.Name }, using oldest version");
                    }
                    else
                    {
                        Console.WriteLine($"Plugin was installed from outside this application (md5: { pluginDll.hash }): { installedVersion }");
                    }

                    wasManuallyInstalled.Add(installedVersion);
                }
            }

            SaveConfig();
        }
Пример #2
0
        /*[Obsolete]
         * public LocalMod(string id, string name, string version, Mod.Download.File binaryFile, bool preventRemoval = false)
         * {
         *  Id = id;
         *  Name = name;
         *  Version = version;
         *  this.binaryFile = binaryFile;
         *  this.preventRemoval = preventRemoval;
         *  affectedFiles = new List<string>();
         *  usedBy = new List<string>();
         *  uses = new List<string>();
         * }*/

        public InstalledMod(Mod mod, BeatSaberInstalledType type)
        {
            Id             = mod.Id;
            Name           = mod.Name;
            Version        = mod.Version;
            GameVersion    = mod.GameVersion;
            binaryFile     = mod.GetPluginBinaryFile(type);
            preventRemoval = mod.required;
            affectedFiles  = mod.GetBestDownloadFor(type).archiveFiles.Select((e) => e.file).ToList();
            usedBy         = new List <string>();
            uses           = new List <string>();
        }