2014-09-23 11:14:30 +00:00
|
|
|
// Copyright (c) 2014 GitHub, Inc. All rights reserved.
|
|
|
|
// Use of this source code is governed by the MIT license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
|
|
|
#ifndef ATOM_COMMON_ASAR_ARCHIVE_H_
|
|
|
|
#define ATOM_COMMON_ASAR_ARCHIVE_H_
|
|
|
|
|
2014-09-24 10:44:00 +00:00
|
|
|
#include <vector>
|
|
|
|
|
2014-09-25 12:38:12 +00:00
|
|
|
#include "base/containers/scoped_ptr_hash_map.h"
|
2014-09-23 11:14:30 +00:00
|
|
|
#include "base/files/file_path.h"
|
|
|
|
#include "base/memory/scoped_ptr.h"
|
|
|
|
|
|
|
|
namespace base {
|
|
|
|
class DictionaryValue;
|
|
|
|
}
|
|
|
|
|
|
|
|
namespace asar {
|
|
|
|
|
2014-09-25 08:56:50 +00:00
|
|
|
class ScopedTemporaryFile;
|
|
|
|
|
|
|
|
// This class represents an asar package, and provides methods to read
|
|
|
|
// information from it.
|
2014-09-25 12:38:12 +00:00
|
|
|
class Archive {
|
2014-09-23 11:14:30 +00:00
|
|
|
public:
|
|
|
|
struct FileInfo {
|
2014-09-24 04:02:33 +00:00
|
|
|
FileInfo() : size(0), offset(0) {}
|
2014-09-23 11:14:30 +00:00
|
|
|
uint32 size;
|
|
|
|
uint64 offset;
|
|
|
|
};
|
|
|
|
|
2014-09-24 04:02:33 +00:00
|
|
|
struct Stats : public FileInfo {
|
|
|
|
Stats() : is_file(true), is_directory(false), is_link(false) {}
|
|
|
|
bool is_file;
|
|
|
|
bool is_directory;
|
|
|
|
bool is_link;
|
|
|
|
};
|
|
|
|
|
2014-09-23 11:14:30 +00:00
|
|
|
explicit Archive(const base::FilePath& path);
|
2014-09-25 12:38:12 +00:00
|
|
|
virtual ~Archive();
|
2014-09-23 11:14:30 +00:00
|
|
|
|
|
|
|
// Read and parse the header.
|
|
|
|
bool Init();
|
|
|
|
|
|
|
|
// Get the info of a file.
|
|
|
|
bool GetFileInfo(const base::FilePath& path, FileInfo* info);
|
|
|
|
|
2014-09-24 04:02:33 +00:00
|
|
|
// Fs.stat(path).
|
|
|
|
bool Stat(const base::FilePath& path, Stats* stats);
|
|
|
|
|
2014-09-24 10:44:00 +00:00
|
|
|
// Fs.readdir(path).
|
|
|
|
bool Readdir(const base::FilePath& path, std::vector<base::FilePath>* files);
|
|
|
|
|
2014-09-25 08:56:50 +00:00
|
|
|
// Copy the file into a temporary file, and return the new path.
|
|
|
|
bool CopyFileOut(const base::FilePath& path, base::FilePath* out);
|
|
|
|
|
2014-09-23 11:14:30 +00:00
|
|
|
base::FilePath path() const { return path_; }
|
2014-09-24 03:10:07 +00:00
|
|
|
base::DictionaryValue* header() const { return header_.get(); }
|
2014-09-23 11:14:30 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
base::FilePath path_;
|
2014-09-23 12:30:07 +00:00
|
|
|
uint32 header_size_;
|
2014-09-23 11:14:30 +00:00
|
|
|
scoped_ptr<base::DictionaryValue> header_;
|
|
|
|
|
2014-09-25 08:56:50 +00:00
|
|
|
// Cached external temporary files.
|
2014-09-25 12:38:12 +00:00
|
|
|
base::ScopedPtrHashMap<base::FilePath, ScopedTemporaryFile> external_files_;
|
2014-09-25 08:56:50 +00:00
|
|
|
|
2014-09-23 11:14:30 +00:00
|
|
|
DISALLOW_COPY_AND_ASSIGN(Archive);
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace asar
|
|
|
|
|
|
|
|
#endif // ATOM_COMMON_ASAR_ARCHIVE_H_
|