Skip to content

Commit

Permalink
Some minor changes
Browse files Browse the repository at this point in the history
  • Loading branch information
MCMi460 committed Aug 13, 2023
1 parent 7b61917 commit adb76a4
Showing 1 changed file with 3 additions and 18 deletions.
21 changes: 3 additions & 18 deletions client/api/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,24 +12,12 @@
import hashlib
import re
import pickle
import re


def getAppPath():
application_path = ""

# Check for macOS platform and NSO-RPC freeze status
if sys.platform.startswith('darwin') and hasattr(sys, 'frozen') and sys.frozen == 'macosx_app':
app_root_folder = os.path.dirname(re.search(r'(.*/NSO-RPC\.app)/', os.path.abspath(__file__)).group(1))

# If the path starts with "/private", assume NSO-RPC is in Downloads folder.
if app_root_folder.startswith("/private"):
applicationPathTmp = app_root_folder.split("/")
applicationPathTmp = applicationPathTmp[len(applicationPathTmp) - 4:len(applicationPathTmp)]
portable_data_path = os.path.join(os.path.expanduser('~/Downloads'), *applicationPathTmp, "NSO-RPC_Data")
if os.path.isdir(portable_data_path):
return portable_data_path

# Check if NSO-RPC_Data exists
potential_data_path = os.path.join(app_root_folder, 'NSO-RPC_Data')
if os.path.isdir(potential_data_path):
Expand All @@ -40,7 +28,8 @@ def getAppPath():
# Windows allows you to move your UserProfile subfolders, Such as Documents, Videos, Music etc.
# However os.path.expanduser does not actually check and assumes its in the default location.
# This tries to correctly resolve the Documents path and fallbacks to default if it fails.
elif platform.system() == 'Windows':
application_path = os.path.expanduser('~/Documents/NSO-RPC')
if platform.system() == 'Windows':
try:
import ctypes.wintypes
CSIDL_PERSONAL = 5 # My Documents
Expand All @@ -50,15 +39,11 @@ def getAppPath():
application_path = os.path.join(buf.value, 'NSO-RPC')
except:
pass
else:
# Default path for other platforms
application_path = os.path.expanduser('~/Documents/NSO-RPC')

# Use Portable path if it exists, else use Default path
portable_data_path = os.path.join(application_path, 'NSO-RPC_Data')
portable_data_path = os.path.join(os.getcwd(), 'NSO-RPC_Data')
return portable_data_path if os.path.isdir(portable_data_path) else application_path


def log(info, time = time.time()):
path = getAppPath()
if not os.path.isdir(path):
Expand Down

0 comments on commit adb76a4

Please sign in to comment.