Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support extracting compiled code #167

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion src/cli/extract.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@
namespace fs = boost::filesystem;

namespace {
void create_output_directory(const extract_options & o);

template <typename Entry>
class processed_item {
Expand Down Expand Up @@ -614,6 +615,8 @@ bool print_file_info(const extract_options & o, const setup::info & info) {
verb = "Testing";
} else if(o.list) {
verb = "Listing";
} else if(o.extract_code) {
verb = "Extracting compiled code";
}
std::cout << verb << " \"" << color::green << name << color::reset
<< "\" - setup data version " << color::white << info.version << color::reset
Expand All @@ -627,7 +630,17 @@ bool print_file_info(const extract_options & o, const setup::info & info) {
std::cout << '\n';
}
#endif


if (o.extract_code) {
util::fstream stream;

create_output_directory(o);
stream.open(o.output_dir / "compiled_code.bin", std::ios_base::out | std::ios_base::binary | std::ios_base::trunc);

stream.write(info.header.compiled_code.data(), static_cast<std::streamsize>(info.header.compiled_code.size()));
stream.close();
}

bool multiple_sections = (o.list_languages + o.gog_game_id + o.list + o.show_password > 1);
if(!o.quiet && multiple_sections) {
std::cout << '\n';
Expand Down Expand Up @@ -1038,6 +1051,7 @@ void process_file(const fs::path & installer, const extract_options & o) {
if(o.extract) {
create_output_directory(o);
}


if(o.list || o.extract) {

Expand Down
1 change: 1 addition & 0 deletions src/cli/extract.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ struct extract_options {
bool list; //!< List files
bool test; //!< Test files (but don't extract)
bool extract; //!< Extract files
bool extract_code;
bool list_languages; //!< List available languages
bool gog_game_id; //!< Show the GOG.com game id
bool show_password; //!< Show password check information
Expand Down
4 changes: 3 additions & 1 deletion src/cli/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ int main(int argc, char * argv[]) {
action.add_options()
("test,t", "Only verify checksums, don't write anything")
("extract,e", "Extract files (default action)")
("code", "Extract compiled code")
("list,l", "Only list files, don't write anything")
("list-sizes", "List file sizes")
("list-checksums", "List file checksums")
Expand Down Expand Up @@ -259,6 +260,7 @@ int main(int argc, char * argv[]) {
bool explicit_list = (options.count("list") != 0);
o.list = explicit_list || o.list_sizes || o.list_checksums;
o.extract = (options.count("extract") != 0);
o.extract_code = (options.count("code") != 0);
o.test = (options.count("test") != 0);
o.list_languages = (options.count("list-languages") != 0);
o.gog_game_id = (options.count("gog-game-id") != 0);
Expand All @@ -270,7 +272,7 @@ int main(int argc, char * argv[]) {
o.show_password = true;
}
bool explicit_action = o.list || o.test || o.extract || o.list_languages
|| o.gog_game_id || o.show_password || o.check_password;
|| o.gog_game_id || o.show_password || o.check_password || o.extract_code;
if(!explicit_action) {
o.extract = true;
}
Expand Down