Skip to content

Commit

Permalink
Merge pull request #65 from R1kaB3rN/update
Browse files Browse the repository at this point in the history
Change update routine
  • Loading branch information
R1kaB3rN authored Mar 17, 2024
2 parents bfc6d65 + 4e787cb commit 9515ce4
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 43 deletions.
19 changes: 17 additions & 2 deletions ULWGL/ulwgl_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,13 @@ def test_update_ulwgl_empty(self):
Path(self.test_user_share, "ULWGL"),
Path(self.test_local_share, "ULWGL"),
)
# When the runtime updates, pressure vessel needs to be updated
copytree(
Path(self.test_user_share, "pressure-vessel"),
Path(self.test_local_share, "pressure-vessel"),
dirs_exist_ok=True,
symlinks=True,
)

self.assertFalse(result, "Expected None when calling _update_ulwgl")

Expand Down Expand Up @@ -378,15 +385,16 @@ def test_update_ulwgl(self):
"ulwgl-run",
]
# Mock an outdated ULWGL_VERSION.json in ~/.local/share/ULWGL
# Downgrade these files: launcher, runner, runtime_platform, pressure_vessel
# Downgrade these files: launcher, runner, runtime_platform
# We don't downgrade Pressure Vessel because it's a runtime property
config = {
"ulwgl": {
"versions": {
"launcher": "0.1-RC2",
"runner": "0.1-RC2",
"runtime_platform": "sniper_platform_0.20240125.75304",
"reaper": "1.0",
"pressure_vessel": "v0.20240211.0",
"pressure_vessel": "v0.20240212.0",
}
}
}
Expand Down Expand Up @@ -492,6 +500,13 @@ def test_update_ulwgl(self):
Path(self.test_user_share, "ULWGL"),
Path(self.test_local_share, "ULWGL"),
)
# When the runtime updates, pressure vessel needs to be updated
copytree(
Path(self.test_user_share, "pressure-vessel"),
Path(self.test_local_share, "pressure-vessel"),
dirs_exist_ok=True,
symlinks=True,
)

self.assertFalse(result, "Expected None when calling _update_ulwgl")

Expand Down
92 changes: 51 additions & 41 deletions ULWGL/ulwgl_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from http.client import HTTPException
from socket import AF_INET, SOCK_DGRAM, socket
from tempfile import mkdtemp
from threading import Thread

