Skip to content

Commit

Permalink
Merge pull request #10 from ThiaudioTT/v0.2.0
Browse files Browse the repository at this point in the history
v0.2.0
  • Loading branch information
ThiaudioTT authored Sep 29, 2022
2 parents 4981cfe + fdd0276 commit cd29c94
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 12 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
*.hoi4
src/discordRPC/dist/
src/discordRPC/build/
src/dist/
src/build/
*.spec
*.exe
2 changes: 1 addition & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ Searching for a good [issue](https://github.com/ThiaudioTT/hoi4-presence/labels/

## how the presence works?

It uses the autosave to get data. So, spend one month in the game to update the presence.
It uses the saves to get data. So, spend one month in the game or save the game to update the presence.

TODO...

Expand Down
15 changes: 14 additions & 1 deletion src/discordRPC/checkupdate.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,30 @@
# COMPILE THIS USING --onefile
import semantic_version
import time
import urllib.request
import time
import json
import sys
import os

def checkUpdate():
try:
localVersion = open("version.json", "r")
# picking the current dir
version_path = ""
if getattr(sys, 'frozen', False):
version_path = os.path.dirname(sys.executable)
else:
version_path = os.path.dirname(os.path.abspath(__file__))

localVersion = open(version_path + "/version.json", "r") # use something like .resolve() or clean code
localVersion = json.load(localVersion)

print("\nLocal version: ")
print(localVersion)
except Exception as e:
print(e)
print("Error while reading version.json")
time.sleep(5)
sys.exit(1)

URL = urllib.request.urlopen("https://raw.githubusercontent.com/ThiaudioTT/hoi4-presence/main/version.json")
Expand All @@ -25,5 +37,6 @@ def checkUpdate():
time.sleep(120)
else:
print("Update not found.")
time.sleep(5)

checkUpdate()
27 changes: 19 additions & 8 deletions src/discordRPC/main.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
from pypresence import Presence
from pathlib import Path
import re
import time
import os
import psutil
import sys
import glob

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

try:
client_id = '1021549599732809820'
Expand All @@ -29,22 +31,30 @@
while gameRunning: # The presence will stay on as long as the program is running, so use some lib
try:

path = Path(__file__).parent.parent / "save games/autosave.hoi4" # wont work if you compile in one single file | use .resolve()?
dateFile = int(os.path.getmtime(path))
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")

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

dateFile = int(os.path.getmtime(lastSavePath))
now = int(time.time())
saveNew = False

# TODO: you can use any file, only check if is new.
if (now - dateFile) <= 120: # calc to see if autosave is recently (2 min recently)
if (now - dateFile) <= 120: # calc to see if save is recently (2 min recently)
saveNew = True
else:
saveNew = False


if(saveNew):
# putting this in a function might be good.

save = open(path, "r")
save = open(lastSavePath, "r")
data = ""
for i in range(5):
data += save.readline()
Expand Down Expand Up @@ -104,6 +114,7 @@
print(data) # debug
except Exception as e:
print(e)
time.sleep(5)

time.sleep(30) #Wait a wee bit
gameRunning = False
Expand Down
4 changes: 3 additions & 1 deletion src/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import sys
import json
from pathlib import Path
# TODO: remove pathlib dependency to compile in onefile.
# TODO: verify if all files are included in /dist/ folder. (like version.json)

print("This script will install the hoi4-presence in your game/save path\nPress enter to continue...")
input()
Expand Down Expand Up @@ -43,7 +45,7 @@
print(documents)
print(documents + "\\hoi4Presence")

source = Path(__file__).parent.resolve() / "discordRPC/dist/hoi4Presence"
source = Path(__file__).parent.resolve() / "discordRPC/dist"
shutil.copytree(source, documents + "\\hoi4Presence")
except Exception as e:
print(e)
Expand Down
2 changes: 1 addition & 1 deletion version.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "0.1.0",
"version": "0.2.0",
"auto-update": false,
"date": "23-sep-2022"
}

0 comments on commit cd29c94

Please sign in to comment.