Compare commits
2
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0438887e91 | ||
|
|
2def4735fc |
No files matched your search
@@ -158,7 +158,17 @@ def ask(channel, request, timeout=TIMEOUT, claim=False):
|
||||
|
||||
def windows_path(unix):
|
||||
tool = bionic_tool(os.environ.get("DD_STORE_PROTON", ""))
|
||||
return (tool and bionic_path(tool, unix)) or "Z:" + unix.replace("/", "\\")
|
||||
if tool:
|
||||
return bionic_path(tool, unix) or "Z:" + unix.replace("/", "\\")
|
||||
return "Z:" + guest_path(unix).replace("/", "\\")
|
||||
|
||||
|
||||
def guest_path(unix):
|
||||
root = os.environ.get("DDNATV_ROOT", "").rstrip("/")
|
||||
for host in dict.fromkeys(filter(None, (root, root and os.path.realpath(root)))):
|
||||
if unix == host or unix.startswith(host + "/"):
|
||||
return unix[len(host):] or "/"
|
||||
return unix
|
||||
|
||||
|
||||
def bionic_tool(proton):
|
||||
|
||||
@@ -170,10 +170,28 @@ class StorePaths(unittest.TestCase):
|
||||
os.environ.pop('DDNATV_ROOT', None)
|
||||
self.assertEqual('Z:\\home\\games\\b.reg', store.windows_path('/home/games/b.reg'))
|
||||
|
||||
def test_other_tools_name_rootfs_host_paths_by_their_guest_paths(self):
|
||||
(self.tool / 'bionic/launch.sh').unlink()
|
||||
with self.env():
|
||||
self.assertEqual('Z:\\tmp\\droiddeck-ea-1\\probe.bat', store.windows_path(ANDROID + '/tmp/droiddeck-ea-1/probe.bat'))
|
||||
self.assertEqual('Z:\\', store.windows_path(ANDROID))
|
||||
self.assertEqual('Z:\\data\\user\\0\\com.droiddeck.launcher\\files\\linuxfs2\\a.reg',
|
||||
store.windows_path(ANDROID + '2/a.reg'))
|
||||
self.assertEqual('Z:\\storage\\emulated\\0\\Games\\a.reg', store.windows_path('/storage/emulated/0/Games/a.reg'))
|
||||
real = '/data/data/com.droiddeck.launcher/files/linuxfs'
|
||||
with self.env(), patch.object(store.os.path, 'realpath', lambda path: real if path == ANDROID else path):
|
||||
self.assertEqual('Z:\\tmp\\droiddeck-ea-2\\registry.reg', store.windows_path(real + '/tmp/droiddeck-ea-2/registry.reg'))
|
||||
with patch.dict(os.environ, {'DD_STORE_PROTON': str(self.tool / 'proton')}):
|
||||
os.environ.pop('DDNATV_ROOT', None)
|
||||
self.assertEqual('Z:\\data\\user\\0\\com.droiddeck.launcher\\files\\linuxfs\\tmp\\c.reg',
|
||||
store.windows_path(ANDROID + '/tmp/c.reg'))
|
||||
|
||||
def test_a_failing_tool_keeps_the_guest_path(self):
|
||||
(self.tool / 'proton').write_text('#!/bin/sh\nexit 1\n')
|
||||
with self.env():
|
||||
self.assertEqual('Z:\\home\\games\\c.reg', store.windows_path('/home/games/c.reg'))
|
||||
self.assertEqual('Z:\\data\\user\\0\\com.droiddeck.launcher\\files\\linuxfs\\tmp\\c.reg',
|
||||
store.windows_path(ANDROID + '/tmp/c.reg'))
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
@@ -3,6 +3,7 @@ import importlib.machinery
|
||||
import importlib.util
|
||||
import json
|
||||
from pathlib import Path
|
||||
import re
|
||||
import subprocess
|
||||
import tempfile
|
||||
import unittest
|
||||
@@ -171,6 +172,53 @@ class EaHook(unittest.TestCase):
|
||||
(pfx / store.EA_HARDWARE).write_text(json.dumps(whole))
|
||||
self.assertEqual(store.ea_hardware(tmp, ''), (whole, 'cached'))
|
||||
|
||||
def native_session(self, tmp):
|
||||
root = Path(tmp) / 'linuxfs'
|
||||
(root / 'tmp').mkdir(parents=True)
|
||||
compat = root / 'root/compat'
|
||||
(compat / 'pfx').mkdir(parents=True)
|
||||
(compat / 'pfx/system.reg').write_text('')
|
||||
proton = Path(tmp) / 'proton'
|
||||
proton.write_text('')
|
||||
env = patch.dict('os.environ', {'DDNATV_ROOT': str(root), 'DD_STORE_PROTON': str(proton)})
|
||||
return root, compat, str(proton), env, patch.object(tempfile, 'tempdir', str(root / 'tmp'))
|
||||
|
||||
def test_a_native_probe_names_its_files_by_their_guest_paths(self):
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
root, compat, proton, env, tmpdir = self.native_session(tmp)
|
||||
seen = []
|
||||
|
||||
def run(command, **kwargs):
|
||||
bat = command[-1]
|
||||
seen.append(bat)
|
||||
text = (root / bat[3:].replace('\\', '/')).read_text()
|
||||
seen.extend(re.findall(r'"([A-Z]:[^"]*)"', text))
|
||||
return subprocess.CompletedProcess(command, 0)
|
||||
|
||||
with env, tmpdir, patch.object(store.subprocess, 'run', run):
|
||||
self.assertEqual('incomplete', store.ea_hardware(str(compat), proton)[1])
|
||||
self.assertTrue(seen)
|
||||
for path in seen:
|
||||
self.assertTrue(path.startswith('Z:\\tmp\\droiddeck-ea-'), path)
|
||||
|
||||
def test_a_native_registry_import_names_its_file_by_its_guest_path(self):
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
root, compat, proton, env, tmpdir = self.native_session(tmp)
|
||||
sources = []
|
||||
|
||||
def run(command, **kwargs):
|
||||
source = command[4]
|
||||
sources.append(source)
|
||||
self.assertTrue((root / source[3:].replace('\\', '/')).is_file(), source)
|
||||
return subprocess.CompletedProcess(command, 0)
|
||||
|
||||
sidecar = {'id': 'OFB-EAST:1', 'title': 'Game', 'extra': {'contentIds': '1'}}
|
||||
with env, tmpdir, patch.object(store.subprocess, 'run', run):
|
||||
self.assertEqual('written', store.ea_registry(root / 'root/Games/Game', sidecar, str(compat), proton))
|
||||
self.assertEqual(2, len(sources))
|
||||
for source in sources:
|
||||
self.assertTrue(source.startswith('Z:\\tmp\\droiddeck-ea-'), source)
|
||||
|
||||
def touchup_setup(self, tmp):
|
||||
folder = Path(tmp) / 'game'
|
||||
(folder / 'Touchup').mkdir(parents=True)
|
||||
|
||||
Reference in new issue
Block a user