Skip to content

Commit

Permalink
add notification for new releases
Browse files Browse the repository at this point in the history
  • Loading branch information
shinrax2 committed Mar 13, 2020
1 parent 468be9b commit c657072
Show file tree
Hide file tree
Showing 6 changed files with 117 additions and 17 deletions.
22 changes: 14 additions & 8 deletions PS3GUD.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,23 @@ def __init__(self, window=None):
self.Updates = {}
self.DlList = []
self.titleid = ""

self.configDefaults = {}
self.configDefaults["dldir"] = "./downloadedPKGs"
self.configDefaults["verify"] = True
self.configDefaults["checkIfAlreadyDownloaded"] = True
self.configDefaults["storageThreshold"] = 95
self.configDefaults["currentLoc"] = "en"
self.configDefaults["checkForNewRelease"] = True

def setWindow(self, window):
self.logger = utils.Logger("log.txt", window)

def setLoc(self, loc):
self.loc = loc

def logHeader(self):
self.logger.log("PS3GameUpdateDownloader")
def logHeader(self, version):
self.logger.log("PS3GameUpdateDownloader "+version)
self.logger.log("Config File: "+self.configFile)
self.logger.log("Language: "+ self.loc.getLoc()+"\n\n")
def loadConfig(self):
Expand All @@ -49,11 +57,7 @@ def loadConfig(self):
self.config = json.loads(f.read())
else:
self.logger.log(self.loc.getKey("msg_noConfigFile"))
self.config["dldir"] = "./downloadedPKGs"
self.config["verify"] = True
self.config["checkIfAlreadyDownloaded"] = True
self.config["storageThreshold"] = 95
self.config["currentLoc"] = "en"
self.config = self.configDefaults

def setConfig(self, config):
self.config = config
Expand All @@ -62,8 +66,10 @@ def setConfig(self, config):
self.logger.log(self.loc.getKey("msg_configFileSaved"))

def getConfig(self, key):
if self.config[key] != None:
try:
return self.config[key]
except KeyError:
return self.configDefaults[key]

def loadTitleDb(self, titledb = "titledb.txt"):
with open(titledb, "r", encoding="utf8") as f:
Expand Down
13 changes: 12 additions & 1 deletion loc/de.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"loc_version": "v005",
"language_name": "Deutsch",
"language_short": "de",

Expand All @@ -13,6 +14,7 @@
"window_config_dldir_label": "Downloadverzeichnis:",
"window_config_verify_label": "Dateien überprüfen:",
"window_config_checkIfAlreadyDownloaded_label": "Prüfen, ob Dateien bereits heruntergeladen wurden:",
"window_config_checkForNewRelease_label": "Neue Version beim Starten suchen:",
"window_config_storageThreshold_label": "Speichergrenze (in %):",
"window_config_currentLoc_label": "Sprache:",
"window_config_cancel_btn": "Abbrechen",
Expand All @@ -27,6 +29,12 @@
"window_select_download_btn": "Herunterladen",
"window_select_cancel_btn": "Abbrechen",

"window_relNotify_title": "Neue Version gefunden!",
"window_relNotify_label": "Aktuelle Version: {0}\nNeue Version: {1}",
"window_relNotify_web_btn": "Öffne Website im Browser",
"window_relNotify_dl_btn": "Mit Browser herunterladen",
"window_relNotify_close_btn": "Schließen",

"msg_configFileLoaded": "Konfigurationsdatei geladen!",
"msg_noConfigFile": "Keine Konfigurationsdatei gefunden! Benutze Vorgaben!",
"msg_configFileSaved": "Konfigurationsdatei gespeichert!",
Expand All @@ -44,5 +52,8 @@
"msg_noVerify": "Datei \"{0}\" wurde nicht überprüft!",
"msg_finishedDownload": "{0} Dateien wurden heruntergeladen!",
"msg_notEnoughDiskSpace": "Nicht genügend Speicherplatz!",
"msg_spaceBelowThreshold": "Freier Speicherplatz unter {0}%"
"msg_spaceBelowThreshold": "Freier Speicherplatz unter {0}%",
"msg_relCheckError": "Konnte nicht nach neuer Version suchen!",
"msg_alreadyUpToDate": "Bereits neuste Version!",
"msg_foundNewRelease": "Neue Version \"{0}\" gefunden"
}
13 changes: 12 additions & 1 deletion loc/en.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"loc_version": "v005",
"language_name": "English",
"language_short": "en",

