From 6460e42bfef80d66c081d385dcf0f2c782a129b3 Mon Sep 17 00:00:00 2001 From: shxyder Date: Sun, 17 May 2026 13:42:42 -0500 Subject: [PATCH] Refactor CSharpExporter for improved error handling --- exporters/csharp_exporter.cpp | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/exporters/csharp_exporter.cpp b/exporters/csharp_exporter.cpp index 4c795174a..7797ca377 100644 --- a/exporters/csharp_exporter.cpp +++ b/exporters/csharp_exporter.cpp @@ -1,9 +1,8 @@ #include "csharp_exporter.h" - #include "compat/fake_csharp_script.h" #include "core/error/error_list.h" #include "core/io/file_access.h" -#include "utility/common.h" // For gdre namespace +#include "utility/common.h" #include "utility/gdre_settings.h" #include "utility/godot_mono_decomp_wrapper.h" @@ -11,18 +10,16 @@ void CSharpExporter::_bind_methods() { } Error CSharpExporter::export_file(const String &out_path, const String &res_path) { - Error err = OK; - ERR_FAIL_COND_V_MSG(!GDRESettings::get_singleton()->has_loaded_dotnet_assembly(), ERR_CANT_RESOLVE, "No dotnet assembly loaded"); + ERR_FAIL_COND_V_MSG(out_path.is_empty(), ERR_INVALID_PARAMETER, "Output path is empty"); + ERR_FAIL_COND_V_MSG(res_path.is_empty(), ERR_INVALID_PARAMETER, "Resource path is empty"); + Ref decompiler = GDRESettings::get_singleton()->get_dotnet_decompiler(); - if (decompiler.is_null()) { - ERR_FAIL_V_MSG(ERR_CANT_RESOLVE, "No dotnet decompiler loaded"); - } + ERR_FAIL_COND_V_MSG(decompiler.is_null(), ERR_CANT_RESOLVE, "No dotnet decompiler loaded"); + auto source = decompiler->decompile_individual_file(res_path); - if (source.is_empty()) { - ERR_FAIL_V_MSG(ERR_CANT_RESOLVE, "Failed to decompile C# script: " + res_path); - } + ERR_FAIL_COND_V_MSG(source.is_empty(), ERR_CANT_RESOLVE, "Failed to decompile C# script: " + res_path); - err = gdre::ensure_dir(out_path.get_base_dir()); + Error err = gdre::ensure_dir(out_path.get_base_dir()); ERR_FAIL_COND_V_MSG(err != OK, err, "Failed to ensure output directory exists: " + out_path.get_base_dir()); Ref f = FileAccess::open(out_path, FileAccess::WRITE); @@ -33,8 +30,11 @@ Error CSharpExporter::export_file(const String &out_path, const String &res_path } Ref CSharpExporter::export_resource(const String &output_dir, Ref import_infos) { - // This should not be used by the import exporter during full project recovery - ERR_FAIL_V_MSG(Ref(), "Not implemented"); + Ref report; + report.instantiate(); + report->set_error(ERR_UNAVAILABLE); + report->set_message("CSharpExporter::export_resource is not implemented"); + return report; } void CSharpExporter::get_handled_types(List *out) const { @@ -58,6 +58,6 @@ String CSharpExporter::get_default_export_extension(const String &res_path) cons Vector CSharpExporter::get_export_extensions(const String &res_path) const { Vector extensions; - extensions.push_back("cs"); + extensions.push_back(get_default_export_extension(res_path)); return extensions; }