diff --git a/extras/Introjucer/Source/Application/jucer_Application.h b/extras/Introjucer/Source/Application/jucer_Application.h index 6aa7727d98..fca52b379a 100644 --- a/extras/Introjucer/Source/Application/jucer_Application.h +++ b/extras/Introjucer/Source/Application/jucer_Application.h @@ -28,6 +28,7 @@ #include "../jucer_Headers.h" #include "jucer_MainWindow.h" #include "jucer_CommandLine.h" +#include "jucer_Module.h" #include "jucer_AutoUpdater.h" #include "../Code Editor/jucer_SourceCodeEditor.h" diff --git a/extras/Introjucer/Source/Application/jucer_AutoUpdater.h b/extras/Introjucer/Source/Application/jucer_AutoUpdater.h index fc422b5911..b5086b2947 100644 --- a/extras/Introjucer/Source/Application/jucer_AutoUpdater.h +++ b/extras/Introjucer/Source/Application/jucer_AutoUpdater.h @@ -141,14 +141,56 @@ return true; } else { -JUCE_COMPILER_WARNING("todo") + File targetFolder (findDefaultModulesFolder()); - File targetFolder; + if (isJuceModulesFolder (targetFolder)) + targetFolder = targetFolder.getParentDirectory(); -// FileChooser f; + FileChooser chooser (TRANS("Please select the location into which you'd like to download the new version"), + targetFolder); - DownloadNewVersionThread::performDownload (info.url, targetFolder); + if (chooser.browseForDirectory()) + { + targetFolder = chooser.getResult(); + + if (isJuceModulesFolder (targetFolder)) + targetFolder = targetFolder.getParentDirectory(); + + if (targetFolder.getChildFile ("JUCE").isDirectory()) + targetFolder = targetFolder.getChildFile ("JUCE"); + + if (targetFolder.getChildFile (".git").isDirectory()) + { + AlertWindow::showMessageBox (AlertWindow::WarningIcon, + TRANS ("Downloading new JUCE version"), + TRANS ("This folder is a GIT repository!\n\n" + "You should use a \"git pull\" to update it to the latest version. " + "Or to use the Introjucer to get an update, you should select an empty " + "folder into which you'd like to download the new code.")); + + return; + } + + if (isJuceFolder (targetFolder)) + { + if (! AlertWindow::showOkCancelBox (AlertWindow::WarningIcon, + TRANS("Overwrite existing JUCE folder?"), + TRANS("Do you want to overwrite the folder:\n\n" + "xfldrx\n\n" + " ..with the latest version from juce.com?\n\n" + "(Please note that this will overwrite everything in that folder!)") + .replace ("xfldrx", targetFolder.getFullPathName()))) + { + return; + } + } + else + { + targetFolder = targetFolder.getChildFile ("JUCE").getNonexistentSibling(); + } + DownloadNewVersionThread::performDownload (info.url, targetFolder); + } } } } @@ -220,7 +262,7 @@ private: } else { -JUCE_COMPILER_WARNING("todo") + new RelaunchTimer (targetFolder); } } } @@ -273,7 +315,8 @@ JUCE_COMPILER_WARNING("todo") { setStatusMessage ("Installing..."); - File tempUnzipped; + File unzipTarget; + bool isUsingTempFolder = false; { MemoryInputStream input (data, false); @@ -282,32 +325,43 @@ JUCE_COMPILER_WARNING("todo") if (zip.getNumEntries() == 0) return Result::fail ("The downloaded file wasn't a valid JUCE file!"); - tempUnzipped = targetFolder.getNonexistentSibling(); + unzipTarget = targetFolder; - if (! tempUnzipped.createDirectory()) - return Result::fail ("Couldn't create a folder to unzip the new version!"); + if (unzipTarget.exists()) + { + isUsingTempFolder = true; + unzipTarget = targetFolder.getNonexistentSibling(); + + if (! unzipTarget.createDirectory()) + return Result::fail ("Couldn't create a folder to unzip the new version!"); + } - Result r (zip.uncompressTo (tempUnzipped)); + Result r (zip.uncompressTo (unzipTarget)); if (r.failed()) { - tempUnzipped.deleteRecursively(); + if (isUsingTempFolder) + unzipTarget.deleteRecursively(); + return r; } } - File oldFolder (targetFolder.getSiblingFile (targetFolder.getFileNameWithoutExtension() + "_old").getNonexistentSibling()); - - if (! targetFolder.moveFileTo (targetFolder.getNonexistentSibling())) + if (isUsingTempFolder) { - tempUnzipped.deleteRecursively(); - return Result::fail ("Could not remove the existing folder!"); - } + File oldFolder (targetFolder.getSiblingFile (targetFolder.getFileNameWithoutExtension() + "_old").getNonexistentSibling()); - if (! tempUnzipped.moveFileTo (targetFolder)) - { - tempUnzipped.deleteRecursively(); - return Result::fail ("Could not overwrite the existing folder!"); + if (! targetFolder.moveFileTo (oldFolder)) + { + unzipTarget.deleteRecursively(); + return Result::fail ("Could not remove the existing folder!"); + } + + if (! unzipTarget.moveFileTo (targetFolder)) + { + unzipTarget.deleteRecursively(); + return Result::fail ("Could not overwrite the existing folder!"); + } } return Result::ok(); @@ -320,6 +374,37 @@ JUCE_COMPILER_WARNING("todo") JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (DownloadNewVersionThread) }; + struct RelaunchTimer : private Timer + { + RelaunchTimer (const File& f) : parentFolder (f) + { + startTimer (1500); + } + + void timerCallback() override + { + stopTimer(); + + File app = parentFolder.getChildFile ( + #if JUCE_MAC + "Introjucer.app"); + #elif JUCE_WINDOWS + "Introjucer.exe"); + #elif JUCE_LINUX + "Introjucer"); + #endif + + JUCEApplication::quit(); + + if (app.exists()) + app.startAsProcess(); + + delete this; + } + + File parentFolder; + }; + JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (LatestVersionChecker) }; diff --git a/extras/Introjucer/Source/Application/jucer_MainWindow.cpp b/extras/Introjucer/Source/Application/jucer_MainWindow.cpp index 341ccce81a..eb0ab70adf 100644 --- a/extras/Introjucer/Source/Application/jucer_MainWindow.cpp +++ b/extras/Introjucer/Source/Application/jucer_MainWindow.cpp @@ -543,3 +543,24 @@ Project* MainWindowList::getFrontmostProject() return nullptr; } + +File findDefaultModulesFolder (bool mustContainJuceCoreModule) +{ + const MainWindowList& windows = IntrojucerApp::getApp().mainWindowList; + + for (int i = windows.windows.size(); --i >= 0;) + { + if (Project* p = windows.windows.getUnchecked (i)->getProject()) + { + const File f (EnabledModuleList::findDefaultModulesFolder (*p)); + + if (isJuceModulesFolder (f) || (f.isDirectory() && ! mustContainJuceCoreModule)) + return f; + } + } + + if (mustContainJuceCoreModule) + return findDefaultModulesFolder (false); + + return File::nonexistent; +} diff --git a/extras/Introjucer/Source/Project/jucer_Module.cpp b/extras/Introjucer/Source/Project/jucer_Module.cpp index 2c33ed6178..4ba59aeb93 100644 --- a/extras/Introjucer/Source/Project/jucer_Module.cpp +++ b/extras/Introjucer/Source/Project/jucer_Module.cpp @@ -895,3 +895,13 @@ void EnabledModuleList::addModuleOfferingToCopy (const File& f) addModule (m.manifestFile, areMostModulesCopiedLocally()); } + +bool isJuceFolder (const File& f) +{ + return isJuceModulesFolder (f.getChildFile ("modules")); +} + +bool isJuceModulesFolder (const File& f) +{ + return f.isDirectory() && f.getChildFile ("juce_core").isDirectory(); +} diff --git a/extras/Introjucer/Source/Project/jucer_Module.h b/extras/Introjucer/Source/Project/jucer_Module.h index 7b72160f66..fecd48319a 100644 --- a/extras/Introjucer/Source/Project/jucer_Module.h +++ b/extras/Introjucer/Source/Project/jucer_Module.h @@ -30,6 +30,11 @@ class ProjectExporter; class ProjectSaver; +//============================================================================== +File findDefaultModulesFolder (bool mustContainJuceCoreModule = true); +bool isJuceModulesFolder (const File&); +bool isJuceFolder (const File&); + //============================================================================== struct ModuleDescription { diff --git a/extras/Introjucer/Source/Project/jucer_ProjectContentComponent.cpp b/extras/Introjucer/Source/Project/jucer_ProjectContentComponent.cpp index 41a9074f65..d3932ebd98 100644 --- a/extras/Introjucer/Source/Project/jucer_ProjectContentComponent.cpp +++ b/extras/Introjucer/Source/Project/jucer_ProjectContentComponent.cpp @@ -241,7 +241,8 @@ void ProjectContentComponent::resized() if (contentView != nullptr) contentView->setBounds (r); - logo->setBounds (r.reduced (r.getWidth() / 4, r.getHeight() / 4)); + if (logo != nullptr) + logo->setBounds (r.reduced (r.getWidth() / 4, r.getHeight() / 4)); } void ProjectContentComponent::lookAndFeelChanged() diff --git a/extras/Introjucer/Source/Wizards/jucer_NewProjectWizard.h b/extras/Introjucer/Source/Wizards/jucer_NewProjectWizard.h index 97e4614f13..616879363b 100644 --- a/extras/Introjucer/Source/Wizards/jucer_NewProjectWizard.h +++ b/extras/Introjucer/Source/Wizards/jucer_NewProjectWizard.h @@ -77,33 +77,6 @@ static File& getLastWizardFolder() return lastFolder; } -static bool isJuceModulesFolder (const File& f) -{ - return f.isDirectory() - && f.getChildFile ("juce_core").isDirectory(); -} - -static File findDefaultModulesFolder (bool mustContainJuceCoreModule = true) -{ - const MainWindowList& windows = IntrojucerApp::getApp().mainWindowList; - - for (int i = windows.windows.size(); --i >= 0;) - { - if (Project* p = windows.windows.getUnchecked (i)->getProject()) - { - const File f (EnabledModuleList::findDefaultModulesFolder (*p)); - - if (isJuceModulesFolder (f) || (f.isDirectory() && ! mustContainJuceCoreModule)) - return f; - } - } - - if (mustContainJuceCoreModule) - return findDefaultModulesFolder (false); - - return File::nonexistent; -} - //============================================================================== struct NewProjectWizard {