Skip to content

Commit

Permalink
wfs-extract: Skip over corrupted folders
Browse files Browse the repository at this point in the history
  • Loading branch information
koolkdev committed Nov 4, 2017
1 parent f0b9b30 commit e299346
Showing 1 changed file with 25 additions and 20 deletions.
45 changes: 25 additions & 20 deletions wfs-extract/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,30 +22,35 @@ void dumpdir(const boost::filesystem::path& target, const std::shared_ptr<Direct
return;
}
}
for (auto item : *dir) {
boost::filesystem::path npath = path / item->GetRealName();
if (verbos)
std::cout << "Dumping " << npath << std::endl;
if (item->IsDirectory()) dumpdir(target, std::dynamic_pointer_cast<Directory>(item), npath, verbos);
else if (item->IsFile()) {
auto file = std::dynamic_pointer_cast<File>(item);
std::ofstream output_file((target / npath).string(), std::ios::binary | std::ios::out);
size_t to_read = file->GetSize();
File::stream stream(file);
std::vector<char> data(0x2000);
while (to_read > 0) {
stream.read(&*data.begin(), std::min(data.size(), to_read));
auto read = stream.gcount();
if (read <= 0) {
std::cerr << "Error: Failed to read " << npath << std::endl;
break;
try {
for (auto item : *dir) {
boost::filesystem::path npath = path / item->GetRealName();
if (verbos)
std::cout << "Dumping " << npath << std::endl;
if (item->IsDirectory()) dumpdir(target, std::dynamic_pointer_cast<Directory>(item), npath, verbos);
else if (item->IsFile()) {
auto file = std::dynamic_pointer_cast<File>(item);
std::ofstream output_file((target / npath).string(), std::ios::binary | std::ios::out);
size_t to_read = file->GetSize();
File::stream stream(file);
std::vector<char> data(0x2000);
while (to_read > 0) {
stream.read(&*data.begin(), std::min(data.size(), to_read));
auto read = stream.gcount();
if (read <= 0) {
std::cerr << "Error: Failed to read " << npath << std::endl;
break;
}
output_file.write((char*)&*data.begin(), read);
to_read -= static_cast<size_t>(read);
}
output_file.write((char*)&*data.begin(), read);
to_read -= static_cast<size_t>(read);
output_file.close();
}
output_file.close();
}
}
catch (Block::BadHash&) {
std::cerr << "Error: Failed to dump folder " << path << std::endl;
}
}

int main(int argc, char *argv[]) {
Expand Down

0 comments on commit e299346

Please sign in to comment.