public void Save(IGeneralConfig config, IFileSystem disk, IJsonUtil jsonUtil) { if (config == null) { throw new ArgumentNullException(nameof(config)); } if (disk == null) { throw new ArgumentNullException(nameof(disk)); } if (jsonUtil == null) { throw new ArgumentNullException(nameof(jsonUtil)); } var path = config.ResolvePath(UserPath); var dir = Path.GetDirectoryName(path); if (!disk.DirectoryExists(dir)) { disk.CreateDirectory(dir); } var json = jsonUtil.Serialize(this); disk.WriteAllText(path, json); }
ISerializer Search(string dir, IGeneralConfig generalConfig, AssetInfo info) { var combined = Path.Combine(dir, info.File.Filename); var filename = Path.GetFileName(combined).ToUpperInvariant(); dir = Path.GetDirectoryName(combined); var resolved = generalConfig.ResolvePath(dir); if (!Directory.Exists(resolved)) { return(null); } var directory = Path.Combine(resolved, filename); if (Directory.Exists(directory)) { var s = _containerLoaderRegistry.Load(directory, info, ContainerFormat.Directory); if (s != null) { return(s); } } var files = Directory.GetFiles(resolved); foreach (var path in files.Where(x => Path.GetFileNameWithoutExtension(x).ToUpperInvariant() == filename)) { if (info.File.Sha256Hashes != null) { var hash = GetHash(path); if (info.File.Sha256Hashes.All(x => !hash.Equals(x, StringComparison.OrdinalIgnoreCase))) { var expected = string.Join(", ", info.File.Sha256Hashes); CoreUtil.LogWarn( $"Found file {path} for asset {info.AssetId}, but its " + $"hash ({hash}) did not match any of the expected ones ({expected})"); return(null); } } ISerializer s; var extension = Path.GetExtension(path).ToUpperInvariant(); switch (extension) { case ".XLD": s = _containerLoaderRegistry.Load(path, info, ContainerFormat.Xld); break; case ".ZIP": s = _containerLoaderRegistry.Load(path, info, ContainerFormat.Zip); break; default: s = _containerLoaderRegistry.Load(path, info, info.File.ContainerFormat); break; } if (s != null) { return(s); } } return(null); }
public static GeneralSettings Load(IGeneralConfig config, IFileSystem disk, IJsonUtil jsonUtil) { if (config == null) { throw new ArgumentNullException(nameof(config)); } if (disk == null) { throw new ArgumentNullException(nameof(disk)); } if (jsonUtil == null) { throw new ArgumentNullException(nameof(jsonUtil)); } var path = config.ResolvePath(UserPath); if (!disk.FileExists(path)) { path = config.ResolvePath(DefaultsPath); } if (!disk.FileExists(path)) { throw new FileNotFoundException($"Could not find default settings file (expected at {path})"); } var settings = disk.FileExists(path) ? jsonUtil.Deserialize <GeneralSettings>(disk.ReadAllBytes(path)) : new GeneralSettings(); if (!settings.ActiveMods.Any()) { settings.ActiveMods.Add("Base"); } return(settings); }
public void LoadMods(IGeneralConfig config) { if (config == null) { throw new ArgumentNullException(nameof(config)); } _mods.Clear(); _modsInReverseDependencyOrder.Clear(); AssetMapping.Global.Clear(); foreach (var mod in Resolve <IGameplaySettings>().ActiveMods) { LoadMod(config.ResolvePath("$(MODS)"), mod); } _modsInReverseDependencyOrder.Reverse(); }