use phosg namespace
This commit is contained in:
+19
-19
@@ -20,10 +20,10 @@ PatchFileIndex::File::File(PatchFileIndex* index)
|
||||
|
||||
std::shared_ptr<const std::string> PatchFileIndex::File::load_data() {
|
||||
if (!this->loaded_data) {
|
||||
string relative_path = join(this->path_directories, "/") + "/" + this->name;
|
||||
string relative_path = phosg::join(this->path_directories, "/") + "/" + this->name;
|
||||
string full_path = this->index->root_dir + "/" + relative_path;
|
||||
patch_index_log.info("Loading data for %s", relative_path.c_str());
|
||||
this->loaded_data = make_shared<string>(load_file(full_path));
|
||||
this->loaded_data = make_shared<string>(phosg::load_file(full_path));
|
||||
this->size = this->loaded_data->size();
|
||||
}
|
||||
return this->loaded_data;
|
||||
@@ -33,49 +33,49 @@ PatchFileIndex::PatchFileIndex(const string& root_dir)
|
||||
: root_dir(root_dir) {
|
||||
|
||||
string metadata_cache_filename = root_dir + "/.metadata-cache.json";
|
||||
JSON metadata_cache_json;
|
||||
phosg::JSON metadata_cache_json;
|
||||
try {
|
||||
string metadata_text = load_file(metadata_cache_filename);
|
||||
metadata_cache_json = JSON::parse(metadata_text);
|
||||
string metadata_text = phosg::load_file(metadata_cache_filename);
|
||||
metadata_cache_json = phosg::JSON::parse(metadata_text);
|
||||
patch_index_log.info("Loaded patch metadata cache from %s", metadata_cache_filename.c_str());
|
||||
} catch (const exception& e) {
|
||||
metadata_cache_json = JSON::dict();
|
||||
metadata_cache_json = phosg::JSON::dict();
|
||||
patch_index_log.warning("Cannot load patch metadata cache from %s: %s", metadata_cache_filename.c_str(), e.what());
|
||||
}
|
||||
|
||||
// Assuming it's rare for patch files to change, we skip writing the metadata
|
||||
// cache if no files were changed at all (which should usually be the case)
|
||||
bool should_write_metadata_cache = false;
|
||||
JSON new_metadata_cache_json = JSON::dict();
|
||||
phosg::JSON new_metadata_cache_json = phosg::JSON::dict();
|
||||
|
||||
vector<string> path_directories;
|
||||
function<void(const string&)> collect_dir = [&](const string& dir) -> void {
|
||||
path_directories.emplace_back(dir);
|
||||
|
||||
string relative_dirs = join(path_directories, "/");
|
||||
string relative_dirs = phosg::join(path_directories, "/");
|
||||
string full_dir_path = root_dir + '/' + relative_dirs;
|
||||
patch_index_log.info("Listing directory %s", full_dir_path.c_str());
|
||||
|
||||
for (const auto& item : list_directory(full_dir_path)) {
|
||||
for (const auto& item : phosg::list_directory(full_dir_path)) {
|
||||
// Skip invisible files (e.g. .DS_Store on macOS)
|
||||
if (starts_with(item, ".")) {
|
||||
if (phosg::starts_with(item, ".")) {
|
||||
continue;
|
||||
}
|
||||
|
||||
string relative_item_path = relative_dirs + '/' + item;
|
||||
string full_item_path = root_dir + '/' + relative_item_path;
|
||||
if (isdir(full_item_path)) {
|
||||
if (phosg::isdir(full_item_path)) {
|
||||
collect_dir(item);
|
||||
} else if (isfile(full_item_path)) {
|
||||
} else if (phosg::isfile(full_item_path)) {
|
||||
|
||||
auto st = stat(full_item_path);
|
||||
auto st = phosg::stat(full_item_path);
|
||||
|
||||
auto f = make_shared<File>(this);
|
||||
f->path_directories = path_directories;
|
||||
f->name = item;
|
||||
|
||||
string compute_crc32s_message; // If not empty, should compute crc32s
|
||||
JSON cache_item_json;
|
||||
phosg::JSON cache_item_json;
|
||||
try {
|
||||
cache_item_json = metadata_cache_json.at(relative_item_path);
|
||||
uint64_t cached_size = cache_item_json.get_int(0);
|
||||
@@ -98,19 +98,19 @@ PatchFileIndex::PatchFileIndex(const string& root_dir)
|
||||
|
||||
if (!compute_crc32s_message.empty()) {
|
||||
auto data = f->load_data(); // Sets f->size
|
||||
f->crc32 = crc32(data->data(), f->size);
|
||||
f->crc32 = phosg::crc32(data->data(), f->size);
|
||||
for (size_t x = 0; x < data->size(); x += 0x4000) {
|
||||
size_t chunk_bytes = min<size_t>(f->size - x, 0x4000);
|
||||
f->chunk_crcs.emplace_back(::crc32(data->data() + x, chunk_bytes));
|
||||
f->chunk_crcs.emplace_back(phosg::crc32(data->data() + x, chunk_bytes));
|
||||
}
|
||||
|
||||
// File was modified or cache item was missing; make a new cache item
|
||||
auto chunk_crcs_item = JSON::list();
|
||||
auto chunk_crcs_item = phosg::JSON::list();
|
||||
for (uint32_t chunk_crc : f->chunk_crcs) {
|
||||
chunk_crcs_item.emplace_back(chunk_crc);
|
||||
}
|
||||
new_metadata_cache_json.emplace(
|
||||
relative_item_path, JSON::list({f->size, st.st_mtime, f->crc32, std::move(chunk_crcs_item)}));
|
||||
relative_item_path, phosg::JSON::list({f->size, st.st_mtime, f->crc32, std::move(chunk_crcs_item)}));
|
||||
should_write_metadata_cache = true;
|
||||
|
||||
} else {
|
||||
@@ -141,7 +141,7 @@ PatchFileIndex::PatchFileIndex(const string& root_dir)
|
||||
|
||||
if (should_write_metadata_cache) {
|
||||
try {
|
||||
save_file(metadata_cache_filename, new_metadata_cache_json.serialize());
|
||||
phosg::save_file(metadata_cache_filename, new_metadata_cache_json.serialize());
|
||||
patch_index_log.info("Saved patch metadata cache to %s", metadata_cache_filename.c_str());
|
||||
} catch (const exception& e) {
|
||||
patch_index_log.warning("Cannot save patch metadata cache to %s: %s", metadata_cache_filename.c_str(), e.what());
|
||||
|
||||
Reference in New Issue
Block a user