public static int GetFileFormat(byte[] aBuffer) { int format = FileFormats.AVS_OFFICESTUDIO_FILE_UNKNOWN; try { if (aBuffer.Length == 0) { format = FileFormats.AVS_OFFICESTUDIO_FILE_DOCUMENT_TXT; } else { format = GetFileFormatBySignature(aBuffer); if (FileFormats.AVS_OFFICESTUDIO_FILE_UNKNOWN == format) { try { using (MemoryStream ms = new MemoryStream(aBuffer)) { OpenMcdf.CompoundFile oCompoundFile = new OpenMcdf.CompoundFile(ms); format = GetFileFormatStorage(oCompoundFile); oCompoundFile.Close(); } } catch { } if (FileFormats.AVS_OFFICESTUDIO_FILE_UNKNOWN == format) { try { using (MemoryStream ms = new MemoryStream(aBuffer)) { if (Ionic.Zip.ZipFile.IsZipFile(ms, false)) { using (Ionic.Zip.ZipFile oZipFile = Ionic.Zip.ZipFile.Read(aBuffer)) { format = GetFileFormatByZip(oZipFile); } } } } catch { } } } } } catch { } return(format); }
public static int GetFileFormat(string sPath) { int format = FileFormats.AVS_OFFICESTUDIO_FILE_UNKNOWN; try { if (new FileInfo(sPath).Length == 0) format = FileFormats.AVS_OFFICESTUDIO_FILE_DOCUMENT_TXT; else { using (FileStream fs = new FileStream(sPath, FileMode.Open, FileAccess.Read)) { byte[] aBuffer = new byte[100]; fs.Read(aBuffer, 0, aBuffer.Length); format = GetFileFormatBySignature(aBuffer); } if (FileFormats.AVS_OFFICESTUDIO_FILE_UNKNOWN == format) { try { OpenMcdf.CompoundFile oCompoundFile = new OpenMcdf.CompoundFile(sPath); format = GetFileFormatStorage(oCompoundFile); oCompoundFile.Close(); } catch { } if (FileFormats.AVS_OFFICESTUDIO_FILE_UNKNOWN == format) { try { if (Ionic.Zip.ZipFile.IsZipFile(sPath)) { using (Ionic.Zip.ZipFile oZipFile = Ionic.Zip.ZipFile.Read(sPath)) { format = GetFileFormatByZip(oZipFile); } } } catch { } } if (FileFormats.AVS_OFFICESTUDIO_FILE_UNKNOWN == format) { string sExtention = Path.GetExtension(sPath).ToLower(); if (".mht" == sExtention) format = FileFormats.AVS_OFFICESTUDIO_FILE_DOCUMENT_MHT; else if (".txt" == sExtention || ".xml" == sExtention || ".xslt" == sExtention) format = FileFormats.AVS_OFFICESTUDIO_FILE_DOCUMENT_TXT; else if (".csv" == sExtention) format = FileFormats.AVS_OFFICESTUDIO_FILE_SPREADSHEET_CSV; else if (".svg" == sExtention) format = FileFormats.AVS_OFFICESTUDIO_FILE_CROSSPLATFORM_SVG; else if (".html" == sExtention || ".htm" == sExtention) format = FileFormats.AVS_OFFICESTUDIO_FILE_DOCUMENT_HTML; else { string sExt = Path.GetExtension(sPath); if (sExt.Length > 0 && '.' == sExt[0]) sExt = sExt.Substring(1); format = FileFormats.FromString(sExt); } } } } } catch { } return format; }
public static int GetFileFormat(byte[] aBuffer) { int format = FileFormats.AVS_OFFICESTUDIO_FILE_UNKNOWN; try { if (aBuffer.Length == 0) format = FileFormats.AVS_OFFICESTUDIO_FILE_DOCUMENT_TXT; else { format = GetFileFormatBySignature(aBuffer); if (FileFormats.AVS_OFFICESTUDIO_FILE_UNKNOWN == format) { try { using (MemoryStream ms = new MemoryStream(aBuffer)) { OpenMcdf.CompoundFile oCompoundFile = new OpenMcdf.CompoundFile(ms); format = GetFileFormatStorage(oCompoundFile); oCompoundFile.Close(); } } catch { } if (FileFormats.AVS_OFFICESTUDIO_FILE_UNKNOWN == format) { try { using (MemoryStream ms = new MemoryStream(aBuffer)) { if (Ionic.Zip.ZipFile.IsZipFile(ms, false)) { using (Ionic.Zip.ZipFile oZipFile = Ionic.Zip.ZipFile.Read(aBuffer)) { format = GetFileFormatByZip(oZipFile); } } } } catch { } } } } } catch { } return format; }
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); } } } }
public static int GetFileFormat(string sPath) { int format = FileFormats.AVS_OFFICESTUDIO_FILE_UNKNOWN; try { if (new FileInfo(sPath).Length == 0) { format = FileFormats.AVS_OFFICESTUDIO_FILE_DOCUMENT_TXT; } else { using (FileStream fs = new FileStream(sPath, FileMode.Open, FileAccess.Read)) { byte[] aBuffer = new byte[100]; fs.Read(aBuffer, 0, aBuffer.Length); format = GetFileFormatBySignature(aBuffer); } if (FileFormats.AVS_OFFICESTUDIO_FILE_UNKNOWN == format) { try { OpenMcdf.CompoundFile oCompoundFile = new OpenMcdf.CompoundFile(sPath); format = GetFileFormatStorage(oCompoundFile); oCompoundFile.Close(); } catch { } if (FileFormats.AVS_OFFICESTUDIO_FILE_UNKNOWN == format) { try { if (Ionic.Zip.ZipFile.IsZipFile(sPath)) { using (Ionic.Zip.ZipFile oZipFile = Ionic.Zip.ZipFile.Read(sPath)) { format = GetFileFormatByZip(oZipFile); } } } catch { } } if (FileFormats.AVS_OFFICESTUDIO_FILE_UNKNOWN == format) { string sExtention = Path.GetExtension(sPath).ToLower(); if (".mht" == sExtention) { format = FileFormats.AVS_OFFICESTUDIO_FILE_DOCUMENT_MHT; } else if (".txt" == sExtention || ".xml" == sExtention || ".xslt" == sExtention) { format = FileFormats.AVS_OFFICESTUDIO_FILE_DOCUMENT_TXT; } else if (".csv" == sExtention) { format = FileFormats.AVS_OFFICESTUDIO_FILE_SPREADSHEET_CSV; } else if (".svg" == sExtention) { format = FileFormats.AVS_OFFICESTUDIO_FILE_CROSSPLATFORM_SVG; } else if (".html" == sExtention || ".htm" == sExtention) { format = FileFormats.AVS_OFFICESTUDIO_FILE_DOCUMENT_HTML; } } } } } catch { } return(format); }
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); } } }