From d11b690708b0684e02195f3f7cbdebf547d8f17f Mon Sep 17 00:00:00 2001 From: Nicole O'Connor Date: Mon, 3 Feb 2025 17:28:18 -0800 Subject: [PATCH] doc a couple files --- include/ansicol.hpp | 2 +- include/bottles.hpp | 6 +++++ src/bottles/bottles.cpp | 33 +++++++++++++++++++++++++ src/modules.txt | 3 +-- src/steam/bottles.cpp | 5 ++++ src/steam/commands.txt | 1 - src/steam/paths.cpp | 8 +++++-- src/steam/test_command.cpp | 49 -------------------------------------- 8 files changed, 52 insertions(+), 55 deletions(-) delete mode 100644 src/steam/commands.txt delete mode 100644 src/steam/test_command.cpp diff --git a/include/ansicol.hpp b/include/ansicol.hpp index 77c7fed..c4919da 100644 --- a/include/ansicol.hpp +++ b/include/ansicol.hpp @@ -1,5 +1,5 @@ /* This file contains string definitions for ANSI color sequences - * it was written by Nicole O'Connor and is available to all + * it was written by Nicole O'Connor and is available to all * under the MIT license. * * Usage: diff --git a/include/bottles.hpp b/include/bottles.hpp index 7348299..a29ccad 100644 --- a/include/bottles.hpp +++ b/include/bottles.hpp @@ -20,6 +20,12 @@ namespace cellar { bottle_labelled, bottle_symlink }; + + /** + * Bottles are the internal name for WINE prefixes. In addition to standard WINE contents, + * bottles contain a configuration file managed by cellar, which labels the bottle as well + * as providing configuration settings. + */ class Bottle { public: // public members diff --git a/src/bottles/bottles.cpp b/src/bottles/bottles.cpp index 4e80381..06195ae 100644 --- a/src/bottles/bottles.cpp +++ b/src/bottles/bottles.cpp @@ -24,6 +24,10 @@ using namespace cellar::bottles; using CommandFunction = cellar::commands::CommandFunction; using json = nlohmann::json; +/** + * @brief Construct an empty bottle object. + * This empty bottle object can then be used to help create new ones. + */ Bottle::Bottle() { // define a null bottle // strings handle themselves @@ -31,6 +35,11 @@ Bottle::Bottle() { type = bottle_anonymous; } +/** + * @brief Construct a bottle object from at a given path. + * + * @param patharg The path to load a bottle from. + */ Bottle::Bottle(string patharg) { output::statement("loading bottle from " + patharg, true); config = json({}); @@ -58,6 +67,14 @@ Bottle::Bottle(string patharg) { } } +/** + * @brief Lists all bottles cellar manages or is otherwise aware of. + * This includes bottles managed by other tools like Steam or Lutris, + * assuming support for those tools is compiled into cellar. (Steam + * support is present; Lutris support is planned for the future.) + * + * @return map All bottles. Bottles managed by other tools have prefixed keys, e.g. Steam bottles use "steam:" + */ map cellar::bottles::get_bottles() { map result; @@ -80,6 +97,19 @@ map cellar::bottles::get_bottles() { return result; } +/** + * @brief Takes an input that refers to a bottle and returns a path to that bottle. + * This input can be any of the following: + * * A bottle name as managed by cellar + * * A prefixed bottle name, in the format `:`. (e.g. `steam:78000`) + * * An absolute or relative path, in which case it is returned with no modification. + * * A path relative to (and starting with ~). cellar will throw a warning in verbose mode, + * since usually the shell expands this for us, but will do a naive replacement on its own + * and try to prevent confused users. + * + * @param bottlechoice Input, usually referring to a specific bottle known to cellar. + * @return string Path to referenced bottle. + */ string cellar::bottles::resolve_bottle(string bottlechoice) { string result; if (bottlechoice.substr(0,1) == "/" || bottlechoice.substr(0,1) == ".") { // absolute or relative path @@ -107,6 +137,9 @@ string cellar::bottles::resolve_bottle(string bottlechoice) { return result; } +/** + * @brief Prints bottles. Used as a command in CLI. + */ void cellar::bottles::print_bottles(int argc, vector argv) { map bottles = get_bottles(); diff --git a/src/modules.txt b/src/modules.txt index 9f4a953..c490b83 100644 --- a/src/modules.txt +++ b/src/modules.txt @@ -1,5 +1,4 @@ core config bottles -launch -steam \ No newline at end of file +launch \ No newline at end of file diff --git a/src/steam/bottles.cpp b/src/steam/bottles.cpp index 01b5e9c..eee9a50 100644 --- a/src/steam/bottles.cpp +++ b/src/steam/bottles.cpp @@ -11,6 +11,11 @@ using namespace tyti; //vdf +/** + * @brief Returns all app bottles managed by Steam. + * + * @return std::map Steam managed bottles. Keys are "steam:". + */ std::map cellar::steam::get_app_bottles() { std::map result; diff --git a/src/steam/commands.txt b/src/steam/commands.txt deleted file mode 100644 index 71e71c1..0000000 --- a/src/steam/commands.txt +++ /dev/null @@ -1 +0,0 @@ -steamtest test_command Test Steam related thing. \ No newline at end of file diff --git a/src/steam/paths.cpp b/src/steam/paths.cpp index 4c4fada..1f552a5 100644 --- a/src/steam/paths.cpp +++ b/src/steam/paths.cpp @@ -12,6 +12,12 @@ using namespace tyti; +/** + * @brief Reads Steam library settings and returns a list of Steam library paths. + * Returns an empty vector if it can't read ~/.steam/root/config/libraryfolders.vdf. + * + * @return std::vector Steam library paths. + */ std::vector cellar::steam::find_steam_libraries() { std::stringstream sstr_steam_library_config; sstr_steam_library_config << std::getenv("HOME"); @@ -23,8 +29,6 @@ std::vector cellar::steam::find_steam_libraries() { if (fd_steam_library_config.fail()) { return result; } // return empty if something went wrong (should cover most problems) auto hnd_steam_library_config = vdf::read(fd_steam_library_config); - std::vector result; - for (auto hnd_library_def : hnd_steam_library_config.childs) { std::string str_index = hnd_library_def.first; auto hnd_library = hnd_library_def.second; diff --git a/src/steam/test_command.cpp b/src/steam/test_command.cpp deleted file mode 100644 index 3259ed2..0000000 --- a/src/steam/test_command.cpp +++ /dev/null @@ -1,49 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include - -#include "vdf_parser.hpp" - -#include "bottles.hpp" -#include "output.hpp" -#include "steam.hpp" -#include "internal/steam.hpp" - -using namespace tyti; // vdf - -void cellar::steam::test_command(int argc, std::vector argv) { - for (std::string str_path_library : cellar::steam::find_steam_libraries()) { - output::statement(str_path_library); - - 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")) { - // \/ string-to-unsigned-long - 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; - } - } - - output::warning("Steam App #" + str_appid + " (" + str_gamename + ")"); - } - } - } -} \ No newline at end of file