Skip to content

Play your Steam library's Windows games on a jailbroken PS5.

C++

Give bottles C:\ProgramData and a Temp folder

Leonardo Lobatoa4c0aba018cc
diff --git a/src/runtime/package_installer.cpp b/src/runtime/package_installer.cpp
index e8c87c3..78d4681 100644
--- a/src/runtime/package_installer.cpp
+++ b/src/runtime/package_installer.cpp
@@ -728,6 +728,17 @@ FilesystemPackageInstaller::TemplateMappings() const {
namespace {
bool TitleDirectoriesPublished(const fs::path& title);
+// The folders of a bottle that wineboot makes on a PC and the kit (which lists files only) never brings, as all
+// of them are empty in the template. Under drive_c/users/prospero: Unity's persistent data path needs
+// AppData/LocalLow (Caves of Qud stops at startup without it), and TEMP and TMP name AppData/Local/Temp.
+constexpr const char* kProfileFolders[] = {"AppData/LocalLow", "AppData/Local", "AppData/Local/Temp", "AppData/Roaming",
+ "Documents", "Saved Games", "Desktop", "Downloads",
+ "Music", "Pictures", "Videos"};
+// Under drive_c: C:\ProgramData (Common AppData; the GeForce NOW SDK that Unreal games ship stops Dead by Daylight
+// without it, and Cloud saves map WinProgramData there) and the public Documents folder. They stay private to the
+// app: only Wine opens them.
+constexpr const char* kDriveFolders[] = {"ProgramData", "users/Public/Documents"};
+
// Creates the missing folders of path with an explicit mode, whatever the umask
// (console titles run with umask 0). Existing folders are left as they are.
void CreateDirectoriesWithMode(const fs::path& path, mode_t mode, std::error_code& error) {
@@ -888,9 +899,43 @@ PackageActionResult FilesystemPackageInstaller::RepairBottle(const RuntimeInstal
if (mode != 0600 && (::chmod(path.c_str(), 0600) != 0 || !SyncPath(path, false)))
return Failed("repair-mode", std::string(name) + " permissions could not be restored");
}
+ AddMissingBottleFolders(record, *paths);
return SettleBottleModes(record);
}
+void FilesystemPackageInstaller::AddMissingBottleFolders(const RuntimeInstall& record, const ResolvedPaths& paths) {
+ // A bottle made before a folder joined the lists gets it here. Folders already there are left as they are, whatever
+ // their mode (FTP or a kit downgrade may have opened them), and the missing ones below are made: the profile's
+ // 0777 with bottle-profile-shared (SettleBottleModes then opens what is in them, as Prepare does), the rest 0700.
+ // One that can't be made is logged, never a failure of the repair.
+ const bool shared = ProfileShared(record, paths);
+ const auto drive = paths.bottle / "drive_c";
+ std::vector<std::string> added, failed;
+ const auto ensure = [&](const fs::path& relative, mode_t mode) {
+ struct stat info{};
+ if (::lstat((drive / relative).c_str(), &info) == 0 || errno != ENOENT) return;
+ auto current = platform::ManagedDirectory::Open(drive, platform::DirectoryPolicy::kApprovedTree);
+ for (const auto& part : relative) {
+ auto next = current ? current->OpenChild(part.string(), platform::DirectoryPolicy::kApprovedTree, true, mode)
+ : std::nullopt;
+ if (!next || !next->Sync() || !current->Sync()) {
+ failed.push_back(relative.string());
+ return;
+ }
+ current = std::move(next);
+ }
+ added.push_back(relative.string());
+ };
+ for (const char* folder : kDriveFolders) ensure(folder, 0700);
+ for (const char* folder : kProfileFolders) ensure(fs::path("users/prospero") / folder, shared ? 0777 : 0700);
+ if (operations_.log && (!added.empty() || !failed.empty())) {
+ std::string line = "bottle folders install=" + record.install_id;
+ for (const auto& folder : added) line += " added=" + folder;
+ for (const auto& folder : failed) line += " failed=" + folder;
+ operations_.log(line);
+ }
+}
+
PackageActionResult FilesystemPackageInstaller::SettleBottleModes(const RuntimeInstall& record) {
const auto paths = Resolve(record);
if (!paths) return Failed("kit-invalid", "record or verified kit view is invalid");
@@ -1311,9 +1356,6 @@ PackageActionResult FilesystemPackageInstaller::CopyMappings(
// where Cloud saves cannot see them.
// With bottle-profile-shared the profile's folders are 0777 (FTP runs as root, which has no
// permission bypass) and anything the kit put there is opened up too.
- static constexpr const char* kProfileFolders[] = {"AppData/LocalLow", "AppData/Local", "AppData/Roaming",
- "Documents", "Saved Games", "Desktop", "Downloads",
- "Music", "Pictures", "Videos"};
if (template_stage) {
const fs::path user = staging / profile_relative;
if (shared_profile) {
@@ -1345,6 +1387,14 @@ PackageActionResult FilesystemPackageInstaller::CopyMappings(
for (auto directory = user / folder; directory != staging; directory = directory.parent_path())
copied_directories.insert(directory);
}
+ for (const char* folder : kDriveFolders) {
+ std::string detail;
+ if (!EnsurePrivateDirectories(paths_.host_data_root, staging, staging / "drive_c" / folder, &detail,
+ staging_traversal))
+ return Failed("private-directory", detail);
+ for (auto directory = staging / "drive_c" / folder; directory != staging; directory = directory.parent_path())
+ copied_directories.insert(directory);
+ }
}
if (stage_kind == "template" && !operations_.validate_bottle(staging))
return Failed("template-validation", "staged bottle failed semantic validation");
diff --git a/src/runtime/package_installer.h b/src/runtime/package_installer.h
index 3a59cc2..8daf015 100644
--- a/src/runtime/package_installer.h
+++ b/src/runtime/package_installer.h
@@ -220,6 +220,9 @@ class FilesystemPackageInstaller final : public PackageInstaller {
// The bottle chain's traversal folders (data root, library, library/prefixes, the bottle), with
// the mode new ones get (0711 when shared). Checks admit 0700 and 0711 either way.
PrivateTraversal BottleTraversal(const ResolvedPaths& paths, bool shared = false) const;
+ // Repair: the profile and drive_c folders a bottle made before they were created (kProfileFolders,
+ // kDriveFolders) lacks; logged, never a failure.
+ void AddMissingBottleFolders(const RuntimeInstall& record, const ResolvedPaths& paths);
// The bottle's way to its profile is 0711 and the profile open: the kit has
// bottle-profile-shared and the record's title was made from it (an older shell demands 0700).
bool ProfileShared(const RuntimeInstall& record, const ResolvedPaths& paths) const;
diff --git a/tests/runtime_package_installer_test.cpp b/tests/runtime_package_installer_test.cpp
index 7e1a953..53425c1 100644
--- a/tests/runtime_package_installer_test.cpp
+++ b/tests/runtime_package_installer_test.cpp
@@ -574,11 +574,17 @@ void CompletePublicationAndFreshInspection() {
CHECK(registry.st_uid == ::geteuid());
CHECK((registry.st_mode & 0777) == 0600);
// The profile's empty folders exist although the kit has no file under users/ (Unity needs LocalLow).
- for (const char* folder : {"AppData/LocalLow", "AppData/Roaming", "Documents", "Saved Games"}) {
+ for (const char* folder : {"AppData/LocalLow", "AppData/Roaming", "AppData/Local/Temp", "Documents", "Saved Games"}) {
struct stat profile{};
CHECK(::lstat((bottle / "drive_c/users/prospero" / folder).c_str(), &profile) == 0 && S_ISDIR(profile.st_mode));
CHECK((profile.st_mode & 0777) == 0700);
}
+ // So do C:\ProgramData and the public Documents, which wineboot makes on a PC.
+ for (const char* folder : {"ProgramData", "users/Public", "users/Public/Documents"}) {
+ struct stat made{};
+ CHECK(::lstat((bottle / "drive_c" / folder).c_str(), &made) == 0 && S_ISDIR(made.st_mode));
+ CHECK(made.st_uid == ::geteuid() && (made.st_mode & 0777) == 0700);
+ }
CHECK(installer.ValidateArtifacts(record).state == PackageActionState::kComplete);
CHECK(installer.PublishProfile(record).state == PackageActionState::kComplete);
const auto status = installer.Inspect(record);
@@ -666,8 +672,10 @@ void SharedProfileBottleModes() {
CHECK(ModeOf(path) == 0711);
for (const auto& path : {bottle / "drive_c/windows", bottle / "dosdevices"}) CHECK(ModeOf(path) == 0700);
CHECK(ModeOf(bottle / "drive_c/windows/system.reg") == 0600);
- for (const char* folder : {"", "AppData", "AppData/LocalLow", "AppData/Roaming", "Documents", "Saved Games"})
+ for (const char* folder : {"", "AppData", "AppData/LocalLow", "AppData/Local/Temp", "AppData/Roaming", "Documents",
+ "Saved Games"})
CHECK(ModeOf(profile / folder) == 0777);
+ CHECK(ModeOf(bottle / "drive_c/ProgramData") == 0700 && ModeOf(bottle / "drive_c/users/Public/Documents") == 0700);
CHECK(ModeOf(profile / "token.txt") == 0600 && ModeOf(profile / "AppData/Launcher") == 0700);
CHECK(ModeOf(profile / "Documents/kit.ini") == 0666 && Read(profile / "Documents/kit.ini") == "kit");
CHECK(installer.ValidateArtifacts(record).state == PackageActionState::kComplete);
@@ -693,6 +701,11 @@ void SharedProfileBottleModes() {
CHECK(installer.SettleBottleModes(record).state == PackageActionState::kComplete);
CHECK(installer.RepairBottle(record).state == PackageActionState::kComplete);
}
+ // Repair adds a shared profile's missing folder open to FTP, and C:\ProgramData private.
+ std::filesystem::remove_all(profile / "AppData/Local/Temp");
+ std::filesystem::remove_all(bottle / "drive_c/ProgramData");
+ CHECK(installer.RepairBottle(record).state == PackageActionState::kComplete);
+ CHECK(ModeOf(profile / "AppData/Local/Temp") == 0777 && ModeOf(bottle / "drive_c/ProgramData") == 0700);
// Wine (umask 077) saves 0600 in 0700 folders; settling opens them again. Links are never
// followed, a file with another link (a private one linked in) is left alone, and the
@@ -861,6 +874,28 @@ void UnsharedBottleStaysPrivate() {
CHECK(installer.SettleBottleModes(record).state == PackageActionState::kComplete);
CHECK(installer.RepairBottle(record).state == PackageActionState::kComplete);
CHECK(ModeOf(bottle / "drive_c/users/prospero/Documents/save.dat") == 0600 && ModeOf(game) == 0700);
+ // A bottle made before these folders were: Repair adds them, private, and leaves one FTP opened as it is.
+ std::filesystem::remove_all(bottle / "drive_c/ProgramData");
+ std::filesystem::remove_all(bottle / "drive_c/users/Public");
+ std::filesystem::remove_all(bottle / "drive_c/users/prospero/AppData/Local");
+ CHECK(::chmod((bottle / "drive_c/users/prospero/Saved Games").c_str(), 0777) == 0);
+ CHECK(installer.RepairBottle(record).state == PackageActionState::kComplete);
+ for (const auto& path : {bottle / "drive_c/ProgramData", bottle / "drive_c/users/Public/Documents",
+ bottle / "drive_c/users/prospero/AppData/Local/Temp"})
+ CHECK(ModeOf(path) == 0700);
+ CHECK(ModeOf(bottle / "drive_c/users/prospero/Saved Games") == 0777);
+ CHECK(installer.RepairBottle(record).state == PackageActionState::kComplete);
+ // Under a folder FTP opened (or a kit downgrade left open), the missing one is still made, private.
+ std::filesystem::remove_all(bottle / "drive_c/users/prospero/AppData/Local/Temp");
+ CHECK(::chmod((bottle / "drive_c/users/prospero/AppData/Local").c_str(), 0777) == 0);
+ CHECK(installer.RepairBottle(record).state == PackageActionState::kComplete);
+ CHECK(ModeOf(bottle / "drive_c/users/prospero/AppData/Local/Temp") == 0700);
+ CHECK(ModeOf(bottle / "drive_c/users/prospero/AppData/Local") == 0777);
+ // A bottle without its profile at all gets it back.
+ std::filesystem::remove_all(bottle / "drive_c/users/prospero");
+ CHECK(installer.RepairBottle(record).state == PackageActionState::kComplete);
+ for (const char* folder : {"", "AppData/LocalLow", "AppData/Local/Temp", "Documents", "Saved Games"})
+ CHECK(ModeOf(bottle / "drive_c/users/prospero" / folder) == 0700);
}
void CancelAndSpaceFailuresAreBounded() {