~cadence/crumpet

1f6165a8af0202bd86ac97b3cd1dbf3590e0cadd — Cadence Ember 10 months ago 8e4de0f
Try to autodetect installations on linux
1 files changed, 31 insertions(+), 1 deletions(-)

M crumpet.py
M crumpet.py => crumpet.py +31 -1
@@ 5,6 5,8 @@ import pathlib
import requests
import shelve
import shutil
import subprocess
import sys

content_host = "https://cadence.moe"



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

def autodetect_game_directory():
	return None # placeholder
	if sys.platform == "windows":
		return None # todo!
	else:
		search_locations = [os.path.expanduser(location) for location in [
			"~/.wine",
			"~/.PlayOnLinux",
			"~/.local/share/wineprefixes",
			"~/.lutris"
		]]
		# try ag first since it is faster
		try:
			s = subprocess.run(["ag", "-g", "/res2.dat$"] + search_locations, capture_output=True, cwd="/")
		except FileNotFoundError:
			s = subprocess.run(["find"] + search_locations + ["res2.dat"], capture_output=True, cwd="/")
		possible_matches = [os.path.dirname(line) for line in bytes.decode(s.stdout).splitlines() if line]
		# initial return decisions
		if len(possible_matches) == 0:
			return None
		if len(possible_matches) == 1:
			return possible_matches[0]
		# multiple matches: need to refine them
		# assume that the game is installed to a path with "Return To Wonderland"
		possible_matches = [line for line in possible_matches if "Return To Wonderland" in line]
		if len(possible_matches) == 1:
			return possible_matches[0]
		# no more strategies for refining
		return None

class Crumpet:
	def _cp_dispatch(self, vpath):


@@ 78,6 106,8 @@ class Crumpet:
			problem = check_game_path(game_path)
			if problem:
				game_directory = autodetect_game_directory()
		else:
			game_directory = autodetect_game_directory()
		# do not need to check customlevels directory since the interface should replace whatever is sent.
		customlevels_directory = db["customlevels_directory"]
		return {