/// <summary> /// Aligns a mod's ModKey to a path's implied ModKey. /// Will adjust its logic based on the MasterFlagSync option: /// - ThrowIfMisaligned: If the path and mod do not match, throw. /// - CorrectToPath: If the path and mod do not match, use path's key. /// </summary> /// <param name="mod">Mod to check and adjust</param> /// <param name="path">Path to compare to</param> /// <returns>ModKey to use</returns> /// <exception cref="ArgumentException">If misaligned and set to ThrowIfMisaligned</exception> public ModKey RunMasterMatch(IModGetter mod, string path) { if (ModKeySync == ModKeySyncOption.NoCheck) { return(mod.ModKey); } if (!ModKey.TryFactory(Path.GetFileName(path), out var pathModKey)) { throw new ArgumentException($"Could not convert path to a ModKey to compare against: {Path.GetFileName(path)}"); } switch (ModKeySync) { case ModKeySyncOption.ThrowIfMisaligned: if (mod.ModKey != pathModKey) { throw new ArgumentException($"ModKeys were misaligned: {mod.ModKey} != {pathModKey}"); } return(mod.ModKey); case ModKeySyncOption.CorrectToPath: return(pathModKey); default: throw new NotImplementedException(); } }
/// <summary> /// Parses a stream to retrieve all ModKeys in expected plugin file format /// </summary> /// <param name="stream">Stream to read from</param> /// <returns>List of modkeys representing a load order</returns> /// <exception cref="ArgumentException">Line in plugin stream is unexpected</exception> public static IExtendedList <ModKey> ProcessLoadOrder(Stream stream) { var ret = new ExtendedList <ModKey>(); using var streamReader = new StreamReader(stream); while (!streamReader.EndOfStream) { var str = streamReader.ReadLine(); var commentIndex = str.IndexOf('#'); if (commentIndex != -1) { str = str.Substring(0, commentIndex); } if (string.IsNullOrWhiteSpace(str)) { continue; } str = str.Trim(); if (!ModKey.TryFactory(str, out var key)) { throw new ArgumentException($"Load order file had malformed line: {str}"); } ret.Add(key); } return(ret); }