~cadence/crumpet

f44e5d45d002f456e427a4575c41d3469c3d561b — Cadence Ember 10 months ago 1f6165a
Try to autodetect installations on Windows
1 files changed, 31 insertions(+), 1 deletions(-)

M crumpet.py
M crumpet.py => crumpet.py +31 -1
@@ 2,6 2,7 @@ import cherrypy
import hashlib
import os
import pathlib
import re
import requests
import shelve
import shutil


@@ 60,7 61,32 @@ def restricted_message():
	return "This action is restricted. You can enable this action by installing Crumpet on your own computer."

def autodetect_game_directory():
	if sys.platform == "windows":
	if sys.platform == "win32":
		# only bother to support x64.
		# if x86 were supported, its prefix would be HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall
		candidates = [c for c in subprocess.run(["REG", "QUERY", "HKEY_LOCAL_MACHINE\\SOFTWARE\\WOW6432Node\\Microsoft\\Windows\\CurrentVersion\\Uninstall"], capture_output=True).stdout.splitlines() if b"Midnight Synergy" in c or b"Return To Wonderland" in c]
		# candidates = [b'HKEY_LOCAL_MACHINE\\SOFTWARE\\WOW6432Node\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\Midnight Synergy Games Collection_is1', b'HKEY_LOCAL_MACHINE\\SOFTWARE\\WOW6432Node\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\Return To Wonderland v1.01_is1', b'HKEY_LOCAL_MACHINE\\SOFTWARE\\WOW6432Node\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\Return To Wonderland_is1']
		candidates.sort()
		preferred = [c for c in candidates if c.endswith(b"\\Return To Wonderland_is1")]
		for c in preferred + candidates:
			info_lines = [re.sub(" +", " ", bytes.decode(line)).split(" ", 3)[1:] for line in subprocess.run(["REG", "QUERY", c], capture_output=True).stdout.splitlines()]
			info_lines = [line for line in info_lines if len(line) == 3]
			info = {line[0]: line[2] for line in info_lines}
			if "InstallLocation" in info:
				try:
					# keep trying to go into "Return To Wonderland" until you can't anymore
					# this ensures we get into the real game directory no matter whether it is from the standalone or the original collection
					install_location = pathlib.WindowsPath(info["InstallLocation"])
					exists = None
					while install_location.exists() and install_location.is_dir():
						exists = install_location
						install_location = install_location.joinpath("Return To Wonderland")
					if exists:
						# this is the final directory to use!
						return str(exists)
				except Exception as e:
					# print the error and move on to the next candidate
					print(e)
		return None # todo!
	else:
		search_locations = [os.path.expanduser(location) for location in [


@@ 132,6 158,8 @@ class Crumpet:
				"message": "Requires `value` string parameter in JSON."
			}
		game_directory = root["value"]
		if game_directory.startswith("file:///"):
			game_directory = game_directory.replace("file:///", "/", 1)
		# Check that the game is there
		game_path = pathlib.Path(game_directory)
		if not game_path.exists() or not game_path.is_dir():


@@ 167,6 195,8 @@ class Crumpet:
				"message": "Requires `value` string parameter in JSON."
			}
		customlevels_directory = root["value"]
		if customlevels_directory.startswith("file:///"):
			customlevels_directory = customlevels_directory.replace("file:///", "/", 1)
		# Check that the directory is there
		customlevels_path = pathlib.Path(customlevels_directory)
		if not customlevels_path.exists() or not customlevels_path.is_dir():