Make NativeImage work with asar archive
This commit is contained in:
parent
98a7f08be2
commit
3678f13dfb
3 changed files with 28 additions and 2 deletions
|
@ -7,11 +7,11 @@
|
|||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "atom/common/asar/asar_util.h"
|
||||
#include "atom/common/native_mate_converters/file_path_converter.h"
|
||||
#include "atom/common/native_mate_converters/gfx_converter.h"
|
||||
#include "atom/common/native_mate_converters/gurl_converter.h"
|
||||
#include "base/base64.h"
|
||||
#include "base/files/file_util.h"
|
||||
#include "base/strings/string_util.h"
|
||||
#include "native_mate/dictionary.h"
|
||||
#include "native_mate/object_template_builder.h"
|
||||
|
@ -86,7 +86,7 @@ bool AddImageSkiaRep(gfx::ImageSkia* image,
|
|||
const base::FilePath& path,
|
||||
double scale_factor) {
|
||||
std::string file_contents;
|
||||
if (!base::ReadFileToString(path, &file_contents))
|
||||
if (!asar::ReadFileToString(path, &file_contents))
|
||||
return false;
|
||||
|
||||
const unsigned char* data =
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
|
||||
#include "atom/common/asar/archive.h"
|
||||
#include "base/files/file_path.h"
|
||||
#include "base/files/file_util.h"
|
||||
#include "base/lazy_instance.h"
|
||||
#include "base/stl_util.h"
|
||||
|
||||
|
@ -57,4 +58,26 @@ bool GetAsarArchivePath(const base::FilePath& full_path,
|
|||
return true;
|
||||
}
|
||||
|
||||
bool ReadFileToString(const base::FilePath& path, std::string* contents) {
|
||||
base::FilePath asar_path, relative_path;
|
||||
if (!GetAsarArchivePath(path, &asar_path, &relative_path))
|
||||
return base::ReadFileToString(path, contents);
|
||||
|
||||
std::shared_ptr<Archive> archive = GetOrCreateAsarArchive(asar_path);
|
||||
if (!archive)
|
||||
return false;
|
||||
|
||||
Archive::FileInfo info;
|
||||
if (!archive->GetFileInfo(relative_path, &info))
|
||||
return false;
|
||||
|
||||
base::File src(asar_path, base::File::FLAG_OPEN | base::File::FLAG_READ);
|
||||
if (!src.IsValid())
|
||||
return false;
|
||||
|
||||
contents->resize(info.size);
|
||||
return static_cast<int>(info.size) == src.Read(
|
||||
info.offset, const_cast<char*>(contents->data()), contents->size());
|
||||
}
|
||||
|
||||
} // namespace asar
|
||||
|
|
|
@ -23,6 +23,9 @@ bool GetAsarArchivePath(const base::FilePath& full_path,
|
|||
base::FilePath* asar_path,
|
||||
base::FilePath* relative_path);
|
||||
|
||||
// Same with base::ReadFileToString but supports asar Archive.
|
||||
bool ReadFileToString(const base::FilePath& path, std::string* contents);
|
||||
|
||||
} // namespace asar
|
||||
|
||||
#endif // ATOM_COMMON_ASAR_ASAR_UTIL_H_
|
||||
|
|
Loading…
Add table
Reference in a new issue