Skip to content

Commit

Permalink
Invalid Json management
Browse files Browse the repository at this point in the history
Past Zeni, why in the world did you even let this past?
  • Loading branch information
ZenithVal committed Feb 27, 2024
1 parent c34a6c2 commit 0bb80b1
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
9 changes: 6 additions & 3 deletions Controllers/DataController.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import time
import os
import ctypes #Required for colored error messages.

DefaultConfig = {
Expand Down Expand Up @@ -61,8 +62,11 @@ def setSettings(self, configJson):
self.XboxJoystickMovement = configJson["XboxJoystickMovement"]
self.Leashes = configJson["PhysboneParameters"]
except Exception as e:
print('\x1b[1;31;40m' + 'Malformed config file. Loading default values.' + '\x1b[0m')
print(e,"was the exception\n")
print('\x1b[1;31;40m' + 'Malformed Config.json contents. Was something missing?' + '\x1b[0m')
print(f"Exception: {e}\nDefault Config will be loaded.\n")
os.system("pause")
print("")

self.IP = DefaultConfig["IP"]
self.ListeningPort = DefaultConfig["ListeningPort"]
self.SendingPort = DefaultConfig["SendingPort"]
Expand All @@ -80,7 +84,6 @@ def setSettings(self, configJson):
self.Logging = DefaultConfig["Logging"]
self.XboxJoystickMovement = DefaultConfig["XboxJoystickMovement"]
self.Leashes = DefaultConfig["PhysboneParameters"]
time.sleep(3)

def addGamepadControls(self, gamepad, runButton):
self.gamepad = gamepad
Expand Down
15 changes: 12 additions & 3 deletions OSCLeash.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def createDefaultConfigFile(configPath): # Creates a default config
program.cls()

# Make sure to change this to the correct version number on releases.
print('\x1b[1;32;40m' + "OSCLeash v2.1.1" + '\x1b[0m')
print('\x1b[1;32;40m' + "OSCLeash v2.1.2" + '\x1b[0m')

# Test if Config file exists. Create the default if it does not.
configRelativePath = "./Config.json"
Expand All @@ -41,8 +41,17 @@ def createDefaultConfigFile(configPath): # Creates a default config
else:
print("Config file found\n")

configData = json.load(open(configRelativePath)) # Config file should be prepared at this point.
settings = ConfigSettings(configData) # Get settings from config file
# load settings
try:
configData = json.load(open(configRelativePath))
except Exception as e:
print('\x1b[1;31;40m' + 'Malformed Config.json file. Fix or delete it to generate a new one.' + '\x1b[0m')
print(f"{e}\nDefault Config will be loaded.\n")

configData = DefaultConfig
os.system("pause")

settings = ConfigSettings(configData)

time.sleep(1)

Expand Down

0 comments on commit 0bb80b1

Please sign in to comment.