private static WimMetadataViewModel LoadWimMetadata(string path) { Log.Verbose("Trying to load WIM metadata file at '{ImagePath}'", path); using (var file = File.OpenRead(path)) { var imageReader = new WindowsImageMetadataReader(); var windowsImageInfo = imageReader.Load(file); if (windowsImageInfo.Images.All(x => x.Architecture != Architecture.Arm64)) { throw new InvalidWimFileException(Resources.WimFileNoValidArchitecture); } var vm = new WimMetadataViewModel(windowsImageInfo, path); Log.Verbose("WIM metadata file at '{ImagePath}' retrieved correctly", path); return(vm); } }
private static void EnsureValidImage(string imagePath, int imageIndex) { Log.Verbose("Checking image at {Path}, with index {Index}", imagePath, imagePath); if (!File.Exists(imagePath)) { throw new FileNotFoundException($"Image not found: {imagePath}. Please, verify that the file exists and it's accessible."); } Log.Verbose("Image file at '{ImagePath}' exists", imagePath); using (var stream = File.OpenRead(imagePath)) { var metadata = new WindowsImageMetadataReader().Load(stream); var imageMetadata = metadata.Images.Single(x => x.Index == imageIndex); if (imageMetadata.Architecture != Architecture.Arm64) { throw new InvalidImageException("The selected image isn't for the ARM64 architecture."); } } }