MCPcopy Create free account
hub / github.com/CalcProgrammer1/OpenRGB / InstallPlugin

Method InstallPlugin

qt/OpenRGBPluginsPage/OpenRGBPluginsPage.cpp:108–164  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

106}
107
108bool Ui::OpenRGBPluginsPage::InstallPlugin(std::string install_file)
109{
110 filesystem::path from_path = filesystem::u8path(install_file);
111 filesystem::path to_path = ResourceManager::get()->GetConfigurationDirectory() / "plugins" / from_path.filename();
112 bool match = false;
113
114 LOG_TRACE("[OpenRGBPluginsPage] Installing plugin %s", install_file.c_str());
115
116 /*-----------------------------------------------------*\
117 | Check if a plugin with this path already exists |
118 \*-----------------------------------------------------*/
119 for(unsigned int plugin_idx = 0; plugin_idx < plugin_manager->ActivePlugins.size(); plugin_idx++)
120 {
121 if(to_path == plugin_manager->ActivePlugins[plugin_idx].path)
122 {
123 match = true;
124 break;
125 }
126 }
127
128 /*-----------------------------------------------------*\
129 | If this plugin already exists, prompt to replace it |
130 \*-----------------------------------------------------*/
131 if(match == true)
132 {
133 QMessageBox::StandardButton reply;
134
135 reply = QMessageBox::question(this, tr("Replace Plugin"), tr("A plugin with this filename is already installed. Are you sure you want to replace this plugin?"), QMessageBox::Yes | QMessageBox::No);
136
137 if(reply != QMessageBox::Yes)
138 {
139 return false;
140 }
141 }
142
143 /*-----------------------------------------------------*\
144 | When replacing, remove the existing plugin before |
145 | copying the file and adding the new one |
146 \*-----------------------------------------------------*/
147 try
148 {
149 plugin_manager->RemovePlugin(to_path);
150
151 LOG_TRACE("[OpenRGBPluginsPage] Copying from %s to %s", from_path.c_str(), to_path.c_str());
152 filesystem::copy(from_path, to_path, filesystem::copy_options::overwrite_existing);
153
154 plugin_manager->AddPlugin(to_path);
155
156 return true;
157 }
158 catch(const std::exception& e)
159 {
160 LOG_ERROR("[OpenRGBPluginsPage] Failed to install plugin: %s", e.what());
161 }
162
163 return false;
164}
165

Callers

nothing calls this directly

Calls 6

getFunction · 0.50
sizeMethod · 0.45
RemovePluginMethod · 0.45
AddPluginMethod · 0.45
whatMethod · 0.45

Tested by

no test coverage detected