bool ProcessLine(string line, int lineNum, ref ModLoadSetting setting)
        {
            line = line.Replace(" ", "").Replace("\t", "");

            if (line.StartsWith("[") && line.EndsWith("]"))
            {
                if (!ProcessModNameLine(line, ref setting))
                {
                    return(false);
                }
            }
            else if (line.StartsWith("Enabled="))
            {
                if (!ProcessIsEnabledLine(line, lineNum, setting))
                {
                    return(false);
                }
            }
            else if (line.StartsWith("Priority="))
            {
                if (!ProcessPriorityLine(line, lineNum, setting))
                {
                    return(false);
                }
            }
            else if (!string.IsNullOrWhiteSpace(line) && !line.StartsWith(";"))
            {
                ShowWarningForMalformedFile($"Unrecognized value on line {lineNum}:\n\n{line}");
                return(false);
            }
            return(true);
        }
        bool ProcessPriorityLine(string line, int lineNum, ModLoadSetting setting)
        {
            if (setting == null)
            {
                ShowWarningForMalformedFile($"The 'Priority' setting on line {lineNum} doesn't have a corresponding mod name.");
                return(false);
            }

            var priorityString = line.Substring(line.IndexOf('=') + 1);
            int parsedPriority;

            if (!int.TryParse(priorityString, out parsedPriority))
            {
                ShowWarningForMalformedFile($"Can't parse the priority on line {lineNum}:\n\n{line}");
                return(false);
            }
            if (TopPriority > parsedPriority || parsedPriority > BottomPriority)
            {
                ShowWarningForMalformedFile($"The priority on line {lineNum} isn't within the valid range of {TopPriority} to {BottomPriority}:\n\n{line}");
                return(false);
            }

            setting.Priority = parsedPriority;
            return(true);
        }
        bool ProcessModNameLine(string line, ref ModLoadSetting setting)
        {
            if (setting != null)
            {
                ShowWarningForMalformedFile($"{setting.ModName} settings are incomplete.  'Enabled' and 'Priority' are both required.");
                return(false);
            }

            var modName = line.Substring(1, line.Length - 2);  // Trim brackets

            setting = new ModLoadSetting(modName);
            return(true);
        }
        bool ProcessIsEnabledLine(string line, int lineNum, ModLoadSetting setting)
        {
            if (setting == null)
            {
                ShowWarningForMalformedFile($"The 'Enabled' setting on line {lineNum} doesn't have a corresponding mod name.");
                return(false);
            }
            if (!new Regex("^Enabled=[0|1]$").IsMatch(line))
            {
                ShowWarningForMalformedFile($"The 'Enabled' setting on line {lineNum} isn't within the valid range of 0 or 1:\n\n{line}");
                return(false);
            }

            setting.IsEnabled = line.EndsWith("1");
            return(true);
        }
        public void Refresh()
        {
            Mods    = new List <ModLoadSetting>();
            IsValid = false;

            if (!File.Exists(FilePath))
            {
                IsValid = true;
                return;
            }

            var lines = File.ReadAllLines(FilePath);

            List <ModLoadSetting> mods           = new List <ModLoadSetting>();
            ModLoadSetting        currModSetting = null;

            for (int i = 0; i < lines.Length; ++i)
            {
                if (!ProcessLine(lines[i], i + 1, ref currModSetting))
                {
                    return;
                }

                if (currModSetting != null &&
                    currModSetting.IsEnabled.HasValue &&
                    currModSetting.Priority.HasValue)
                {
                    mods.Add(currModSetting);
                    currModSetting = null;
                }
            }

            IsValid = true;

            Mods = mods
                   .OrderBy(m => m.Priority)
                   .ThenBy(m => m.ModName)
                   .ToList();
        }
 public int Compare(ModLoadSetting x, ModLoadSetting y)
 {
     if (x.IsEnabled.Value)
     {
         if (y.IsEnabled.Value)
         {
             return(x.Priority.Value.CompareTo(y.Priority.Value));
         }
         else
         {
             return(-1);  // Only x is enabled
         }
     }
     else if (y.IsEnabled.Value)
     {
         return(1);  // Only y is enabled
     }
     else
     {
         return(Compare(x.ModName, y.ModName));  // Neither is enabled
     }
 }
Exemplo n.º 7
0
        static void PrioritizeMergedMod(CustomLoadOrder loadOrder, ModLoadSetting mergedModSetting)
        {
            // Priority of min - 1 will be incremented to min
            var priority = CustomLoadOrder.TopPriority - 1;

            if (mergedModSetting != null)
            {
                mergedModSetting.IsEnabled = true;
                mergedModSetting.Priority  = priority;
            }
            else
            {
                loadOrder.Mods.Insert(0, new ModLoadSetting
                {
                    ModName   = Paths.RetrieveMergedModName(),
                    IsEnabled = true,
                    Priority  = priority
                });
            }

            IncrementLeadingContiguousPriorities(loadOrder, priority);

            loadOrder.Save();
        }
        bool ProcessPriorityLine(string line, int lineNum, ModLoadSetting setting)
        {
            if (setting == null)
            {
                ShowWarningForMalformedFile($"The 'Priority' setting on line {lineNum} doesn't have a corresponding mod name.");
                return false;
            }

            var priorityString = line.Substring(line.IndexOf('=') + 1);
            int parsedPriority;

            if (!int.TryParse(priorityString, out parsedPriority))
            {
                ShowWarningForMalformedFile($"Can't parse the priority on line {lineNum}:\n\n{line}");
                return false;
            }
            if (TopPriority > parsedPriority || parsedPriority > BottomPriority)
            {
                ShowWarningForMalformedFile($"The priority on line {lineNum} isn't within the valid range of {TopPriority} to {BottomPriority}:\n\n{line}");
                return false;
            }

            setting.Priority = parsedPriority;
            return true;
        }
        bool ProcessModNameLine(string line, ref ModLoadSetting setting)
        {
            if (setting != null)
            {
                ShowWarningForMalformedFile($"{setting.ModName} settings are incomplete.  'Enabled' and 'Priority' are both required.");
                return false;
            }

            var modName = line.Substring(1, line.Length - 2);  // Trim brackets
            setting = new ModLoadSetting(modName);
            return true;
        }
        bool ProcessLine(string line, int lineNum, ref ModLoadSetting setting)
        {
            line = line.Replace(" ", "").Replace("\t", "");

            if (line.StartsWith("[") && line.EndsWith("]"))
            {
                if (!ProcessModNameLine(line, ref setting))
                    return false;
            }
            else if (line.StartsWith("Enabled="))
            {
                if (!ProcessIsEnabledLine(line, lineNum, setting))
                    return false;
            }
            else if (line.StartsWith("Priority="))
            {
                if (!ProcessPriorityLine(line, lineNum, setting))
                    return false;
            }
            else if (!string.IsNullOrWhiteSpace(line) && !line.StartsWith(";"))
            {
                ShowWarningForMalformedFile($"Unrecognized value on line {lineNum}:\n\n{line}");
                return false;
            }
            return true;
        }
        bool ProcessIsEnabledLine(string line, int lineNum, ModLoadSetting setting)
        {
            if (setting == null)
            {
                ShowWarningForMalformedFile($"The 'Enabled' setting on line {lineNum} doesn't have a corresponding mod name.");
                return false;
            }
            if (!new Regex("^Enabled=[0|1]$").IsMatch(line))
            {
                ShowWarningForMalformedFile($"The 'Enabled' setting on line {lineNum} isn't within the valid range of 0 or 1:\n\n{line}");
                return false;
            }

            setting.IsEnabled = line.EndsWith("1");
            return true;
        }