Skip to content

Commit

Permalink
refactor(discordRPC): modulize getSave
Browse files Browse the repository at this point in the history
  • Loading branch information
ThiaudioTT committed Jun 29, 2024
1 parent 50ea4fc commit 68ec120
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions src/discordRPC/hoi4RPC.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,18 @@

# FLAGS FOR THE COMPILER: --name hoi4Presence --noconsole --onefile

def getSavePath() -> str:
"Gets the save path for the save files"
save_path = ""
# Check if the script is compiled or not
if getattr(sys, 'frozen', False): save_path = os.path.dirname(sys.executable)
else: save_path = os.path.dirname(os.path.abspath(__file__)) # case is not compiled

# getting the save files path
save_path = os.path.abspath(save_path + "/../" + "/save games/*.hoi4")

return save_path

try:
client_id = '1021549599732809820'
RPC = Presence(client_id) # Initialize the Presence class
Expand All @@ -31,17 +43,12 @@
gameRunning = True
while gameRunning: # The presence will stay on as long as the program is running, so use some lib
try:
SAVE_PATH = getSavePath()

path = "" # path to the saves
if getattr(sys, 'frozen', False):
path = os.path.dirname(sys.executable)
else:
path = os.path.dirname(os.path.abspath(__file__))

path = os.path.abspath(path + "/../" + "/save games/*.hoi4")
#TODO: refactor this code.

# getting the last modified save file
listSaves = glob.glob(path)
listSaves = glob.glob(SAVE_PATH)
lastSavePath = max(listSaves, key=os.path.getmtime)

dateFile = int(os.path.getmtime(lastSavePath))
Expand Down

0 comments on commit 68ec120

Please sign in to comment.