Пример #1
0
 private static void WriteUserData(UserdataFileFormat udf)
 {
     using (FormattedWriter fw = new FormattedWriter("sites.info"))
     {
         fw.Write(udf);
     }
 }
Пример #2
0
        private void btn_savetiles_Click(object sender, EventArgs e)
        {
            SaveFileDialog sfd = new SaveFileDialog();
            sfd.ShowDialog();
            if (string.IsNullOrEmpty(sfd.FileName))
            {
                return;
            }
            for (int i = 256; i < 8192; i *= 2)
            {
                using (FormattedWriter tiles = new FormattedWriter(sfd.FileName + ".tiles"))
                {
                    bool bigenough = true;
                    List<BasicTileFormat> tf = new List<BasicTileFormat>();
                    using (Bitmap bmp = new Bitmap(i, i))
                    {
                        int curx = 0;
                        int cury = 0;
                        using (Graphics g = Graphics.FromImage(bmp))
                        {
                            int count = 0;
                            tiles.Write(flow_tiles.Controls.Count);
                            foreach (Control ctl in flow_tiles.Controls)
                            {
                                if (ctl.Tag is SimpleTile)
                                {
                                    tiles.Write(TileType.SIMPLE);
                                    var st = ctl.Tag as SimpleTile;
                                    var res = InsertSimpleTile(tf, bmp, ref curx, ref cury, g, ref count, st);
                                    if (!res)
                                    {
                                        bigenough = false;
                                        break;
                                    }
                                    tiles.Write(st.num);
                                }
                                else if (ctl.Tag is AutoTile)
                                {
                                    var at = ctl.Tag as AutoTile;
                                    tiles.Write(at.Type);

                                    List<int> atfs = new List<int>();

                                    foreach (var st in at.rawtiles)
                                    {
                                        var res = InsertSimpleTile(tf, bmp, ref curx, ref cury, g, ref count, st);
                                        if (!res)
                                        {
                                            bigenough = false;
                                            break;
                                        }
                                        atfs.Add(st.num);
                                    }

                                    AutoTileFormat atf = new AutoTileFormat();
                                    atf.numOfTiles = atfs.Count;
                                    atf.basictiles = atfs.ToArray();
                                    tiles.Write(atf);
                                }
                            }
                        }

                        if (bigenough)
                        {
                            bmp.Save(sfd.FileName + ".png", ImageFormat.Png);
                            using (FormattedWriter basictiles = new FormattedWriter(sfd.FileName + ".basictiles"))
                            {
                                basictiles.Write((int)tf.Count);
                                foreach (var tile in tf)
                                {
                                    basictiles.Write(tile);
                                }
                            }
                            break;
                        }
                    }
                }
            }
        }
Пример #3
0
        public static void SerializeDirToPak(string dir, string pakfile)
        {
            string[] allFiles = recursiveGetFiles(dir, "");

            List<Dir> dirEntryList = new List<Dir>();

            using (FormattedWriter fw = new FormattedWriter(pakfile)) {
                // Write files
                foreach (var file in allFiles) {
                    fw.Write(new Signature() { signature = stringFileHeader2 });
                    File f = new File();
                    byte[] bytes = System.IO.File.ReadAllBytes(Path.Combine(dir, file));
                    byte[] compressed = decryptBytesWithTable(ZlibCodecCompress(bytes), 0x3ff, 1, table2);
                    f.compressedSize = (uint)compressed.Length;
                    f.compressionMethod = 8;
                    CRC32 dataCheckSum = new CRC32();
                    f.crc = dataCheckSum.GetCrc32(new MemoryStream(bytes));
                    f.data = compressed;
                    f.extractSystem = 0;
                    f.extractVersion = 20;
                    f.extraField = new byte[0];
                    f.extraFieldLength = 0;
                    f.filename = Encoding.UTF8.GetBytes(file);
                    f.filenameLength = (ushort)f.filename.Length;
                    f.generalPurposeFlagBits = 0;
                    f.lastModDate = 0;
                    f.lastModTime = 0;
                    f.uncompressedSize = (uint)bytes.Length;
                    fw.Write(f);

                    Dir d = new Dir();
                    d.comment = new byte[0];
                    d.commentLength = 0;
                    d.compressedSize = f.compressedSize;
                    d.compressType = f.compressionMethod;
                    d.crc = f.crc;
                    d.createSystem = f.extractSystem;
                    d.createVersion = f.extractVersion;
                    d.date = f.lastModDate;
                    d.diskNumberStart = 0;
                    d.externalFileAttributes = 33;
                    d.extractSystem = f.extractSystem;
                    d.extractVersion = f.extractVersion;
                    d.extraField = new byte[0];
                    d.extraFieldLength = 0;
                    d.filename = f.filename;
                    d.filenameLength = f.filenameLength;
                    d.flagBits = f.generalPurposeFlagBits;
                    d.internalFileAttributes = 0;
                    d.localHeaderOffset = 0;
                    d.time = f.lastModTime;
                    d.uncompressedSize = f.uncompressedSize;

                    dirEntryList.Add(d);
                }

                var dirEntryListStartPos = fw.BaseStream.BaseStream.Position;
                foreach (var d in dirEntryList) {
                    fw.Write(new Signature() { signature = stringCentralDir2 });
                    fw.Write(d);
                }
                var dirEntryListEndPos = fw.BaseStream.BaseStream.Position;

                End e = new End();
                e.byteSizeOfCentralDirectory = (uint)(dirEntryListEndPos - dirEntryListStartPos);
                e.centralDirRecordsOnDisk = (short)dirEntryList.Count;
                e.centralDirStartDisk = 0;
                e.comment = new byte[0];
                e.commentLength = 0;
                e.diskNumber = 0;
                e.offsetOfStartOfCentralDirectory = (uint)dirEntryListStartPos;
                e.totalNumOfCentralDirRecords = (short)dirEntryList.Count;

                fw.Write(new Signature() { signature = stringEndArchive2 });
                fw.Write(e);
            }
        }
