GooEngine: Version warning script for non-goo-engine builds
This commit is contained in:
@@ -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")
|
||||
|
||||
@@ -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 #####
|
||||
|
||||
# <pep8 compliant>
|
||||
|
||||
"""
|
||||
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()
|
||||
@@ -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")) {
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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),
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user