Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
83cff10
Update all paths to use pathlib Path objects
amarzot Jan 10, 2024
08cc70e
Update autoupdater.py too
amarzot Jan 14, 2024
2012947
Adjusted one additional path to be pathlib, in prep for Linux compati…
StevenLares Feb 20, 2024
1f72e36
Added a function to launcherUtils that returns the correct executable…
StevenLares Feb 20, 2024
a002281
Changed download links to point to the latest release, instead of an …
StevenLares Feb 20, 2024
a1b7675
Updated utils functions to include linux / unix commands. Also, I cha…
StevenLares Feb 21, 2024
025befd
Removed lines that created a mod directory on the filesystem that was…
StevenLares Feb 21, 2024
75ff8ef
Fixed bug where the use of pathlib Path caused a crash with 'launcher…
StevenLares Feb 22, 2024
ca63a7d
Changed some os path functions to pathlib builtin functions. Also, mo…
StevenLares Feb 24, 2024
c44b200
Renamed AppdataPATH to LauncherInstallPath
StevenLares Feb 24, 2024
781524c
Moved redundant code regarding checking for opengoal mod launcher upd…
StevenLares Feb 24, 2024
2ffcc36
Moved pysimplegui layout code to its own utility class, layoutUtils.
StevenLares Feb 22, 2024
93c1871
Merge branch 'layout_utils' into linux_compat
StevenLares Feb 27, 2024
39f7353
Increased Y size of column containing buttons and mod info. This is a…
StevenLares Feb 29, 2024
f393896
Since Linux does not have a COMPUTERNAME variable in its environment,…
StevenLares Feb 29, 2024
8b2c3a8
Created bash scripts that build the launcher executables for Linux
StevenLares Feb 29, 2024
9948fa9
Removed TODO's I added earlier in earlier commits, that do not need t…
StevenLares Feb 29, 2024
bab64d0
Corrected order of Linux symlinks
StevenLares Mar 4, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
107 changes: 62 additions & 45 deletions Launcher with autoupdater.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,19 @@
from datetime import datetime
from os.path import exists
from pathlib import Path
from appdirs import AppDirs
import subprocess
AppdataPATH = os.getenv('APPDATA') + "\\OpenGOAL-UnofficialModLauncher\\"
from utils import launcherUtils

dirs = AppDirs(roaming=True)
LauncherInstallPATH = Path(dirs.user_data_dir) / "OpenGOAL-UnofficialModLauncher"

OpengoalModLauncher_exe = launcherUtils.get_exe("OpengoalModLauncher")
gk_exe = launcherUtils.get_exe("gk")
decompiler_exe = launcherUtils.get_exe("decompiler")
goalc_exe = launcherUtils.get_exe("goalc")
extractor_exe = launcherUtils.get_exe("extractor")


def show_progress(block_num, block_size, total_size):
if total_size > 0:
Expand All @@ -18,17 +29,25 @@ def show_progress(block_num, block_size, total_size):
except Exception as e:
pass # Handle the exception if the window or element does not exist


def try_remove_file(file):
if exists(file):
os.remove(file)


def try_remove_dir(dir):
if exists(dir):
shutil.rmtree(dir)

def check_for_updates():


# TODO:
# The logic will need to be adjusted to use different criteria to return the latest executable
# with regards to the user's platform.
# Currently, it determines the executable using only the latest release at the launch_url
# (assuming no network error, otherwise it goes into the else statement)
# However, at the moment this leads to only the Windows exe being chosen and latest_release_assets_url gets
# assigned accordingly
def get_latest_release_info():
launch_url = "https://api.github.com/repos/OpenGOAL-Unofficial-Mods/OpenGoal-ModLauncher-dev/releases"
response = requests.get(url=launch_url, params={'address': "yolo"})