Пример #4
0
        private void FontWindow_Load(object sender, EventArgs e)
        {
            Thread t = new Thread(() =>
            {
                int posx = 0;
                int posy = 0;
                Bitmap b = new Bitmap(256, 256);
                using (Graphics g = Graphics.FromImage(b))
                {
                    g.FillRectangle(new SolidBrush(Color.FromArgb(128, Color.Black)), new Rectangle(0, 0, 256, 256));
                }

                List<FontInfo> fis = new List<FontInfo>();

                for (uint i = 32; i < 256; i++)
                {
                    Invoke(new Action(() => pictureBox1.Image = b));

                    Bitmap dummy = new Bitmap(256, 256);
                    using (Graphics dummyg = Graphics.FromImage(dummy))
                    {
                        string chr = ((char)i).ToString();
                        var size = dummyg.MeasureString(chr, font, 100);
                        var sizetypo = dummyg.MeasureString(chr, font, 100, StringFormat.GenericTypographic);
                        int advance = (int)size.Width;

                        Invoke(new Action(() =>
                        {
                            if (posx + advance > b.Width)
                            {
                                posx = 0;
                                posy += (int)size.Height + 1;
                            }

                            using (Graphics g = Graphics.FromImage(b))
                            {
                                g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAliasGridFit;

                                g.DrawString(chr, font, Brushes.White, posx, posy);
                            }

                            FontInfo fi = new FontInfo()
                            {
                                chr = i,
                                width = sizetypo.Width+1,
                                height = sizetypo.Height,
                                x1 = (float)((double)posx / b.Size.Width),
                                y1 = (float)(((double)posy + sizetypo.Height) / b.Size.Height),
                                x2 = (float)(((double)posx + sizetypo.Width+1) / b.Size.Width),
                                y2 = (float)(((double)posy + sizetypo.Height) / b.Size.Height),
                                x3 = (float)(((double)posx + sizetypo.Width+1) / b.Size.Width),
                                y3 = (float)((double)posy / b.Size.Height),
                                x4 = (float)((double)posx / b.Size.Width),
                                y4 = (float)((double)posy / b.Size.Height),
                            };
                            fis.Add(fi);

                            Refresh();
                        }));

                        posx += advance;
                    }
                }

                BeginInvoke(new Action(() => {
                    SaveFileDialog sfd = new SaveFileDialog();
                    sfd.ShowDialog();
                    if (string.IsNullOrEmpty(sfd.FileName))
                    {
                        return;
                    }
                    b.Save(sfd.FileName + ".png");
                    using (FormattedWriter fw = new FormattedWriter(sfd.FileName + ".font"))
                    {
                        fw.Write((int)fis.Count);
                        foreach (var fi in fis)
                        {
                            fw.Write(fi);
                        }
                    }

                }));
            });
            t.Start();
        }
Пример #5
0
        private void btn_Save_Click(object sender, EventArgs e)
        {
            SaveFileDialog sfd = new SaveFileDialog();
            sfd.ShowDialog();
            sfd.Filter = "Neuron State Files (*.neuron)|*.neuron";
            if (sfd.FileName != null)
            {
                using (FormattedWriter fw = new FormattedWriter(sfd.FileName))
                {
                    ProgramStateFile psf = new ProgramStateFile();
                    psf.version = 0;
                    psf.nodes = inputs.Concat(hiddens).Concat(outputs).Select(x => new Node()
                    {
                        x = x.MainControl.Location.X,
                        y = x.MainControl.Location.Y,
                        size = x.Data.size,
                        name = new StringData() { Contents = x.Data.name },
                        type = x.Data.fvt,
                        numlinks = x.Edges.Count,
                        links = x.Edges.Select(edge => new Link()
                        {
                            matrix = new MatrixFormat(edge.Value.Data.weights.CopyToArray()),
                            nodename = new StringData() { Contents = edge.Key.Data.name }
                        }).ToArray()
                    }).ToArray();
                    psf.numNodes = psf.nodes.Length;

                    psf.configurations = new StringData[data_configurations.Rows.Count];
                    for (int i = 0; i < psf.configurations.Length; i++)
                    {
                        psf.configurations[i].Contents = data_configurations.Rows[i].Cells[2].Value.ToString();
                    }
                    psf.numConfigurations = psf.configurations.Length;

                    psf.trainings = new StringData[data_training.Rows.Count];
                    for (int i = 0; i < psf.trainings.Length; i++)
                    {
                        psf.trainings[i].Contents = data_training.Rows[i].Cells[2].Value.ToString();
                    }
                    psf.numTrainings = psf.trainings.Length;

                    psf.crossValidations = new StringData[data_crossValidationData.Rows.Count];
                    for (int i = 0; i < psf.crossValidations.Length; i++)
                    {
                        psf.crossValidations[i].Contents = data_crossValidationData.Rows[i].Cells[2].Value.ToString();
                    }
                    psf.numCrossValidations = psf.crossValidations.Length;

                    fw.Write(psf);
                }
            }
        }