コード例 #1
0
        public object Clone(bool SurfaceOnly)
        {
            var clone = new ModViewModel(this.Id, this.Directory, this.Type);

            clone.Enabled  = this.Enabled;
            clone.Expanded = this.Expanded;
            clone.Color    = this.Color;

            if (!SurfaceOnly)
            {
                foreach (var c in this.Childs)
                {
                    clone.Childs.Add((ModViewModel)c.Clone());
                }
            }
            return(clone);
        }
コード例 #2
0
        public void SortWithRWMSDB(bool RemoveEmptyDirectory = true)
        {
            if (this.RWMSDB == null)
            {
                return;
            }

            var unknown = new ModViewModel("unknown", "Unknown mods on RWMSDB")
            {
                Color = Colors.DarkGray
            };

            // Search all mods
            Action <ModViewModel> explore = null;

            explore = new Action <ModViewModel>(x => {
                if (x.Type != ModType.Directory)
                {
                    unknown.Childs.Add((ModViewModel)x.Clone(false));
                }

                foreach (var y in x.Childs)
                {
                    explore(y);
                }
            });
            foreach (var x in this.ModList)
            {
                explore(x);
            }

            var list = new ObservableCollection <ModViewModel>();

            var rnd = new Random();

            this.RWMSDBCat.cat
            .OrderBy(x => x.Value.Weight)
            .ToList()
            .ForEach(x => list.Add(
                         new ModViewModel(x.Key, x.Value.Description)
            {
                Expanded = false,
                Color    = ColorTable.ColorList[rnd.Next(ColorTable.ColorList.Length)]
            }
                         ));
            list.Add(unknown);

            var db = this.RWMSDB.db;

            foreach (var i in db)
            {
                var targetName     = i.Key;
                var targetCategory = i.Value;

                var targets = unknown.Childs.Where(x => x.Type != ModType.Directory && x.Name == targetName).ToArray();
                if (targets.Length > 0)
                {
                    var dest = list.FirstOrDefault(x => x.Type == ModType.Directory && x.Id == targetCategory);
                    if (dest == null)
                    {
                        continue;                                   // Category not found, keep unknown directory
                    }
                    foreach (var target in targets)
                    {
                        unknown.Childs.Remove(target);
                    }

                    if (targets.Length == 1)
                    {
                        // Single mods, just move to destination
                        dest.Childs.Add(targets.First());
                    }
                    else
                    {
                        // Multiple mods, move to new directory that created to destination
                        var newDir = new ModViewModel("grp_" + targetName, "📚 " + targetName);
                        foreach (var target in targets)
                        {
                            newDir.Childs.Add(target);
                        }
                        dest.Childs.Add(newDir);
                    }
                }
            }

            if (RemoveEmptyDirectory)
            {
                list.Where(x => x.Type == ModType.Directory && x.Childs.Count == 0)
                .ToList()
                .ForEach(x => list.Remove(x));
            }

            this.ModList = list;
        }
コード例 #3
0
        public bool LoadMods(string path)
        {
            var config = new INI();

            // Mod list
            var mods = new List <ModViewModel>();

            // Listing local mods (except Core)
            var LocalModDir = Path.Combine(config.Read("RimWorldDir", "Directories"), "Mods");
            var LocalMods   = Directory.GetDirectories(LocalModDir)
                              .Select(x => Path.GetFileName(x))
                              .ToArray();

            // Listing steam mods
            var SteamModDir = Path.Combine(config.Read("WorkshopDir", "Directories"));
            var SteamMods   = Directory.GetDirectories(SteamModDir)
                              .Select(x => Path.GetFileName(x))
                              .ToArray();

            var mc = new ModsConfig(path);

            if (!mc.Loaded)
            {
                return(false);
            }

            var ActivatedMods = mc.activeMods();
            var PlainList     = new List <ModViewModel>();
            var MissingList   = new List <string>();

            Action <RawMod, ModViewModel> explore = null;

            explore = new Action <RawMod, ModViewModel>((node, target) => {
                ModViewModel mod = null;

                if (node.Name != null && node.Name.Length > 0)
                {
                    mod = new ModViewModel(
                        node.Id,
                        node.Name
                        )
                    {
                        Expanded = false
                    };
                }
                else
                {
                    var isLocal = LocalMods.Contains(node.Id);
                    mod         = new ModViewModel(
                        node.Id,
                        Path.Combine(isLocal ? LocalModDir : SteamModDir, node.Id),
                        isLocal ? ModType.Local : ModType.Steam
                        );
                }

                if (mod.Id != null)
                {
                    if (node.Color != Colors.Transparent)
                    {
                        mod.Color = node.Color;
                    }

                    mod.Enabled = node.Enabled;

                    if (target == null)
                    {
                        mods.Add(mod);
                    }
                    else
                    {
                        target.Childs.Add(mod);
                    }

                    PlainList.Add(mod);
                }
                else
                {
                    if (node.Name == null || node.Name.Length == 0)
                    {
                        MissingList.Add(node.Id);
                    }
                }

                if (node.Childs != null)
                {
                    foreach (var y in node.Childs)
                    {
                        explore(y, mod.Id == null ? target : mod);
                    }
                }
            });
            foreach (var raw in ActivatedMods)
            {
                explore(raw, null);
            }

            var DeactivatedMods = LocalMods
                                  .Concat(SteamMods)
                                  .Where(x => !PlainList.Any(y => y.Id == x))
                                  .ToArray();

            foreach (var modName in DeactivatedMods)
            {
                var isLocal = LocalMods.Contains(modName);
                mods.Add(new ModViewModel(
                             modName,
                             Path.Combine(isLocal ? LocalModDir : SteamModDir, modName),
                             isLocal ? ModType.Local : ModType.Steam
                             )
                {
                    Enabled = false
                });
            }

            this.ModList = new ObservableCollection <ModViewModel>(
                mods.Select(x => {
                if (x.Color == Colors.Transparent)
                {
                    x.Color = ModColor.GetModColor(config.Read("ConfigurationDir", "Directories"), x.Id);
                }
                return(x);
            })
                );
            this.SelectedMod = this.ModList.FirstOrDefault();

            if (MissingList.Count > 0)
            {
                File.WriteAllLines(
                    Path.Combine(
                        Path.GetDirectoryName(Assembly.GetEntryAssembly().Location),
                        "MissingMods.txt"
                        ),
                    MissingList
                    .Where(x => int.TryParse(x, out _))
                    .Select(x => "https://steamcommunity.com/sharedfiles/filedetails/?id=" + x)
                    );

                MessageBox.Show(
                    "Failed to load all mod list, missing mods:" + Environment.NewLine
                    + string.Join(Environment.NewLine, MissingList.Select(x => "- " + x))
                    + Environment.NewLine + Environment.NewLine
                    + "Check 'MissingMods.txt' on RWMV directory.",
                    "RimWorldModVisualizer",
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Exclamation
                    );
            }
            return(true);
        }