public bool Extract(string filePath, string destination, string[] find, string[] replace, bool overwrite) { if (destination.EndsWith("\\")) { destination = destination.TrimEnd('\\'); } filePath = this.TrimPath(filePath); int lastSlash = filePath.LastIndexOf('\\'); string folderPath = ""; if (lastSlash > -1) { folderPath = filePath.Substring(0, lastSlash); } destination = destination.Replace('\\', Constants.DirectoryChar); SgaFolder container = root.DigFor(folderPath); if (container != null) { string fileName = filePath.Substring(filePath.LastIndexOf('\\') + 1); return(container.Extract(fileName, destination, find, replace, overwrite)); } else { ExtractFileFail(null, "path not found"); return(false); //throw exception } }
/// <summary> /// /// </summary> /// <param name="dirOffset"></param> /// <param name="itemOffset"></param> /// <param name="folderID"></param> /// <returns></returns> public SgaFolder ReadFolder(long dirOffset, long itemOffset, long folderID) { SgaFolder folder = null; Hashtable ht = new Hashtable(); ht["FolderNameOffset"] = ReadLong(dirOffset + BaseOffset + (FolderInfoLength * folderID), 4); ht["SubDirIDBegin"] = ReadLong(dirOffset + BaseOffset + 4 + (FolderInfoLength * folderID), 2); ht["SubDirIDEnd"] = ReadLong(dirOffset + BaseOffset + 6 + (FolderInfoLength * folderID), 2); ht["FileIDBegin"] = ReadLong(dirOffset + BaseOffset + 8 + (FolderInfoLength * folderID), 2); ht["FileIDEnd"] = ReadLong(dirOffset + BaseOffset + 10 + (FolderInfoLength * folderID), 2); string tmpName = ReadString(itemOffset + BaseOffset + (long)ht["FolderNameOffset"], -1); tmpName = tmpName.Substring(tmpName.LastIndexOf('\\') + 1); folder = new SgaFolder(folderID, tmpName, ht); long startID = (long)ht["SubDirIDBegin"]; long endID = (long)ht["SubDirIDEnd"]; if (startID < endID) { SgaFolder tempFolder = null; for (long i = startID; i < endID; i++) { tempFolder = ReadFolder(dirOffset, itemOffset, i); tempFolder.Parent = folder; } } return(folder); }
public void ExtractFolderSuccess(SgaFolder folder) { if (OnExtractFolderSuccess != null) { OnExtractFolderSuccess("Folder", folder.Path, ""); } }
/// <summary> /// /// </summary> /// <param name="idNum"></param> /// <param name="nameIn"></param> /// <param name="attr"></param> public SgaFile(long idNum, string nameIn, Hashtable attr) { attrib = attr; id = idNum; parent = null; name = nameIn; extension = name.Substring(name.LastIndexOf('.') + 1).ToLower(); }
/// <summary> /// /// </summary> /// <param name="pathIn"></param> public SgaArchive(string pathIn) { path = pathIn; file = new FileInfo(this.path); sr = new SgaReader(path); sr.Archive = this; attrib = sr.ReadHeaders(); root = sr.ReadFolders((long)attrib["DirOffset"], (long)attrib["ItemOffset"], attrib["TocAlias"].ToString()); root.ParentArchive = this; }
public void ExtractFolderFail(SgaFolder folder, string reason) { if (OnExtractFolderFail != null) { if (folder == null) { OnExtractFolderFail("Folder", "unknown", reason); } else { OnExtractFolderFail("Folder", folder.Path, reason); } } }
public bool ExtractType(string ext, string folderPath, string destination, string[] find, string[] replace, bool recursive, bool overwrite) { folderPath = this.TrimPath(folderPath); SgaFolder container = root.DigFor(folderPath); if (container != null) { return(container.ExtractType(ext, destination, find, replace, recursive, overwrite)); } else { ExtractFolderFail(null, "path not found"); return(false); } }
public bool ExtractFolder(string folderPath, string destination, string[] find, string[] replace, bool recursive, bool overwrite) { destination = destination.Replace('\\', Constants.DirectoryChar); folderPath = folderPath.TrimEnd(Constants.DirectoryChar); folderPath = TrimPath(folderPath); SgaFolder container = root.DigFor(folderPath); if (container != null) { return(container.ExtractAll(destination, find, replace, recursive, overwrite)); } else { ExtractFolderFail(container, "path not found"); return(false); } }
/// <summary> /// /// </summary> /// <param name="dirOffset"></param> /// <param name="itemOffset"></param> /// <returns></returns> public SgaFolder ReadFolders(long dirOffset, long itemOffset, string rootName) { SgaFolder root = null; try { FileStream input = sga.OpenRead(); br = new BinaryReader(input); Hashtable ht = new Hashtable(); ht["FolderNameOffset"] = ReadLong(dirOffset + BaseOffset, 4); ht["SubDirIDBegin"] = ReadLong(dirOffset + BaseOffset + 4, 2); ht["SubDirIDEnd"] = ReadLong(dirOffset + BaseOffset + 6, 2); ht["FileIDBegin"] = ReadLong(dirOffset + BaseOffset + 8, 2); ht["FileIDEnd"] = ReadLong(dirOffset + BaseOffset + 10, 2); root = new SgaFolder(0, rootName, ht); long startID = (long)ht["SubDirIDBegin"]; long endID = (long)ht["SubDirIDEnd"]; if (startID < endID) { SgaFolder tempFolder = null; for (long i = startID; i < endID; i++) { tempFolder = ReadFolder(dirOffset, itemOffset, i); tempFolder.Parent = root; } } } finally { br.Close(); } return(root); }