Skip to content

Instantly share code, notes, and snippets.

@PeterTh
Last active February 15, 2025 14:55
Show Gist options
  • Save PeterTh/3b9b8be1aa4a9c87257b825dd4ea3567 to your computer and use it in GitHub Desktop.
Save PeterTh/3b9b8be1aa4a9c87257b825dd4ea3567 to your computer and use it in GitHub Desktop.
Workaround for loading saves from other games on Steam Deck
// This is part of the function that finds the path for the previous games' saves for importing
// ideally you should also cache the result if this is required more than once
using namespace fs = std::filesystem;
std::string path = ph3lib::os::commonFolder(ph3lib::os::CommonFolder::SavedGames) + "/Falcom/Kuro/";
if (fs::exists(path)) {
return path;
}
// special handling for when running on the Steam Deck (or a Wine environment in general)
PH3LIB_INFO("Saves folder {} doesn't exist, maybe Proton?", path);
const auto winePrefix = getenv("WINEPREFIX");
if (winePrefix) {
PH3LIB_INFO(" -> found wine prefix: {}", winePrefix);
if (!fs::exists(fs::path{ winePrefix })) {
PH3LIB_INFO(" -> doesn't exist");
return path;
}
// prefix + path_to_c_mount + (winpath - "C:\")
path = ph3lib::utils::FilePath(winePrefix) + "/../../2138610/pfx/drive_c/" + path.substr(3);
PH3LIB_INFO(" -> checking: {}", path);
if (fs::exists(path)) {
PH3LIB_INFO(" -> success!");
return path;
}
PH3LIB_INFO(" -> doesn't exist");
} else {
PH3LIB_INFO("WINEPREFIX env var not found");
}
@jyrkive
Copy link

jyrkive commented Feb 7, 2025

For reference, the recommended way to obtain the path to the "Saved Games" directory is SHGetKnownFolderPath:

PWSTR savedGamesDirectory;
HRESULT hr = SHGetKnownFolderPath(FOLDERID_SavedGames, 0, nullptr, &savedGamesDirectory);
if (FAILED(hr)) {
    // handle error
}
// savedGamesDirectory now contains the path

@PeterTh
Copy link
Author

PeterTh commented Feb 8, 2025

Right -- that's what ph3lib::os::commonFolder does, but the example is a bit incomplete without that.

@jyrkive
Copy link

jyrkive commented Feb 8, 2025

Heh, I figured it would. I posted my comment for the benefit of others who might stumble upon this gist.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment