示例#1
0
        /// <summary>
        /// Store target file as *.wmf file
        /// </summary>
        /// <param name="text"></param>
        /// <param name="filePath"></param>
        /// <param name="start"></param>
        /// <param name="end"></param>
        /// <returns></returns>
        private static string StoreTargetFileFromWmf(string text, string filePath, int start, int end)
        {
            string ext         = ".wmf";
            string filePathNew =
                Path.Combine(Path.GetDirectoryName(filePath), $"{Path.GetFileNameWithoutExtension(filePath)}{ext}");

            StoreAsAsciiFile(text, start, end, filePathNew);
            if (DirFiles.FileDelete(filePath))
            {
                return(filePathNew);
            }
            else
            {
                return("");
            }
        }
示例#2
0
        /// <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("");
            }
        }