private static void StoreAsAsciiFile(string text, int start, int end, string filePathNew) { using (MemoryStream bytes = new MemoryStream()) { bool highByte = true; byte b = 0; for (int i = start; i < end; i++) { char c = text[i]; if (char.IsWhiteSpace(c)) { continue; } if (highByte) { b = (byte)(16 * GetHexValue(c)); } else { b |= GetHexValue(c); bytes.WriteByte(b); } highByte = !highByte; } DirFiles.WriteAllBytes(filePathNew, bytes.ToArray()); } }
/// <summary> /// Store the CFB file in target format /// </summary> /// <param name="text"></param> /// <param name="filePath"></param> /// <param name="ignoreNotSupportedFiles"></param> /// <param name="start"></param> /// <param name="end"></param> /// <returns></returns> private static string StoreTargetFileFromCfb(string text, string filePath, bool ignoreNotSupportedFiles, int start, int end) { // find object type of OLE Regex rxObjectType = new Regex(@"objclass\s+([^}]*)}"); Match match = rxObjectType.Match(text.Substring(0, 70)); string typeText = ""; string ext = ""; if (match.Success) { typeText = match.Groups[1].Value; } // DOORS file types supported and tested string[] lTypes = { "AcroExch." }; //,"Excel.", "Word."}; string[] lExtensions = { ".pdf" }; //, "xlsx", "docx" }; string[] lCompoundFileStreamName = { "CONTENTS" }; int j = 0; string componentFileStreamName = ""; foreach (var type in lTypes) { if (typeText.Contains(type)) { ext = lExtensions[j]; componentFileStreamName = lCompoundFileStreamName[j]; break; } j += 1; } if (ext == "") { string newFilePath = $@"{filePath}.notSupported"; if (!ignoreNotSupportedFiles) { MessageBox.Show($@"File: '{filePath}' File type not supported: '{typeText}' Supported ole types: '{String.Join(", ", lTypes)}' Copied to: {DirFiles.GetMessageFromFile(newFilePath)} ", @"Can't convert *.ole to file, not supported type!"); } DirFiles.FileMove(filePath, newFilePath); return(newFilePath); } string filePathNew = Path.Combine(Path.GetDirectoryName(filePath), $"{Path.GetFileNameWithoutExtension(filePath)}{ext}"); StoreAsAsciiFile(text, start, end, filePathNew); // By DOORS supported file type if (componentFileStreamName != "") { using (CompoundFile cf = new CompoundFile(filePathNew)) { CFStream foundStream = cf.RootStorage.GetStream("CONTENTS"); DirFiles.WriteAllBytes(filePathNew, foundStream.GetData().ToArray()); } } if (DirFiles.FileDelete(filePath)) { return(filePathNew); } else { return(""); } }