static internal byte[] LoadGMLLData(string gmllFileName) { byte[] gmFileData = null; try { using (FileStream gmStream = File.OpenRead(gmllFileName)) { MemoryStream decompGMStream = Compress.DecompressStream(gmStream); gmFileData = TrimToGMLLData(decompGMStream.ToArray()); } } catch (Exception e) { DebugLogger.Log("Images", "Caught exception trying to load GMLL data - {0}", e.Message); } return(gmFileData); }
static internal ImageLoadResult LoadFile(string fileName) { try { Bitmap bm = new Bitmap(fileName); return(new ImageLoadResult(bm)); } catch (Exception) { ; } MemoryStream streamToUse; using (FileStream fs = File.OpenRead(fileName)) { streamToUse = Compress.DecompressStream(fs); } byte[] headerBytes = new byte[4]; streamToUse.Read(headerBytes, 0, headerBytes.Length); streamToUse.Position = 0; string header = Encoding.ASCII.GetString(headerBytes); if (header == "GTMP") { Bitmap image = GTMP.GTMPFile.Parse(streamToUse); return(new ImageLoadResult(image, ImageType.GTMP)); } else if (header == "GM\x3\x0") { return(new ImageLoadResult(GTMP.GMFile.Parse(streamToUse))); } // also allow files that have been pre-converted by the GT2ImageConverter else if (header == "GMLL") { Bitmap bm = GTMP.GMFile.ParseGMLLData(streamToUse.ToArray(), 0, null); return(new ImageLoadResult(bm, ImageType.GMLL)); } throw new InvalidDataException("File type not recognized"); }
public static bool Load(string fileName, out Bitmap bg, out Bitmap fg, out byte[] fgGMLL, out List <IBox> boxes, out GTMP.GMFile.GMMetadata metadata) { fg = bg = null; fgGMLL = null; boxes = null; metadata = null; DebugLogger.Log("Project", "Loading file at {0}", fileName); if (DebugLogger.DoDebugActions()) { string projectCopy = Globals.MakeDebugSaveName(true, Path.GetFileName(fileName)); File.Copy(fileName, projectCopy, true); } byte[] projectBytes; using (FileStream fs = File.OpenRead(fileName)) { projectBytes = Compress.DecompressStream(fs).ToArray(); } string jsonText = Encoding.UTF8.GetString(projectBytes); GMSerializedProject projectData = Json.Parse <GMSerializedProject>(jsonText); IconImgType projType = projectData.gt2BoxVersion; IconImgType currentType = Globals.App.GT2Version; Debug.Assert(projType != IconImgType.Invalid); if (projType != currentType) { System.Windows.Forms.DialogResult res = MainForm.DisplayMsgBox( System.Windows.Forms.MessageBoxButtons.YesNoCancel, System.Windows.Forms.MessageBoxIcon.Question, "{0} was saved with GT2 Version {1} which is different from the current version {2}. Change the current version?", fileName, projType, currentType ); if (res != System.Windows.Forms.DialogResult.Yes) { return(false); } Globals.App.GT2Version = projType; Hardcoded.Refresh(System.Windows.Forms.Application.StartupPath); } byte[] imageData; if (!String.IsNullOrEmpty(projectData.background)) { imageData = Convert.FromBase64String(projectData.background); bg = Images.FromBytes(imageData); } else { bg = null; } if (!String.IsNullOrEmpty(projectData.foreground)) { fgGMLL = Convert.FromBase64String(projectData.foreground); fg = Images.FromBytes(fgGMLL); } metadata = projectData.fileMetadata; boxes = new List <IBox>(); foreach (IconImgBox img in projectData.iconBoxes) { boxes.Add(img); } foreach (Box box in projectData.boxes) { boxes.Add(box); } return(true); }