Пример #1
0
        public static void Uninstall(InstalledItem ii)
        {
            /*
             * List<string> files = new List<string>(), dirs = new List<string>();
             * foreach (var ver in ii.Versions) {
             *  string file = System.IO.Path.Combine(Sys.Settings.LibraryLocation, ver.InstalledLocation);
             *  if (System.IO.File.Exists(file))
             *      files.Add(ver.InstalledLocation);
             *  else if (System.IO.Directory.Exists(file))
             *      dirs.Add(ver.InstalledLocation);
             * }
             *
             * string err;
             * switch (CheckDeleteAll(files, dirs, out err)) {
             *  case DeleteStatus.DidntStart:
             *      Sys.Message(new WMessage() { Text = err });
             *      return;
             *  case DeleteStatus.Partial:
             *      Sys.Message(new WMessage() { Text = "Some files could not be deleted, were they in use?" });
             *      break;
             * }
             */

            Sys.Library.QueuePendingDelete(ii.Versions.Select(v => v.InstalledLocation));
            Sys.Library.RemoveInstall(ii);
            Sys.Message(new WMessage()
            {
                Text = "Uninstalled " + ii.CachedDetails.Name
            });
            Sys.Library.AttemptDeletions();
        }
Пример #2
0
        public void RemoveInstall(InstalledItem ii)
        {
            var exist = GetItem(ii.ModID); //forces lookup creation

            if (exist != null)
            {
                Items.Remove(exist);
            }
            _lookup.Remove(ii.ModID);
            Sys.SetStatus(ii.ModID, ModStatus.NotInstalled);
            Sys.Save();
        }
Пример #3
0
        public void AddInstall(InstalledItem ii)
        {
            var exist = GetItem(ii.ModID); //forces lookup creation

            if (exist != null)
            {
                Items.Remove(exist);
            }
            Items.Add(ii);
            _lookup[ii.ModID] = ii;
            PendingDelete.RemoveAll(s => s.Equals(ii.LatestInstalled.InstalledLocation, StringComparison.InvariantCultureIgnoreCase));
            Sys.SetStatus(ii.ModID, ModStatus.Installed);
            Sys.Save();
        }
Пример #4
0
            public override void DownloadComplete(System.ComponentModel.AsyncCompletedEventArgs e)
            {
                if (e.Error != null)
                {
                    Sys.Message(new WMessage($"[{StringKey.ErrorDownloading}] {Mod.Name}")
                    {
                        TextTranslationKey = StringKey.ErrorDownloading, LoggedException = e.Error
                    });
                    Sys.RevertStatus(Mod.ID);
                    return;
                }

                InstalledItem inst    = Sys.Library.GetItem(Mod.ID);
                bool          isIro   = Path.GetExtension(_dest) == ".iro";
                string        modName = Mod?.Name;

                if (string.IsNullOrWhiteSpace(modName))
                {
                    modName = ModImporter.ParseNameFromFileOrFolder(_dest);
                }

                try
                {
                    Mod = ModImporter.ImportMod(_dest, modName, isIro, noCopy: true); // noCopy set to true because ProcessDownload() already copied the downloaded mod to the 'mods' library folder
                }
                catch (Exception ex)
                {
                    base.Error(ex);
                    return;
                }

                if (inst == null)
                {
                    Sys.Message(new WMessage($"[{StringKey.Installed}] {Mod.Name}")
                    {
                        TextTranslationKey = StringKey.Installed
                    });
                }
                else
                {
                    Sys.Message(new WMessage($"[{StringKey.Updated}] {Mod.Name}")
                    {
                        TextTranslationKey = StringKey.Updated
                    });
                }

                Sys.SetStatus(Mod.ID, ModStatus.Installed);
                Sys.SaveLibrary();
            }
Пример #5
0
            private void ProcessDownload(object state)
            {
                string patchfile = Path.Combine(Sys.Settings.LibraryLocation, "temp", Filename);

                try
                {
                    if (Install == null)
                    {
                        Install = Sys.Library.GetItem(Mod.ID);

                        if (Install == null)
                        {
                            // don't go any further since mod is not installed
                            Error(new Exception($"{Mod.Name} not installed"));
                            return;
                        }
                    }

                    string source = Path.Combine(Sys.Settings.LibraryLocation, Install.LatestInstalled.InstalledLocation);
                    using (var iro = new _7thWrapperLib.IrosArc(source, true))
                    {
                        using (var patch = new _7thWrapperLib.IrosArc(patchfile))
                        {
                            iro.ApplyPatch(patch, (d, msg) =>
                            {
                                Sys.Message(new WMessage(msg, WMessageLogLevel.LogOnly));
                                SetPercentComplete((int)(100 * d));
                            });
                        }
                    }

                    File.Delete(patchfile);
                }
                catch (Exception e)
                {
                    Error(e);
                    return;
                }

                SetPercentComplete(100);
                Complete();
            }
Пример #6
0
 public static void Uninstall(InstalledItem ii)
 {
     Sys.Library.QueuePendingDelete(ii.Versions.Select(v => v.InstalledLocation));
     Sys.Library.RemoveInstall(ii);
     Sys.Library.AttemptDeletions();
 }
