diff options
| author | william341 <[email protected]> | 2017-06-18 16:43:30 -0700 |
|---|---|---|
| committer | GitHub <[email protected]> | 2017-06-18 16:43:30 -0700 |
| commit | ba80dcf3f80018cbb041b62ad8a40268427d1311 (patch) | |
| tree | f0bd18b2355d34c07c744c3cd82a4725a799eecd /LinuxLauncher/shiftos.py | |
| parent | 771c20cfb3a703e0f1550fdcf9eb07b78298c944 (diff) | |
| parent | 12acff8742f4c64976bfabee1b70dc515190fc7c (diff) | |
| download | shiftos_thereturn-ba80dcf3f80018cbb041b62ad8a40268427d1311.tar.gz shiftos_thereturn-ba80dcf3f80018cbb041b62ad8a40268427d1311.tar.bz2 shiftos_thereturn-ba80dcf3f80018cbb041b62ad8a40268427d1311.zip | |
Merge pull request #2 from shiftos-game/master
wew
Diffstat (limited to 'LinuxLauncher/shiftos.py')
| -rw-r--r-- | LinuxLauncher/shiftos.py | 94 |
1 files changed, 94 insertions, 0 deletions
diff --git a/LinuxLauncher/shiftos.py b/LinuxLauncher/shiftos.py new file mode 100644 index 0000000..7fa5a6d --- /dev/null +++ b/LinuxLauncher/shiftos.py @@ -0,0 +1,94 @@ +#!/usr/bin/env python +import os, xdg.BaseDirectory, sys, subprocess, tempfile, distutils.spawn + +def GetPrimaryDisplayCurrentResolution(): + xrandr = subprocess.check_output(["xrandr"]) + if not isinstance(xrandr, str): + xrandr = xrandr.decode() + elems = xrandr.splitlines() + item = "" + res = None + while not item.startswith(" "): + item = elems.pop() + while item.startswith(" "): + if "*" in item: + res = item.split(" ")[1] + break + item = elems.pop() + if not res: + raise OSError("Failed to find the screen resolution.") + return res + +def RunCmd(cmd): + if os.system(cmd) != 0: + raise OSError(cmd) + +def SetRegistryKeys(dictionary): + with tempfile.NamedTemporaryFile(suffix = ".reg") as reg: + regdata = "Windows Registry Editor Version 5.00\r\n" + for key, val in dictionary.items(): + seg = key.split("\\") + path = "\\".join(seg[:-1]) + realkey = seg[-1] + regdata += '\r\n[{0}]\r\n"{1}"="{2}"\r\n'.format(path, realkey, val) + reg.write(regdata.encode()) + reg.flush() + RunCmd("{0} regedit /C {1}".format(WinePath, reg.name)) + +def UpdateSymlinks(src, dest): + src = os.path.abspath(src) + dest = os.path.abspath(dest) + + # Add new directories and symlinks to the destination folder. + for subdir, dirs, files in os.walk(src): + for dirname in dirs: + destpath = os.path.join(dest, os.path.relpath(subdir, src), dirname) + if not os.path.isdir(destpath): + os.makedirs(destpath) + for fname in files: + srcpath = os.path.join(subdir, fname) + destpath = os.path.join(dest, os.path.relpath(subdir, src), fname) + if not os.path.exists(destpath): + os.symlink(srcpath, destpath) + + # Prune old symlinks from the destination folder. + for subdir, dirs, files in os.walk(dest): + for fname in files: + srcpath = os.path.join(subdir, fname) + destpath = os.path.join(dest, os.path.relpath(subdir, src), fname) + if os.path.islink(destpath): + if os.readlink(destpath).startswith(src): + if not os.path.exists(srcpath): + os.remove(destpath) + +GamePath = os.path.dirname(os.path.realpath(__file__)) + +GlobalDataPath = os.path.join(GamePath, "data") + +WinePath = distutils.spawn.find_executable("wine64") +if not WinePath: + WinePath = distutils.spawn.find_executable("wine") +if not WinePath: + raise FileNotFoundError("Could not find 'wine64' or 'wine'.") + +HomePath = os.path.join(xdg.BaseDirectory.xdg_data_home, "ShiftOS") +LocalDataPath = os.path.join(HomePath, "drive_c", "ShiftOS") + +if __name__ == "__main__": + + os.environ["WINEPREFIX"] = HomePath + + if not os.path.exists(HomePath): + RunCmd("wineboot") + + UpdateSymlinks(GlobalDataPath, LocalDataPath) + + os.chdir(LocalDataPath) + + SetRegistryKeys( + { + r"HKEY_CURRENT_USER\Software\Wine\Explorer\Desktop": "Default", + r"HKEY_CURRENT_USER\Software\Wine\Explorer\Desktops\Default": GetPrimaryDisplayCurrentResolution() + }) + + RunCmd("{0} ShiftOS.WinForms.exe".format(WinePath)) |
