mirror of
https://github.com/MaSzyna-EU07/StarterNG.git
synced 2026-12-03 02:05:18 +01:00
Compare commits
12 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 4f57881902 | |||
| 7a03cc0c6a | |||
| 9fe767cf9f | |||
| fdcf33069d | |||
| ece440e566 | |||
| 3dfcbca711 | |||
| 9668b4d3b6 | |||
| a3fc1dd1ac | |||
| 2f0f7ebe43 | |||
| b8c1560220 | |||
| f2fbb6d0d6 | |||
| ad58d0f838 |
@@ -52,7 +52,7 @@ jobs:
|
||||
persist-credentials: false
|
||||
|
||||
- name: Setup .NET 10
|
||||
uses: actions/setup-dotnet@a98b56852c35b8e3190ac28c8c2271da59106c68 # v6.0.0
|
||||
uses: actions/setup-dotnet@0f4a354dd5547a28c70b7853dbd95d5b67886e73 # v6.1.0
|
||||
with:
|
||||
dotnet-version: 10.0.x
|
||||
|
||||
@@ -142,7 +142,7 @@ jobs:
|
||||
persist-credentials: false
|
||||
|
||||
- name: Setup .NET 10
|
||||
uses: actions/setup-dotnet@a98b56852c35b8e3190ac28c8c2271da59106c68 # v6.0.0
|
||||
uses: actions/setup-dotnet@0f4a354dd5547a28c70b7853dbd95d5b67886e73 # v6.1.0
|
||||
with:
|
||||
dotnet-version: 10.0.x
|
||||
|
||||
|
||||
@@ -62,7 +62,7 @@ jobs:
|
||||
persist-credentials: false
|
||||
|
||||
- name: Setup .NET 10
|
||||
uses: actions/setup-dotnet@a98b56852c35b8e3190ac28c8c2271da59106c68 # v6.0.0
|
||||
uses: actions/setup-dotnet@0f4a354dd5547a28c70b7853dbd95d5b67886e73 # v6.1.0
|
||||
with:
|
||||
dotnet-version: 10.0.x
|
||||
|
||||
@@ -71,6 +71,8 @@ jobs:
|
||||
|
||||
# sonar.qualitygate.wait=true blocks the end step until the server has
|
||||
# processed the report, so the job's result is the quality gate's.
|
||||
# tools/ holds the developers' helper scripts, outside the app and its tests:
|
||||
# analysed like the rest, but not counted for coverage.
|
||||
- name: Begin analysis
|
||||
env:
|
||||
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
|
||||
@@ -84,6 +86,7 @@ jobs:
|
||||
/d:sonar.scm.revision="${{ github.event.pull_request.head.sha || github.sha }}"
|
||||
/d:sonar.cs.opencover.reportsPaths="TestResults/**/coverage.opencover.xml"
|
||||
/d:sonar.cs.vstest.reportsPaths="TestResults/*.trx"
|
||||
/d:sonar.coverage.exclusions="tools/**"
|
||||
/d:sonar.qualitygate.wait=true
|
||||
|
||||
# A full, non-incremental build: the analyzers only see what is compiled.
|
||||
|
||||
@@ -46,3 +46,17 @@ the packaged artifacts — tagged `latest` for `main` and `staging` for `staging
|
||||
```sh
|
||||
dotnet build StarterNG/StarterNG.csproj
|
||||
```
|
||||
|
||||
## Translations
|
||||
|
||||
The texts are in `StarterNG/startercfg/lang/<code>.xml`; `en.xml` is the reference.
|
||||
The tests require every language to have every key of `en.xml` except the optional
|
||||
ones (ending in `Desc`, starting with `Cmd.`), which fall back to English. After a
|
||||
change to `en.xml`, or before merging a translation made from an older one:
|
||||
|
||||
```sh
|
||||
python tools/sync_lang.py --check # lists what is missing or no longer used
|
||||
python tools/sync_lang.py # adds missing keys in English, removes the unused ones
|
||||
```
|
||||
|
||||
Added keys are marked `<!-- untranslated -->` for the translator.
|
||||
|
||||
@@ -6,14 +6,27 @@ namespace StarterNG.Tests;
|
||||
public class WindowSurfacesTests
|
||||
{
|
||||
[Fact]
|
||||
public void Windows_draws_into_the_window_surface_and_never_through_winui_composition()
|
||||
public void Windows_draws_into_a_directcomposition_surface_and_never_through_winui_composition()
|
||||
{
|
||||
var options = WindowSurfaces.Win32Options;
|
||||
|
||||
Assert.Equal(new[] { Win32CompositionMode.RedirectionSurface }, options.CompositionMode);
|
||||
Assert.Equal(Win32CompositionMode.DirectComposition, options.CompositionMode.First());
|
||||
Assert.DoesNotContain(Win32CompositionMode.WinUIComposition, options.CompositionMode);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void The_window_surface_is_only_the_fallback()
|
||||
{
|
||||
// There ANGLE presents through a swap chain, and the Steam overlay draws over it.
|
||||
Assert.Equal(Win32CompositionMode.RedirectionSurface, WindowSurfaces.Win32Options.CompositionMode.Last());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void No_swap_chain_of_its_own_is_asked_for()
|
||||
{
|
||||
Assert.DoesNotContain(Win32CompositionMode.LowLatencyDxgiSwapChain, WindowSurfaces.Win32Options.CompositionMode);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void The_graphics_card_still_draws()
|
||||
{
|
||||
|
||||
@@ -3,17 +3,24 @@ using Avalonia;
|
||||
namespace StarterNG.Infrastructure;
|
||||
|
||||
/// <summary>
|
||||
/// On Windows the graphics card draws each window of the starter into a surface of that
|
||||
/// window, not into Avalonia's default WinUI composition visual. On Windows 11 25H2 that
|
||||
/// On Windows the graphics card draws each window of the starter into a DirectComposition
|
||||
/// surface, not into Avalonia's default WinUI composition visual. On Windows 11 25H2 that
|
||||
/// visual was left empty on many starts: the main window, or a dialog opened later,
|
||||
/// stayed black while the others drew, and came back only now and then. Composition is
|
||||
/// there for see-through windows and backdrops, and the starter has none.
|
||||
/// stayed black while the others drew, and came back only now and then.
|
||||
/// The window's own redirection surface is only the fallback: there ANGLE draws through a
|
||||
/// swap chain of the window, and the Steam overlay, which Steam puts into the starter as
|
||||
/// the game it launches, hooks that swap chain's Present and draws its frame counter and
|
||||
/// notifications over the starter. A composition surface is drawn without a Present.
|
||||
/// </summary>
|
||||
public static class WindowSurfaces
|
||||
{
|
||||
public static Win32PlatformOptions Win32Options => new()
|
||||
{
|
||||
CompositionMode = new[] { Win32CompositionMode.RedirectionSurface }
|
||||
CompositionMode = new[]
|
||||
{
|
||||
Win32CompositionMode.DirectComposition,
|
||||
Win32CompositionMode.RedirectionSurface
|
||||
}
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,173 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Brings the language files of the starter in line with en.xml.
|
||||
|
||||
For every language file in StarterNG/startercfg/lang (or the codes given):
|
||||
- a key en.xml has and the language lacks is added with the English text, right after the
|
||||
key it follows in en.xml, and marked <!-- untranslated -->;
|
||||
- a key en.xml no longer has is removed.
|
||||
Keys the starter falls back to English for by itself (ending in "Desc", starting with "Cmd.")
|
||||
are only added with --all. Everything else in the file - comments, order, line endings - stays
|
||||
as it is.
|
||||
|
||||
python tools/sync_lang.py # every language
|
||||
python tools/sync_lang.py zh cz # only these
|
||||
python tools/sync_lang.py --check # only report; exit code 1 when a file is out of line
|
||||
"""
|
||||
|
||||
import argparse
|
||||
import re
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
LANG_DIR = Path(__file__).resolve().parent.parent / "StarterNG" / "startercfg" / "lang"
|
||||
STRING = re.compile(r'<String key="(?P<key>[^"]+)">.*?</String>', re.DOTALL)
|
||||
LANGUAGE_TAG = re.compile(r"<Language\b[^>]*>")
|
||||
UNTRANSLATED = "<!-- untranslated -->"
|
||||
|
||||
|
||||
def is_optional(key):
|
||||
return key.endswith("Desc") or key.startswith("Cmd.")
|
||||
|
||||
|
||||
def read(path):
|
||||
raw = path.read_bytes()
|
||||
bom = raw.startswith(b"\xef\xbb\xbf")
|
||||
text = raw[3 if bom else 0:].decode("utf-8")
|
||||
newline = "\r\n" if "\r\n" in text else "\n"
|
||||
return text, bom, newline
|
||||
|
||||
|
||||
def write(path, text, bom):
|
||||
path.write_bytes((b"\xef\xbb\xbf" if bom else b"") + text.encode("utf-8"))
|
||||
|
||||
|
||||
def strings(text):
|
||||
"""key -> match, in the order of the file; a key given twice keeps its first."""
|
||||
found = {}
|
||||
for match in STRING.finditer(text):
|
||||
found.setdefault(match.group("key"), match)
|
||||
return found
|
||||
|
||||
|
||||
def line_start(text, pos):
|
||||
return text.rfind("\n", 0, pos) + 1
|
||||
|
||||
|
||||
def line_end(text, pos):
|
||||
"""Just past the newline ending the line that pos is on."""
|
||||
end = text.find("\n", pos)
|
||||
return len(text) if end < 0 else end + 1
|
||||
|
||||
|
||||
def removal_span(text, match):
|
||||
"""The element with its whole lines when nothing but blanks and a comment share them."""
|
||||
start, end = match.span()
|
||||
first = line_start(text, start)
|
||||
last = line_end(text, end)
|
||||
before = text[first:start]
|
||||
after = text[end:last].strip()
|
||||
if before.strip() == "" and (after == "" or (after.startswith("<!--") and after.endswith("-->"))):
|
||||
return first, last
|
||||
return start, end
|
||||
|
||||
|
||||
def english_line(en_text, match, newline):
|
||||
indent = en_text[line_start(en_text, match.start()):match.start()]
|
||||
if indent.strip():
|
||||
indent = " "
|
||||
element = match.group(0).replace("\r\n", "\n").replace("\n", newline)
|
||||
return f"{indent}{element} {UNTRANSLATED}{newline}"
|
||||
|
||||
|
||||
def insert_position(text, own, en_keys, key, after_tag):
|
||||
"""Just after the nearest key before this one in en.xml that the file has and keeps."""
|
||||
for previous in reversed(en_keys[:en_keys.index(key)]):
|
||||
if previous in own:
|
||||
return line_end(text, own[previous].end())
|
||||
return after_tag
|
||||
|
||||
|
||||
def apply_edits(text, edits):
|
||||
"""edits: (start, end, replacement) on the original text.
|
||||
|
||||
Applied from the end so the offsets stay valid. Where a removal starts at the place of an
|
||||
insert, the removal goes first, or it would take away the inserted line instead of its own.
|
||||
Inserts at one place keep the order of en.xml.
|
||||
"""
|
||||
def order(edit):
|
||||
index, (start, end, _) = edit
|
||||
return start, 1 if end > start else 0, index
|
||||
|
||||
for _, (start, end, replacement) in sorted(enumerate(edits), key=order, reverse=True):
|
||||
text = text[:start] + replacement + text[end:]
|
||||
return text
|
||||
|
||||
|
||||
def synced_text(path, text, newline, own, missing, obsolete, en_text, en_strings):
|
||||
edits = [(*removal_span(text, own[key]), "") for key in obsolete]
|
||||
|
||||
tag = LANGUAGE_TAG.search(text)
|
||||
if tag is None:
|
||||
sys.exit(f"{path.name}: no <Language> element")
|
||||
after_tag = line_end(text, tag.end())
|
||||
|
||||
en_keys = list(en_strings)
|
||||
for key in missing:
|
||||
anchor = insert_position(text, own, en_keys, key, after_tag)
|
||||
edits.append((anchor, anchor, english_line(en_text, en_strings[key], newline)))
|
||||
return apply_edits(text, edits)
|
||||
|
||||
|
||||
def report(name, missing, obsolete, detailed):
|
||||
print(f"{name}: {len(missing)} to add in English, {len(obsolete)} no longer in en.xml")
|
||||
if detailed:
|
||||
for key in missing:
|
||||
print(f" missing {key}")
|
||||
for key in obsolete:
|
||||
print(f" obsolete {key}")
|
||||
|
||||
|
||||
def sync(path, en_text, en_strings, add_optional, check):
|
||||
"""True when the file was out of line with en.xml (and, without check, is now brought in line)."""
|
||||
text, bom, newline = read(path)
|
||||
own = strings(text)
|
||||
|
||||
obsolete = [key for key in own if key not in en_strings]
|
||||
missing = [key for key in en_strings
|
||||
if key not in own and (add_optional or not is_optional(key))]
|
||||
if not obsolete and not missing:
|
||||
print(f"{path.name}: in line with en.xml")
|
||||
return False
|
||||
|
||||
report(path.name, missing, obsolete, check)
|
||||
if not check:
|
||||
write(path, synced_text(path, text, newline, own, missing, obsolete, en_text, en_strings), bom)
|
||||
return True
|
||||
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser(description=__doc__.splitlines()[0])
|
||||
parser.add_argument("codes", nargs="*", help="language codes, e.g. zh cz; every language when none")
|
||||
parser.add_argument("--all", action="store_true", help="add the optional keys (*Desc, Cmd.*) too")
|
||||
parser.add_argument("--check", action="store_true", help="only report, change nothing")
|
||||
args = parser.parse_args()
|
||||
|
||||
en_text, _, _ = read(LANG_DIR / "en.xml")
|
||||
en_strings = strings(en_text)
|
||||
|
||||
if args.codes:
|
||||
paths = [LANG_DIR / f"{code}.xml" for code in args.codes]
|
||||
for path in paths:
|
||||
if not path.is_file():
|
||||
sys.exit(f"no language file {path}")
|
||||
else:
|
||||
paths = sorted(p for p in LANG_DIR.glob("*.xml") if p.name != "en.xml")
|
||||
|
||||
out_of_line = False
|
||||
for path in paths:
|
||||
out_of_line |= sync(path, en_text, en_strings, args.all, args.check)
|
||||
return 1 if args.check and out_of_line else 0
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.exit(main())
|
||||
Reference in New Issue
Block a user