private AllImagesDoWorkResult LoadAllImages(Stream iso, string path, Action <int> progressReporter) { bool progress = progressReporter != null; int total = 0; int complete = 0; int imagesProcessed = 0; if (progress) { images.ForEach(i => total += i.Count); } foreach (AbstractImageList imgList in images) { foreach (AbstractImage img in imgList) { string name = string.Empty; name = img.GetSaveFileName(); name = Path.Combine(path, name); if (File.Exists(name)) { if (img.CanSelectPalette() && (img.PaletteCount > 1)) { ISelectablePalette4bppImage img4bpp = ((ISelectablePalette4bppImage)img); bool importExport8bpp = img4bpp.ImportExport8bpp; int currentPalette = img4bpp.CurrentPalette; img4bpp.ImportExport8bpp = true; img4bpp.CurrentPalette = Math.Max(0, img4bpp.CurrentPalette - 15); img.WriteImageToIso(iso, name); img4bpp.ImportExport8bpp = importExport8bpp; img4bpp.CurrentPalette = currentPalette; } else { img.WriteImageToIso(iso, name); } imagesProcessed++; } if (progress) { progressReporter((100 * (complete++)) / total); } } } return(new AllImagesDoWorkResult(AllImagesDoWorkResult.Result.Success, imagesProcessed)); }
private AllImagesDoWorkResult DumpAllImages(Stream iso, string path, Action <int> progressReporter) { bool progress = progressReporter != null; int total = 0; int complete = 0; int imagesProcessed = 0; if (progress) { images.ForEach(i => total += i.Count); } if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } foreach (AbstractImageList imgList in images) { foreach (AbstractImage img in imgList) { string name = string.Empty; name = img.GetSaveFileName(); //if (img.Context == Context.US_PSX ) //{ // var pos = img.Position as PatcherLib.Iso.PsxIso.KnownPosition; // name = string.Format( "{0}_{1}.png", pos.Sector, pos.StartLocation ); //} //else if (img.Position is PatcherLib.Iso.PspIso.KnownPosition) //{ // var pos = img.Position as PatcherLib.Iso.PspIso.KnownPosition; // name = string.Format( "{0}_{1}.png", pos.SectorEnum, pos.StartLocation ); //} if (!string.IsNullOrEmpty(name)) { //Bitmap bmp = img.GetImageFromIso( iso ); //bmp.Save( Path.Combine( path, name ), System.Drawing.Imaging.ImageFormat.Bmp ); string fullPath = Path.Combine(path, name); using (System.IO.Stream s = System.IO.File.Open(fullPath, System.IO.FileMode.Create)) { if (img.CanSelectPalette() && (img.PaletteCount > 1)) { ISelectablePalette4bppImage img4bpp = ((ISelectablePalette4bppImage)img); bool importExport8bpp = img4bpp.ImportExport8bpp; int currentPalette = img4bpp.CurrentPalette; img4bpp.ImportExport8bpp = true; img4bpp.CurrentPalette = Math.Max(0, img4bpp.CurrentPalette - 15); img.SaveImage(iso, s); img4bpp.ImportExport8bpp = importExport8bpp; img4bpp.CurrentPalette = currentPalette; } else { img.SaveImage(iso, s); } } imagesProcessed++; } if (progress) { progressReporter((100 * (complete++)) / total); } } } return(new AllImagesDoWorkResult(AllImagesDoWorkResult.Result.Success, imagesProcessed)); }
private AllImagesDoWorkResult LoadAllImages(Stream iso, string path, Action <int> progressReporter) { bool progress = progressReporter != null; int total = 0; int complete = 0; int imagesProcessed = 0; if (progress) { images.ForEach(i => total += i.Count); } HashSet <string> usedFilenameSet = new HashSet <string>(); foreach (AbstractImageList imgList in images) { foreach (AbstractImage img in imgList) { string name = string.Empty; name = img.GetSaveFileName(); if (usedFilenameSet.Contains(name)) { name = name.Replace(".", "_2."); } int num = 3; while (usedFilenameSet.Contains(name)) { name = name.Replace("_" + (num - 1) + ".", "_" + (num) + "."); num++; } string filePath = Path.Combine(path, name); if (File.Exists(filePath)) { if (img.CanSelectPalette() && (img.PaletteCount > 1)) { ISelectablePalette4bppImage img4bpp = ((ISelectablePalette4bppImage)img); bool importExport8bpp = img4bpp.ImportExport8bpp; int currentPalette = img4bpp.CurrentPalette; img4bpp.ImportExport8bpp = true; img4bpp.CurrentPalette = Math.Max(0, img4bpp.CurrentPalette - 15); img.WriteImageToIso(iso, filePath); img4bpp.ImportExport8bpp = importExport8bpp; img4bpp.CurrentPalette = currentPalette; } else { img.WriteImageToIso(iso, filePath); } usedFilenameSet.Add(name); imagesProcessed++; } if (progress) { progressReporter((100 * (complete++)) / total); } } } return(new AllImagesDoWorkResult(AllImagesDoWorkResult.Result.Success, imagesProcessed)); }