コード例 #1
0
        private void WriteStorage(OpenMcdf.CFStorage cfstorage, string directory, uint depth, ref System.Collections.Generic.List <string> outputfiles)
        {
            KRSrcWorkflow.WFFileType.FileType type = KRSrcWorkflow.WFFileType.GetOleFileType(cfstorage);
            if ((cfstorage.Name != "Root Entry") || ((cfstorage.Name == "Root Entry") && (type == KRSrcWorkflow.WFFileType.FileType.OlePackage || type == KRSrcWorkflow.WFFileType.FileType.OleContents)))
            {
                string filename = string.Empty;
                if (type == KRSrcWorkflow.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 == KRSrcWorkflow.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 == KRSrcWorkflow.WFFileType.FileType.OleWord || type == WFFileType.FileType.OlePublisher)
            {
                try
                {
                    OpenMcdf.CFStorage objectpool = cfstorage.GetStorage(type == KRSrcWorkflow.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, KRSrcWorkflow.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);
                    }
                }
            }
        }
コード例 #2
0
        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);
                }
            }
        }