Skip to content

Commit

Permalink
Added serial number checker and error + yes/no page
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrew committed Jun 5, 2019
1 parent 5f716d1 commit 215769c
Show file tree
Hide file tree
Showing 26 changed files with 914 additions and 475 deletions.
9 changes: 3 additions & 6 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
/cache/*
/hbupdater/*
settings.txt
/downloads/*
/payloads/*
/titledb/*
nut/*
/fluffy/*
/conf/*
/tools/*
user_repos.json
conf/nut.conf
conf/users.conf
fluffy.conf
fluffy.log
*.pyc
guisettings_user.json
guisettings_user.json
129 changes: 64 additions & 65 deletions HBUpdaterGUI.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,13 @@
if sys.version_info[0] < 3 or sys.version_info[1] < 6:
sys.exit("Python 3.6 or greater is required to run this program.")

version = "0.8 (Beta)"
version = "0.9 (Beta)"
print("HBUpdaterGUI version {}".format(version))

#My modules
from modules.format import * #We import format in this manner for simplicity's sake
import modules.guicore as guicore
import modules.HBUpdater as HBUpdater #import backend, will not run standalone
import modules.homebrewcore as homebrewcore
import modules.locations as locations
import modules.webhandler as webhandler

Expand All @@ -34,33 +33,12 @@
from tkinter.constants import *
print("using tkinter version {}".format(tk.Tcl().eval('info patchlevel')))

#import pages for FrameManager (Needs to be done after dict is populated)
import pages.injectorpage as ip
import pages.mainpage as mp
import pages.settingspage as sp
import pages.addrepopage as ar
import pages.installerhelperpage as hp
import pages.pythonnxpage as py
import pages.cfwpage as fw
errorstate = None

#Main frame handler, raises and pages in z layer
class FrameManager(tk.Tk):
def __init__(self, *args, **kwargs):
tk.Tk.__init__(self, *args, **kwargs)

if platform.system() == 'Windows':
try:
print("Windows detected, setting icon")
self.iconbitmap(homebrewcore.joinpaths(homebrewcore.assetfolder, 'HBUpdater.ico'))
except:
print("Failed to set icon")
elif platform.system() == "Linux":
try:
print("Linux detected, setting icon")
self.iconbitmap(homebrewcore.joinpaths(homebrewcore.assetfolder, 'HBUpdater.xbm'))
except:
print("Failed to set icon")


# self.resizable(False,False)
self.geometry("790x510") #startup size 720p
self.minsize(width=790, height=510) #minimum size currently supported
Expand All @@ -72,64 +50,85 @@ def __init__(self, *args, **kwargs):
container.grid_rowconfigure(0, weight=1)
container.grid_columnconfigure(0, weight=1)

#import pages
import pages.injectorpage as ip
import pages.mainpage as mp
import pages.settingspage as sp
import pages.addrepopage as ar
import pages.installerhelperpage as hp
import pages.pythonnxpage as py
import pages.cfwpage as fw
import pages.errorpage as ep
import pages.homepage as lp
import pages.gamespage as gp
import pages.serialpage as cp

self.frames = {}
#Add frames to dict, with keyword being the name of the frame
for F in (mp.mainPage,ip.injectorScreen,sp.settingsPage,ar.addRepoScreen,hp.installerHelperPage,py.pynxPage,fw.cfwPage):
for F in (mp.mainPage,ip.injectorScreen,sp.settingsPage,ar.addRepoScreen,hp.installerHelperPage,py.pynxPage,fw.cfwPage,ep.errorPage,lp.homePage,gp.gamesPage,cp.serialPage):
page_name = F.__name__
frame = F(parent=container, controller=self,back_command = lambda: self.show_frame("mainPage"))
frame = F(parent=container, controller=self,back_command = lambda: self.show_frame("homePage"))
self.frames[page_name] = frame

frame.grid(row=0, column=0, sticky="nsew")

self.show_frame("mainPage") #Show the main page frame
if platform.system() == 'Windows':
try:
print("Windows detected, setting icon")
self.iconbitmap(os.path.join(locations.assetfolder, 'HBUpdater.ico'))
except:
print("Failed to set icon")
elif platform.system() == "Linux":
try:
print("Linux detected, setting icon")
self.iconbitmap(os.path.join(locations.assetfolder, 'HBUpdater.xbm'))
except:
print("Failed to set icon")

self.bind("<<error>>", self.on_error)
self.show_frame("homePage") #Show the main page frame

def on_error(self,event):
global errorstate
self.frames["errorPage"].raiseError(errorstate)
self.show_frame("errorPage")

def seterrorstate(self,state):
global errorstate
errorstate = state

def show_frame(self, page_name):
#Show a frame for the given page name
frame = self.frames[page_name]
frame.event_generate("<<ShowFrame>>")
frame.tkraise()

def UseCachedJson():
hblist = webhandler.getJsonSoftwareLinks(locations.softwarelist)
repodict = webhandler.getJsonSoftwareLinks(guicore.makerepodict())
pylist = webhandler.getJsonSoftwareLinks(locations.nxpythonlist)
cfwlist = webhandler.getJsonSoftwareLinks(locations.customfirmwarelist)
hblist.extend(repodict)
guicore.setDict(hblist)
guicore.setIJlist(webhandler.getJsonSoftwareLinks(locations.payloadlist))
guicore.setNXPYList(pylist)
guicore.setCFWlist(cfwlist)
guicore.setPayloadInjector(webhandler.getJsonSoftwareLinks(locations.payloadinjector))

def GetUpdatedJson():
hblist = webhandler.getUpdatedSoftwareLinks(locations.softwarelist)
repodict = webhandler.getUpdatedSoftwareLinks(guicore.makerepodict())
pylist = webhandler.getUpdatedSoftwareLinks(locations.nxpythonlist)
cfwlist = webhandler.getUpdatedSoftwareLinks(locations.customfirmwarelist)
hblist.extend(repodict)
guicore.setDict(hblist)
guicore.setIJlist(webhandler.getUpdatedSoftwareLinks(locations.payloadlist))
guicore.setNXPYList(pylist)
guicore.setCFWlist(cfwlist)
guicore.setPayloadInjector(webhandler.getUpdatedSoftwareLinks(locations.payloadinjector))

def stripversion(string):
characterstostrip = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz()-"
for character in characterstostrip:
string = string.replace(character,"")
return string

def CheckForUpdates():
updatefile = webhandler.getJson("HBUpdater", locations.updateapi)
if updatefile == None:
print("Failed to download HBU update file. A new version may be avaialable.")
else:
with open(updatefile,encoding="utf-8") as json_file: #jsonfile is path, json_file is file obj
jfile = json.load(json_file)
newestversion = jfile[0]["tag_name"]
if float(stripversion(newestversion)) > float(stripversion(version)):
print("A new update to HBUpdater is avaialable, go to https://www.github.com/LyfeOnEdge/HBUpdater/releases to download it.")
else:
print("HBUpdater is up to date")

# def HandleUserAddedRepos():
if __name__ == '__main__':
if guicore.checkguisetting("guisettings","automatically_check_for_updates"):
GetUpdatedJson() #use this to download new json (required to get updates)
CheckForUpdates()
else:
UseCachedJson() #use this to use only pre-downloaded json files

#Add missing dict item for each homebrew
for softwarechunk in guicore.hblist:
softwarechunk["photopath"] = None
for softwarechunk in guicore.nxpylist:
softwarechunk["photopath"] = None
for softwarechunk in guicore.ijlist:
softwarechunk["photopath"] = None
for softwarechunk in guicore.cfwlist:
softwarechunk["photopath"] = None
print("Update checking diabled")

gui = FrameManager()
gui.title("HBUpdater {}".format(version))
gui.mainloop()
gui.mainloop()
Binary file added assets/beta.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/games.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/homebrew.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 3 additions & 2 deletions guisettings_default.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
{
"guisettings" : {
"automatically_check_for_updates" : 1
"automatically_check_for_updates" : 1,
"automatically_check_for_repo_updates" : 1
},
"fusee-launcher" : {
"version": "not installed",
"location": "none"
},
}
}
50 changes: 27 additions & 23 deletions modules/HBUpdater.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,37 +7,41 @@
if __name__ == '__main__':
sys.exit("This script was not meant to run without a frontend. Exiting...")

version = "0.8 (Beta)"
version = "0.9 (Beta)"
print("HBUpdater version {}".format(version))

#My modules
from modules.format import *
import modules.homebrewcore as homebrewcore
import modules.locations as locations
import modules.webhandler as webhandler

chosensdpath = None
sdpathset = False

#folders and files for tracking installed apps on the sd
trackingfolder = ""
trackingfile = ""



#update global "chosensdpath"
def setSDpath(sdpath):
global chosensdpath
global trackingfoldername
global trackingfolder
global trackingfilename
global trackingfile
global sdpathset
if not(str(sdpath) == ""):
chosensdpath = sdpath
print("SD path set to: {}".format(str(chosensdpath)))
sdpathset = True

trackingfolder = homebrewcore.joinpaths(chosensdpath, homebrewcore.trackingfolder)
if not homebrewcore.direxist(trackingfolder):
trackingfolder = os.path.join(chosensdpath, locations.trackingfolder)
if not os.path.isdir(trackingfolder):
os.mkdir(trackingfolder)
trackingfile = homebrewcore.joinpaths(trackingfolder, homebrewcore.trackingfile)
if not homebrewcore.exists(trackingfile):
trackingfile = os.path.join(trackingfolder, locations.trackingfile)
if not os.path.isfile(trackingfile):
with open(trackingfile, "w+") as jfile:
initdata = {}
initdata["created_with"] = version
Expand All @@ -59,7 +63,7 @@ def installitem(dicty, option, suboption, group):
print("\n")
softwarename = dicty[option]["software"]

location = getlogsetting(group, softwarename, "location")
location = getlogvalue(group, softwarename, "location")

with open(dicty[option]["githubjson"]) as json_file: #jsonfile is path, json_file is file obj
jfile = json.load(json_file)
Expand All @@ -76,11 +80,11 @@ def installitem(dicty, option, suboption, group):

if type(location) is list:
for loc in location:
if homebrewcore.exists(loc):
if os.path.isfile(loc):
os.remove(loc)
print("removed old file {}".format(loc))
elif type(location) is str:
if homebrewcore.exists(location):
if os.path.isfile(location):
os.remove(location)
print("removed {}".format(location))

Expand All @@ -97,16 +101,16 @@ def installitem(dicty, option, suboption, group):
def installfiletosd(filename,subfolder):
global chosensdpath

file = homebrewcore.joinpaths(homebrewcore.downloadsfolder, filename)
file = os.path.join(locations.downloadsfolder, filename)

if not subfolder == None:
subdir = homebrewcore.joinpaths(chosensdpath,subfolder)
subdir = os.path.join(chosensdpath,subfolder)
else:
subdir = chosensdpath

sdlocation = homebrewcore.joinpaths(subdir, filename)
sdlocation = os.path.join(subdir, filename)

if not homebrewcore.direxist(subdir):
if not os.path.isdir(subdir):
os.mkdir(subdir)

if filename.endswith(".nro") or filename.endswith(".py"):
Expand All @@ -126,7 +130,7 @@ def installfiletosd(filename,subfolder):
sdlocation = zipObj.namelist()
namelist = []
for location in sdlocation:
namelist.append(homebrewcore.joinpaths(subdir,location))
namelist.append(os.path.join(subdir,location))
print("files copied: \n {}".format(namelist))
print(subdir)
return namelist
Expand All @@ -139,12 +143,12 @@ def uninstallsoftware(group, softwarename):
if not sdpathset:
print("SD path not set, can't uninstall")
return
if checkversion(softwarename) == "not installed":
if getlogstatus(group,softwarename) == "not installed":
print("Not installed.")
return


filestoremove = getlogitem(group, softwarename,"location")
filestoremove = getlogvalue(group, softwarename,"location")
print("removing {}".format(filestoremove))
if 'str' in str(type(filestoremove)):
os.remove(filestoremove)
Expand All @@ -160,24 +164,24 @@ def uninstallsoftware(group, softwarename):
# print("removed folder {}".format(file))

newentry = {
softwarename : {
"version": "not installed",
"location": None,
}
"software": softwarename,
"version": "not installed",
"location": None,
}
updatelog(newentry)

updatelog(group, newentry)
print("uninstalled {}".format(softwarename))





def updatelog(group, newentry):
if not homebrewcore.direxist(trackingfolder):
if not os.path.isdir(trackingfolder):
os.mkdir(trackingfolder)

#create log is it doesn't exist
if homebrewcore.exists(trackingfile):
if os.path.isfile(trackingfile):
pass
# print("Found Tracking File")
else:
Expand Down
Loading

0 comments on commit 215769c

Please sign in to comment.