deployment
This commit is contained in:
@@ -6,10 +6,11 @@ import json
|
||||
import time
|
||||
|
||||
# Import utility functions from main module
|
||||
from ..presets import (
|
||||
get_preset_path, get_persistent_preset_path, get_addon_version,
|
||||
get_blend_file_presets, save_blend_file_preset, delete_blend_file_preset,
|
||||
refresh_presets_sync, ensure_presets_available
|
||||
from ..presets.storage_system import (
|
||||
save_preset_unified, get_unified_preset_list,
|
||||
get_blend_file_presets, delete_blend_file_preset,
|
||||
refresh_presets_sync, ensure_presets_available,
|
||||
get_preset_path, get_persistent_preset_path
|
||||
)
|
||||
from ..utils import bl_info
|
||||
|
||||
@@ -161,46 +162,11 @@ class TEXT_TEXTURE_OT_save_preset(Operator):
|
||||
preset_data['image_overlays'].append(overlay_data)
|
||||
|
||||
try:
|
||||
# Primary: Save to blend file (new system)
|
||||
print(f"[PRESET SAVE DEBUG] Attempting to save to blend file...")
|
||||
blend_success = save_blend_file_preset(preset_name, preset_data)
|
||||
print(f"[PRESET SAVE DEBUG] Blend file save result: {blend_success}")
|
||||
# Save based on checkbox setting - single destination only
|
||||
success = save_preset_unified(preset_data, preset_name, props.save_with_blend_file)
|
||||
|
||||
# ALWAYS save to persistent storage for cross-blend-file sharing and addon update survival
|
||||
persistent_file = os.path.join(get_persistent_preset_path(), f"{preset_name}.json")
|
||||
print(f"[PRESET SAVE DEBUG] Attempting to save to persistent file: {persistent_file}")
|
||||
persistent_success = True
|
||||
try:
|
||||
with open(persistent_file, 'w') as f:
|
||||
json.dump(preset_data, f, indent=2)
|
||||
print(f"[PRESET SAVE DEBUG] Successfully saved preset '{preset_name}' to persistent storage")
|
||||
|
||||
# VERIFY: Read back the persistent file to confirm shader properties were saved
|
||||
print(f"[PRESET SAVE DEBUG] Verifying persistent file contents...")
|
||||
with open(persistent_file, 'r') as f:
|
||||
saved_data = json.load(f)
|
||||
print(f"[PRESET SAVE DEBUG] Persistent file shader properties verification:")
|
||||
print(f"[PRESET SAVE DEBUG] disable_shadows: {saved_data.get('disable_shadows', 'NOT FOUND')}")
|
||||
print(f"[PRESET SAVE DEBUG] disable_reflections: {saved_data.get('disable_reflections', 'NOT FOUND')}")
|
||||
print(f"[PRESET SAVE DEBUG] disable_backfacing: {saved_data.get('disable_backfacing', 'NOT FOUND')}")
|
||||
|
||||
except Exception as persistent_error:
|
||||
print(f"[PRESET SAVE DEBUG] Warning: Failed to save persistent preset file: {persistent_error}")
|
||||
persistent_success = False
|
||||
|
||||
# Also save to legacy location for backward compatibility (optional)
|
||||
legacy_success = True
|
||||
try:
|
||||
legacy_file = os.path.join(get_preset_path(), f"{preset_name}.json")
|
||||
with open(legacy_file, 'w') as f:
|
||||
json.dump(preset_data, f, indent=2)
|
||||
print(f"[PRESET SAVE DEBUG] Also saved to legacy location for backward compatibility")
|
||||
except Exception as legacy_error:
|
||||
print(f"[PRESET SAVE DEBUG] Note: Could not save to legacy location: {legacy_error}")
|
||||
legacy_success = False
|
||||
|
||||
if not blend_success and not persistent_success:
|
||||
self.report({'ERROR'}, f"Failed to save preset to both blend file and persistent storage")
|
||||
if not success:
|
||||
self.report({'ERROR'}, f"Failed to save preset '{preset_name}'")
|
||||
return {'CANCELLED'}
|
||||
|
||||
# Check if preset already exists in the collection and update it
|
||||
@@ -213,28 +179,18 @@ class TEXT_TEXTURE_OT_save_preset(Operator):
|
||||
if not existing_preset:
|
||||
preset = props.presets.add()
|
||||
preset.name = preset_name
|
||||
# Priority: Blend file > Persistent file
|
||||
preset.source = 'BLEND_FILE' if blend_success else 'PERSISTENT_FILE'
|
||||
preset.source = 'BLEND_FILE' if props.save_with_blend_file else 'PERSISTENT_FILE'
|
||||
else:
|
||||
# Update source based on where it was successfully saved
|
||||
existing_preset.source = 'BLEND_FILE' if blend_success else 'PERSISTENT_FILE'
|
||||
|
||||
# Don't clear the input field - keep the name for easy re-saving
|
||||
# props.new_preset_name = "New Preset"
|
||||
# Update source based on where it was saved
|
||||
existing_preset.source = 'BLEND_FILE' if props.save_with_blend_file else 'PERSISTENT_FILE'
|
||||
|
||||
# Provide clear feedback
|
||||
storage_info = ""
|
||||
if blend_success and persistent_success:
|
||||
storage_info = " (saved to blend file + persistent storage)"
|
||||
elif blend_success:
|
||||
storage_info = " (saved to blend file)"
|
||||
elif persistent_success:
|
||||
storage_info = " (saved to persistent storage)"
|
||||
location = "with .blend file" if props.save_with_blend_file else "to persistent storage"
|
||||
|
||||
if self.overwrite:
|
||||
self.report({'INFO'}, f"✅ Preset '{preset_name}' updated successfully{storage_info}")
|
||||
self.report({'INFO'}, f"✅ Preset '{preset_name}' updated {location}")
|
||||
else:
|
||||
self.report({'INFO'}, f"✅ Preset '{preset_name}' saved successfully{storage_info}")
|
||||
self.report({'INFO'}, f"✅ Preset '{preset_name}' saved {location}")
|
||||
|
||||
except (OSError, IOError, json.JSONEncodeError) as e:
|
||||
self.report({'ERROR'}, f"Failed to save preset: {str(e)}")
|
||||
@@ -301,57 +257,17 @@ class TEXT_TEXTURE_OT_load_preset(Operator):
|
||||
print(f"[PRESET LOAD DEBUG] shader_connection: {props.shader_connection}")
|
||||
|
||||
try:
|
||||
# Three-tier loading priority: Blend File > Persistent File > Legacy File
|
||||
blend_presets = get_blend_file_presets()
|
||||
preset_data = None
|
||||
source = 'BLEND_FILE'
|
||||
# Get unified preset list and find the one to load
|
||||
all_presets = get_unified_preset_list()
|
||||
|
||||
print(f"[PRESET LOAD DEBUG] Available blend file presets: {list(blend_presets.keys())}")
|
||||
|
||||
if self.preset_name in blend_presets:
|
||||
preset_data = blend_presets[self.preset_name]
|
||||
source = 'BLEND_FILE'
|
||||
print(f"[PRESET LOAD DEBUG] Loading preset '{self.preset_name}' from blend file")
|
||||
print(f"[PRESET LOAD DEBUG] Blend file preset shader properties:")
|
||||
print(f"[PRESET LOAD DEBUG] disable_shadows: {preset_data.get('disable_shadows', 'NOT FOUND')}")
|
||||
print(f"[PRESET LOAD DEBUG] disable_reflections: {preset_data.get('disable_reflections', 'NOT FOUND')}")
|
||||
print(f"[PRESET LOAD DEBUG] disable_backfacing: {preset_data.get('disable_backfacing', 'NOT FOUND')}")
|
||||
else:
|
||||
# Try persistent storage next
|
||||
persistent_file = os.path.join(get_persistent_preset_path(), f"{self.preset_name}.json")
|
||||
print(f"[PRESET LOAD DEBUG] Preset not in blend file, trying persistent file: {persistent_file}")
|
||||
if os.path.exists(persistent_file):
|
||||
with open(persistent_file, 'r') as f:
|
||||
preset_data = json.load(f)
|
||||
source = 'PERSISTENT_FILE'
|
||||
print(f"[PRESET LOAD DEBUG] Loading preset '{self.preset_name}' from persistent file")
|
||||
print(f"[PRESET LOAD DEBUG] Persistent file preset shader properties:")
|
||||
print(f"[PRESET LOAD DEBUG] disable_shadows: {preset_data.get('disable_shadows', 'NOT FOUND')}")
|
||||
print(f"[PRESET LOAD DEBUG] disable_reflections: {preset_data.get('disable_reflections', 'NOT FOUND')}")
|
||||
print(f"[PRESET LOAD DEBUG] disable_backfacing: {preset_data.get('disable_backfacing', 'NOT FOUND')}")
|
||||
else:
|
||||
# Fallback to legacy local file
|
||||
legacy_file = os.path.join(get_preset_path(), f"{self.preset_name}.json")
|
||||
print(f"[PRESET LOAD DEBUG] Preset not in persistent storage, trying legacy file: {legacy_file}")
|
||||
if os.path.exists(legacy_file):
|
||||
with open(legacy_file, 'r') as f:
|
||||
preset_data = json.load(f)
|
||||
source = 'LOCAL_FILE'
|
||||
print(f"[PRESET LOAD DEBUG] Loading preset '{self.preset_name}' from legacy file")
|
||||
print(f"[PRESET LOAD DEBUG] Legacy file preset shader properties:")
|
||||
print(f"[PRESET LOAD DEBUG] disable_shadows: {preset_data.get('disable_shadows', 'NOT FOUND')}")
|
||||
print(f"[PRESET LOAD DEBUG] disable_reflections: {preset_data.get('disable_reflections', 'NOT FOUND')}")
|
||||
print(f"[PRESET LOAD DEBUG] disable_backfacing: {preset_data.get('disable_backfacing', 'NOT FOUND')}")
|
||||
else:
|
||||
print(f"[PRESET LOAD DEBUG] Legacy file does not exist: {legacy_file}")
|
||||
self.report({'ERROR'}, f"Preset not found in any storage location: {self.preset_name}")
|
||||
return {'CANCELLED'}
|
||||
|
||||
if not preset_data:
|
||||
print(f"[PRESET LOAD DEBUG] No preset data found!")
|
||||
self.report({'ERROR'}, f"No data found for preset: {self.preset_name}")
|
||||
if self.preset_name not in all_presets:
|
||||
self.report({'ERROR'}, f"Preset '{self.preset_name}' not found")
|
||||
return {'CANCELLED'}
|
||||
|
||||
preset_data, source = all_presets[self.preset_name]
|
||||
|
||||
print(f"[PRESET LOAD DEBUG] Loading preset '{self.preset_name}' from {source}")
|
||||
|
||||
props.is_updating = True
|
||||
|
||||
# Skip loading text to prevent overwriting current text
|
||||
|
||||
Reference in New Issue
Block a user