private string EncodeFB2File(string fb2FileName) { string fb2EncodedFileName = Path.GetFileNameWithoutExtension(fb2FileName) + ".fb2"; using (FB2StreamReader sr = new FB2StreamReader(fb2FileName, fb2Encoding)) { string line; using (StreamWriter sw = new StreamWriter(fb2EncodedFileName)) { while ((line = sr.ReadLine()) != null) { if (line.StartsWith("<?xml version")) { line = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"; } sw.WriteLine(line); } } } return(fb2EncodedFileName); }
/*private void StoreImageToFile(byte[] p) * { * using (BinaryWriter bw = new BinaryWriter(new FileStream("test.jpeg", FileMode.Create, FileAccess.Write))) * { * bw.Write(p); * } * }*/ private void LoadFB2ToXDocument(string fb2FileName, int itteration) { using (FB2StreamReader sr = new FB2StreamReader(fb2FileName, fb2Encoding)) { try { fb2XDocument = XDocument.Load(sr); } catch { sr.Close(); if (itteration == 0) { TryEncodeFixAndLoad(fb2FileName, itteration); } else { throw new Exception(string.Format("Can't load fb2 file: {0}", fb2FileName)); } } } fb2Sources = File.ReadAllBytes(fb2FileName); }
/*private void StoreImageToFile(byte[] p) { using (BinaryWriter bw = new BinaryWriter(new FileStream("test.jpeg", FileMode.Create, FileAccess.Write))) { bw.Write(p); } }*/ private void LoadFB2ToXDocument(string fb2FileName, int itteration) { using (FB2StreamReader sr = new FB2StreamReader(fb2FileName, fb2Encoding)) { try { fb2XDocument = XDocument.Load(sr); } catch { sr.Close(); if (itteration == 0) { TryEncodeFixAndLoad(fb2FileName, itteration); } else { throw new Exception(string.Format("Can't load fb2 file: {0}", fb2FileName)); } } } fb2Sources = File.ReadAllBytes(fb2FileName); }
private string EncodeFB2File(string fb2FileName) { string fb2EncodedFileName = Path.GetFileNameWithoutExtension(fb2FileName) + ".fb2"; using (FB2StreamReader sr = new FB2StreamReader(fb2FileName, fb2Encoding)) { string line; using (StreamWriter sw = new StreamWriter(fb2EncodedFileName)) { while ((line = sr.ReadLine()) != null) { if (line.StartsWith("<?xml version")) { line = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"; } sw.WriteLine(line); } } } return fb2EncodedFileName; }