Expand All @@ -13,6 +14,7 @@
"window_config_dldir_label": "Download directory:",
"window_config_verify_label": "Verify files:",
"window_config_checkIfAlreadyDownloaded_label": "Check if file was already downloaded:",
"window_config_checkForNewRelease_label": "Check for a new release at startup:",
"window_config_storageThreshold_label": "Storage threshold (in %):",
"window_config_currentLoc_label": "Language:",
"window_config_cancel_btn": "Cancel",
Expand All @@ -27,6 +29,12 @@
"window_select_download_btn": "Download",
"window_select_cancel_btn": "Cancel",

"window_relNotify_title": "New release found!",
"window_relNotify_label": "Current version: {0}\nNew version: {1}",
"window_relNotify_web_btn": "Open website in browser",
"window_relNotify_dl_btn": "Download with browser",
"window_relNotify_close_btn": "Close",

"msg_configFileLoaded": "Loaded configuration file!",
"msg_noConfigFile": "No configuration file found! Using defaults!",
"msg_configFileSaved": "Saved configuration file!",
Expand All @@ -44,5 +52,8 @@
"msg_noVerify": "File \"{0}\" was not verified!",
"msg_finishedDownload": "Finished downloading {0} files!",
"msg_notEnoughDiskSpace": "Not enough free disk space!",
"msg_spaceBelowThreshold": "Free disk space is below {0}%"
"msg_spaceBelowThreshold": "Free disk space is below {0}%",
"msg_relCheckError": "Couldn't check for new release!",
"msg_alreadyUpToDate": "Already on the newest release!",
"msg_foundNewRelease": "Found new Release \"{0}\""
}
53 changes: 46 additions & 7 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
#
# PS3GameUpdateDownloader by shinrax2

#builtin
import webbrowser
#pip packages
import PySimpleGUI as sg
#local files
Expand All @@ -17,6 +19,8 @@ def updatePackToTable(update):
i+=1
data.append(row)
return data

rel = utils.UpdaterGithubRelease("release.json")
ps3 = PS3GUD.PS3GUD()
ps3.loadConfig()
loc = utils.Loc()
Expand All @@ -34,11 +38,45 @@ def updatePackToTable(update):
window = sg.Window(loc.getKey("window_main_title"), layout1)
ps3.setWindow(window)
win2_act = False
ps3.logHeader()
relCheck = False
ps3.logHeader(rel.getVersion())
ps3.loadTitleDb()