Expand All @@ -42,18 +61,31 @@ def check_for_updates():
else:
print("WARNING: Failed to query GitHub API, you might be rate-limited. Using default fallback release instead.")
latest_release = datetime(2023, 7, 23)
latest_release_assets_url = "https://github.com/OpenGOAL-Unofficial-Mods/OpenGoal-ModLauncher-dev/releases/download/v1.10fixoldpckernel/openGOALModLauncher.exe"
latest_release_assets_url = "https://github.com/OpenGOAL-Unofficial-Mods/OpenGoal-ModLauncher-dev/releases/download/latest/" + OpengoalModLauncher_exe

return latest_release_assets_url, latest_release


def get_latest_write_date():
last_write = datetime(2020, 5, 17)
if os.path.exists(AppdataPATH + "\\OpengoalModLauncher.exe"):
last_write = datetime.utcfromtimestamp(Path(AppdataPATH + "\\OpengoalModLauncher.exe").stat().st_mtime)
if (LauncherInstallPATH / OpengoalModLauncher_exe).exists():
last_write = datetime.utcfromtimestamp((LauncherInstallPATH / OpengoalModLauncher_exe).stat().st_mtime)
return last_write

need_update = bool((last_write < latest_release))

window['installed_version'].update(f"Currently installed version created on: {last_write.strftime('%Y-%m-%d %H:%M:%S')}")
def need_update(last_write, latest_release):
return bool((last_write < latest_release))


def check_for_updates():
latest_release_assets_url, latest_release = get_latest_release_info()
last_write = get_latest_write_date()

window['installed_version'].update(
f"Currently installed version created on: {last_write.strftime('%Y-%m-%d %H:%M:%S')}")
window['newest_version'].update(f"Newest version created on: {latest_release.strftime('%Y-%m-%d %H:%M:%S')}")

if need_update:
if need_update(last_write, latest_release):
window['update_status'].update("An update is available. Click 'Update' to install.")
window['update_button'].update(visible=True)
window['launch_button'].update(visible=False)
Expand All @@ -62,66 +94,51 @@ def check_for_updates():
window['update_button'].update(visible=False)
window['launch_button'].update(visible=True)

def download_newest_mod():
AppdataPATH = os.getenv('APPDATA') + "\\OpenGOAL-UnofficialModLauncher\\"

launch_url = "https://api.github.com/repos/OpenGOAL-Unofficial-Mods/OpenGoal-ModLauncher-dev/releases"
response = requests.get(url=launch_url, params={'address': "yolo"})

if response is not None and response.status_code == 200:
r = json.loads(json.dumps(response.json()))
latest_release = datetime.strptime(r[0].get("published_at").replace("T", " ").replace("Z", ""),
'%Y-%m-%d %H:%M:%S')
latest_release_assets_url = (json.loads(
json.dumps(requests.get(url=r[0].get("assets_url"), params={'address': "yolo"}).json())))[0].get(
"browser_download_url")
else:
print("WARNING: Failed to query GitHub API, you might be rate-limited. Using default fallback release instead.")
latest_release = datetime(2023, 7, 23)
latest_release_assets_url = "https://github.com/OpenGOAL-Unofficial-Mods/OpenGoal-ModLauncher-dev/releases/download/v1.10fixoldpckernel/openGOALModLauncher.exe"

last_write = datetime(2020, 5, 17)
if os.path.exists(AppdataPATH + "\\OpengoalModLauncher.exe"):
last_write = datetime.utcfromtimestamp(Path(AppdataPATH + "\\OpengoalModLauncher.exe").stat().st_mtime)
def download_newest_mod():
latest_release_assets_url, latest_release = get_latest_release_info()
last_write = get_latest_write_date()

need_update = bool((last_write < latest_release))
if need_update(last_write, latest_release):
temp_dir = LauncherInstallPATH / "temp"

if need_update:
window['update_status'].update("Starting Update...")
try_remove_dir(AppdataPATH + "/temp")
if not os.path.exists(AppdataPATH + "/temp"):
os.makedirs(AppdataPATH + "/temp")
try_remove_dir(temp_dir)
if not temp_dir.exists():
temp_dir.mkdir()

window['update_status'].update("Downloading update from " + latest_release_assets_url)
file = urllib.request.urlopen(latest_release_assets_url)
urllib.request.urlretrieve(latest_release_assets_url, AppdataPATH + "/temp/OpengoalModLauncher.exe", show_progress)
urllib.request.urlretrieve(latest_release_assets_url, temp_dir / OpengoalModLauncher_exe, show_progress)
window['update_status'].update("Done downloading")

