Write() public method

public Write ( byte value ) : void
value byte
return void
Esempio n. 1
0
        public void Save(string filename)
        {
            if (File.Exists(filename))
            {
                File.Delete(filename);
            }

            uint fileSize = 8; // 'icns' + fileSize
            uint tocSize  = 8; // TOC header

            foreach (var icon in Icons)
            {
                if (icon.Type == IcnsType.unsupported)
                {
                    continue;
                }

                var saveBuffer = icon.GetSaveBuffer();
                fileSize += (uint)saveBuffer.Length + 8; // OSType + data size + savebuffer
                tocSize  += 8;                           // TOC entry
            }
            fileSize += tocSize;

            using (var fs = File.Create(filename)) {
                using (var writer = new BinaryWriterBigEndian(fs)) {
                    writer.Write(Encoding.ASCII.GetBytes("icns"));
                    writer.WriteBigEndian(fileSize);

                    writer.Write(Encoding.ASCII.GetBytes("TOC "));
                    writer.WriteBigEndian(tocSize);

                    foreach (var icon in Icons)
                    {
                        if (icon.Type == IcnsType.unsupported)
                        {
                            continue;
                        }

                        var saveBuffer = icon.GetSaveBuffer();
                        writer.Write(Encoding.ASCII.GetBytes(GetIdentForType(icon.Type)));
                        writer.WriteBigEndian((uint)saveBuffer.Length);
                    }

                    foreach (var icon in Icons)
                    {
                        if (icon.Type == IcnsType.unsupported)
                        {
                            continue;
                        }

                        var saveBuffer = icon.GetSaveBuffer();
                        writer.Write(Encoding.ASCII.GetBytes(GetIdentForType(icon.Type)));
                        writer.WriteBigEndian((uint)saveBuffer.Length + 8);
                        writer.Write(saveBuffer.ToArray());
                    }
                }
            }
        }
Esempio n. 2
0
        public void Write()
        {
            var align  = 14;
            var offset = Align(4 + FatEntries.Count * 5 * 4, align);

            // Determine offsets
            foreach (var entry in FatEntries)
            {
                entry.offset = (uint)offset;
                entry.align  = (uint)align;

                offset = Align(offset + (int)entry.size, align);
            }

            if (FatEntries.Count == 0)
            {
            }
            else if (FatEntries.Count == 1)
            {
                Console.WriteLine($"Writing {_path} {FatEntries[0].cputype} from {FatEntries[0].srcentry.path}");
                File.Copy(FatEntries[0].srcentry.path, _path);
            }
            else
            {
                Console.WriteLine($"Writing {_path}:");
                using (var dst = new FileStream(_path, FileMode.Create, FileAccess.Write))
                {
                    // Write Header
                    using (var writer = new BinaryWriterBigEndian(dst))
                    {
                        writer.Write(0xCAFEBABE);
                        writer.Write(FatEntries.Count);

                        foreach (var entry in FatEntries)
                        {
                            writer.Write((uint)entry.cputype);
                            writer.Write((uint)entry.cpusubtype);
                            writer.Write(entry.offset);
                            writer.Write(entry.size);
                            writer.Write(entry.align);
                        }
                    }

                    foreach (var entry in FatEntries)
                    {
                        Console.WriteLine($"  - {entry.cputype} from {entry.srcentry.path}");
                        using (var src = new FileStream(entry.srcentry.path, FileMode.Open, FileAccess.Read))
                        {
                            dst.Seek(entry.offset, SeekOrigin.Begin);
                            src.Seek(entry.srcentry.offset, SeekOrigin.Begin);

                            var remaining = (int)entry.size;
                            var buf       = new byte[64 * 1024];
                            while (remaining != 0)
                            {
                                var size = Math.Min(remaining, buf.Length);
                                src.Read(buf, 0, size);
                                dst.Write(buf, 0, size);
                                remaining -= size;
                            }
                        }
                    }
                }
            }
        }
Esempio n. 3
0
 private Packer PackTrue()
 {
     writer.Write(MsgPack.BoolTrueType);
     return(this);
 }