diff --git a/scripts/startup/bl_ui/space_userpref.py b/scripts/startup/bl_ui/space_userpref.py index 684eafe4c35..14560da7037 100644 --- a/scripts/startup/bl_ui/space_userpref.py +++ b/scripts/startup/bl_ui/space_userpref.py @@ -1533,6 +1533,7 @@ class USERPREF_PT_saveload_blend(SaveLoadPanel, CenterAlignMixIn, Panel): col = layout.column(heading="Text Files") col.prop(paths, "use_tabs_as_spaces") + col.prop(paths, "save_version_warning") col = layout.column() col.prop(paths, "save_version") diff --git a/scripts/startup/goo_engine_file_warning.py b/scripts/startup/goo_engine_file_warning.py new file mode 100644 index 00000000000..ff86a29b8c0 --- /dev/null +++ b/scripts/startup/goo_engine_file_warning.py @@ -0,0 +1,62 @@ +# ##### BEGIN GPL LICENSE BLOCK ##### +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; either version 2 +# of the License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software Foundation, +# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +# +# ##### END GPL LICENSE BLOCK ##### + +# + +""" +Custom file version warning system, to avoid mistakes with regular blender builds and production files. +""" + +import bpy +from bpy.types import Operator +from bpy.app.handlers import persistent +import os + +script_name = ".version_warning.py" +script_content = """ +import bpy + +def draw_popup_warning(self, context): + self.layout.label(text=f"Warning: file edited in Goo Engine, data may be lost if used in standard Blender!") + +if not bpy.app.version_string.endswith('Goo Engine'): + print("File loaded, not a Goo Engine build!") + bpy.context.window_manager.popup_menu(draw_popup_warning, title="Warning", icon='ERROR') +""" + + +@persistent +def save_handler(_): + if not bpy.context.preferences.filepaths.save_version_warning: + return + text = bpy.data.texts.get(script_name) + if not text: + text = bpy.data.texts.new(script_name) + text.use_module = True + text.clear() + text.write(script_content) + +def register(): + bpy.app.handlers.save_pre.append(save_handler) + +def unregister(): + bpy.app.handlers.save_pre.remove(save_handler) + + +if __name__ == "__main__": + register() \ No newline at end of file diff --git a/source/blender/blenloader/intern/versioning_300.cc b/source/blender/blenloader/intern/versioning_300.cc index cda958e2729..73015d980ad 100644 --- a/source/blender/blenloader/intern/versioning_300.cc +++ b/source/blender/blenloader/intern/versioning_300.cc @@ -68,6 +68,7 @@ #include "BKE_node.hh" #include "BKE_screen.h" #include "BKE_simulation_state_serialize.hh" +#include "BKE_text.h" #include "BKE_workspace.h" #include "RNA_access.h" @@ -4319,6 +4320,17 @@ void blo_do_versions_300(FileData *fd, Library * /*lib*/, Main *bmain) } } + /* Goo engine version warning script - remove the old one if it exists. */ + if (!MAIN_VERSION_ATLEAST(bmain, 306, 0)) { + LISTBASE_FOREACH_MUTABLE (Text *, text, &bmain->texts) { + if (strcmp(text->id.name, "TX.version_warning.py") > 0) { + continue; + } + BLI_remlink(&bmain->texts, text); + BKE_id_free(bmain, text); + } + } + if (!MAIN_VERSION_ATLEAST(bmain, 306, 3)) { /* Z bias for retopology overlay. */ if (!DNA_struct_elem_find(fd->filesdna, "View3DOverlay", "float", "retopology_offset")) { diff --git a/source/blender/blenloader/intern/versioning_userdef.c b/source/blender/blenloader/intern/versioning_userdef.c index d59b990414f..b870db3fecb 100644 --- a/source/blender/blenloader/intern/versioning_userdef.c +++ b/source/blender/blenloader/intern/versioning_userdef.c @@ -447,7 +447,7 @@ void blo_do_versions_userdef(UserDef *userdef) if (!USER_VERSION_ATLEAST(278, 6)) { /* Clear preference flags for re-use. */ - userdef->flag &= ~(USER_FLAG_NUMINPUT_ADVANCED | USER_FLAG_UNUSED_2 | USER_FLAG_UNUSED_3 | + userdef->flag &= ~(USER_FLAG_NUMINPUT_ADVANCED | USER_FLAG_VERSION_SCRIPT | USER_FLAG_UNUSED_3 | USER_FLAG_UNUSED_6 | USER_FLAG_UNUSED_7 | USER_FLAG_UNUSED_9 | USER_DEVELOPER_UI); userdef->uiflag &= ~(USER_HEADER_BOTTOM); diff --git a/source/blender/makesdna/DNA_userdef_types.h b/source/blender/makesdna/DNA_userdef_types.h index e0ac3c2437a..749ecf3def5 100644 --- a/source/blender/makesdna/DNA_userdef_types.h +++ b/source/blender/makesdna/DNA_userdef_types.h @@ -1034,7 +1034,7 @@ typedef enum eUserPref_SpaceData_Flag { typedef enum eUserPref_Flag { USER_AUTOSAVE = (1 << 0), USER_FLAG_NUMINPUT_ADVANCED = (1 << 1), - USER_FLAG_UNUSED_2 = (1 << 2), /* cleared */ + USER_FLAG_VERSION_SCRIPT = (1 << 2), /* cleared */ USER_FLAG_UNUSED_3 = (1 << 3), /* cleared */ USER_FLAG_UNUSED_4 = (1 << 4), /* cleared */ USER_TRACKBALL = (1 << 5), diff --git a/source/blender/makesrna/intern/rna_userdef.c b/source/blender/makesrna/intern/rna_userdef.c index 50611bf87c5..378ce6957bc 100644 --- a/source/blender/makesrna/intern/rna_userdef.c +++ b/source/blender/makesrna/intern/rna_userdef.c @@ -6409,6 +6409,13 @@ static void rna_def_userdef_filepaths(BlenderRNA *brna) "Tabs as Spaces", "Automatically convert all new tabs into spaces for new and loaded text files"); + prop = RNA_def_property(srna, "save_version_warning", PROP_BOOLEAN, PROP_NONE); + RNA_def_property_boolean_negative_sdna(prop, NULL, "flag", USER_FLAG_VERSION_SCRIPT); + RNA_def_property_boolean_default(prop, true); + RNA_def_property_ui_text(prop, + "Embed version warning popup", + "Embed a script that provides a warning pop-up if this file is opened in a non-GooEngine build"); + /* Directories. */ prop = RNA_def_property(srna, "font_directory", PROP_STRING, PROP_DIRPATH);