@@ -60,46 +60,53 @@ def have_settings_changed(autosplit: AutoSplit):
60
60
61
61
62
62
def save_settings (autosplit : AutoSplit ):
63
+ """
64
+ @return: The save settings filepath. Or None if "Save Settings As" is cancelled
65
+ """
63
66
if not autosplit .last_successfully_loaded_settings_file_path :
64
- save_settings_as (autosplit )
65
- else :
66
- autosplit .last_saved_settings = get_save_settings_values (autosplit )
67
- # save settings to a .pkl file
68
- with open (autosplit .last_successfully_loaded_settings_file_path , "wb" ) as file :
69
- pickle .dump (autosplit .last_saved_settings , file )
67
+ return save_settings_as (autosplit )
68
+
69
+ autosplit .last_saved_settings = get_save_settings_values (autosplit )
70
+ # Save settings to a .pkl file
71
+ with open (autosplit .last_successfully_loaded_settings_file_path , "wb" ) as file :
72
+ pickle .dump (autosplit .last_saved_settings , file )
73
+ return autosplit .last_successfully_loaded_settings_file_path
70
74
71
75
72
76
def save_settings_as (autosplit : AutoSplit ):
77
+ """
78
+ @return: The save settings filepath selected. Empty if cancelled
79
+ """
73
80
# User picks save destination
74
- autosplit . save_settings_file_path = QtWidgets .QFileDialog .getSaveFileName (
81
+ save_settings_file_path = QtWidgets .QFileDialog .getSaveFileName (
75
82
autosplit ,
76
83
"Save Settings As" ,
77
- os .path .join (auto_split_directory , "settings.pkl" ),
84
+ autosplit .last_successfully_loaded_settings_file_path
85
+ or os .path .join (auto_split_directory , "settings.pkl" ),
78
86
"PKL (*.pkl)" )[0 ]
79
87
80
88
# If user cancels save destination window, don't save settings
81
- if not autosplit . save_settings_file_path :
82
- return
89
+ if not save_settings_file_path :
90
+ return ""
83
91
84
92
autosplit .last_saved_settings = get_save_settings_values (autosplit )
85
93
86
- # save settings to a .pkl file
87
- with open (autosplit . save_settings_file_path , "wb" ) as file :
94
+ # Save settings to a .pkl file
95
+ with open (save_settings_file_path , "wb" ) as file :
88
96
pickle .dump (autosplit .last_saved_settings , file )
89
97
90
- # Wording is kinda off here but this needs to be here for an edge case:
91
- # for when a file has never loaded, but you save file as successfully.
92
- autosplit .last_successfully_loaded_settings_file_path = autosplit .save_settings_file_path
98
+ autosplit .last_successfully_loaded_settings_file_path = save_settings_file_path
99
+ return save_settings_file_path
93
100
94
101
95
- def __load_settings_from_file (autosplit : AutoSplit ):
102
+ def __load_settings_from_file (autosplit : AutoSplit , load_settings_file_path : str ):
96
103
try :
97
- with open (autosplit . load_settings_file_path , "rb" ) as file :
104
+ with open (load_settings_file_path , "rb" ) as file :
98
105
settings : list [Any ] = RestrictedUnpickler (file ).load ()
99
106
settings_count = len (settings )
100
107
if settings_count < 18 :
101
108
autosplit .show_error_signal .emit (error_messages .old_version_settings_file )
102
- return
109
+ return False
103
110
# v1.3-1.4 settings. Add default pause_key and auto_start_on_reset_setting
104
111
if settings_count == 18 :
105
112
settings .insert (9 , "" )
@@ -110,11 +117,11 @@ def __load_settings_from_file(autosplit: AutoSplit):
110
117
# v1.6.X settings
111
118
elif settings_count != 21 :
112
119
autosplit .show_error_signal .emit (error_messages .invalid_settings )
113
- return
120
+ return False
114
121
autosplit .last_loaded_settings = settings
115
122
except (FileNotFoundError , MemoryError , pickle .UnpicklingError ):
116
123
autosplit .show_error_signal .emit (error_messages .invalid_settings )
117
- return
124
+ return False
118
125
119
126
autosplit .split_image_directory = settings [0 ]
120
127
autosplit .split_image_folder_input .setText (settings [0 ])
@@ -147,46 +154,44 @@ def __load_settings_from_file(autosplit: AutoSplit):
147
154
autosplit .live_image .setText ("Reload settings after opening"
148
155
f'\n "{ autosplit .window_text } "'
149
156
"\n to automatically load Live Capture" )
157
+ return True
150
158
151
159
152
160
def load_settings (
153
161
autosplit : AutoSplit ,
154
- load_settings_on_open : bool = False ,
155
- load_settings_from_livesplit : bool = False
162
+ from_path : str = ""
156
163
):
157
- if load_settings_on_open :
158
- settings_files = [
159
- file for file
160
- in os .listdir (auto_split_directory )
161
- if file .endswith (".pkl" )]
162
-
163
- # find all .pkls in AutoSplit folder, error if there is none or more than 1
164
- if len (settings_files ) < 1 :
165
- error_messages .no_settings_file_on_open ()
166
- autosplit .last_loaded_settings = []
167
- return
168
- if len (settings_files ) > 1 :
169
- error_messages .too_many_settings_files_on_open ()
170
- autosplit .last_loaded_settings = []
171
- return
172
- autosplit .load_settings_file_path = os .path .join (auto_split_directory , settings_files [0 ])
173
-
174
- elif not load_settings_on_open and not load_settings_from_livesplit :
175
- autosplit .load_settings_file_path = QtWidgets .QFileDialog .getOpenFileName (
176
- autosplit ,
177
- "Load Settings" ,
178
- os .path .join (auto_split_directory , "settings.pkl" ),
179
- "PKL (*.pkl)" )[0 ]
180
- if not autosplit .load_settings_file_path :
181
- return
182
-
183
- __load_settings_from_file (autosplit )
184
-
185
- autosplit .last_successfully_loaded_settings_file_path = autosplit .load_settings_file_path
164
+ load_settings_file_path = from_path or QtWidgets .QFileDialog .getOpenFileName (
165
+ autosplit ,
166
+ "Load Settings" ,
167
+ os .path .join (auto_split_directory , "settings.pkl" ),
168
+ "PKL (*.pkl)" )[0 ]
169
+ if not (load_settings_file_path and __load_settings_from_file (autosplit , load_settings_file_path )):
170
+ return
171
+
172
+ autosplit .last_successfully_loaded_settings_file_path = load_settings_file_path
186
173
autosplit .check_live_image ()
187
174
autosplit .load_start_image ()
188
175
189
176
177
+ def load_settings_on_open (autosplit : AutoSplit ):
178
+ settings_files = [
179
+ file for file
180
+ in os .listdir (auto_split_directory )
181
+ if file .endswith (".pkl" )]
182
+
183
+ # find all .pkls in AutoSplit folder, error if there is none or more than 1
184
+ if len (settings_files ) < 1 :
185
+ error_messages .no_settings_file_on_open ()
186
+ autosplit .last_loaded_settings = []
187
+ return
188
+ if len (settings_files ) > 1 :
189
+ error_messages .too_many_settings_files_on_open ()
190
+ autosplit .last_loaded_settings = []
191
+ return
192
+ load_settings (autosplit , os .path .join (auto_split_directory , settings_files [0 ]))
193
+
194
+
190
195
def load_check_for_updates_on_open (autosplit : AutoSplit ):
191
196
"""
192
197
Retrieve the "Check For Updates On Open" QSettings and set the checkbox state
0 commit comments