Compare commits

..
Author SHA1 Message Date
The412Banner 5c8a54ef95 fix(agent): keep replies with tables still while the theme color cycles
The Markdown renderer baked the link and code colors into its spans and
was rebuilt on every color step, so each step parsed the reply again and
reset its table rows, which measure one line high until drawn. Link and
code colors now come from the TextView and a live code theme, so a color
step only recolors the reply.
2026-11-29 15:52:51 +00:00
8 changed files with 148 additions and 232 deletions

No files matched your search

@@ -2,6 +2,7 @@ package com.droiddeck.launcher.ui
import android.content.Context
import android.content.Intent
import android.graphics.Paint
import android.net.Uri
import android.text.Selection
import android.text.Spannable
@@ -22,8 +23,11 @@ import com.droiddeck.launcher.R
import io.noties.markwon.AbstractMarkwonPlugin
import io.noties.markwon.Markwon
import io.noties.markwon.MarkwonConfiguration
import io.noties.markwon.MarkwonSpansFactory
import io.noties.markwon.MarkwonVisitor
import io.noties.markwon.core.MarkwonTheme
import io.noties.markwon.core.spans.CodeBlockSpan
import io.noties.markwon.core.spans.CodeSpan
import io.noties.markwon.ext.strikethrough.StrikethroughPlugin
import io.noties.markwon.ext.tables.TableAwareMovementMethod
import io.noties.markwon.ext.tables.TablePlugin
@@ -35,7 +39,10 @@ import org.commonmark.ext.gfm.tables.TableCell
import org.commonmark.ext.gfm.tables.TableHead
import org.commonmark.ext.gfm.tables.TableRow
import org.commonmark.node.AbstractVisitor
import org.commonmark.node.Code
import org.commonmark.node.CustomNode
import org.commonmark.node.FencedCodeBlock
import org.commonmark.node.IndentedCodeBlock
import org.commonmark.node.Node
@Composable
@@ -46,9 +53,8 @@ internal fun AgentMarkdown(text: String, modifier: Modifier) {
val density = LocalDensity.current
val textSize = with(density) { 15.sp.toPx() }
val lineSpacing = with(density) { 3.sp.toPx() }
val renderer = remember(context, pal.primary2, pal.surfaceVariant, density) {
agentMarkdownRenderer(context, pal.primary2.toArgb(), pal.surfaceVariant.toArgb())
}
val theme = remember(context, pal.id, density) { AgentMarkdownTheme(context) }
val renderer = remember(theme) { agentMarkdownRenderer(context, theme) }
val rendered = remember(renderer, text) { renderer.toMarkdown(text) }
AndroidView(
modifier = modifier,
@@ -62,12 +68,25 @@ internal fun AgentMarkdown(text: String, modifier: Modifier) {
view.setLinkTextColor(pal.primary2.toArgb())
view.setTextSize(android.util.TypedValue.COMPLEX_UNIT_PX, textSize)
view.setLineSpacing(lineSpacing, 1f)
val codeBackground = pal.surfaceVariant.toArgb()
if (theme.codeBackground != codeBackground) {
theme.codeBackground = codeBackground
view.invalidate()
}
setAgentMarkdown(view, renderer, rendered)
},
)
}
internal fun agentMarkdownRenderer(context: Context, linkColor: Int, codeBackground: Int): Markwon =
internal class AgentMarkdownTheme(context: Context) : MarkwonTheme(MarkwonTheme.builderWithDefaults(context)) {
var codeBackground = 0
override fun getCodeBackgroundColor(paint: Paint) = codeBackground
override fun getCodeBlockBackgroundColor(paint: Paint) = codeBackground
}
internal fun agentMarkdownRenderer(context: Context, theme: AgentMarkdownTheme): Markwon =
Markwon.builder(context)
.usePlugin(StrikethroughPlugin.create())
.usePlugin(TablePlugin.create(context))
@@ -104,8 +123,10 @@ internal fun agentMarkdownRenderer(context: Context, linkColor: Int, codeBackgro
builder.append(text)
}
override fun configureTheme(builder: MarkwonTheme.Builder) {
builder.linkColor(linkColor).codeBackgroundColor(codeBackground)
override fun configureSpansFactory(builder: MarkwonSpansFactory.Builder) {
builder.setFactory(Code::class.java) { _, _ -> CodeSpan(theme) }
builder.setFactory(FencedCodeBlock::class.java) { _, _ -> CodeBlockSpan(theme) }
builder.setFactory(IndentedCodeBlock::class.java) { _, _ -> CodeBlockSpan(theme) }
}
override fun configureConfiguration(builder: MarkwonConfiguration.Builder) {
@@ -0,0 +1,84 @@
package com.droiddeck.launcher.ui
import android.text.Spanned
import android.text.TextPaint
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.toArgb
import androidx.compose.ui.platform.LocalView
import io.noties.markwon.core.spans.CodeSpan
import io.noties.markwon.ext.tables.TableRowSpan
import org.junit.Assert.assertEquals
import org.junit.Assert.assertNotSame
import org.junit.Assert.assertSame
import org.junit.Assert.assertTrue
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
import org.robolectric.RobolectricTestRunner
import org.robolectric.annotation.Config
import org.robolectric.annotation.ConscryptMode
@RunWith(RobolectricTestRunner::class)
@Config(sdk = [34], application = android.app.Application::class)
@ConscryptMode(ConscryptMode.Mode.OFF)
class AgentMarkdownPaletteTest {
@get:Rule val compose = createRobolectricComposeRule()
private val reply = "Run `build` first\n\n| Step | Result |\n| --- | --- |\n| Build | [PR](https://github.com/owner/repo/pull/1) |\n\nDone"
private var palette by mutableStateOf(Themes.innerGamer(0f))
private fun View.markdownView(): TextView? = when (this) {
is TextView -> this
is ViewGroup -> (0 until childCount).firstNotNullOfOrNull { getChildAt(it).markdownView() }
else -> null
}
private fun showReply(): TextView {
lateinit var root: View
compose.setContent {
root = LocalView.current
CompositionLocalProvider(LocalPalette provides palette) { AgentMarkdown(reply, Modifier) }
}
compose.waitForIdle()
return requireNotNull(root.markdownView())
}
private fun assertColors(view: TextView, expected: Palette) {
assertEquals(expected.primary2.toArgb(), view.paint.linkColor)
val code = TextPaint()
(view.text as Spanned).getSpans(0, view.text.length, CodeSpan::class.java).single().updateDrawState(code)
assertEquals(expected.surfaceVariant.toArgb(), code.bgColor)
}
@Test fun innerGamerHueStepsRecolorTheReplyWithoutRenderingItAgain() {
val view = showReply()
val rendered = view.tag as Spanned
val rows = rendered.getSpans(0, rendered.length, TableRowSpan::class.java).toSet()
assertTrue(rows.isNotEmpty())
for (hue in listOf(3f, 90f, 180f, 357f)) {
palette = Themes.innerGamer(hue)
compose.waitForIdle()
assertSame(rendered, view.tag)
val current = view.text as Spanned
assertEquals(rows, current.getSpans(0, current.length, TableRowSpan::class.java).toSet())
assertColors(view, palette)
}
}
@Test fun switchingThemesRendersTheReplyInTheNewColors() {
val view = showReply()
for (id in listOf(Themes.GRAPHITE, Themes.WHITE_RED, Themes.INNER_GAMER)) {
val before = view.tag
palette = Themes.byId(id)
compose.waitForIdle()
assertNotSame(before, view.tag)
assertColors(view, palette)
}
}
}
@@ -4,6 +4,8 @@ import android.content.Intent
import android.content.ClipboardManager
import android.text.Selection
import android.text.Spannable
import io.noties.markwon.core.spans.CodeBlockSpan
import io.noties.markwon.core.spans.CodeSpan
import io.noties.markwon.ext.tables.TableRowSpan
import android.graphics.Color
import android.text.Spanned
@@ -23,7 +25,7 @@ import org.robolectric.annotation.Config
@ConscryptMode(ConscryptMode.Mode.OFF)
class AgentMarkdownTest {
private val context get() = RuntimeEnvironment.getApplication()
private val renderer get() = agentMarkdownRenderer(context, Color.BLUE, Color.DKGRAY)
private val renderer get() = agentMarkdownRenderer(context, AgentMarkdownTheme(context).apply { codeBackground = Color.DKGRAY })
private fun Spanned.links() = getSpans(0, length, ClickableSpan::class.java).toList()
@Test fun namedPullRequestLinksKeepTheirLabelsAndOpenAnExternalBrowser() {
@@ -85,27 +87,47 @@ class AgentMarkdownTest {
renderer.render(root)
}
@Test fun colorChangesPreserveSelectionAndRefreshLinkSpans() {
@Test fun rendererChangesPreserveSelectionAndLinksFollowTheViewLinkColor() {
val source = "Read [the PR](https://github.com/owner/repo/pull/1)"
val view = TextView(context).apply { setTextIsSelectable(true) }
val original = renderer
setAgentMarkdown(view, original, original.toMarkdown(source))
Selection.setSelection(view.text as Spannable, 5, 11)
val updated = agentMarkdownRenderer(context, Color.RED, Color.LTGRAY)
val updated = agentMarkdownRenderer(context, AgentMarkdownTheme(context).apply { codeBackground = Color.LTGRAY })
val rendered = updated.toMarkdown(source)
setAgentMarkdown(view, updated, rendered)
assertEquals(5, view.selectionStart)
assertEquals(11, view.selectionEnd)
assertSame(rendered, view.tag)
val paint = android.text.TextPaint()
view.setLinkTextColor(Color.RED)
val paint = android.text.TextPaint().apply { set(view.paint) }
(view.text as Spanned).links().single().updateDrawState(paint)
assertEquals(Color.RED, paint.color)
}
@Test fun codeBackgroundsFollowTheThemeWithoutRenderingAgain() {
val theme = AgentMarkdownTheme(context).apply { codeBackground = Color.DKGRAY }
val rendered = agentMarkdownRenderer(context, theme).toMarkdown("Run `inline`\n\n~~~\nblock\n~~~\n\n indented")
theme.codeBackground = Color.RED
val inline = android.text.TextPaint()
rendered.getSpans(0, rendered.length, CodeSpan::class.java).single().updateDrawState(inline)
assertEquals(Color.RED, inline.bgColor)
val blocks = rendered.getSpans(0, rendered.length, CodeBlockSpan::class.java)
assertEquals(2, blocks.size)
for (block in blocks) {
var filled = 0
val canvas = object : android.graphics.Canvas(android.graphics.Bitmap.createBitmap(10, 10, android.graphics.Bitmap.Config.ARGB_8888)) {
override fun drawRect(rect: android.graphics.Rect, paint: android.graphics.Paint) { filled = paint.color }
}
block.drawLeadingMargin(canvas, android.graphics.Paint(), 0, 1, 0, 5, 10, rendered, 0, 1, true, null)
assertEquals(Color.RED, filled)
}
}
@Test fun reversedSelectionsAndCursorsSurviveColorChangesButNotContentChanges() {
val view = TextView(context).apply { setTextIsSelectable(true) }
val original = renderer
val updated = agentMarkdownRenderer(context, Color.RED, Color.LTGRAY)
val updated = agentMarkdownRenderer(context, AgentMarkdownTheme(context).apply { codeBackground = Color.LTGRAY })
setAgentMarkdown(view, original, original.toMarkdown("A long reply"))
for ((start, end) in listOf(8 to 2, 4 to 4)) {
Selection.setSelection(view.text as Spannable, start, end)
@@ -1099,7 +1099,6 @@ def newest_foreign_backup(backups):
def restore_compatible_system_dlls(prefix, proton, env=None):
restored = []
game = (env or {}).get("STEAM_COMPAT_INSTALL_PATH")
for folder, name, path, source, machines, builtins, backups in prefix_system_dlls(prefix, proton, env):
if not path.is_symlink() or not path.is_file():
continue
@@ -1112,7 +1111,7 @@ def restore_compatible_system_dlls(prefix, proton, env=None):
if backup is None or backup.is_symlink() or not backup.is_file():
continue
machine = pe_machine(backup)
if machine is None or not PE["machine_compatible"](backup, machines, machine, builtins, name, game):
if machine is None or not PE["machine_compatible"](backup, machines, machine, builtins, name):
continue
try:
os.replace(backup, path)
@@ -1124,12 +1123,11 @@ def restore_compatible_system_dlls(prefix, proton, env=None):
def repair_foreign_system_dlls(prefix, proton, env=None):
repaired = []
game = (env or {}).get("STEAM_COMPAT_INSTALL_PATH")
for folder, name, path, source, machines, builtins, backups in prefix_system_dlls(prefix, proton, env):
if path.is_symlink() or not path.is_file():
continue
machine = pe_machine(path)
if machine is None or PE["machine_compatible"](path, machines, machine, builtins, game=game):
if machine is None or PE["machine_compatible"](path, machines, machine, builtins):
continue
link = path.parent / (name + ".dd-new")
backup = path.parent / (name + FOREIGN_SUFFIX)
@@ -479,7 +479,7 @@ def save_state(compat, state):
os.replace(temp, compat / STATE)
def foreign_component(rel, path, machines, dist=None, game=None):
def foreign_component(rel, path, machines, dist=None):
parts = Path(rel).parts
folder = parts[2] if len(parts) > 2 and parts[:2] == ("drive_c", "windows") else None
if not machines or folder not in PE_MACHINES or not rel.lower().endswith(".dll"):
@@ -487,7 +487,7 @@ def foreign_component(rel, path, machines, dist=None, game=None):
machine = pe_machine(path)
libdir, compatible = machines[folder]
builtins = dist / libdir if dist else None
return machine is not None and not machine_compatible(path, compatible, machine, builtins, game=game)
return machine is not None and not machine_compatible(path, compatible, machine, builtins)
def pending_for(app_id, pending=PENDING):
@@ -549,7 +549,6 @@ def apply(compat_path, app_id, selection=SELECTION, store=STORE, pending=PENDING
placed_stems = set()
machines = PE["proton_pe_machines"](proton, env) if proton else None
dist = Path(proton).parent / "files/lib/wine" if proton else None
game = (env or {}).get("STEAM_COMPAT_INSTALL_PATH")
saved_overrides = state.get("overrides") if isinstance(state.get("overrides"), dict) else {}
saved_requires = state.get("requires") if isinstance(state.get("requires"), dict) else {}
recorded = [c for c in state.get("components", []) if isinstance(c, str) and valid_id(c)]
@@ -589,7 +588,7 @@ def apply(compat_path, app_id, selection=SELECTION, store=STORE, pending=PENDING
kept_requires[cid] = list(requires)
values += [(cid, value) for value in registry]
for rel, src in files:
foreign = foreign_component(rel, src, machines, dist, game)
foreign = foreign_component(rel, src, machines, dist)
if foreign:
skipped.add(Path(rel).stem.lower())
changed = False
@@ -610,10 +609,9 @@ def apply(compat_path, app_id, selection=SELECTION, store=STORE, pending=PENDING
path = existing(pfx / rel)
saved = compat / BACKUP / rel
if saved.is_file():
if foreign_component(rel, saved, machines, dist, game):
if foreign_component(rel, saved, machines, dist):
if path is not None and not path.is_symlink():
path.unlink()
keep[rel] = cid
continue
target = path or (pfx / rel)
os.replace(saved, target)
@@ -1,12 +1,8 @@
#!/usr/bin/python3
import mmap
import os
import re
from pathlib import Path
VC_RUNTIME = re.compile(r"(msvc[pr]\d.*|vcruntime\d.*|vcomp\d*|vcamp\d.*|vccorlib\d.*|concrt\d.*|mfcm?\d.*)\.dll",
re.IGNORECASE)
PE_MACHINES = {
"system32": ("aarch64-windows", frozenset((0xAA64, 0xA641))),
"syswow64": ("i386-windows", frozenset((0x14C,))),
@@ -83,8 +79,8 @@ def pe_has_arm64ec_metadata(path):
def pe_imports(path):
try:
with open(path, "rb") as source:
image = mmap.mmap(source.fileno(), 0, access=mmap.ACCESS_READ)
except (OSError, ValueError):
image = source.read()
except OSError:
return None
try:
if image[:2] != b"MZ":
@@ -141,13 +137,9 @@ def pe_imports(path):
return names
except (IndexError, ValueError):
return None
finally:
image.close()
PROGRAM_IMPORTS = {}
GAME_IMPORTS = {}
GAME_DEPTH = 4
def program_imports(builtins):
@@ -174,42 +166,13 @@ def program_imports(builtins):
return PROGRAM_IMPORTS[key]
def game_imports(folder):
key = str(folder)
if key not in GAME_IMPORTS:
arm64, arm64ec = set(), set()
root = os.path.realpath(folder)
for top, dirs, files in os.walk(root):
if os.path.relpath(top, root).count(os.sep) >= GAME_DEPTH:
dirs[:] = []
for entry in files:
if not entry.lower().endswith((".exe", ".dll")):
continue
path = os.path.join(top, entry)
machine = pe_machine(path)
if machine == 0xAA64:
found = arm64
elif machine == 0x8664 and pe_has_arm64ec_metadata(path):
found = arm64ec
else:
continue
found |= pe_imports(path) or set()
GAME_IMPORTS[key] = (frozenset(arm64), frozenset(arm64ec))
return GAME_IMPORTS[key]
def machine_compatible(path, machines, machine=None, builtins=None, name=None, game=None):
def machine_compatible(path, machines, machine=None, builtins=None, name=None):
machine = pe_machine(path) if machine is None else machine
if machine == 0x8664 and 0xA641 in machines:
if pe_has_arm64ec_metadata(path):
return True
imported = program_imports(builtins) if builtins is not None else None
name = (name or Path(path).name).lower()
if game:
arm64, arm64ec = game_imports(game)
if name in arm64 or (name in arm64ec and VC_RUNTIME.fullmatch(name)):
return False
return imported is not None and name not in imported
return imported is not None and (name or Path(path).name).lower() not in imported
if machine == 0x8664 and pe_has_arm64ec_metadata(path):
return False
return machine in machines
-118
View File
@@ -3499,22 +3499,6 @@ def program_image(machine, imports):
return bytes(image)
def arm64ec_program_image(imports):
image = bytearray(program_image(0x8664, imports))
directory = 68 + 20 + 112 + 10 * 8
image[directory:directory + 4] = (0x1100).to_bytes(4, "little")
image[directory + 4:directory + 8] = (0xD0).to_bytes(4, "little")
image[0x300:0x304] = (0xD0).to_bytes(4, "little")
image[0x3C8:0x3D0] = (0x10000000).to_bytes(8, "little")
return bytes(image)
def arm64x_program_image(imports):
image = bytearray(arm64ec_program_image(imports))
image[68:70] = (0xAA64).to_bytes(2, "little")
return bytes(image)
def bytes_path(folder, data):
path = folder / "image.exe"
path.write_bytes(data)
@@ -3589,108 +3573,6 @@ class ForeignSystemDllTest(unittest.TestCase):
self.assertFalse((windows / "system32" / name).is_symlink())
self.assertEqual(0x8664, MODULE["pe_machine"](windows / "system32" / name))
def arm64ec_game(self, tmp, shipping):
game = Path(tmp) / "common/Game"
binaries = game / "Game/Binaries/Win64"
binaries.mkdir(parents=True)
(game / "Game.exe").write_bytes(program_image(0x8664, ["kernel32.dll"]))
(binaries / "Game-Win64-Shipping.exe").write_bytes(shipping)
(binaries / "plugin.dll").write_bytes(program_image(0x8664, ["concrt140.dll"]))
return {"STEAM_COMPAT_INSTALL_PATH": str(game)}
def visual_cpp_prefix(self, tmp):
proton, compat, windows = self.prefix(tmp)
builtins = proton.parent / "files/lib/wine/aarch64-windows"
for name in ("vcruntime140.dll", "msvcp140.dll", "concrt140.dll", "vulkan-1.dll", "d3dcompiler_47.dll"):
(builtins / name).write_bytes(program_image(0xAA64, []))
(windows / "system32" / name.upper()).write_bytes(pe_image(0x8664))
return proton, compat, windows
def test_x64_runtime_an_arm64ec_game_image_imports_is_replaced_by_the_builtin(self):
with tempfile.TemporaryDirectory() as tmp:
proton, compat, windows = self.visual_cpp_prefix(tmp)
env = self.arm64ec_game(tmp, arm64ec_program_image(["VCRUNTIME140.dll", "MSVCP140.dll", "vulkan-1.dll"]))
fixed = MODULE["repair_foreign_system_dlls"](str(compat), str(proton), env)
self.assertEqual(["system32/MSVCP140.DLL (machine 0x8664)", "system32/VCRUNTIME140.DLL (machine 0x8664)"], fixed)
for name in ("CONCRT140.DLL", "VULKAN-1.DLL"):
self.assertFalse((windows / "system32" / name).is_symlink())
self.assertEqual(0x8664, MODULE["pe_machine"](windows / "system32" / name))
self.assertEqual([], MODULE["restore_compatible_system_dlls"](str(compat), str(proton), env))
self.assertEqual([], MODULE["repair_foreign_system_dlls"](str(compat), str(proton), env))
restored = MODULE["restore_compatible_system_dlls"](str(compat), str(proton))
self.assertEqual(2, len(restored))
self.assertFalse((windows / "system32/VCRUNTIME140.DLL").is_symlink())
def test_x64_runtime_stays_for_x64_games_and_launches_without_a_game_folder(self):
with tempfile.TemporaryDirectory() as tmp:
proton, compat, windows = self.visual_cpp_prefix(tmp)
env = self.arm64ec_game(tmp, program_image(0x8664, ["VCRUNTIME140.dll", "MSVCP140.dll"]))
self.assertEqual([], MODULE["repair_foreign_system_dlls"](str(compat), str(proton), env))
self.assertEqual([], MODULE["repair_foreign_system_dlls"](str(compat), str(proton), {}))
self.assertEqual([], MODULE["repair_foreign_system_dlls"](
str(compat), str(proton), {"STEAM_COMPAT_INSTALL_PATH": str(Path(tmp) / "missing")}))
for name in ("VCRUNTIME140.DLL", "MSVCP140.DLL"):
self.assertFalse((windows / "system32" / name).is_symlink())
def arm64_game(self, tmp, exe_imports, plugin_imports=()):
game = Path(tmp) / "common/Game"
binaries = game / "BinArm64"
binaries.mkdir(parents=True)
(game / "Game.exe").write_bytes(program_image(0x8664, ["kernel32.dll"]))
(binaries / "Game.arm64.exe").write_bytes(program_image(0xAA64, exe_imports))
(binaries / "plugin.dll").write_bytes(arm64x_program_image(list(plugin_imports)))
return {"STEAM_COMPAT_INSTALL_PATH": str(game)}
def test_x64_dlls_an_arm64_game_image_imports_are_replaced_by_the_builtins(self):
with tempfile.TemporaryDirectory() as tmp:
proton, compat, windows = self.visual_cpp_prefix(tmp)
env = self.arm64_game(tmp, ["MSVCP140.dll", "D3DCOMPILER_47.dll"], ["VCRUNTIME140.dll"])
fixed = MODULE["repair_foreign_system_dlls"](str(compat), str(proton), env)
self.assertEqual(["system32/D3DCOMPILER_47.DLL (machine 0x8664)", "system32/MSVCP140.DLL (machine 0x8664)",
"system32/VCRUNTIME140.DLL (machine 0x8664)"], fixed)
for name in ("D3DCOMPILER_47.DLL", "MSVCP140.DLL", "VCRUNTIME140.DLL"):
self.assertTrue((windows / "system32" / name).is_symlink())
self.assertEqual(0xAA64, MODULE["pe_machine"](windows / "system32" / name))
for name in ("CONCRT140.DLL", "VULKAN-1.DLL"):
self.assertFalse((windows / "system32" / name).is_symlink())
self.assertEqual(0x8664, MODULE["pe_machine"](windows / "system32" / name))
self.assertEqual([], MODULE["restore_compatible_system_dlls"](str(compat), str(proton), env))
self.assertEqual([], MODULE["repair_foreign_system_dlls"](str(compat), str(proton), env))
self.assertEqual(3, len(MODULE["restore_compatible_system_dlls"](str(compat), str(proton))))
self.assertFalse((windows / "system32/D3DCOMPILER_47.DLL").is_symlink())
def test_x64_dlls_an_arm64_game_does_not_import_stay(self):
with tempfile.TemporaryDirectory() as tmp:
proton, compat, windows = self.visual_cpp_prefix(tmp)
env = self.arm64_game(tmp, ["kernel32.dll"], ["user32.dll"])
self.assertEqual([], MODULE["repair_foreign_system_dlls"](str(compat), str(proton), env))
for name in ("D3DCOMPILER_47.DLL", "MSVCP140.DLL", "VCRUNTIME140.DLL"):
self.assertFalse((windows / "system32" / name).is_symlink())
def test_non_runtime_dlls_stay_for_x64_and_arm64ec_games(self):
for shipping in (program_image(0x8664, ["MSVCP140.dll", "D3DCOMPILER_47.dll"]),
arm64ec_program_image(["D3DCOMPILER_47.dll"])):
with tempfile.TemporaryDirectory() as tmp:
proton, compat, windows = self.visual_cpp_prefix(tmp)
env = self.arm64ec_game(tmp, shipping)
self.assertEqual([], MODULE["repair_foreign_system_dlls"](str(compat), str(proton), env))
for name in ("D3DCOMPILER_47.DLL", "MSVCP140.DLL"):
self.assertEqual(0x8664, MODULE["pe_machine"](windows / "system32" / name))
def test_arm64ec_images_below_the_scanned_depth_are_ignored(self):
with tempfile.TemporaryDirectory() as tmp:
proton, compat, windows = self.visual_cpp_prefix(tmp)
game = Path(tmp) / "common/Deep"
deep = game.joinpath(*("d%d" % level for level in range(MODULE["PE"]["GAME_DEPTH"] + 2)))
deep.mkdir(parents=True)
(deep / "tool.exe").write_bytes(arm64ec_program_image(["VCRUNTIME140.dll"]))
env = {"STEAM_COMPAT_INSTALL_PATH": str(game)}
self.assertEqual([], MODULE["repair_foreign_system_dlls"](str(compat), str(proton), env))
(deep.parent / "tool.exe").write_bytes(arm64ec_program_image(["VCRUNTIME140.dll"]))
MODULE["PE"]["GAME_IMPORTS"].clear()
self.assertEqual(["system32/VCRUNTIME140.DLL (machine 0x8664)"],
MODULE["repair_foreign_system_dlls"](str(compat), str(proton), env))
def test_repaired_dll_proton_programs_do_not_import_gets_its_native_copy_back(self):
with tempfile.TemporaryDirectory() as tmp:
proton, compat, windows = self.prefix(tmp)
-52
View File
@@ -6,8 +6,6 @@ import unittest
from pathlib import Path
from unittest import mock
from tools.tests.test_game_environment import arm64ec_program_image, program_image
BIN = Path(__file__).resolve().parents[1] / "linuxfs/overlay/usr/local/bin"
MODULE = runpy.run_path(str(BIN / "droiddeck-wincomponents"))
GAME_ENV = runpy.run_path(str(BIN / "droiddeck-game-env"))
@@ -171,56 +169,6 @@ class WinComponentsTest(unittest.TestCase):
self.assertEqual(MODULE["pe_machine"](self.pfx / "system32/msvcp140.dll"), 0x8664)
self.assertEqual(MODULE["pe_machine"](self.pfx / "system32/vcruntime140.dll"), 0x8664)
def test_x64_runtime_an_arm64ec_game_imports_is_not_placed(self):
proton = self.proton()
game = Path(self.tmp.name) / "common/Game/Game/Binaries/Win64"
game.mkdir(parents=True)
(game / "Game-Win64-Shippingarm64ec.exe").write_bytes(arm64ec_program_image(["MSVCP140.dll", "VCRUNTIME140.dll"]))
names = ["concrt140", "msvcp140", "vcruntime140"]
self.component("vc", names, {"system32/%s.dll" % name: self.pe_image(0x8664) for name in names})
self.pick("vc")
env = {"STEAM_COMPAT_INSTALL_PATH": str(game.parents[2])}
for _ in range(2):
placed, _ = self.apply(proton, env)
self.assertEqual(placed, ["concrt140"])
self.assertEqual(MODULE["pe_machine"](self.pfx / "system32/concrt140.dll"), 0x8664)
self.assertFalse((self.pfx / "system32/msvcp140.dll").exists())
self.assertFalse((self.pfx / "system32/vcruntime140.dll").exists())
def arm64_game(self, imports):
game = Path(self.tmp.name) / "common/Game/BinArm64"
game.mkdir(parents=True)
(game / "Game.arm64.exe").write_bytes(program_image(0xAA64, imports))
return {"STEAM_COMPAT_INSTALL_PATH": str(game.parent)}
def test_x64_dlls_an_arm64_game_imports_are_not_placed(self):
proton = self.proton()
env = self.arm64_game(["MSVCP140.dll", "D3DCOMPILER_47.dll"])
names = ["concrt140", "d3dcompiler_47", "msvcp140", "vcruntime140"]
self.component("vc", names, {"system32/%s.dll" % name: self.pe_image(0x8664) for name in names})
self.pick("vc")
for _ in range(2):
placed, _ = self.apply(proton, env)
self.assertEqual(placed, ["concrt140", "vcruntime140"])
self.assertEqual(MODULE["pe_machine"](self.pfx / "system32/vcruntime140.dll"), 0x8664)
self.assertFalse((self.pfx / "system32/msvcp140.dll").exists())
self.assertFalse((self.pfx / "system32/d3dcompiler_47.dll").exists())
def test_saved_original_stays_tracked_while_a_game_defers_its_restoration(self):
proton = self.proton()
original = self.pe_image(0x8664) + b"original"
self.pfx.joinpath("system32").mkdir(parents=True)
self.pfx.joinpath("system32/msvcp140.dll").write_bytes(original)
self.component("vc", ["msvcp140"], {"system32/msvcp140.dll": self.pe_image(0x8664)})
self.pick("vc")
self.apply(proton)
self.assertNotEqual(original, (self.pfx / "system32/msvcp140.dll").read_bytes())
self.pick()
self.apply(proton, self.arm64_game(["MSVCP140.dll"]))
self.assertFalse((self.pfx / "system32/msvcp140.dll").exists())
self.apply(proton)
self.assertEqual(original, (self.pfx / "system32/msvcp140.dll").read_bytes())
def test_deselected_component_restores_the_saved_x64_dll(self):
proton = self.proton()
self.pfx.joinpath("system32").mkdir(parents=True)