private static int GetFileFormatStorage(OpenMcdf.CompoundFile oCompoundFile)
 {
     int format = FileFormats.AVS_OFFICESTUDIO_FILE_UNKNOWN;
     try
     {
         oCompoundFile.RootStorage.GetStream("WordDocument");
         format = FileFormats.AVS_OFFICESTUDIO_FILE_DOCUMENT_DOC;
     }
     catch
     {
     }
     if (FileFormats.AVS_OFFICESTUDIO_FILE_UNKNOWN == format)
     {
         try
         {
             oCompoundFile.RootStorage.GetStream("Workbook");
             format = FileFormats.AVS_OFFICESTUDIO_FILE_SPREADSHEET_XLS;
         }
         catch
         {
         }
     }
     if (FileFormats.AVS_OFFICESTUDIO_FILE_UNKNOWN == format)
     {
         try
             {
                 oCompoundFile.RootStorage.GetStream("PowerPoint Document");
                 format = FileFormats.AVS_OFFICESTUDIO_FILE_PRESENTATION_PPT;
             }
             catch
             {
             }
     }
     if (FileFormats.AVS_OFFICESTUDIO_FILE_UNKNOWN == format)
     {
         try
         {
             oCompoundFile.RootStorage.GetStorage("\x0006DataSpaces");
             format = FileFormats.AVS_OFFICESTUDIO_FILE_OTHER_MS_OFFCRYPTO;
         }
         catch
         {
         }
     }
     return format;
 }
 private void Write(OpenMcdf.CFStorage tostorage, OpenMcdf.CFStorage fromstorage)
 {
     foreach (OpenMcdf.CFItem childitem in fromstorage.EnumChildren)
     {
         if (childitem is OpenMcdf.CFStream)
         {
             OpenMcdf.CFStream olechildstream = tostorage.AddStream(childitem.Name);
             olechildstream.SetData(((OpenMcdf.CFStream)childitem).GetData());
         }
         else if (childitem is OpenMcdf.CFStorage)
         {
             OpenMcdf.CFStorage olechildstorage = tostorage.AddStorage(childitem.Name);
             Write(olechildstorage, (OpenMcdf.CFStorage)childitem);
         }
     }
 }
        private void WriteStorage(OpenMcdf.CFStorage cfstorage, string directory, uint depth, ref System.Collections.Generic.List<string> outputfiles)
        {
            SFWorkflow.WFFileType.FileType type = SFWorkflow.WFFileType.GetOleFileType(cfstorage);
            if ((cfstorage.Name != "Root Entry") || ((cfstorage.Name == "Root Entry") && (type == SFWorkflow.WFFileType.FileType.OlePackage || type == SFWorkflow.WFFileType.FileType.OleContents)))
            {
                string filename = string.Empty;
                if (type == SFWorkflow.WFFileType.FileType.OlePackage)
                {
                    Ole10Native olenative = new Ole10Native(new System.IO.MemoryStream(cfstorage.GetStream(Convert.ToChar((byte)1).ToString() + "Ole10Native").GetData()));
                    filename = olenative.FileName;
                    int idx = olenative.FileName.LastIndexOf("\\");
                    if (idx != -1)
                        filename = olenative.FileName.Substring(idx + 1);
                    filename = String.Format("{0}\\{1}", directory, filename);
                    using (System.IO.FileStream fs = new System.IO.FileStream(filename, System.IO.FileMode.Create, System.IO.FileAccess.Write))
                    {
                        fs.Write(olenative.NativeData, 0, olenative.NativeData.Length);
                    }
                }
                else if (type == SFWorkflow.WFFileType.FileType.OleContents)
                {
                    filename = String.Format("{0}\\{1}", directory, "contents");
                    using (System.IO.FileStream fs = new System.IO.FileStream(filename, System.IO.FileMode.Create, System.IO.FileAccess.Write))
                    {
                        byte [] data = cfstorage.GetStream("CONTENTS").GetData();
                        fs.Write(data, 0, data.Length);
                    }
                }
                else
                {
                    OpenMcdf.CompoundFile tmp = new OpenMcdf.CompoundFile();
                    Write(tmp.RootStorage, cfstorage);
                    filename = String.Format("{0}\\{1}", directory, cfstorage.Name);
                    tmp.Save(filename);
                    tmp.Close();
                }
                outputfiles.Add(filename);
            }

            if (depth == 0)
                return;
            depth--;

            if (type == SFWorkflow.WFFileType.FileType.OleWord || type == WFFileType.FileType.OlePublisher)
            {
                try
                {
                    OpenMcdf.CFStorage objectpool = cfstorage.GetStorage(type == SFWorkflow.WFFileType.FileType.OleWord ? "ObjectPool" : "Objects");
                    if (objectpool != null)
                        cfstorage = objectpool;
                }
                catch (Exception)
                {
                }
            }

            if (cfstorage != null)
            {
                foreach (OpenMcdf.CFItem item in cfstorage.EnumChildren.Where(x => x.IsStorage))
                {
                    string filedir = string.Format("{0}\\{1}", directory, SFWorkflow.WFUtilities.GetNextDirectoryNumber(directory));
                    if (!System.IO.Directory.Exists(filedir))
                        System.IO.Directory.CreateDirectory(filedir);
                    if (System.IO.Directory.Exists(filedir))
                        WriteStorage((OpenMcdf.CFStorage)item, filedir, depth, ref outputfiles);
                }
            }
        }
Пример #4
0
        public static FileType GetOleFileType(OpenMcdf.CFStorage cfstorage)
        {
            switch(cfstorage.CLSID.ToString())
            {
                case "000C1084-0000-0000-C000-000000000046":
                    return FileType.OleMsi;
                case "000C1086-0000-0000-C000-000000000046":
                    return FileType.OleMsp;
                case "000C1082-0000-0000-C000-000000000046":
                    return FileType.OleMst;
                case "00020810-0000-0000-c000-000000000046":
                    return FileType.OleExcel;
                case "64818d10-4f9b-11cf-86ea-00aa00b929e8":
                    return FileType.OlePowerPoint;
                case "00020906-0000-0000-c000-000000000046":
                    return FileType.OleWord;
                case "00021a14-0000-0000-c000-000000000046":
                    return FileType.OleVisio;
                case "74b78f3a-c8c8-11d1-be11-00c04fb6faf1":
                    return FileType.OleProject;
                case "00021201-0000-0000-00c0-000000000046":
                    return FileType.OlePublisher;
                case "00020d0b-0000-0000-c000-000000000046":
                    return FileType.OleMsg;
            }

            foreach (OpenMcdf.CFItem item in cfstorage.EnumChildren.Where(x => x.IsStream))
            {
                if (item.Name == Convert.ToChar((byte)1).ToString(CultureInfo.InvariantCulture) + "Ole10Native")
                    return FileType.OlePackage;
                if (item.Name == "CONTENTS")
                    return FileType.OleContents;
                if (item.Name == "WordDocument")
                    return FileType.OleWord;
                else if (item.Name == "Workbook")
                    return FileType.OleExcel;
                else if (item.Name == "VisioDocument")
                    return FileType.OleVisio;
                else if (item.Name == "PowerPoint Document")
                    return FileType.OlePowerPoint;
            }

            return FileType.Ole;
        }