diff --git a/src/common/plugins.cpp b/src/common/plugins.cpp index 1aae7397..b545abc6 100644 --- a/src/common/plugins.cpp +++ b/src/common/plugins.cpp @@ -5,7 +5,7 @@ namespace fs = boost::filesystem; -LibArchitecture find_dll_architecture(fs::path plugin_path) { +LibArchitecture find_dll_architecture(const fs::path& plugin_path) { std::ifstream file(plugin_path, std::ifstream::binary | std::ifstream::in); // The linker will place the offset where the PE signature is placed at the @@ -51,3 +51,23 @@ LibArchitecture find_dll_architecture(fs::path plugin_path) { << std::hex << machine_type; throw std::runtime_error(error_msg.str()); } + +PluginType plugin_type_from_string(const std::string& plugin_type) { + if (plugin_type == "vst2") { + return PluginType::vst2; + } else if (plugin_type == "vst3") { + return PluginType::vst3; + } else { + return PluginType::unknown; + } +} + +std::string plugin_type_to_string(const PluginType& plugin_type) { + if (plugin_type == PluginType::vst2) { + return "vst2"; + } else if (plugin_type == PluginType::vst3) { + return "vst3"; + } else { + return "unknown"; + } +} diff --git a/src/common/plugins.h b/src/common/plugins.h index 2dd310dd..37f69b7a 100644 --- a/src/common/plugins.h +++ b/src/common/plugins.h @@ -29,6 +29,19 @@ */ enum class LibArchitecture { dll_32, dll_64 }; +/** + * A tag to differentiate between different plugin types. + * `plugin_tyep_to_string()` and `plugin_type_from_string()` can be used to + * convert these values to and from strings. The string form is used as a + * command line argument for the individual Wine host applications, and the enum + * form is passed directly in `GroupRequest`. + * + * The `unkonwn` tag is not used directly, but in the event that we do call + * `plugin_type_from_string()` with some invalid value we can use it to + * gracefully show an error message without resorting to exceptions. + */ +enum class PluginType { vst2, vst3, unknown }; + /** * Determine the architecture of a `.dll` file based on the file header. * @@ -40,4 +53,7 @@ enum class LibArchitecture { dll_32, dll_64 }; * @return The detected architecture. * @throw std::runtime_error If the file is not a .dll file. */ -LibArchitecture find_dll_architecture(boost::filesystem::path); +LibArchitecture find_dll_architecture(const boost::filesystem::path&); + +PluginType plugin_type_from_string(const std::string& plugin_type); +std::string plugin_type_to_string(const PluginType& plugin_type);