Skip to content

Commit

Permalink
Release 5.14 now compatible with Millennium, auto-check Steam updates
Browse files Browse the repository at this point in the history
  • Loading branch information
Jonius7 committed Jun 2, 2024
1 parent 7893271 commit 7818427
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 24 deletions.
44 changes: 36 additions & 8 deletions backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
from datetime import datetime, timezone
import requests
from requests_oauthlib import OAuth1Session
from hashlib import sha1
import time
import hashlib
from pathlib import Path

##########################################
### CONSTANTS
Expand Down Expand Up @@ -294,22 +294,22 @@ def help():
#for item in l:


def get_file_hash(filepath):
def get_git_file_hash(filepath, encoding="UTF-8"):
'''
UTILITY: Returns the git SHA hash of a file.
'''
try:
#exclude .png for filehash
if os.path.isfile(filepath) and os.path.splitext(filepath)[1] != ".png":
with open(filepath, 'r', encoding="UTF-8") as f, \
open(filepath + ".temp", 'w', encoding="UTF-8", newline='\n') as f1:
with open(filepath, 'r', encoding=encoding) as f, \
open(filepath + ".temp", 'w', encoding=encoding, newline='\n') as f1:
f1.writelines(f.readlines())
f.close()
f1.close()

filesize_bytes = os.path.getsize(filepath + ".temp")

s = sha1()
s = hashlib.sha1()
s.update(b"blob %u\0" % filesize_bytes)

with open(filepath + ".temp", 'rb') as g:
Expand All @@ -324,6 +324,30 @@ def get_file_hash(filepath):
print("Unable to get hash of file: " + filepath, file=sys.stderr)
print_traceback()

def get_md5_file_hash(filepath):
'''
UTILITY: Returns the MD5 hash of a file.
'''
try:
#exclude .png for filehash
if os.path.isfile(filepath):
with open(filepath, "rb") as f:
file_hash = hashlib.md5()
while chunk := f.read(8192):
file_hash.update(chunk)
return file_hash.hexdigest()
except:
print("Unable to get hash of file: " + filepath, file=sys.stderr)
print_traceback()

def get_path_with_wildcard(filepath = r"C:\Program Files (x86)\0E Games\Steam\package",
search_term = "steamui_websrc_all.zip.vz.*"):
'''
UTILITY: Returns the filepath (filename) of file using a search wildcard
defaults to Steam\package steamui_websrc_all.zip.vz.* file
'''
return next(Path(filepath).glob(search_term))

### Check CSS Patched
def is_css_patched(filename="2.css"):
'''
Expand Down Expand Up @@ -1306,6 +1330,10 @@ def update_json_last_patched_date(json_data):
json_data["lastPatchedDate"] = get_remote_datetime()
#print(json_data)
write_json_data(json_data)

def update_steamui_websrc_hash(json_data):
json_data["steamui_websrc_all.zip.vz_hash"] = get_md5_file_hash(get_path_with_wildcard())
write_json_data(json_data)

### file management functions as part of auto-update
### file_dates - dictionary of filenames with their dates
Expand Down Expand Up @@ -1336,7 +1364,7 @@ def hash_compare_small_update_files(file_dates, json_data):
#print(local_filepath)
if os.path.exists(local_filepath) and os.path.isfile(local_filepath):
#if local hash != remote hash
if (get_file_hash(local_filepath) != filedata["sha"] and
if (get_git_file_hash(local_filepath) != filedata["sha"] and
local_filepath != "scss/libraryroot.custom.scss" and
local_filepath != "scss/_custom_module1.scss" and
local_filepath != "scss/_custom_module2.scss"):
Expand All @@ -1353,7 +1381,7 @@ def hash_compare_small_update_files(file_dates, json_data):
dir_filepath = local_filepath + "/" + dir_filedata["name"]
if (os.path.exists(dir_filepath) and
os.path.isfile(dir_filepath)):
if (get_file_hash(dir_filepath) != filedata["sha"] and
if (get_git_file_hash(dir_filepath) != filedata["sha"] and
os.path.splitext(dir_filepath)[1] != ".png"):
print("New Version | " + dir_filepath)
updatetype_files.append(dir_filepath)
Expand Down
4 changes: 3 additions & 1 deletion docs/Changelog - old_glory GUI.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
## SteamUI-OldGlory GUI Changelog

1.1.2
1.1.3 Now auto-checks if there is a new Steam Update and notifies accordingly

1.1.2 *(5.14-pre1)* New Install Location dropdown (now compatible with Millennium)

**1.1.1.1** **(Release 5.13)**

Expand Down
9 changes: 0 additions & 9 deletions get_md5_hash.py

This file was deleted.

1 change: 1 addition & 0 deletions manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ def install_click(event, page, controller):
### To be changed in a later version
backend.write_js_fixes(controller.js_config, controller.special_js_config)
backend.write_css_configurables(controller.css_config)
backend.update_steamui_websrc_hash(controller.json_data)

#applying settings
change_javascript = check_if_css_requires_javascript(page, controller, settings)
Expand Down
19 changes: 14 additions & 5 deletions old_glory.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@

class OldGloryApp(tk.Tk):
def __init__(self, *args, **kwargs):
self.version = "1.1.2"
self.release = "5.14-pre1"
self.version = "1.1.3"
self.release = "5.14"

### Window Frame
tk.Tk.__init__(self, *args, **kwargs)
Expand Down Expand Up @@ -71,8 +71,10 @@ def __init__(self, *args, **kwargs):
self.show_frame("StartPage")

### Run Update Checks with show frame
thread = Thread(target = self.update_check, args = ())
thread.start()
thread1 = Thread(target = self.steam_update_check, args = ())
thread1.start()
thread2 = Thread(target = self.update_check, args = ())
thread2.start()

def set_window_dimensions(self, width, height):
self.windowW = width
Expand Down Expand Up @@ -130,6 +132,12 @@ def get_frame(self, name):
return frame
'''

def steam_update_check(self):
pass
self.current_file_hash = backend.get_md5_file_hash(backend.get_path_with_wildcard())
if self.current_file_hash != self.json_data["steamui_websrc_all.zip.vz_hash"]:
print("New Steam Update detected. If the Steam window does not appear, try using the Remake JS button in Settings.", file=sys.stderr)

#init text log
def update_check(self):
### Check if CSS Patched
Expand Down Expand Up @@ -1544,7 +1552,8 @@ def reset_all_tweaks(event, controller):
backend.clear_js_working_files()

def remake_js(event, controller):
backend.clear_js_working_files()
controller.json_data["steamui_websrc_all.zip.vz_hash"] = controller.current_file_hash
backend.clear_js_working_files()
thread = Thread(target = run_js_tweaker, args = (controller, 1,))
thread.start()
#thread.join()
Expand Down
1 change: 1 addition & 0 deletions old_glory_data.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"jsModifFile": "sp.modif.js",
"jsPatchedFile": "sq.js",
"jsOriginalFile": "sp.js.original",
"steamui_websrc_all.zip.vz_hash": "543ddfbd73d1bb57720f1545974908c7",
"lastPatchedDate": "2024-05-30T14:41:52Z",
"themes": {
"steam-library": {
Expand Down
2 changes: 1 addition & 1 deletion tests/tests_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def test_filename_too_long_for_html(self):

def test_get_function_performance(self):
start_time = time.time()
print(backend.get_file_hash("../scss/_sidebar.scss"))
print(backend.get_git_file_hash("../scss/_sidebar.scss"))
print("--- %s seconds ---" % (time.time() - start_time))


Expand Down

0 comments on commit 7818427

Please sign in to comment.