示例#1
0
        public static void Save(
            string fileName,
            Image bg,
            byte[] fgGMLL,
            List <IBox> boxes,
            GTMP.GMFile.GMMetadata metadata,
            IconImgType fileVersion
            )
        {
            Debug.Assert(fileVersion != IconImgType.Invalid);
            DebugLogger.Log("Project", "Saving project to {0}", fileName);
            GMSerializedProject gmp = new GMSerializedProject();

            gmp.foreground = (fgGMLL != null) ? Convert.ToBase64String(fgGMLL) : String.Empty;
            byte[] imageData = Images.GetBytes(bg, System.Drawing.Imaging.ImageFormat.Png);
            gmp.background    = Convert.ToBase64String(imageData);
            gmp.fileMetadata  = metadata;
            gmp.gt2BoxVersion = fileVersion;
            SeparateBoxes(boxes, out gmp.boxes, out gmp.iconBoxes);
            string projectFile = Json.Serialize(gmp);

#if DEBUG
            File.WriteAllText(@"T:\gmpproj.txt", projectFile);
#endif
            MemoryStream compProj = Compress.ZipCompressString(projectFile);
            File.WriteAllBytes(fileName, compProj.ToArray());
            if (DebugLogger.DoDebugActions())
            {
                string projectCopy = Globals.MakeDebugSaveName(true, Path.GetFileName(fileName));
                File.WriteAllBytes(projectCopy, compProj.ToArray());
            }
        }
示例#2
0
        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);
        }