Пример #7
0
            public override void DownloadComplete(System.ComponentModel.AsyncCompletedEventArgs e)
            {
                if (e.Error != null)
                {
                    Sys.Message(new WMessage()
                    {
                        Text = $"Error downloading {Mod.Name}\r\n{e.Error.ToString()}", LoggedException = e.Error
                    });
                    Sys.RevertStatus(Mod.ID);
                    return;
                }

                InstalledItem inst = Sys.Library.GetItem(Mod.ID);

                if (inst == null)
                {
                    try
                    {
                        Mod = new ModImporter().ParseModXmlFromSource(_dest, Mod);

                        Sys.Library.AddInstall(new InstalledItem()
                        {
                            ModID         = Mod.ID,
                            CachedDetails = Mod,
                            UpdateType    = Sys.Library.DefaultUpdate,
                            Versions      = new List <InstalledVersion>()
                            {
                                new InstalledVersion()
                                {
                                    InstalledLocation = System.IO.Path.GetFileName(_dest), VersionDetails = Mod.LatestVersion
                                }
                            }
                        });
                    }
                    catch (Exception ex)
                    {
                        base.Error(ex);
                        return;
                    }

                    Sys.Message(new WMessage()
                    {
                        Text = "Installed " + Mod.Name, Link = "iros://" + Mod.ID.ToString()
                    });
                    Sys.SetStatus(Mod.ID, ModStatus.Installed);
                }
                else
                {
                    try
                    {
                        inst.CachedDetails = new ModImporter().ParseModXmlFromSource(_dest, Mod);

                        // 7H 2.0 NOTE: GeneralOptions.KeepOldVersions is always FALSE and is hidden from the user.. The conditional is kept in-case we ever want to try re-enabling it.
                        if (!Sys.Settings.HasOption(GeneralOptions.KeepOldVersions))
                        {
                            foreach (string ivfile in inst.Versions.Select(v => v.InstalledLocation))
                            {
                                string ifile = System.IO.Path.Combine(Sys.Settings.LibraryLocation, ivfile);

                                if (ifile == _dest)
                                {
                                    continue; // skip file that was just copied as the new version may have overwritten the old version file so they have the same file name
                                }

                                if (System.IO.File.Exists(ifile))
                                {
                                    System.IO.File.Delete(ifile);
                                }
                                else if (System.IO.Directory.Exists(ifile))
                                {
                                    System.IO.Directory.Delete(ifile, true);
                                }
                            }
                            inst.Versions.Clear();
                        }

                        inst.Versions.Add(new InstalledVersion()
                        {
                            InstalledLocation = System.IO.Path.GetFileName(_dest), VersionDetails = Mod.LatestVersion
                        });
                    }
                    catch (Exception ex)
                    {
                        base.Error(ex);
                        return;
                    }

                    Sys.Message(new WMessage()
                    {
                        Text = "Updated " + Mod.Name, Link = "iros://" + Mod.ID.ToString()
                    });
                    Sys.SetStatus(Mod.ID, ModStatus.Installed);
                }

                Sys.Save();
            }
Пример #8
0
        public IEnumerable <string> GetDetails()
        {
            List <string> profileDetails = new List <string>();

            profileDetails.Add($"7th Heaven Version: {Sys.AppVersion}\n");

            foreach (ProfileItem item in Items)
            {
                InstalledItem mod = Sys.Library.GetItem(item.ModID);

                if (mod != null)
                {
                    Mod details = mod.CachedDetails;

                    if (details != null)
                    {
                        profileDetails.Add(String.Format("# {0}", details.Name));
                        profileDetails.Add(String.Format("\tID: {0}", details.ID));
                        profileDetails.Add(String.Format("\tVersion: {0}", mod.LatestInstalled.VersionDetails.Version));
                    }
                    else
                    {
                        profileDetails.Add(String.Format("\tModID {0}", mod.ModID));
                    }

                    profileDetails.Add(String.Format("\tIs Active: {0}", item.IsModActive));



                    ModInfo info         = mod.GetModInfo();
                    string  detailFormat = "";

                    if (info != null)
                    {
                        detailFormat = item.GetFormatString(info);
                    }

                    foreach (ProfileSetting config in item.Settings)
                    {
                        if (info != null)
                        {
                            // extract configuration variable name and name of the selected value from Mod Info
                            ConfigOption configOption = info.Options.FirstOrDefault(o => o.ID == config.ID);
                            string       optionValue  = "";

                            if (configOption.Type == OptionType.Bool)
                            {
                                optionValue = (config.Value == 1).ToString();
                            }
                            else
                            {
                                optionValue = $"\"{configOption.Values.Where(o => o.Value == config.Value).Select(o => o.Name).FirstOrDefault()}\"";
                            }


                            string name  = $"\"{configOption.Name}\"";
                            string id    = $"({config.ID})";
                            string value = $"({config.Value})";

                            profileDetails.Add(string.Format(detailFormat, name, id, "=", optionValue, value)); // "=" is passed into string.Format() so all equal signs are aligned using the {2, 2} syntax
                        }
                        else
                        {
                            profileDetails.Add(String.Format("\t{0} = {1}", config.ID, config.Value));
                        }
                    }
                }
            }

            return(profileDetails);
        }
Пример #9
0
 public void DeleteAndRemoveInstall(InstalledItem ii, IEnumerable <string> versionFilesToDelete)
 {
     QueuePendingDelete(versionFilesToDelete);
     RemoveInstall(ii);
     AttemptDeletions();
 }
Пример #10
0
 public void DeleteAndRemoveInstall(InstalledItem ii)
 {
     DeleteAndRemoveInstall(ii, ii.Versions.Select(v => v.InstalledLocation));
 }