From 850edd546c7f2dbf3d2299882f53a1ceee209c77 Mon Sep 17 00:00:00 2001 From: Eran Tiktin Date: Sat, 8 Aug 2015 21:57:29 +0300 Subject: [PATCH] Added support for reading .ico from asar If the file path is to an asar archive, we extract the file to temp, so LoadImage can load it --- atom/common/api/atom_api_native_image.cc | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/atom/common/api/atom_api_native_image.cc b/atom/common/api/atom_api_native_image.cc index 1594dcb8f8..1ad9ed0e36 100644 --- a/atom/common/api/atom_api_native_image.cc +++ b/atom/common/api/atom_api_native_image.cc @@ -23,6 +23,7 @@ #include "ui/gfx/image/image_skia.h" #include "ui/gfx/image/image_util.h" #if defined(OS_WIN) +#include "atom/common/asar/archive.h" #include "ui/gfx/icon_util.h" #endif @@ -214,10 +215,22 @@ mate::Handle NativeImage::CreateFromJPEG( // static mate::Handle NativeImage::CreateFromPath( - v8::Isolate* isolate, const base::FilePath& path) { + v8::Isolate* isolate, const base::FilePath& file_path) { gfx::ImageSkia image_skia; + base::FilePath path(file_path); if (path.MatchesExtension(FILE_PATH_LITERAL(".ico"))) { #if defined(OS_WIN) + // If file is in asar archive, we extract it to a temp file so LoadImage can + // load it + base::FilePath asar_path, relative_path; + if (asar::GetAsarArchivePath(path, &asar_path, &relative_path)) { + std::shared_ptr archive = + asar::GetOrCreateAsarArchive(asar_path); + if (archive) { + archive->CopyFileOut(relative_path, &path); + } + } + HICON icon = static_cast(LoadImage(NULL, path.value().c_str(), IMAGE_ICON,