Пример #1
0
        void RecompressGMFiles(object o)
        {
            RecompressThreadArgs rta = (RecompressThreadArgs)o;
            string inDir             = rta.inDir;

            string[] allFiles     = Directory.GetFiles(inDir);
            int      numFiles     = allFiles.Length;
            WaitDlg  dlg          = rta.dlg;
            string   pngDirectory = Path.Combine(inDir, "bmp");

            dlg.UpdateStatus("Recompressing {0} files", numFiles);
            string outDir   = rta.outDir;
            string gmllFile = @"T:\out.gmll";

            for (int i = 0; i < numFiles; ++i)
            {
                Box.ResetIndexCount();
                string       currentFile = allFiles[i];
                byte[]       gmFileData;
                MemoryStream decompGM;
                using (FileStream fs = File.OpenRead(currentFile))
                {
                    decompGM   = Compress.GZipDecompress(fs);
                    gmFileData = decompGM.ToArray();
                }
                string curFile               = Path.GetFileName(currentFile);
                string pngFile               = Path.Combine(pngDirectory, curFile + ".bmp");
                GTMP.GMFile.GMFileInfo fi    = GTMP.GMFile.Parse(decompGM);
                List <IBox>            boxes = ConvertGMFileBoxes(fi.Boxes);
                if (!Tools.ConvertImageTo(pngFile, gmllFile, Tools.ConvertType.GM))
                {
                    dlg.UpdateStatus(String.Format("Couldn't convert {0} to GT2 foreground, skipping", pngFile));
                    continue;
                }

                try
                {
                    byte[] gmllData    = Images.LoadGMLLData(gmllFile);
                    string newFileName = Path.Combine(outDir, curFile);
                    GMProject.ExportGM(newFileName, boxes, fi.Metadata, gmllData);
                }
                catch (InvalidBoxStateException ibse)
                {
                    DebugLogger.Log("Debug", "Exception was from {0}", currentFile);
                    dlg.UpdateStatus("Caught invalid box exception {0} for {1} in file {2}", ibse.Message, ibse.InvalidBox.Name, currentFile);
                    File.Delete(gmllFile);
                }

                if ((i != 0) && ((i % 100) == 0))
                {
                    dlg.UpdateStatus(String.Format("Tested {0} files", i));
                }
            }
            dlg.AllowClose("All done");
        }
Пример #2
0
 private void SaveChanges(string fileName)
 {
     GMProject.Save(
         fileName,
         canvas.Image,
         currentForegroundGMLLData,
         new List <IBox>(allBoxes.Items),
         (GTMP.GMFile.GMMetadata)metadataPropertyList.SelectedObject,
         Globals.App.GT2Version
         );
     ClearUnsavedChanges();
     SetTitleFileName(fileName);
 }
Пример #3
0
        private void ExportToGMFile()
        {
            string outFileName = GetSaveFileName(this, "Save Foreground GM File", "GT2 GM File (*.gm)|*.gm|All Files (*.*)|*.*", null);

            if (String.IsNullOrEmpty(outFileName))
            {
                return;
            }
            GMProject.ExportGM(
                outFileName,
                new List <IBox>(allBoxes.Items),
                (GTMP.GMFile.GMMetadata)metadataPropertyList.SelectedObject,
                currentForegroundGMLLData
                );
        }
Пример #4
0
        public static byte[] CheckConvertImageTo(Bitmap bm, ConvertType type)
        {
            string tempIn  = Path.GetTempFileName();
            string tempOut = Path.GetTempFileName();

            bm.Save(tempIn, System.Drawing.Imaging.ImageFormat.Png);
            bool converted = ConvertImageTo(tempIn, tempOut, type);

            GMProject.DeleteFileLoop(tempIn);
            byte[] gmllData = null;
            if (converted)
            {
                gmllData = File.ReadAllBytes(tempOut);
            }
            GMProject.DeleteFileLoop(tempOut);
            return(gmllData);
        }
Пример #5
0
        private void ProjectLoad()
        {
            string fileName = GetOpenFileName(this, "Open Project file", "GMCreator Project Files|*.gmproj", null);

            if (String.IsNullOrEmpty(fileName))
            {
                return;
            }
            Bitmap      fg, bg;
            List <IBox> boxes;

            GTMP.GMFile.GMMetadata metadata;
            byte[] gmllData = null;
            if (!GMProject.Load(fileName, out bg, out fg, out gmllData, out boxes, out metadata))
            {
                return;
            }
            if (!CloseCurrentFile())
            {
                return;
            }
            if (fg != null)
            {
                ReplaceForegroundImage(gmllData, fg);
            }
            if (bg != null)
            {
                Images.ImageLoadResult imageInfo = new Images.ImageLoadResult(bg);
                BGImageLoad(null, imageInfo);
            }
            allBoxes.Load(boxes);
            metadataPropertyList.SelectedObject = metadata;
            ClearUnsavedChanges();
            SetTitleFileName(fileName);
            currentProjectFileName = fileName;
        }