Exemplo n.º 1
0
 private static void ReadFileContents(string path, ref List <BinData> datas)
 {
     using (FileStream fstream = new FileStream(path, FileMode.Open)) {
         using (BinaryReader breader = new BinaryReader(fstream)) {
             int rows = breader.ReadInt32();
             for (int i = 0; i < rows; i++)
             {
                 BinData binData = new BinData();
                 binData.ID   = breader.ReadInt32();
                 binData.Name = breader.ReadString();
                 int propCount = breader.ReadInt32();
                 for (int p = 0; p < propCount; p++)
                 {
                     binData.properties.Add(breader.ReadString());
                 }
                 if (breader.ReadBoolean())
                 {
                     int    bufferLength = breader.ReadInt32();
                     byte[] buffer       = breader.ReadBytes(bufferLength);
                     using (MemoryStream memStream = new MemoryStream(buffer)) {
                         Image  image = Image.FromStream(memStream);
                         Bitmap bmp   = new Bitmap(image.Width, image.Height, PixelFormat.Format16bppRgb555);
                         bmp.MakeTransparent();
                         using (var g = Graphics.FromImage(bmp)) {
                             g.DrawImage(image, new Rectangle(0, 0, image.Width, image.Height));
                         }
                         image.Dispose();
                         binData.image = bmp;
                     }
                 }
                 string allProperties = "";
                 foreach (string prop in binData.properties)
                 {
                     allProperties += prop + "\r\n";
                 }
                 datas.Add(binData);
             }
         }
     }
 }
Exemplo n.º 2
0
        /// <summary>
        /// Add a row data to the specified grid view using
        /// parsed bin data
        /// </summary>
        /// <param name="grid">the grid view to add a row to</param>
        /// <param name="binData">bin data (wz files that were parsed then saved as a bin file type)</param>
        public void AddGridRow(DataGridView grid, BinData binData)
        {
            string allProperties = "";

            foreach (string prop in binData.properties)
            {
                allProperties += prop + "\r\n";
            }

            string filter = SearchTextBox.Text;

            if (filter?.Length > 0 && !binData.Search(filter))
            {
                return;
            }

            if (!IsDisposed && InvokeRequired)
            {
                Image image = binData?.image;
                Invoke(new Action(() => {
                    grid.Rows.Add(binData.ID, image, binData.Name, allProperties);
                }));
            }
        }
Exemplo n.º 3
0
        internal static void ExportGrid(DataViewer view, string folder)
        {
            string directory = $"{ExportFolder}/{folder}";

            Directory.CreateDirectory(directory);
            string path = $"{directory}/{((TabPage) view.Parent).Text}.bin";

            using (BinaryWriter bwriter = new BinaryWriter(new FileStream(path, FileMode.Create))) {
                var rows = view.GridView.Rows;
                bwriter.Write(rows.Count);
                for (int a = 0; a < rows.Count; a++)
                {
                    var     cells   = rows[a].Cells;
                    BinData binData = new BinData();
                    for (int b = 0; b < cells.Count; b++)
                    {
                        var    cell          = cells[b];
                        string ownColumnName = cell.OwningColumn.Name;
                        if (ownColumnName.EndsWith("ID"))
                        {
                            binData.ID = (int)cell.Value;
                        }
                        else if (ownColumnName.EndsWith("Image"))
                        {
                            binData.image = (Bitmap)cell.Value;
                        }
                        else if (ownColumnName.EndsWith("Name"))
                        {
                            binData.Name = (string)cell.Value;
                        }
                        else if (ownColumnName.EndsWith("Properties"))
                        {
                            string[] properties = ((string)cell.Value).Split(new[] { "\r\n" }, StringSplitOptions.None);
                            foreach (string prop in properties)
                            {
                                binData.properties.Add(prop);
                            }
                        }
                        else
                        {
                            Debug.WriteLine($"Unhandled column '{ownColumnName}'");
                            continue;
                        }
                    }
                    bwriter.Write(binData.ID);
                    bwriter.Write(binData.Name);
                    var propCount = binData.properties.Count;
                    bwriter.Write(propCount);
                    foreach (string prop in binData.properties)
                    {
                        bwriter.Write(prop);
                    }
                    bwriter.Write(binData.image != null);
                    if (binData.image != null)
                    {
                        using (MemoryStream memStream = new MemoryStream()) {
                            binData.image.Save(memStream, ImageFormat.Png);
                            byte[] buffer = memStream.GetBuffer();
                            bwriter.Write(buffer.Length);
                            bwriter.Write(buffer);
                        }
                    }
                }
            }
        }