if ps3.getConfig("checkForNewRelease"):
relCheck = True
while True:
event, values = window.read()
if relCheck:
data = rel.checkForNewRelease()
if data == False:
ps3.logger.log(loc.getKey("msg_relCheckError"))
relCheck = False
elif data == 1:
ps3.logger.log(loc.getKey("msg_alreadyUpToDate"))
relCheck = False
else:
ps3.logger.log(loc.getKey("msg_foundNewRelease", [data["version"]]))
relCheck = False
layoutRelNotify = [
[sg.Text(loc.getKey("window_relNotify_label", [rel.getVersion(), data["version"]]))],
[sg.Button(loc.getKey("window_relNotify_web_btn"), key="web"), sg.Button(loc.getKey("window_relNotify_dl_btn"), key="dl"), sg.Button(loc.getKey("window_relNotify_close_btn"), key="close")]
]
winRelNotify = sg.Window(loc.getKey("window_relNotify_title"), layoutRelNotify)
while True:
evRel, valRel = winRelNotify.read()
if evRel == "close":
winRelNotify.close()
break
if evRel in (None, "Exit"):
winRelNotify.close()
break
if evRel == "web":
webbrowser.open_new(data["releaseUrlWeb"])
winRelNotify.close()
break
if evRel == "dl":
webbrowser.open_new(data["releaseUrlDl"])
winRelNotify.close()
break
event, values = window.read()
if event == "Exit":
break
if event in (None, "Exit"):
Expand All @@ -54,6 +92,7 @@ def updatePackToTable(update):
[sg.Text(loc.getKey("window_config_dldir_label")), sg.In(ps3.getConfig("dldir"), key="dldir"), sg.FolderBrowse(target="dldir")],
[sg.Text(loc.getKey("window_config_verify_label")), sg.Checkbox("", default=ps3.getConfig("verify"), key="verify")],
[sg.Text(loc.getKey("window_config_checkIfAlreadyDownloaded_label")),sg.Checkbox("", default=ps3.getConfig("checkIfAlreadyDownloaded"), key="checkIfAlreadyDownloaded")],
[sg.Text(loc.getKey("window_config_checkForNewRelease_label")), sg.Checkbox("", default=ps3.getConfig("checkForNewRelease"), key="checkForNewRelease")],
[sg.Text(loc.getKey("window_config_storageThreshold_label")), sg.Spin([i for i in range(1, 100)], initial_value=ps3.getConfig("storageThreshold"), key="storageThreshold")],
[sg.Text(loc.getKey("window_config_currentLoc_label")), sg.DropDown(locChoices, size=(8, 15), key="currentLoc")],
[sg.Button(loc.getKey("window_config_cancel_btn"), key="Cancel"),sg.Button(loc.getKey("window_config_save_btn"), key="Save")]
Expand All @@ -65,11 +104,11 @@ def updatePackToTable(update):
winConfig.Close()
window.UnHide()
break
elif evConfig in (None, "Exit"):
if evConfig in (None, "Exit"):
winConfig.Close()
window.UnHide()
break
elif evConfig == "Save" and valConfig["currentLoc"] != "":
if evConfig == "Save" and valConfig["currentLoc"] != "":
cL = valConfig["currentLoc"]
for l in ll:
if cL == l["language_name"]:
Expand Down Expand Up @@ -110,13 +149,13 @@ def updatePackToTable(update):
window.UnHide()
tryDl = False
break
elif ev2 == "Cancel":
if ev2 == "Cancel":
win2.Close()
win2_act = False
window.UnHide()
tryDl = False
break
elif ev2 == "OK" and val2["drop"] != "":
if ev2 == "OK" and val2["drop"] != "":
drop = val2["drop"]
if drop == loc.getKey("window_select_all_text"):
drop = loc.getKey("window_select_all_text")
Expand Down
4 changes: 4 additions & 0 deletions release.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"version": "v005",
"releaseUrl": "https://api.github.com/repos/shinrax2/PS3GameUpdateDownloader/releases/latest"
}
29 changes: 29 additions & 0 deletions utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import os
import platform
import json
import urllib.request

class Logger():
def __init__(self, logfile, window=None):
Expand Down Expand Up @@ -82,6 +83,34 @@ def getKey(self, key, args=[]):
except KeyError:
return "ERROR \""+key+"\""

class UpdaterGithubRelease():
def __init__(self, releaseFile):
self.rF = releaseFile
self.release = {}
with open(self.rF, "r", encoding="utf8") as f:
self.release = json.loads(f.read())

def getVersion(self):
return self.release["version"]

def checkForNewRelease(self):
try:
resp = urllib.request.urlopen(self.release["releaseUrl"])
data = resp.read()
data.decode("utf-8")
resp = json.loads(data)
except urllib.error.HTTPError:
return False
if int(self.release["version"][1:]) < int(resp["tag_name"][1:]):
rel = {}
rel["version"] = resp["tag_name"]
rel["releaseUrlWeb"] = "https://github.com/shinrax2/PS3GameUpdateDownloader/releases/latest"
rel["releaseUrlDl"] = resp["assets"][0]["browser_download_url"]
return rel
else:
return 1


def formatSize(size):
if int(size) > 1024-1 and int(size) < 1024*1024 : #KB
return str(format(float(size)/1024, '.2f'))+"KB"
Expand Down

0 comments on commit c657072

Please sign in to comment.