예제 #1
0
 public static GPK CreateFromFolder(GPKType gpkType, String srcFolder, String outZipFile)
 {
     ZIP zipfile = new ZIP(outZipFile);
     using (StreamWriter sw = new StreamWriter(srcFolder + "\\Type.txt"))
         sw.WriteLine(gpkType == GPKType.Graphics ? "GFX" : "FNT");
     zipfile.Files.AddRange(Directory.GetFiles(srcFolder));
     zipfile.Save();
     zipfile.Close();
     File.Delete(srcFolder + "\\Type.txt");
     return GPK.Load(outZipFile);
 }
예제 #2
0
        public static void Convert(String src, String dst)
        {
            FileInfo fi = new FileInfo(src);
            FileInfo fiDst = new FileInfo(dst);
            FPG fpg = FPG.Open(src);
            String outFile = dst;

            List<String> Lfiles = new List<String>();
            String tmpFolder = Path.GetTempPath() + fi.Name + DateTime.Now.Ticks.ToString() + "\\";
            if (!Directory.Exists(tmpFolder))
                Directory.CreateDirectory(tmpFolder);

            foreach (MAP m in fpg.Maps)
            {
                String name = m.Code.ToString().PadLeft(3, '0') + "_" + m.Name;
                String pngFile = tmpFolder + name + ".png";
                m.ExportToPNG(fpg.Pal, pngFile);
                PNG p = new PNG(pngFile);
                p.SetTextChunk("Description", m.Name);
                if (m.ControlPoints.Count == 0)
                    m.ControlPoints.Add(0, new Point(m.Width / 2, m.Height / 2));

                String chunk = String.Empty;
                foreach (KeyValuePair<int, Point> kv in m.ControlPoints.OrderBy(x => x.Key))
                    chunk += kv.Key + "=" + kv.Value.X + "," + kv.Value.Y + "|";
                chunk = chunk.Substring(0, chunk.Length - 1);
                p.SetTextChunk("ControlPoints", chunk);

                p.Save(pngFile);
                Lfiles.Add(pngFile);
            }

            using (StreamWriter sw = new StreamWriter(tmpFolder + "\\Type.txt"))
                sw.WriteLine("GFX");
            Lfiles.Add(tmpFolder + "\\Type.txt");

            ZIP zipfile = new ZIP(outFile);
            zipfile.Files.AddRange(Lfiles);
            zipfile.Save();
            zipfile.Close();

            if (Directory.Exists(tmpFolder))
                Directory.Delete(tmpFolder, true);
        }
예제 #3
0
        public static GPK Create(GPKType type, string filename)
        {
            ZIP zipfile = new ZIP(filename);

            String tmpFilename = Path.GetTempFileName();
            String tmpFolder = tmpFilename + "_dir\\";
            if (!Directory.Exists(tmpFolder))
                Directory.CreateDirectory(tmpFolder);
            File.Delete(tmpFilename);

            using (StreamWriter sw = new StreamWriter(tmpFolder + "\\Type.txt"))
                sw.WriteLine(type == GPKType.Graphics ? "GFX" : "FNT");
            zipfile.Files.AddRange(Directory.GetFiles(tmpFolder));
            zipfile.Save();
            zipfile.Close();
            Directory.Delete(tmpFolder, true);

            return GPK.Load(filename);
        }
