Skip to content

Commit

Permalink
Bring back script encryption in export preset
Browse files Browse the repository at this point in the history
Retrieved working implementation from 2.1 branch and adapted to
existing export preset system.

Added Script tab in export preset to export script as raw text,
compiled, or encrypted (same as in 2.1). The script encryption key is
visually validated. The script export mode and the key is saved per
per preset in `export_presets.cfg`, so it makes sense to ignore this
file in version control system.

Each custom exporting procedure can retrieve an export preset set
during project exporting. Refactored project export dialog a bit to
allow easier code comprehension.
  • Loading branch information
Andrii Doroshenko (Xrayez) committed Dec 24, 2018
1 parent 10e9221 commit ba13a2b
Show file tree
Hide file tree
Showing 5 changed files with 259 additions and 33 deletions.
50 changes: 49 additions & 1 deletion editor/editor_export.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -222,10 +222,33 @@ String EditorExportPreset::get_custom_features() const {
return custom_features;
}

void EditorExportPreset::set_script_export_mode(int p_mode) {

script_mode = p_mode;
EditorExport::singleton->save_presets();
}

int EditorExportPreset::get_script_export_mode() const {

return script_mode;
}

void EditorExportPreset::set_script_encryption_key(const String &p_key) {

script_key = p_key;
EditorExport::singleton->save_presets();
}

String EditorExportPreset::get_script_encryption_key() const {

return script_key;
}

EditorExportPreset::EditorExportPreset() :
export_filter(EXPORT_ALL_RESOURCES),
export_path(""),
runnable(false) {
runnable(false),
script_mode(MODE_SCRIPT_COMPILED) {
}

///////////////////////////////////
Expand Down Expand Up @@ -474,6 +497,18 @@ void EditorExportPlatform::_edit_filter_list(Set<String> &r_list, const String &
memdelete(da);
}

void EditorExportPlugin::set_export_preset(const Ref<EditorExportPreset> &p_preset) {

if (p_preset.is_valid()) {
export_preset = p_preset;
}
}

Ref<EditorExportPreset> EditorExportPlugin::get_export_preset() const {

return export_preset;
}

void EditorExportPlugin::add_file(const String &p_path, const Vector<uint8_t> &p_file, bool p_remap) {

ExtraFile ef;
Expand Down Expand Up @@ -658,6 +693,9 @@ Error EditorExportPlatform::export_project_files(const Ref<EditorExportPreset> &

Vector<Ref<EditorExportPlugin> > export_plugins = EditorExport::get_singleton()->get_export_plugins();
for (int i = 0; i < export_plugins.size(); i++) {

export_plugins.write[i]->set_export_preset(p_preset);

if (p_so_func) {
for (int j = 0; j < export_plugins[i]->shared_objects.size(); j++) {
p_so_func(p_udata, export_plugins[i]->shared_objects[j]);
Expand Down Expand Up @@ -1048,6 +1086,7 @@ void EditorExport::_save() {
config->set_value(section, "platform", preset->get_platform()->get_name());
config->set_value(section, "runnable", preset->is_runnable());
config->set_value(section, "custom_features", preset->get_custom_features());

bool save_files = false;
switch (preset->get_export_filter()) {
case EditorExportPreset::EXPORT_ALL_RESOURCES: {
Expand All @@ -1071,6 +1110,8 @@ void EditorExport::_save() {
config->set_value(section, "exclude_filter", preset->get_exclude_filter());
config->set_value(section, "export_path", preset->get_export_path());
config->set_value(section, "patch_list", preset->get_patches());
config->set_value(section, "script_export_mode", preset->get_script_export_mode());
config->set_value(section, "script_encryption_key", preset->get_script_encryption_key());

String option_section = "preset." + itos(i) + ".options";

Expand Down Expand Up @@ -1233,6 +1274,13 @@ void EditorExport::load_config() {
preset->add_patch(patch_list[i]);
}

if (config->has_section_key(section, "script_export_mode")) {
preset->set_script_export_mode(config->get_value(section, "script_export_mode"));
}
if (config->has_section_key(section, "script_encryption_key")) {
preset->set_script_encryption_key(config->get_value(section, "script_encryption_key"));
}

String option_section = "preset." + itos(index) + ".options";

List<String> options;
Expand Down
20 changes: 20 additions & 0 deletions editor/editor_export.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,12 @@ class EditorExportPreset : public Reference {
EXPORT_SELECTED_RESOURCES,
};

enum ScriptExportMode {
MODE_SCRIPT_TEXT,
MODE_SCRIPT_COMPILED,
MODE_SCRIPT_ENCRYPTED,
};

private:
Ref<EditorExportPlatform> platform;
ExportFilter export_filter;
Expand All @@ -75,6 +81,9 @@ class EditorExportPreset : public Reference {

String custom_features;

int script_mode;
String script_key;

protected:
bool _set(const StringName &p_name, const Variant &p_value);
bool _get(const StringName &p_name, Variant &r_ret) const;
Expand Down Expand Up @@ -118,6 +127,12 @@ class EditorExportPreset : public Reference {
void set_export_path(const String &p_path);
String get_export_path() const;

void set_script_export_mode(int p_mode);
int get_script_export_mode() const;

void set_script_encryption_key(const String &p_key);
String get_script_encryption_key() const;

const List<PropertyInfo> &get_properties() const { return properties; }

EditorExportPreset();
Expand Down Expand Up @@ -260,6 +275,8 @@ class EditorExportPlugin : public Reference {

friend class EditorExportPlatform;

Ref<EditorExportPreset> export_preset;

Vector<SharedObject> shared_objects;
struct ExtraFile {
String path;
Expand Down Expand Up @@ -294,6 +311,9 @@ class EditorExportPlugin : public Reference {
void _export_end_script();

protected:
void set_export_preset(const Ref<EditorExportPreset> &p_preset);
Ref<EditorExportPreset> get_export_preset() const;

void add_file(const String &p_path, const Vector<uint8_t> &p_file, bool p_remap);
void add_shared_object(const String &p_path, const Vector<String> &tags);

Expand Down
Loading

0 comments on commit ba13a2b

Please sign in to comment.