| 2891 | } |
| 2892 | |
| 2893 | Error ResourceFormatSaverCSharpScript::save(const Ref<Resource> &p_resource, const String &p_path, uint32_t p_flags) { |
| 2894 | Ref<CSharpScript> sqscr = p_resource; |
| 2895 | ERR_FAIL_COND_V(sqscr.is_null(), ERR_INVALID_PARAMETER); |
| 2896 | |
| 2897 | String source = sqscr->get_source_code(); |
| 2898 | |
| 2899 | #ifdef TOOLS_ENABLED |
| 2900 | if (!FileAccess::exists(p_path)) { |
| 2901 | // The file does not yet exist, let's assume the user just created this script. In such |
| 2902 | // cases we need to check whether the solution and csproj were already created or not. |
| 2903 | if (!_create_project_solution_if_needed()) { |
| 2904 | ERR_PRINT("C# project could not be created; cannot add file: '" + p_path + "'."); |
| 2905 | } |
| 2906 | } |
| 2907 | #endif |
| 2908 | |
| 2909 | { |
| 2910 | Error err; |
| 2911 | Ref<FileAccess> file = FileAccess::open(p_path, FileAccess::WRITE, &err); |
| 2912 | ERR_FAIL_COND_V_MSG(err != OK, err, "Cannot save C# script file '" + p_path + "'."); |
| 2913 | |
| 2914 | file->store_string(source); |
| 2915 | |
| 2916 | if (file->get_error() != OK && file->get_error() != ERR_FILE_EOF) { |
| 2917 | return ERR_CANT_CREATE; |
| 2918 | } |
| 2919 | } |
| 2920 | |
| 2921 | #ifdef TOOLS_ENABLED |
| 2922 | if (ScriptServer::is_reload_scripts_on_save_enabled()) { |
| 2923 | CSharpLanguage::get_singleton()->reload_tool_script(p_resource, false); |
| 2924 | } |
| 2925 | #endif |
| 2926 | |
| 2927 | return OK; |
| 2928 | } |
| 2929 | |
| 2930 | void ResourceFormatSaverCSharpScript::get_recognized_extensions(const Ref<Resource> &p_resource, List<String> *p_extensions) const { |
| 2931 | if (Object::cast_to<CSharpScript>(p_resource.ptr())) { |
no test coverage detected