|
1 | 1 | #! /usr/bin/python3 -OOt
|
2 | 2 |
|
3 | 3 | # --- Version number ---
|
4 |
| -converterVersion = "001003005" # Change the number if you want to trigger an update. |
| 4 | +converterVersion = "001003006" # Change the number if you want to trigger an update. |
5 | 5 | # --- Variable to enable debug mode ---
|
6 | 6 | development_version = False
|
7 | 7 |
|
|
29 | 29 | import re
|
30 | 30 | from multiprocessing import Process
|
31 | 31 | import traceback
|
32 |
| - |
| 32 | +config_file = "~/.config/linux-file-converter-addon/config.json" |
| 33 | +config_file = str(Path(config_file).expanduser()) |
| 34 | +config_dir = pathlib.Path(config_file).parent |
33 | 35 | # --- Create magic object ---
|
34 | 36 | mime = magic.Magic(mime=True)
|
35 | 37 |
|
|
67 | 69 | if not scriptUpdateable:
|
68 | 70 | print(f"ERROR(Nautilus-file-converter)(402): No permission to self-update; script at \"{currentPath}/{os.path.basename(__file__)}\" is not writeable. View https://github.com/Lich-Corals/linux-file-converter-addon/blob/main/markdown/errors-and-warnings.md for more information.")
|
69 | 71 |
|
70 |
| -if not os.access(currentPath, os.W_OK): |
71 |
| - print(f"ERROR(Nautilus-file-converter)(403): No permission to write configuration file; \"{currentPath}\" is not writeable. View https://github.com/Lich-Corals/linux-file-converter-addon/blob/main/markdown/errors-and-warnings.md for more information.") |
72 |
| - |
73 | 72 | # --- Set default configs ---
|
74 |
| -_configPreset = { # These are the pre-defined default settings; edit NFC43-Config.json if the program has permission to write. |
| 73 | +_configPreset = { # These are the default settings and will reset with each update; edit ~/.config/linux-file-converter-addon/config.json if the program has permission to read and write it. |
75 | 74 | "automaticUpdates": True,
|
76 | 75 | "showPatchNotes": True,
|
77 | 76 | "showPatchNoteButton": True,
|
|
84 | 83 | "showDummyOption": True,
|
85 | 84 | "displayFinishNotification": True
|
86 | 85 | }
|
| 86 | + |
| 87 | +# --- Move settings from old config file to new location if the old one exists --- |
| 88 | +if not os.path.isdir(config_dir): |
| 89 | + os.system(f'mkdir "{config_dir}"') |
| 90 | +if Path(f"{currentPath}/NFC43-Config.json").is_file() and os.access(f"{currentPath}/NFC43-Config.json", os.W_OK): |
| 91 | + with open(f"{currentPath}/NFC43-Config.json", 'r') as jsonFile: |
| 92 | + try: |
| 93 | + old_config = json.load(jsonFile) |
| 94 | + except json.decoder.JSONDecodeError: |
| 95 | + old_config = _configPreset |
| 96 | + jsonFile.close() |
| 97 | + _configPreset = old_config.copy() |
| 98 | + with open(f"{currentPath}/NFC43-Config.json", 'w') as old_config_file: |
| 99 | + old_config["comment"] = f"THIS FILE DOES NOT CONFIGURE ANYTHING ANYMORE. USE {config_file} INSTEAD!" |
| 100 | + old_config = json.dumps(old_config, indent=4) |
| 101 | + old_config_file.write(old_config) |
| 102 | + old_config_file.close() |
| 103 | + os.system(f'mv "{currentPath}/NFC43-Config.json" "{currentPath}/NFC43-Config.json.DISABLED"') |
| 104 | + os.system(f'notify-send --app-name="linux-file-converter-addon" "Config file moved." "Your new config file is here:\n{config_dir}"') |
87 | 105 | _config = _configPreset
|
88 | 106 |
|
89 | 107 | # --- Load or store configs json ---
|
90 |
| -if scriptUpdateable: |
| 108 | +if os.access(config_dir, os.W_OK): |
91 | 109 | try:
|
92 |
| - if Path(f"{currentPath}/NFC43-Config.json").is_file(): |
93 |
| - with open(f"{currentPath}/NFC43-Config.json", 'r') as jsonFile: |
| 110 | + if Path(config_file).is_file(): |
| 111 | + with open(config_file, 'r') as jsonFile: |
94 | 112 | try:
|
95 | 113 | configJson = json.load(jsonFile)
|
96 | 114 | except json.decoder.JSONDecodeError:
|
|
102 | 120 | configJson = json.dumps(_config, indent=4)
|
103 | 121 | else:
|
104 | 122 | configJson = json.dumps(_configPreset, indent=4)
|
105 |
| - with open(f"{currentPath}/NFC43-Config.json", "w") as jsonFile: |
| 123 | + with open(config_file, "w") as jsonFile: |
106 | 124 | jsonFile.write(configJson)
|
107 | 125 | except:
|
108 | 126 | print("ERROR(Nautilus-file-converter)(401): Something went wrong while loading or updating the configuration file.")
|
109 | 127 | print(f"{traceback.format_exc()}")
|
| 128 | +else: |
| 129 | + print(f"ERROR(Nautilus-file-converter)(403): No permission to write configuration file; \"{config_dir}\" is not writeable. View https://github.com/Lich-Corals/linux-file-converter-addon/blob/main/markdown/errors-and-warnings.md for more information.") |
110 | 130 |
|
111 | 131 | # --- Check for updates and update if auto-update is enabled ---
|
112 | 132 | if _config["automaticUpdates"]:
|
|
0 commit comments