window['update_status'].update("Removing previous installation " + AppdataPATH)
try_remove_dir(AppdataPATH + "/data")
try_remove_file(AppdataPATH + "/gk.exe")
try_remove_file(AppdataPATH + "/goalc.exe")
try_remove_file(AppdataPATH + "/extractor.exe")
window['update_status'].update(f"Removing previous installation {LauncherInstallPATH}")
try_remove_dir(LauncherInstallPATH / "data")
try_remove_file(LauncherInstallPATH / gk_exe)
try_remove_file(LauncherInstallPATH / goalc_exe)
try_remove_file(LauncherInstallPATH / extractor_exe)

window['update_status'].update("Extracting update")
temp_dir = AppdataPATH + "/temp"
try_remove_file(temp_dir + "/updateDATA.zip")

try_remove_file(temp_dir / "updateDATA.zip")
sub_dir = temp_dir
all_files = os.listdir(sub_dir)
for f in all_files:
shutil.move(sub_dir + "/" + f, AppdataPATH + "/" + f)
shutil.move(sub_dir / f, LauncherInstallPATH / f)
try_remove_dir(temp_dir)
window['update_status'].update("Update complete")
window['update_button'].update(visible=False)
window['launch_button'].update(visible=True)


layout = [
[sg.Text("OpenGOAL Mod Updater", font=("Helvetica", 16))],
[sg.Text("Installed Version:", size=(20, 1)), sg.Text("", size=(20, 1), key='installed_version')],
[sg.Text("Newest Version:", size=(20, 1)), sg.Text("", size=(20, 1), key='newest_version')],
[sg.ProgressBar(100, orientation='h', size=(20, 20), key='progress_bar')],
[sg.Text("", size=(40, 1), key='update_status')],
[sg.Button("Check for Updates"), sg.Button("Update", visible=False, key='update_button'), sg.Button("Launch", visible=False, key='launch_button'), sg.Button("Exit")]
[sg.Button("Check for Updates"), sg.Button("Update", visible=False, key='update_button'),
sg.Button("Launch", visible=False, key='launch_button'), sg.Button("Exit")]
]

window = sg.Window("OpenGOAL Mod Updater", layout, finalize=True)
Expand All @@ -136,6 +153,6 @@ def download_newest_mod():
download_newest_mod()
elif event == "launch_button":
window.close()
subprocess.call([ AppdataPATH + "openGOALModLauncher.exe"])
subprocess.call([str(LauncherInstallPATH / OpengoalModLauncher_exe)])

window.close()
17 changes: 17 additions & 0 deletions buildlaunchercoreEXE
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/bin/bash

# These three lines set the working path to this script's path.
# It is equivalent to %~dp0 used in Windows batch files
# https://stackoverflow.com/questions/207959/equivalent-of-dp0-retrieving-source-file-name-in-sh
cd `dirname $0`
mypath=`pwd`
cd "$mypath"


pyinstaller --onefile openGOALModLauncher.py --icon resources/appicon.ico

mv "${mypath}/dist/openGOALModLauncher" "${mypath}"

rm -rf "${mypath}/dist"
rm -rf "${mypath}/build"
rm "${mypath}/openGOALModLauncher.spec"
16 changes: 16 additions & 0 deletions buildlauncherupdaterexe
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/bin/bash

# These three lines set the working path to this script's path.
# It is equivalent to %~dp0 used in Windows batch files
# https://stackoverflow.com/questions/207959/equivalent-of-dp0-retrieving-source-file-name-in-sh
cd `dirname $0`
mypath=`pwd`
cd "$mypath"

# --hide-console is Windows only
pyinstaller --onefile "Launcher with autoupdater.py" --icon resources/appicon.ico

mv "${mypath}/dist/Launcher with autoupdater" "${mypath}"

rm -rf "${mypath}/dist"
rm -rf "${mypath}/build"
Loading