Limo
A simple mod manager
Loading...
Searching...
No Matches
tool.h
Go to the documentation of this file.
1
5
6#pragma once
7
8#include <filesystem>
9#include <json/json.h>
10#include <map>
11
12
16class Tool
17{
18public:
31
33 Tool() = default;
40 Tool(const std::string& name, const std::filesystem::path& icon_path, const std::string& command);
50 Tool(const std::string& name,
51 const std::filesystem::path& icon_path,
52 const std::filesystem::path& executable_path,
53 const std::filesystem::path& working_directory,
54 const std::map<std::string, std::string>& environment_variables,
55 const std::string& arguments);
66 Tool(const std::string& name,
67 const std::filesystem::path& icon_path,
68 const std::filesystem::path& executable_path,
69 const std::filesystem::path& prefix_path,
70 const std::filesystem::path& working_directory,
71 const std::map<std::string, std::string>& environment_variables,
72 const std::string& arguments);
85 Tool(const std::string& name,
86 const std::filesystem::path& icon_path,
87 const std::filesystem::path& executable_path,
88 bool use_flatpak_protontricks,
89 int steam_app_id,
90 const std::filesystem::path& working_directory,
91 const std::map<std::string, std::string>& environment_variables,
92 const std::string& arguments,
93 const std::string& protontricks_arguments);
101 Tool(const std::string& name,
102 const std::filesystem::path& icon_path,
103 int steam_app_id,
104 bool use_flatpak_steam);
109 Tool(const Json::Value& json_object);
110
116 std::string getCommand(bool is_flatpak) const;
121 Json::Value toJson() const;
126 std::string getName() const;
131 std::filesystem::path getIconPath() const;
136 std::filesystem::path getExecutablePath() const;
141 Runtime getRuntime() const;
146 bool usesFlatpakRuntime() const;
151 std::filesystem::path getPrefixPath() const;
156 int getSteamAppId() const;
161 std::filesystem::path getWorkingDirectory() const;
166 std::map<std::string, std::string> const getEnvironmentVariables() const;
171 std::string getArguments() const;
176 std::string getProtontricksArguments() const;
182 std::string getCommandOverwrite() const;
183
184private:
186 std::string name_;
188 std::filesystem::path icon_path_;
190 std::filesystem::path executable_path_;
196 std::filesystem::path prefix_path_;
203 std::filesystem::path working_directory_;
205 std::map<std::string, std::string> environment_variables_;
207 std::string arguments_;
211 std::string command_overwrite_ = "";
212
219 void appendEnvironmentVariables(std::string& command,
220 const std::map<std::string, std::string>& environment_variables,
221 bool is_flatpak) const;
227 std::string encloseInQuotes(const std::string& string) const;
228};
std::map< std::string, std::string > const getEnvironmentVariables() const
Returns a map containing environment variables and their values.
Definition tool.cpp:206
Runtime getRuntime() const
Returns the runtime used to run the tool.
Definition tool.cpp:181
Tool(const std::string &name, const std::filesystem::path &icon_path, int steam_app_id, bool use_flatpak_steam)
Constructs a tool using the steam runtime.
std::string command_overwrite_
If not empty: Ignore all other settings and run this command directly.
Definition tool.h:211
std::filesystem::path icon_path_
Path to an icon representing the tool.
Definition tool.h:188
std::filesystem::path prefix_path_
If runtime is wine: Path to the wine prefix.
Definition tool.h:196
std::filesystem::path getExecutablePath() const
Returns the path to the executable of the tool.
Definition tool.cpp:176
std::string getCommandOverwrite() const
Returns the overwrite command. If this is not empty: Ignore all other settings and run this command d...
Definition tool.cpp:221
Tool(const std::string &name, const std::filesystem::path &icon_path, const std::filesystem::path &executable_path, bool use_flatpak_protontricks, int steam_app_id, const std::filesystem::path &working_directory, const std::map< std::string, std::string > &environment_variables, const std::string &arguments, const std::string &protontricks_arguments)
Constructs a tool using the protontricks runtime.
bool use_flatpak_runtime_
If runtime is proton or steam: Whether to use the flatpak version.
Definition tool.h:194
bool usesFlatpakRuntime() const
Returns true if flatpak version of protontricks or steam is used.
Definition tool.cpp:186
std::filesystem::path executable_path_
Path to the executable of the tool.
Definition tool.h:190
std::string getCommand(bool is_flatpak) const
Constructs the command used to run this tool and returns it.
Definition tool.cpp:87
std::string getArguments() const
Returns the arguments to be passed to the executable.
Definition tool.cpp:211
std::filesystem::path working_directory_
Working directory in which to run the command.
Definition tool.h:203
Tool()=default
Default constructor.
std::map< std::string, std::string > environment_variables_
Maps environment variables to their values.
Definition tool.h:205
Tool(const std::string &name, const std::filesystem::path &icon_path, const std::string &command)
Constructs a tool that runs the given command directly.
Runtime
Describes how the tool is to be run.
Definition tool.h:21
@ protontricks
Tool is to be run through proton by calling protontricks.
Definition tool.h:27
@ native
Tool is to be run directly.
Definition tool.h:23
@ steam
Tool is a steam app.
Definition tool.h:29
@ wine
Tool is to be run through wine.
Definition tool.h:25
std::filesystem::path getIconPath() const
Returns the path to an icon representing the tool.
Definition tool.cpp:171
std::filesystem::path getPrefixPath() const
Returns the path to the wine prefix.
Definition tool.cpp:191
Runtime runtime_
Runtime used to run the tool.
Definition tool.h:192
std::filesystem::path getWorkingDirectory() const
Returns the working directory in which to run the command.
Definition tool.cpp:201
std::string name_
Name of the tool.
Definition tool.h:186
std::string protontricks_arguments_
Arguments to be passed to protontricks.
Definition tool.h:209
std::string encloseInQuotes(const std::string &string) const
Encloses the given string in quotes, if it is not already enclosed.
Definition tool.cpp:241
Json::Value toJson() const
Serializes this object to JSON.
Definition tool.cpp:143
void appendEnvironmentVariables(std::string &command, const std::map< std::string, std::string > &environment_variables, bool is_flatpak) const
Appends the given environment variables to the given command.
Definition tool.cpp:226
Tool(const std::string &name, const std::filesystem::path &icon_path, const std::filesystem::path &executable_path, const std::filesystem::path &prefix_path, const std::filesystem::path &working_directory, const std::map< std::string, std::string > &environment_variables, const std::string &arguments)
Constructs a tool using the wine runtime.
int getSteamAppId() const
Returns the ID of the steam app containing the proton prefix.
Definition tool.cpp:196
std::string getName() const
Return this tool's name.
Definition tool.cpp:166
Tool(const std::string &name, const std::filesystem::path &icon_path, const std::filesystem::path &executable_path, const std::filesystem::path &working_directory, const std::map< std::string, std::string > &environment_variables, const std::string &arguments)
Constructs a tool using the native runtime.
std::string getProtontricksArguments() const
Returns the arguments to be passed to protontricks.
Definition tool.cpp:216
int steam_app_id_
If runtime is proton: ID of the steam app containing the proton prefix. If runtime is Steam: ID of th...
Definition tool.h:201
std::string arguments_
Arguments to be passed to the executable.
Definition tool.h:207