public IPackage Load(string path, IFileLoadService fileLoadService) { Utils.LogDebug($"Loading package from {path}"); if (!Directory.Exists(path)) { Utils.LogError("Package directory doesn't exist!"); return(null); } var packDir = new DirectoryInfo(path); var packageFilePath = Path.Combine(packDir.FullName, _packageMainFileName); if (!File.Exists(packageFilePath)) { Utils.LogError("Package main file doesn't exist!"); return(null); } IPackage package = Utils.ReadFileAndDeserializeJson <T>(packageFilePath); if (package == null) { Utils.LogError("Package main file deserialization failed!"); return(null); } var mod = Localizer.GetWrappedMod(package.ModName); if (mod == null) { Utils.LogError($"Package Mod {package.ModName} not loaded!"); return(null); } package.Mod = mod; foreach (var fileTypeName in package.FileList) { Utils.LogDebug($"Loading file [{fileTypeName}]"); var filePath = Path.Combine(packDir.FullName, fileTypeName + ".json"); using (var fs = new FileStream(filePath, FileMode.Open)) { var file = fileLoadService.Load(fs, fileTypeName); package.AddFile(file); } } Utils.LogDebug($"Package [{package.Name} loaded.]"); return(package); }
public IPackage Load(string path, IFileLoadService fileLoadService) { Utils.LogDebug($"Loading package from {path}"); if (!System.IO.File.Exists(path)) { Utils.LogError("Package file doesn't exist!"); return(null); } using (var zipFileToOpen = new FileStream(path, FileMode.Open)) { using (var archive = new ZipArchive(zipFileToOpen, ZipArchiveMode.Read)) { var packageStream = archive.GetEntry(_packageMainFileName)?.Open(); IPackage package = Utils.ReadFileAndDeserializeJson <T>(packageStream); if (package == null) { Utils.LogError("Package main file deserialization failed!"); return(null); } var mod = Localizer.GetWrappedMod(package.ModName); if (mod == null) { Utils.LogError($"Package Mod {package.ModName} not loaded!"); return(null); } package.Mod = mod; foreach (var fileTypeName in package.FileList) { Utils.LogDebug($"Loading file [{fileTypeName}]"); var fs = archive.GetEntry($"{fileTypeName}.json")?.Open(); var file = fileLoadService.Load(fs, fileTypeName); package.AddFile(file); } Utils.LogDebug($"Package [{package.Name} loaded.]"); return(package); } } }