From b32259c56deef0fec1d2ef994c6d5f27d9280272 Mon Sep 17 00:00:00 2001 From: Nicole O'Connor Date: Mon, 27 Jan 2025 16:51:54 -0800 Subject: [PATCH] cellar list now includes proton bottles --- include/steam.hpp | 2 ++ src/bottles/bottles.cpp | 11 +++++++++ src/bottles/create.cpp | 2 +- src/steam/bottles.cpp | 50 +++++++++++++++++++++++++++++++++++++++++ 4 files changed, 64 insertions(+), 1 deletion(-) create mode 100644 src/steam/bottles.cpp diff --git a/include/steam.hpp b/include/steam.hpp index 752b847..70bdce4 100644 --- a/include/steam.hpp +++ b/include/steam.hpp @@ -1,9 +1,11 @@ #pragma once +#include #include "bottles.hpp" namespace cellar { namespace steam { extern cellar::bottles::Bottle app_bottle(unsigned appid); + extern std::map get_app_bottles(); } } \ No newline at end of file diff --git a/src/bottles/bottles.cpp b/src/bottles/bottles.cpp index f604191..4265583 100644 --- a/src/bottles/bottles.cpp +++ b/src/bottles/bottles.cpp @@ -9,9 +9,13 @@ #include "nlohmann/json.hpp" #include "bottles.hpp" +#include "cmake.hpp" #include "internal/bottles.hpp" #include "fs.hpp" #include "output.hpp" +#ifdef ENABLE_STEAM +#include "steam.hpp" +#endif using namespace std; using namespace cellar; @@ -66,6 +70,13 @@ map cellar::bottles::get_bottles() { result[item] = output; } +#ifdef ENABLE_STEAM + map bottles_proton = cellar::steam::get_app_bottles(); + for (auto item : bottles_proton) { + result.insert_or_assign(item.first, item.second); + } +#endif + return result; } diff --git a/src/bottles/create.cpp b/src/bottles/create.cpp index dac1941..fed40e5 100644 --- a/src/bottles/create.cpp +++ b/src/bottles/create.cpp @@ -39,7 +39,7 @@ void cellar::bottles::create_bottle(int argc, vector argv) { if (bottlechoice.substr(0,1) == "/" || bottlechoice.substr(0,1) == ".") { // absolute or relative path fullbottlepath = bottlechoice; } else if (bottlechoice.substr(0,1) == "~") { // "absolute" path in home directory, not expanded by the shell for some reason (i've seen some shit) - // this is a naive replacement and will fail if the user tries something like ~nick/.wine + // this is a naive replacement and will fail if the user tries something like ~nicole/.wine // i'm figuring at that point if you're doing that, you'll also recognize if your shell // isn't actually expanding your path... bottlechoice.replace(0,1,getenv("HOME")); diff --git a/src/steam/bottles.cpp b/src/steam/bottles.cpp new file mode 100644 index 0000000..5dc5747 --- /dev/null +++ b/src/steam/bottles.cpp @@ -0,0 +1,50 @@ +#include +#include +#include +#include + +#include "vdf_parser.hpp" + +#include "bottles.hpp" +#include "steam.hpp" +#include "internal/steam.hpp" + +using namespace tyti; //vdf + +std::map cellar::steam::get_app_bottles() { + std::map result; + + for (std::string str_path_library : cellar::steam::find_steam_libraries()) { + std::filesystem::path pth_library(str_path_library); + std::filesystem::path pth_steam_cellar = pth_library / "steamapps/compatdata"; + + for (auto const& itm_appid : std::filesystem::directory_iterator(pth_steam_cellar)) { + auto pth_appid = itm_appid.path(); + if (std::filesystem::is_directory(pth_appid / "pfx") && ! std::filesystem::is_empty(pth_appid / "pfx")) { + std::string str_appid = pth_appid.filename().string(); // should become, e.g. 1124300 + auto pth_appmanifest = pth_library / ("steamapps/appmanifest_" + str_appid + ".acf"); + if (! std::filesystem::exists(pth_appmanifest) ) { continue; } + std::string str_gamename = ""; + + std::ifstream fd_appmanifest(pth_appmanifest); + auto hnd_appmanifest = vdf::read(fd_appmanifest); + for (auto hnd_appmanifest_def : hnd_appmanifest.attribs) { + std::string str_index = hnd_appmanifest_def.first; + std::string str_value = hnd_appmanifest_def.second; + + if (str_index == "name") { + str_gamename = str_value; + break; + } + } + + auto curbottle = cellar::bottles::Bottle(pth_appid.string()); + curbottle.set_config("description", str_gamename); + curbottle.save_config(); + result[std::string("proton-" + pth_appid.filename().string())] = curbottle; + } + } + } + + return result; +} \ No newline at end of file