@@ -127,13 +127,13 @@ def merge_settings(self, default, user):
127
127
def read_from_file (self , file_path , path_mode = "ignore" ):
128
128
""" Load JSON settings from a file """
129
129
try :
130
- with open (file_path , 'r' ) as f :
130
+ with open (file_path , 'r' , encoding = 'utf-8' ) as f :
131
131
contents = f .read ()
132
132
if contents :
133
133
if path_mode == "absolute" :
134
134
# Convert any paths to absolute
135
135
contents = self .convert_paths_to_absolute (file_path , contents )
136
- return json .loads (contents , strict = False )
136
+ return json .loads (contents )
137
137
except Exception as ex :
138
138
msg = ("Couldn't load {} file: {}" .format (self .data_type , ex ))
139
139
log .error (msg )
@@ -145,11 +145,11 @@ def read_from_file(self, file_path, path_mode="ignore"):
145
145
def write_to_file (self , file_path , data , path_mode = "ignore" , previous_path = None ):
146
146
""" Save JSON settings to a file """
147
147
try :
148
- contents = json .dumps (data , indent = 1 )
148
+ contents = json .dumps (data , ensure_ascii = False , indent = 1 )
149
149
if path_mode == "relative" :
150
150
# Convert any paths to relative
151
151
contents = self .convert_paths_to_relative (file_path , previous_path , contents )
152
- with open (file_path , 'w' ) as f :
152
+ with open (file_path , 'w' , encoding = 'utf-8' ) as f :
153
153
f .write (contents )
154
154
except Exception as ex :
155
155
msg = ("Couldn't save {} file:\n {}\n {}" .format (self .data_type , file_path , ex ))
@@ -164,18 +164,18 @@ def replace_string_to_absolute(self, match):
164
164
# Find absolute path of file (if needed)
165
165
if "@transitions" in path :
166
166
new_path = path .replace ("@transitions" , os .path .join (info .PATH , "transitions" ))
167
- new_path = json .dumps (new_path ) # Escape backslashes
167
+ new_path = json .dumps (new_path , ensure_ascii = False )
168
168
return '"%s": %s' % (key , new_path )
169
169
170
170
elif "@assets" in path :
171
171
new_path = path .replace ("@assets" , path_context ["new_project_assets" ])
172
- new_path = json .dumps (new_path ) # Escape backslashes
172
+ new_path = json .dumps (new_path , ensure_ascii = False )
173
173
return '"%s": %s' % (key , new_path )
174
174
175
175
else :
176
176
# Convert path to the correct relative path
177
177
new_path = os .path .abspath (os .path .join (path_context .get ("new_project_folder" , "" ), path ))
178
- new_path = json .dumps (new_path ) # Escape backslashes
178
+ new_path = json .dumps (new_path , ensure_ascii = False )
179
179
return '"%s": %s' % (key , new_path )
180
180
181
181
def convert_paths_to_absolute (self , file_path , data ):
@@ -205,7 +205,7 @@ def replace_string_to_relative(self, match):
205
205
if info .THUMBNAIL_PATH in folder_path :
206
206
# Convert path to relative thumbnail path
207
207
new_path = os .path .join ("thumbnail" , file_path ).replace ("\\ " , "/" )
208
- new_path = json .dumps (new_path ) # Escape backslashes
208
+ new_path = json .dumps (new_path , ensure_ascii = False )
209
209
return '"%s": %s' % (key , new_path )
210
210
211
211
# Determine if @transitions path is found
@@ -215,7 +215,7 @@ def replace_string_to_relative(self, match):
215
215
216
216
# Convert path to @transitions/ path
217
217
new_path = os .path .join ("@transitions" , category_path , file_path ).replace ("\\ " , "/" )
218
- new_path = json .dumps (new_path ) # Escape backslashes
218
+ new_path = json .dumps (new_path , ensure_ascii = False )
219
219
return '"%s": %s' % (key , new_path )
220
220
221
221
# Determine if @assets path is found
@@ -225,7 +225,7 @@ def replace_string_to_relative(self, match):
225
225
226
226
# Convert path to @transitions/ path
227
227
new_path = os .path .join (folder_path , file_path ).replace ("\\ " , "/" )
228
- new_path = json .dumps (new_path ) # Escape backslashes
228
+ new_path = json .dumps (new_path , ensure_ascii = False )
229
229
return '"%s": %s' % (key , new_path )
230
230
231
231
# Find absolute path of file (if needed)
@@ -239,7 +239,7 @@ def replace_string_to_relative(self, match):
239
239
# Calculate new relateive path
240
240
new_rel_path_folder = os .path .relpath (orig_abs_folder , path_context .get ("new_project_folder" , "" ))
241
241
new_rel_path = os .path .join (new_rel_path_folder , file_path ).replace ("\\ " , "/" )
242
- new_rel_path = json .dumps (new_rel_path ) # Escape backslashes
242
+ new_rel_path = json .dumps (new_rel_path , ensure_ascii = False )
243
243
return '"%s": %s' % (key , new_rel_path )
244
244
245
245
def convert_paths_to_relative (self , file_path , previous_path , data ):
0 commit comments