예제 #1
0
        public static void Write(CNC_File cncFile, string path)
        {
            byte[] bytes = cncFile.SaveToBytes();

            //Saving
            File.WriteAllBytes(path, bytes.ToArray());
        }
예제 #2
0
        public static CNC_File Read(byte[] rawBytes)
        {
            //Validation
            if (BitConverter.ToInt32(rawBytes, 0) != CNC_SIGNATURE)
            {
                throw new InvalidDataException("CNC_SIGNATURE not found at offset 0x0. Parse failed.");
            }

            int count  = BitConverter.ToUInt16(rawBytes, 6);
            int offset = BitConverter.ToInt32(rawBytes, 8);

            //Parse file
            CNC_File cncFile = new CNC_File()
            {
                CncEntries = new List <CNC_Entry>()
            };

            for (int i = 0; i < count; i++)
            {
                cncFile.CncEntries.Add(CNC_Entry.Read(rawBytes, offset));
                offset += 12;
            }

            return(cncFile);
        }
예제 #3
0
        public static CNC_File Read(string path, bool writeXml)
        {
            byte[] rawBytes = File.ReadAllBytes(path);

            CNC_File cncFile = Read(rawBytes);

            //Write Xml
            if (writeXml)
            {
                YAXSerializer serializer = new YAXSerializer(typeof(CNC_File));
                serializer.SerializeToFile(cncFile, path + ".xml");
            }

            return(cncFile);
        }