Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions clean/installer/src/wg_core/util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -257,12 +257,15 @@ wstring PathForGamePrefix(const wstring& path) {
wstring head = path, tail;
char* u = nullptr;
while (!(u = unixName(head.c_str()))) {
if (head.size() <= 3) return path;
const size_t cut = head.find_last_of(L"\\/");
if (cut == wstring::npos || cut < 3) return path;
if (cut == wstring::npos || cut < 2) return path;
tail = head.substr(cut) + tail;
head.resize(cut);
head.resize(cut == 2 ? 3 : cut); // keep the separator on a drive root: "C:\" converts, "C:" alone is not tried
}
wstring z = L"Z:" + FromUtf8(u) + tail;
string unixPath = u;
if (!tail.empty() && unixPath.size() > 1 && unixPath.back() == '/') unixPath.pop_back(); // a root's Unix name ends in '/'; the tail brings its own separator
wstring z = L"Z:" + FromUtf8(unixPath.c_str()) + tail;
HeapFree(GetProcessHeap(), 0, u);
for (wchar_t& c : z)
if (c == L'/') c = L'\\';
Expand Down
26 changes: 11 additions & 15 deletions clean/installer/tests/wg_core_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -227,24 +227,13 @@ int main() {
card(L"card17", "0x1002\n", "0x7550 \n"); // two RDNA 4 cards: the lower number first
require(Contains(LinuxRdna4Name(drm), L"7550"), "LinuxRdna4Name: cards in number order");
}
// under Wine an RDNA 4 card that Linux reports is found even when Wine's own DXGI names an old Radeon
// under Wine an RDNA 4 card that Linux reports is found even when Wine's own DXGI names an old Radeon. Which cards
// LinuxRdna4Name looks at is checked above on the made-up folder (card20 and card17 included); here DetectGpu must follow it.
if (UnderWine()) {
auto sysfs = [](const wstring& p) { // the C runtime reads to the end of file (sysfs reports 4096 bytes)
string s;
if (FILE* f = _wfopen(p.c_str(), L"rb")) { char b[64]; size_t n; while ((n = fread(b, 1, sizeof b, f)) > 0) s.append(b, n); fclose(f); }
return s;
};
bool linuxRdna4 = false;
for (int i = 0; i < 16 && !linuxRdna4; ++i) {
const wstring dev = L"Z:\\sys\\class\\drm\\card" + std::to_wstring(i) + L"\\device\\";
const unsigned long v = strtoul(sysfs(dev + L"vendor").c_str(), nullptr, 16), id = strtoul(sysfs(dev + L"device").c_str(), nullptr, 16);
linuxRdna4 = v == 0x1002 && (id == 0x7550 || id == 0x7551 || id == 0x7590 || id == 0x7591);
}
const wstring fromLinux = LinuxRdna4Name();
const GpuInfo gpu = DetectGpu();
std::wcout << L"under Wine: Linux reports RDNA 4: " << linuxRdna4 << L"; LinuxRdna4Name: \"" << fromLinux << L"\"; DetectGpu: " << gpu.name << L" (rdna4 " << gpu.rdna4 << L")\n";
require(fromLinux.empty() != linuxRdna4, "LinuxRdna4Name: the RDNA 4 card Linux reports, and only then");
if (linuxRdna4) require(gpu.amd && gpu.rdna4, "DetectGpu under Wine: the RDNA 4 card Linux reports");
std::wcout << L"under Wine: LinuxRdna4Name: \"" << fromLinux << L"\"; DetectGpu: " << gpu.name << L" (rdna4 " << gpu.rdna4 << L")\n";
if (!fromLinux.empty()) require(gpu.amd && gpu.rdna4, "DetectGpu under Wine: the RDNA 4 card Linux reports");
}

// a store's launch exe is a hint only: a launcher stub (REDprelauncher.exe) gives way to the exe discovery
Expand Down Expand Up @@ -321,6 +310,13 @@ int main() {
if (UnderWine())
require(StartsWithI(deep, L"Z:\\") && deep.size() > deepTail.size() && deep.compare(deep.size() - deepTail.size(), deepTail.size(), deepTail) == 0,
"PathForGamePrefix under Wine: a Z: path for missing folders too");
// only the drive's root converts (Wine cannot make a Unix name for a DOS device name like CON, so the first folder fails too):
// the walk still reaches the root, so the path is converted
const wstring rootTail = L"\\con\\F\\model.wgcm", atRoot = PathForGamePrefix(L"C:" + rootTail);
if (UnderWine())
require(StartsWithI(atRoot, L"Z:\\") && atRoot.size() > rootTail.size() && atRoot.compare(atRoot.size() - rootTail.size(), rootTail.size(), rootTail) == 0 &&
atRoot.find(L"\\\\") == wstring::npos,
"PathForGamePrefix under Wine: a Z: path when only the drive's root exists");
require(PathForGamePrefix(L"").empty(), "PathForGamePrefix of an empty path");
// a drive the prefix doesn't map: no Z: path can be made, the path comes back as it is (the install then
// reports it, install.cpp ModelPathForGame)
Expand Down
Loading