public Boolean ExtractAll(AsarArchive archive, String destination, bool emptyDir = false) { _filesToExtract = new List <AsarFile>(); /* ENABLE FOR EMPTY FOLDERS (ONLY IF NEEDED) */ _emptyDir = emptyDir; JObject jObject = archive.GetHeader().GetHeaderJson(); if (jObject.HasValues) { TokenIterator(jObject.First); } byte[] bytes = archive.GetBytes(); int filesDone = 0; foreach (AsarFile aFile in _filesToExtract) { int size = aFile.GetSize(); int offset = archive.GetBaseOffset() + aFile.GetOffset(); if (size > -1) { byte[] fileBytes = new byte[size]; Buffer.BlockCopy(bytes, offset, fileBytes, 0, size); Utilities.WriteFile(fileBytes, destination + aFile.GetPath()); } else { if (_emptyDir) { Utilities.CreateDirectory(destination + aFile.GetPath()); } } filesDone++; FileExtracted?.Invoke(this, new AsarExtractEvent(aFile, filesDone, _filesToExtract.Count)); } return(false); }
public Boolean Extract(AsarArchive archive, String filepath, String destination) { String[] path = filepath.Split('/'); JToken token = archive.GetHeader().GetHeaderJson(); for (int i = 0; i < path.Length; i++) { token = token["files"][path[i]]; } int size = token.Value <int>("size"); int offset = archive.GetBaseOffset() + token.Value <int>("offset"); byte[] fileBytes = archive.GetBytes().Skip(offset).Take(size).ToArray(); Utilities.WriteFile(fileBytes, destination); return(false); }