bool ConvertFile(ref BML bml) { bool result = true; if (File.Exists(filename_dst)) { 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; } bw.Close(); return(result); }
bool ProcessFile() { FileStream strm; try { strm = File.OpenRead(filename_src); } catch { return(false); } if (!strm.CanRead) { return(false); } BinaryReader br = new BinaryReader(strm); BML bml = null; bool valid = true; if (CheckExtension(filename_src)) { bml = new BML(); valid = bml.ReadBML(br); } else if (CheckExtension(filename_src, "xml")) { bml = new BML(); valid = bml.ReadXML(br); } else { valid = false; } strm.Close(); if (valid) { return(ConvertFile(ref bml)); } return(valid); }