bool ConvertFile(ref BML bml) { bool result = true; //Console.WriteLine("Exporting to {0}...", filename_dst); if (File.Exists(filename_dst)) { //Console.WriteLine("Warning: destination file will be replaced"); File.Delete(filename_dst); } BinaryWriter bw = new BinaryWriter(File.OpenWrite(filename_dst)); if (CheckExtension(filename_dst, "xml")) { string data = ""; bml.ExportXML(ref data); // writing raw data otherwise we get the string encoding header bw.Write(Encoding.Default.GetBytes(data), 0, data.Length); } else if (CheckExtension(filename_dst)) { bml.ExportBML(bw); } else { result = false; //Console.WriteLine("Unexpected destination file type \"{0}\"", filename_dst); } bw.Close(); return(result); }
bool ProcessFile() { FileStream strm; try { strm = File.OpenRead(filename_src); } catch { //Console.WriteLine("Unable to open \"{0}\"", filename_src); return(false); } if (!strm.CanRead) { //Console.WriteLine("Unable to read \"{0}\"", filename_src); return(false); } BinaryReader br = new BinaryReader(strm); BML bml = null; bool valid = true; if (CheckExtension(filename_src)) { bml = new BML(); //Console.WriteLine("Reading as BML..."); valid = bml.ReadBML(br); if (!valid) { //Console.WriteLine("Reading BML failed"); } } else if (CheckExtension(filename_src, "xml")) { bml = new BML(); //Console.WriteLine("Reading as XML..."); valid = bml.ReadXML(br); if (!valid) { //Console.WriteLine("Reading XML failed"); } } else { valid = false; // Console.WriteLine("Unexpected source file type \"{0}\"", filename_src); } strm.Close(); if (valid) { return(ConvertFile(ref bml)); } return(valid); }