コード例 #1
0
        public void ReplaceImage(string path, WcgImage image, int?x = null, int?y = null)
        {
            //Width = Math.Max(image.Width, Width);
            //Height = Math.Max(image.Height, Height);
            path = Path.GetFileNameWithoutExtension(path);

            byte[] data;
            using (var memory = new MemoryStream())
            {
                image.Save(memory);
                data = memory.ToArray();
            }


            byte     flag  = 0;
            LwgEntry entry = null;

            if (HasEntry(path))
            {
                entry = GetEntry(path);
            }
            else
            {
                entry      = new LwgEntry();
                entry.Path = path;

                _Entries.Add(entry);
            }

            entry.Content = data;
            entry.X       = x ?? entry.X;
            entry.Y       = y ?? entry.Y;
        }
コード例 #2
0
        private static void FillEntry(LwgEntry entry, string path, bool aggressive)
        {
            string[] fileEndings = new string[] { ".wcg", ".msk" };
            entry.Content = new byte[0];

            if (entry.Flag != (byte)LWGFlags.String)
            {
                string ePath = Path.Combine(path, entry.Path);
                if (aggressive && File.Exists(ePath + ".png"))
                {
                    var img = WcgImage.FromImage(ePath + ".png");
                    using (var memory = new MemoryStream())
                    {
                        img.Save(memory);
                        entry.Content = memory.ToArray();
                    }
                }
                else
                {
                    foreach (var ext in fileEndings)
                    {
                        if (File.Exists(ePath + ext))
                        {
                            entry.Content = File.ReadAllBytes(ePath + ext);
                        }
                    }
                }
            }
        }
コード例 #3
0
        /// <summary>
        /// Fills the object.
        /// </summary>
        private void Decode(Stream input)
        {
            using (var reader = new BinaryReader(input))
            {
                // READ HEADER
                var magic = new string(reader.ReadChars(_Magic.Length));
                if (magic != _Magic)
                {
                    throw new InvalidDataException("Not a LWG archive.");
                }

                Height = reader.ReadInt32();
                Width  = reader.ReadInt32();
                int fileCount = reader.ReadInt32();

                //var dummy = reader.ReadInt32();
                input.Seek(4, SeekOrigin.Current); // Skip 4

                int tableSize     = reader.ReadInt32();
                int fileDataStart = (int)input.Position + tableSize + 4;
                var flagList      = new HashSet <byte>();

                // Parse file table
                for (int i = 0; i < fileCount; i++)
                {
                    var item = new LwgEntry();

                    item.X    = reader.ReadInt32();
                    item.Y    = reader.ReadInt32();
                    item.Flag = reader.ReadByte();

                    flagList.Add(item.Flag);

                    item.Offset = fileDataStart + reader.ReadInt32();
                    item.Size   = reader.ReadInt32();
                    var nameSize = (int)reader.ReadByte();

                    item.Path = _ShiftJIS.GetString(reader.ReadBytes(nameSize));

                    _Entries.Add(item);
                }

                // Extract actual data
                foreach (var item in _Entries)
                {
                    input.Seek(item.Offset, SeekOrigin.Begin);
                    item.Content = reader.ReadBytes(item.Size);
                }

                var position = input.Position;
                var length   = input.Length;
            }
        }