Skip to content

Commit ac2570c

Browse files
committed
Add code option to save files to user directory
1 parent 134fbb1 commit ac2570c

1 file changed

Lines changed: 19 additions & 13 deletions

File tree

config/options.py

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@
4747
from ..addon_common.common.utils import normalize_triplequote
4848
from ..addon_common.hive.hive import Hive
4949

50-
5150
###########################################
5251
# RetopoFlow Configurations
5352

@@ -463,19 +462,23 @@ class Options:
463462
'select automerge': True,
464463
}
465464

466-
db = None # current options dict
467-
fndb = None # name of file in which to store db (set up in __init__)
468-
is_dirty = False # does the internal db differ from db stored in file? (need writing)
469-
last_change = 0 # when did we last changed an option?
470-
write_delay = 1.0 # seconds to wait before writing db to file
471-
write_error = False # True when we failed to write options to file
465+
db = None # current options dict
466+
fndb = None # name of file in which to store db (set up in __init__)
467+
is_dirty = False # does the internal db differ from db stored in file? (need writing)
468+
last_change = 0 # when did we last changed an option?
469+
write_delay = 1.0 # seconds to wait before writing db to file
470+
write_error = False # True when we failed to write options to file
471+
save_options_to_user = False # Saves to the user folder instead of add-on folder
472472

473473
def __init__(self):
474474
self._callbacks = []
475475
self._calling = False
476476
if not Options.fndb:
477-
Options.fndb = get_path_from_addon_root(retopoflow_files['options filename'])
478-
# Options.fndb = self.get_path('options filename')
477+
if Options.save_options_to_user:
478+
bpy.utils.user_resource("DATAFILES", create=True) # Ensures datafiles folder exists
479+
Options.fndb = bpy.utils.user_resource("DATAFILES", path=retopoflow_files['options filename'], create=False)
480+
else:
481+
Options.fndb = get_path_from_addon_root(retopoflow_files['options filename'])
479482
print(f'RetopoFlow options path: {Options.fndb}')
480483
self.read()
481484
self['version update'] = (self['rf version'] != retopoflow_product['version'])
@@ -506,7 +509,10 @@ def call_callbacks(self):
506509
self._calling = False
507510

508511
def get_path(self, key):
509-
return get_path_from_addon_root(retopoflow_files[key])
512+
if Options.save_options_to_user:
513+
return bpy.utils.user_resource("DATAFILES", path=retopoflow_files[key], create=False)
514+
else:
515+
return get_path_from_addon_root(retopoflow_files[key])
510516

511517
def get_path_incremented(self, key):
512518
p = self.get_path(key)
@@ -1005,7 +1011,7 @@ def _convert_to_json_serializable(cls, obj):
10051011
return {k: cls._convert_to_json_serializable(v) for k, v in obj.items()}
10061012
elif isinstance(obj, (list, tuple)):
10071013
return [cls._convert_to_json_serializable(item) for item in obj]
1008-
1014+
10091015
# Check for custom Color class from addon_common.common.maths...
10101016
if isinstance(obj, Color):
10111017
# Use Color.as_vec4().to_tuple() as specified
@@ -1117,7 +1123,7 @@ def _get_default(cls, *keys):
11171123
def set(cls, *args):
11181124
# always get the full data dict first
11191125
data = cls._get_data()
1120-
1126+
11211127
if len(args) == 1:
11221128
# `args` contains a dictionary
11231129
dict_keys_vals = args[0]
@@ -1142,7 +1148,7 @@ def s(d, path, dkv):
11421148
for key in keys[:-1]:
11431149
parent_data = parent_data[key]
11441150
parent_data[keys[-1]] = value
1145-
1151+
11461152
# save the modified data back to the text block
11471153
cls._save_data(data)
11481154

0 commit comments

Comments
 (0)