Move GetAsarArchivePath to asar_util.h
This commit is contained in:
parent
3b3a025ed4
commit
98a7f08be2
3 changed files with 31 additions and 30 deletions
|
@ -17,8 +17,11 @@ typedef std::map<base::FilePath, std::shared_ptr<Archive>> ArchiveMap;
|
|||
|
||||
namespace {
|
||||
|
||||
// The global instance of ArchiveMap, will be destroyed on exit.
|
||||
static base::LazyInstance<ArchiveMap> g_archive_map = LAZY_INSTANCE_INITIALIZER;
|
||||
|
||||
const base::FilePath::CharType kAsarExtension[] = FILE_PATH_LITERAL(".asar");
|
||||
|
||||
} // namespace
|
||||
|
||||
std::shared_ptr<Archive> GetOrCreateAsarArchive(const base::FilePath& path) {
|
||||
|
@ -32,4 +35,26 @@ std::shared_ptr<Archive> GetOrCreateAsarArchive(const base::FilePath& path) {
|
|||
return archive_map[path];
|
||||
}
|
||||
|
||||
bool GetAsarArchivePath(const base::FilePath& full_path,
|
||||
base::FilePath* asar_path,
|
||||
base::FilePath* relative_path) {
|
||||
base::FilePath iter = full_path;
|
||||
while (true) {
|
||||
base::FilePath dirname = iter.DirName();
|
||||
if (iter.MatchesExtension(kAsarExtension))
|
||||
break;
|
||||
else if (iter == dirname)
|
||||
return false;
|
||||
iter = dirname;
|
||||
}
|
||||
|
||||
base::FilePath tail;
|
||||
if (!iter.AppendRelativePath(full_path, &tail))
|
||||
return false;
|
||||
|
||||
*asar_path = iter;
|
||||
*relative_path = tail;
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace asar
|
||||
|
|
|
@ -18,6 +18,11 @@ class Archive;
|
|||
// Gets or creates a new Archive from the path.
|
||||
std::shared_ptr<Archive> GetOrCreateAsarArchive(const base::FilePath& path);
|
||||
|
||||
// Separates the path to Archive out.
|
||||
bool GetAsarArchivePath(const base::FilePath& full_path,
|
||||
base::FilePath* asar_path,
|
||||
base::FilePath* relative_path);
|
||||
|
||||
} // namespace asar
|
||||
|
||||
#endif // ATOM_COMMON_ASAR_ASAR_UTIL_H_
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue