Skip to content

Commit e137059

Browse files
committed
Also show security warning when opening plugdata packages from the internet
1 parent 77f87b1 commit e137059

2 files changed

Lines changed: 46 additions & 28 deletions

File tree

Source/PluginEditor.cpp

Lines changed: 45 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -856,35 +856,53 @@ void PluginEditor::fileDragMove(StringArray const& files, int const x, int const
856856

857857
void PluginEditor::installPackage(File const& file)
858858
{
859-
auto zip = ZipFile(file);
860-
auto patchesDir = ProjectInfo::appDataDir.getChildFile("Patches");
861-
auto extractedDir = File::createTempFile("");
862-
auto const result = zip.uncompressTo(extractedDir, false);
863-
if (result.wasOk()) {
864-
auto const macOSTrash = ProjectInfo::appDataDir.getChildFile("Patches").getChildFile("__MACOSX");
865-
if (macOSTrash.isDirectory()) {
866-
macOSTrash.deleteRecursively();
867-
}
868-
869-
auto extractedLocation = extractedDir.getChildFile(zip.getEntry(0)->filename);
870-
auto const metaFile = extractedLocation.getChildFile("meta.json");
871-
if (!metaFile.existsAsFile()) {
872-
PatchInfo info;
873-
info.title = file.getFileNameWithoutExtension();
874-
info.setInstallTime(Time::currentTimeMillis());
875-
auto json = info.json;
876-
metaFile.replaceWithText(info.json);
859+
auto install = [this, file]{
860+
auto zip = ZipFile(file);
861+
auto patchesDir = ProjectInfo::appDataDir.getChildFile("Patches");
862+
auto extractedDir = File::createTempFile("");
863+
auto const result = zip.uncompressTo(extractedDir, false);
864+
if (result.wasOk()) {
865+
auto const macOSTrash = ProjectInfo::appDataDir.getChildFile("Patches").getChildFile("__MACOSX");
866+
if (macOSTrash.isDirectory()) {
867+
macOSTrash.deleteRecursively();
868+
}
869+
870+
auto extractedLocation = extractedDir.getChildFile(zip.getEntry(0)->filename);
871+
auto const metaFile = extractedLocation.getChildFile("meta.json");
872+
if (!metaFile.existsAsFile()) {
873+
PatchInfo info;
874+
info.title = file.getFileNameWithoutExtension();
875+
info.setInstallTime(Time::currentTimeMillis());
876+
auto json = info.json;
877+
metaFile.replaceWithText(info.json);
878+
} else {
879+
auto info = PatchInfo(JSON::fromString(metaFile.loadFileAsString()));
880+
info.setInstallTime(Time::currentTimeMillis());
881+
auto json = info.json;
882+
metaFile.replaceWithText(info.json);
883+
extractedLocation.moveFileTo(patchesDir.getChildFile(info.getNameInPatchFolder()));
884+
}
885+
MessageManager::callAsync([this, file]{
886+
Dialogs::showMultiChoiceDialog(&openedDialog, this, "Successfully installed " + file.getFileNameWithoutExtension(), [](int) { }, { "Dismiss" }, Icons::Checkmark);
887+
});
888+
877889
} else {
878-
auto info = PatchInfo(JSON::fromString(metaFile.loadFileAsString()));
879-
info.setInstallTime(Time::currentTimeMillis());
880-
auto json = info.json;
881-
metaFile.replaceWithText(info.json);
882-
extractedLocation.moveFileTo(patchesDir.getChildFile(info.getNameInPatchFolder()));
890+
MessageManager::callAsync([this, file]{
891+
Dialogs::showMultiChoiceDialog(&openedDialog, this, "Failed to install " + file.getFileNameWithoutExtension(), [](int) { }, { "Dismiss" });
892+
});
883893
}
884-
885-
Dialogs::showMultiChoiceDialog(&openedDialog, this, "Successfully installed " + file.getFileNameWithoutExtension(), [](int) { }, { "Dismiss" }, Icons::Checkmark);
886-
} else {
887-
Dialogs::showMultiChoiceDialog(&openedDialog, this, "Failed to install " + file.getFileNameWithoutExtension(), [](int) { }, { "Dismiss" });
894+
};
895+
896+
if(OSUtils::isFileQuarantined(file))
897+
{
898+
Dialogs::showMultiChoiceDialog(&openedDialog, this, "This patch was downloaded from the internet. Installing patches from untrusted sources may pose security risks. Do you want to proceed?" , [install, file](int const choice) {
899+
if (choice == 0) {
900+
OSUtils::removeFromQuarantine(file);
901+
install();
902+
} }, { "Trust and Install", "Cancel" }, Icons::Warning);
903+
}
904+
else {
905+
install();
888906
}
889907
}
890908

Source/Utility/OSUtils.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -574,7 +574,7 @@ bool OSUtils::isFileQuarantined(const juce::File& file)
574574
void OSUtils::removeFromQuarantine(const juce::File& file)
575575
{
576576
#if JUCE_MAC
577-
const const char* attrName = "com.apple.quarantine";
577+
const char* attrName = "com.apple.quarantine";
578578
const char* path = file.getFullPathName().toRawUTF8();
579579
removexattr(path, attrName, 0);
580580
#elif JUCE_WINDOWS

0 commit comments

Comments
 (0)