예제 #4
0
        public static void Convert(String src, String dst)
        {
            FileInfo fi = new FileInfo(src);
            FileInfo fiDst = new FileInfo(dst);
            FNT fnt = FNT.Open(src);
            String outFile = dst;

            List<String> Lfiles = new List<String>();
            String tmpFolder = Path.GetTempPath() + fi.Name + DateTime.Now.Ticks.ToString() + "\\";
            if (!Directory.Exists(tmpFolder))
                Directory.CreateDirectory(tmpFolder);

            foreach (FNT.FNTStruct f in fnt.Characters.Where(x => x.FileOffset > 0 && x.Map.Width > 0 && x.Map.Height > 0))
            {
                String name = f.Map.Code.ToString().PadLeft(3, '0');
                String pngFile = tmpFolder + name + ".png";
                f.Map.ExportToPNG(fnt.Pal, pngFile);
                PNG p = new PNG(pngFile);
                p.SetTextChunk("Description", name);
                p.SetTextChunk("OffsetPos", f.OffX + "," + f.OffY);
                p.SetTextChunk("OffsetSize", f.OffWidth + "," + f.OffHeight);
                p.Save(pngFile);
                Lfiles.Add(pngFile);
            }

            using (StreamWriter sw = new StreamWriter(tmpFolder + "\\Type.txt"))
                sw.WriteLine("FNT");
            Lfiles.Add(tmpFolder + "\\Type.txt");

            ZIP zipfile = new ZIP(outFile);
            zipfile.Files.AddRange(Lfiles);
            zipfile.Save();
            zipfile.Close();

            if (Directory.Exists(tmpFolder))
                Directory.Delete(tmpFolder, true);
        }
예제 #5
0
 public void Close()
 {
     ZIP zipfile = new ZIP(_filename);
     using (StreamWriter sw = new StreamWriter(TempFolder + "\\Type.txt"))
         sw.WriteLine(PackageType == GPKType.Graphics ? "GFX" : "FNT");
     zipfile.Files.AddRange(Directory.GetFiles(TempFolder));
     zipfile.Save();
     zipfile.Close();
     Directory.Delete(TempFolder, true);
     TempFolder = null;
 }
예제 #6
0
        public static void Convert(String src, String dst)
        {
            FileInfo fi = new FileInfo(src);
            FileInfo fiDst = new FileInfo(dst);

            List<String> Lfiles = new List<String>();
            String tmpFolder = Path.GetTempPath() + fi.Name + DateTime.Now.Ticks.ToString() + "\\";
            String outFolder = tmpFolder + "output\\";
            if (!Directory.Exists(outFolder))
                Directory.CreateDirectory(outFolder);

            ZIP z = new ZIP();
            try
            {
                z = new ZIP(fi.FullName);
                z.Open();

                font f = Xml.Deserialize<font>("<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + z.ExtractFileToString("font.fnt"));

                foreach (fontPage p in f.pages)
                    z.ExtractFile(p.file, tmpFolder + p.file);

                foreach (fontCharsChar c in f.chars.@char)
                {
                    if (c.width == 0 && c.height == 0)
                        continue;

                    String outFile = outFolder + c.id.ToString().PadLeft(3, '0') + ".png";
                    Rectangle rCrop = new Rectangle(c.x, c.y, c.width, c.height);
                    using (Bitmap bSrc = Image.FromFile(tmpFolder + f.pages[c.page].file) as Bitmap)
                    {
                        using (Bitmap bDst = new Bitmap(c.width, c.height))
                        {
                            using (Graphics g = Graphics.FromImage(bDst))
                                g.DrawImage(bSrc, new Rectangle(0, 0, bDst.Width, bDst.Height), rCrop, GraphicsUnit.Pixel);
                            bDst.Save(outFile);
                        }
                    }
                    PNG p = new PNG(outFile);
                    p.SetTextChunk("Description", c.id.ToString());
                    p.SetTextChunk("OffsetPos", "0,0");
                    p.SetTextChunk("OffsetSize", c.xoffset + "," + c.yoffset);
                    p.Save(outFile);
                    Lfiles.Add(outFile);
                }
                z.Close();
            }
            catch (Exception)
            {
                z.Close();
            }

            using (StreamWriter sw = new StreamWriter(outFolder + "\\Type.txt"))
                sw.WriteLine("FNT");
            Lfiles.Add(outFolder + "\\Type.txt");

            ZIP fnt = new ZIP(dst);
            fnt.Files.AddRange(Lfiles);
            fnt.Save();
            fnt.Close();

            if (Directory.Exists(tmpFolder))
                Directory.Delete(tmpFolder, true);
        }