Add a plugin type tag and conversion functions

This commit is contained in:
Robbert van der Helm
2020-11-30 21:51:28 +01:00
parent 47baef3107
commit 67388dc2a6
2 changed files with 38 additions and 2 deletions
+21 -1
View File
@@ -5,7 +5,7 @@
namespace fs = boost::filesystem; 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); 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 // 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; << std::hex << machine_type;
throw std::runtime_error(error_msg.str()); 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";
}
}
+17 -1
View File
@@ -29,6 +29,19 @@
*/ */
enum class LibArchitecture { dll_32, dll_64 }; 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. * 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. * @return The detected architecture.
* @throw std::runtime_error If the file is not a .dll file. * @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);