try:
from tarfile import tar_filter
Expand Down Expand Up @@ -209,6 +210,7 @@ def _install_ulwgl(
SteamRT, Pressure Vessel, ULWGL-Launcher, ULWGL Launcher files, Reaper
and ULWGL_VERSION.json
"""
thread: Thread = None
log.debug("New install detected")
log.console("Setting up Unified Launcher for Windows Games on Linux ...")

Expand All @@ -223,7 +225,8 @@ def _install_ulwgl(
copy(root.joinpath("reaper"), local.joinpath("reaper"))

# Runtime platform
setup_runtime(root, json)
thread = Thread(target=setup_runtime, args=(root, json))
thread.start()

# Launcher files
for file in root.glob("*.py"):
Expand Down Expand Up @@ -253,6 +256,7 @@ def _install_ulwgl(
"../../../ULWGL/ulwgl_run.py"
)

thread.join(timeout=180)
log.console("Completed.")


Expand All @@ -274,6 +278,7 @@ def _update_ulwgl(
In the case that existing writable directories we copy to are in a partial
state, a best effort is made to restore the missing files
"""
thread: Thread = None
log.debug("Existing install detected")

# Attempt to copy only the updated versions
Expand All @@ -287,9 +292,8 @@ def _update_ulwgl(
# Directory is absent
if not local.joinpath("reaper").is_file():
log.warning("Reaper not found")
log.console(f"Copying {key} -> {local} ...")

copy(root.joinpath("reaper"), local.joinpath("reaper"))
log.console(f"Restored {key} to {val} ...")

# Update
if val != reaper:
Expand All @@ -299,57 +303,44 @@ def _update_ulwgl(
copy(root.joinpath("reaper"), local.joinpath("reaper"))

json_local["ulwgl"]["versions"]["reaper"] = val
elif key == "pressure_vessel":
# Pressure Vessel
pv: str = json_local["ulwgl"]["versions"]["pressure_vessel"]

# Directory is absent
if not local.joinpath("pressure-vessel").is_dir():
log.warning("Pressure Vessel not found")
log.console(f"Copying {key} -> {val} ...")

copytree(
root.joinpath("pressure-vessel"),
local.joinpath("pressure-vessel"),
dirs_exist_ok=True,
symlinks=True,
)
elif local.joinpath("pressure-vessel").is_dir() and val != pv:
# Update
log.console(f"Updating {key} to {val}")

rmtree(local.joinpath("pressure-vessel").as_posix())
copytree(
root.joinpath("pressure-vessel"),
local.joinpath("pressure-vessel"),
dirs_exist_ok=True,
symlinks=True,
)

json_local["ulwgl"]["versions"]["pressure_vessel"] = val
elif key == "runtime_platform":
# Old runtime
runtime: str = json_local["ulwgl"]["versions"]["runtime_platform"]

# Directory is absent
if not (local.joinpath(runtime).is_dir() or local.joinpath(val).is_dir()):
# Redownload the runtime if absent or pressure vessel is absent
if (
not local.joinpath(runtime).is_dir()
or not local.joinpath("pressure-vessel").is_dir()
):
# Redownload
log.warning("Runtime Platform not found")

# Download the runtime from the official source
setup_runtime(root, json_root)
elif local.joinpath(runtime).is_dir() and val != runtime:
if local.joinpath("pressure-vessel").is_dir():
rmtree(local.joinpath("pressure-vessel").as_posix())
if local.joinpath(runtime).is_dir():
rmtree(local.joinpath(runtime).as_posix())

thread = Thread(target=setup_runtime, args=(root, json_root))
thread.start()
log.console(f"Restoring Runtime Platform to {val} ...")
elif (
local.joinpath(runtime).is_dir()
and local.joinpath("pressure-vessel").is_dir()
and val != runtime
):
# Update
log.console(f"Updating {key} to {val}")

rmtree(local.joinpath("pressure-vessel").as_posix())
rmtree(local.joinpath(runtime).as_posix())
setup_runtime(root, json_root)
thread = Thread(target=setup_runtime, args=(root, json_root))
thread.start()

json_local["ulwgl"]["versions"]["runtime_platform"] = val
elif key == "launcher":
# Launcher
# NOTE: We do not attempt to restore missing launcher files
is_missing: bool = False
launcher: str = json_local["ulwgl"]["versions"]["launcher"]

# Update
if val != launcher:
log.console(f"Updating {key} to {val}")

Expand All @@ -364,14 +355,29 @@ def _update_ulwgl(
local.joinpath("ulwgl-run").symlink_to("ulwgl_run.py")

json_local["ulwgl"]["versions"]["launcher"] = val
continue

# Check for missing files
for file in root.glob("*.py"):
if (
not file.name.startswith("ulwgl_test")
and not local.joinpath(file.name).is_file()
):
is_missing = True
log.warning("Missing %s", file.name)
copy(file, local.joinpath(file.name))

if is_missing:
log.console(f"Restored {key} to {val}")
local.joinpath("ulwgl-run").unlink(missing_ok=True)
local.joinpath("ulwgl-run").symlink_to("ulwgl_run.py")
elif key == "runner":
# Runner
runner: str = json_local["ulwgl"]["versions"]["runner"]

# Directory is absent
if not steam_compat.joinpath("ULWGL-Launcher").is_dir():
log.warning("ULWGL-Launcher not found")
log.console(f"Copying ULWGL-Launcher -> {steam_compat} ...")

copytree(
root.joinpath("ULWGL-Launcher"),
Expand All @@ -383,6 +389,7 @@ def _update_ulwgl(
steam_compat.joinpath("ULWGL-Launcher", "ulwgl-run").symlink_to(
"../../../ULWGL/ulwgl_run.py"
)
log.console(f"Restored ULWGL-Launcher to {val}")
elif steam_compat.joinpath("ULWGL-Launcher").is_dir() and val != runner:
# Update
log.console(f"Updating {key} to {val}")
Expand All @@ -401,6 +408,9 @@ def _update_ulwgl(

json_local["ulwgl"]["versions"]["runner"] = val

if thread:
thread.join(timeout=180)

# Finally, update the local config file
with local.joinpath(CONFIG).open(mode="w") as file:
dump(json_local, file, indent=4)
Expand Down

0 comments on commit 9515ce4

Please sign in to comment.