|
35 | 35 | #include <Windows.h> |
36 | 36 | #endif |
37 | 37 |
|
| 38 | +namespace fs = std::filesystem; |
38 | 39 |
|
39 | 40 | //----------------------------------------------------------------------- |
40 | 41 | static inline File getPluginsDirectory() { |
@@ -996,9 +997,17 @@ void PluginInfoComponent::buttonClicked(Button* button) |
996 | 997 | if(!uninstallPlugin(pInfo.pluginName)) |
997 | 998 | { |
998 | 999 | LOGE("Failed to uninstall ", pInfo.displayName); |
| 1000 | + AlertWindow::showMessageBoxAsync(AlertWindow::WarningIcon, |
| 1001 | + "[Plugin Installer] " + pInfo.displayName, |
| 1002 | + "Failed to uninstall " + pInfo.displayName); |
999 | 1003 | } |
1000 | 1004 | else |
| 1005 | + { |
1001 | 1006 | LOGC(pInfo.displayName, " uninstalled successfully!"); |
| 1007 | + AlertWindow::showMessageBoxAsync(AlertWindow::InfoIcon, |
| 1008 | + "[Plugin Installer] " + pInfo.displayName, |
| 1009 | + pInfo.displayName + " uninstalled successfully"); |
| 1010 | + } |
1002 | 1011 | } |
1003 | 1012 | else if (button == &documentationButton) |
1004 | 1013 | { |
@@ -1049,7 +1058,7 @@ void PluginInfoComponent::run() |
1049 | 1058 | { |
1050 | 1059 | AlertWindow::showMessageBoxAsync(AlertWindow::WarningIcon, |
1051 | 1060 | "[Plugin Installer] ERROR", |
1052 | | - "Unable to current installed version of " + pInfo.displayName + "... Plugin update failed."); |
| 1061 | + "Unable to remove current installed version of " + pInfo.displayName + "... Plugin update failed."); |
1053 | 1062 |
|
1054 | 1063 | LOGE("Unable to remove current installed version of " + pInfo.displayName + "... Plugin update failed."); |
1055 | 1064 | return; |
@@ -1386,7 +1395,7 @@ bool PluginInfoComponent::uninstallPlugin(const String& plugin) |
1386 | 1395 |
|
1387 | 1396 | //delete plugin file |
1388 | 1397 | File pluginFile = getPluginsDirectory().getChildFile(dllName); |
1389 | | - if(!pluginFile.deleteFile()) |
| 1398 | + if(!pluginFile.deleteRecursively()) |
1390 | 1399 | { |
1391 | 1400 | LOGE("Unable to delete plugin file ", pluginFile.getFullPathName(), " ... Please remove it manually!!"); |
1392 | 1401 | return false; |
@@ -1502,47 +1511,77 @@ int PluginInfoComponent::downloadPlugin(const String& plugin, const String& vers |
1502 | 1511 | } |
1503 | 1512 | } |
1504 | 1513 |
|
1505 | | - // Uncompress plugin zip file in temp directory |
1506 | | - String pluginDllPath; |
1507 | | - |
| 1514 | + // Create temp directory to uncompress the plugin |
1508 | 1515 | File tempDir = File::getSpecialLocation(File::tempDirectory).getChildFile("open-ephys"); |
1509 | 1516 | tempDir.createDirectory(); |
1510 | 1517 |
|
1511 | | - pluginZip.uncompressTo(tempDir); |
| 1518 | + // Delete any existing files in temp directory |
| 1519 | + if (tempDir.getChildFile("plugins").exists()) |
| 1520 | + tempDir.getChildFile("plugins").deleteRecursively(); |
1512 | 1521 |
|
1513 | | - if(!isDependency) |
| 1522 | + if (tempDir.getChildFile("shared").exists()) |
| 1523 | + tempDir.getChildFile("shared").deleteRecursively(); |
| 1524 | + |
| 1525 | + // Uncompress the plugin zip file to temp directory |
| 1526 | + juce::Result res = pluginZip.uncompressTo(tempDir); |
| 1527 | + |
| 1528 | + if (res.failed()) |
1514 | 1529 | { |
1515 | | - // copy plugin DLL from temp directory to actual location |
1516 | | - bool copySuccess = tempDir.getChildFile("plugins").getChildFile(dllName) |
1517 | | - .copyFileTo(getPluginsDirectory().getChildFile(dllName)); |
| 1530 | + LOGE("Failed to uncompress plugin zip file: ", res.getErrorMessage()); |
| 1531 | + tempDir.deleteRecursively(); |
| 1532 | + pluginFile.deleteFile(); |
| 1533 | + return 2; |
| 1534 | + } |
| 1535 | + |
| 1536 | + String pluginDllPath; |
1518 | 1537 |
|
1519 | | - File dllFile = getPluginsDirectory().getChildFile(dllName); |
1520 | | - pluginDllPath = dllFile.getFullPathName(); |
| 1538 | + // copy plugin DLL from temp directory to actual location |
| 1539 | + if(!isDependency) |
| 1540 | + { |
| 1541 | + fs::path tempPluginPath = tempDir.getChildFile("plugins").getFullPathName().toStdString(); |
| 1542 | + fs::path destPluginPath = getPluginsDirectory().getFullPathName().toStdString(); |
1521 | 1543 |
|
1522 | | - if(!copySuccess && !dllFile.exists()) |
| 1544 | + // Copy only if plugin file exists |
| 1545 | + if(fs::exists(tempPluginPath)) |
| 1546 | + { |
| 1547 | + const auto copyOptions = fs::copy_options::overwrite_existing |
| 1548 | + | fs::copy_options::recursive; |
| 1549 | + try { |
| 1550 | + fs::copy(tempPluginPath, destPluginPath, copyOptions); |
| 1551 | + } catch(fs::filesystem_error& e) { |
| 1552 | + LOGE("Could not copy plugin files: \"", e.what(), "\""); |
| 1553 | + tempDir.deleteRecursively(); |
| 1554 | + pluginFile.deleteFile(); |
| 1555 | + return 2; |
| 1556 | + } |
| 1557 | + } |
| 1558 | + else |
1523 | 1559 | { |
1524 | | - LOGE("Unable to copy necessary plugin files!"); |
| 1560 | + LOGE("Plugin file not found in temp directory!!"); |
| 1561 | + tempDir.deleteRecursively(); |
1525 | 1562 | pluginFile.deleteFile(); |
1526 | 1563 | return 2; |
1527 | 1564 | } |
| 1565 | + |
| 1566 | + pluginDllPath = getPluginsDirectory().getChildFile(dllName).getFullPathName(); |
1528 | 1567 | } |
1529 | 1568 |
|
1530 | 1569 | /* Copy shared files |
1531 | 1570 | * Uses C++17's filesystem::copy functionality to allow copying symlinks |
1532 | 1571 | */ |
1533 | | - std::filesystem::path tempSharedPath = tempDir.getChildFile("shared").getFullPathName().toStdString(); |
1534 | | - std::filesystem::path destSharedPath = getSharedDirectory().getFullPathName().toStdString(); |
| 1572 | + fs::path tempSharedPath = tempDir.getChildFile("shared").getFullPathName().toStdString(); |
| 1573 | + fs::path destSharedPath = getSharedDirectory().getFullPathName().toStdString(); |
1535 | 1574 |
|
1536 | 1575 | // Copy only if shared files exist |
1537 | | - if(std::filesystem::exists(tempSharedPath)) |
| 1576 | + if(fs::exists(tempSharedPath)) |
1538 | 1577 | { |
1539 | | - const auto copyOptions = std::filesystem::copy_options::overwrite_existing |
1540 | | - | std::filesystem::copy_options::recursive |
1541 | | - | std::filesystem::copy_options::copy_symlinks |
| 1578 | + const auto copyOptions = fs::copy_options::overwrite_existing |
| 1579 | + | fs::copy_options::recursive |
| 1580 | + | fs::copy_options::copy_symlinks |
1542 | 1581 | ; |
1543 | 1582 | try { |
1544 | | - std::filesystem::copy(tempSharedPath, destSharedPath, copyOptions); |
1545 | | - } catch(std::filesystem::filesystem_error& e) { |
| 1583 | + fs::copy(tempSharedPath, destSharedPath, copyOptions); |
| 1584 | + } catch(fs::filesystem_error& e) { |
1546 | 1585 | LOGE("Could not copy shared files: \"", e.what(), "\""); |
1547 | 1586 | } |
1548 | 1587 | } |
|
0 commit comments