|
1 | 1 | import json
|
2 | 2 |
|
3 | 3 |
|
| 4 | +# noinspection PyBroadException |
| 5 | +def tryLoad(key): |
| 6 | + appcfg = readAppConfig() |
| 7 | + try: |
| 8 | + data = appcfg[key] |
| 9 | + except: |
| 10 | + data = getDefaultConfig()[key] |
| 11 | + return data |
| 12 | + |
| 13 | + |
| 14 | +def getDefaultConfig(): |
| 15 | + data = { |
| 16 | + "app_name": "FastCode.Ninja LockDown", |
| 17 | + "app_version": "0.0.1", |
| 18 | + "app_author": "Emir Tunahan Alim", |
| 19 | + "app_author_email": "emrtnhalim@gmail.com", |
| 20 | + "app_description": "Cross-platform multi-lingual screen locker app for computers and smart boards.", |
| 21 | + "github_user": "https://github.com/Eta06", |
| 22 | + "github_repo": "https://github.com/Eta06/LockDown", |
| 23 | + "app_license": "Apache License 2.0", |
| 24 | + "app_license_url": "https://github.com/Eta06/LockDown/blob/main/LICENSE", |
| 25 | + "app_language": "", |
| 26 | + "app_port": "4900" |
| 27 | + } |
| 28 | + return data |
| 29 | + |
| 30 | + |
4 | 31 | def readAppConfig():
|
5 | 32 | try:
|
6 | 33 | with open("appconfig.json", "r") as f:
|
7 | 34 | data = json.load(f)
|
8 | 35 | return data
|
9 | 36 | except FileNotFoundError:
|
10 | 37 | with open("appconfig.json", "w") as f:
|
11 |
| - data = { |
12 |
| - "app_name": "FastCode.Ninja LockDown", |
13 |
| - "app_version": "0.0.1", |
14 |
| - "app_author": "Emir Tunahan Alim", |
15 |
| - "app_author_email": "emrtnhalim@gmail.com", |
16 |
| - "app_description": "Cross-platform multi-lingual screen locker app for computers and smart boards.", |
17 |
| - "github_user": "https://github.com/Eta06", |
18 |
| - "github_repo": "https://github.com/Eta06/LockDown", |
19 |
| - "app_license": "Apache License 2.0", |
20 |
| - "app_license_url": "https://github.com/Eta06/LockDown/blob/main/LICENSE", |
21 |
| - "app_language": "", |
22 |
| - } |
| 38 | + data = getDefaultConfig() |
23 | 39 | json.dump(data, f, indent=4)
|
24 | 40 | return data
|
25 | 41 |
|
|
0 commit comments