Recognize asar archive with unpacked files
This commit is contained in:
parent
dc82553fc3
commit
b5a8cfb704
9 changed files with 84 additions and 55 deletions
|
@ -81,18 +81,22 @@ bool GetNodeFromPath(std::string path,
|
|||
bool FillFileInfoWithNode(Archive::FileInfo* info,
|
||||
uint32 header_size,
|
||||
const base::DictionaryValue* node) {
|
||||
int size;
|
||||
if (!node->GetInteger("size", &size))
|
||||
return false;
|
||||
info->size = static_cast<uint32>(size);
|
||||
|
||||
info->unpacked = false;
|
||||
if (node->GetBoolean("unpacked", &info->unpacked) && info->unpacked)
|
||||
return true;
|
||||
|
||||
std::string offset;
|
||||
if (!node->GetString("offset", &offset))
|
||||
return false;
|
||||
if (!base::StringToUint64(offset, &info->offset))
|
||||
return false;
|
||||
|
||||
int size;
|
||||
if (!node->GetInteger("size", &size))
|
||||
return false;
|
||||
|
||||
info->offset += header_size;
|
||||
info->size = static_cast<uint32>(size);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -240,6 +244,11 @@ bool Archive::CopyFileOut(const base::FilePath& path, base::FilePath* out) {
|
|||
if (!GetFileInfo(path, &info))
|
||||
return false;
|
||||
|
||||
if (info.unpacked) {
|
||||
*out = path_.AddExtension(FILE_PATH_LITERAL("unpacked")).Append(path);
|
||||
return true;
|
||||
}
|
||||
|
||||
scoped_ptr<ScopedTemporaryFile> temp_file(new ScopedTemporaryFile);
|
||||
if (!temp_file->InitFromFile(path_, info.offset, info.size))
|
||||
return false;
|
||||
|
|
|
@ -25,6 +25,7 @@ class Archive {
|
|||
public:
|
||||
struct FileInfo {
|
||||
FileInfo() : size(0), offset(0) {}
|
||||
bool unpacked;
|
||||
uint32 size;
|
||||
uint64 offset;
|
||||
};
|
||||
|
@ -55,6 +56,7 @@ class Archive {
|
|||
bool Realpath(const base::FilePath& path, base::FilePath* realpath);
|
||||
|
||||
// Copy the file into a temporary file, and return the new path.
|
||||
// For unpacked file, this method will return its real path.
|
||||
bool CopyFileOut(const base::FilePath& path, base::FilePath* out);
|
||||
|
||||
base::FilePath path() const { return path_; }
|
||||
|
|
|
@ -71,6 +71,13 @@ bool ReadFileToString(const base::FilePath& path, std::string* contents) {
|
|||
if (!archive->GetFileInfo(relative_path, &info))
|
||||
return false;
|
||||
|
||||
if (info.unpacked) {
|
||||
base::FilePath real_path;
|
||||
// For unpacked file it will return the real path instead of doing the copy.
|
||||
archive->CopyFileOut(relative_path, &real_path);
|
||||
return base::ReadFileToString(real_path, contents);
|
||||
}
|
||||
|
||||
base::File src(asar_path, base::File::FLAG_OPEN | base::File::FLAG_READ);
|
||||
if (!src.IsValid())
|
||||
return false;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue