Skip to content

Commit

Permalink
Fixed a paths problems with the html viewer
Browse files Browse the repository at this point in the history
  • Loading branch information
Gemmstone committed Mar 21, 2024
1 parent f2c6b66 commit 1d2664b
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Data/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"volume threshold": 22,
"scream threshold": 93,
"delay threshold": 14,
"microphone selection": 3,
"microphone selection": 2,
"microphone mute": false,
"background color": 0,
"export mode": 0,
Expand Down
39 changes: 36 additions & 3 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,41 @@ def compare_versions(current_version, latest_version):
return True # Up to date


def is_path(string):
# Check if the string is an absolute path
if os.path.isabs(string):
return True
# Check if the string has an extension
_, extension = os.path.splitext(string)
if extension:
return True
# Check if the string contains path separators
if os.path.sep in string:
return True
return False


def update_nested_dict(dest_data, source_data):
for key, value in source_data.items():
if isinstance(value, dict):
if is_path(os.path.normpath(key)):
if os.path.normpath(key) not in dest_data:
dest_data[os.path.normpath(key)] = value
else:
update_nested_dict(dest_data[key], value)
else:
if key not in dest_data:
dest_data[key] = value
else:
update_nested_dict(dest_data[key], value)
else:
if is_path(os.path.normpath(key)):
if os.path.normpath(key) not in dest_data:
dest_data[os.path.normpath(key)] = value
else:
dest_data[key] = value


def update_json_file(source_path, dest_path):
with open(source_path, 'r') as source_file:
source_data = json.load(source_file)
Expand All @@ -68,9 +103,7 @@ def update_json_file(source_path, dest_path):
with open(dest_path, 'w', encoding='utf-8') as dest_file:
json.dump(source_data, dest_file, indent=4, ensure_ascii=False)
else:
for key, value in source_data.items():
if key not in dest_data:
dest_data[key] = value
update_nested_dict(dest_data, source_data)

with open(dest_path, 'w') as dest_file:
json.dump(dest_data, dest_file, indent=4, ensure_ascii=False)
Expand Down

0 comments on commit 1d2664b

Please sign in to comment.