MissingFilesDialog.cpp 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672
  1. #include "ui/MissingFilesDialog.h"
  2. #include "core/SearchIndex.h"
  3. #include "engine/PluginHost.h"
  4. #include "ui/FileChoosers.h"
  5. #include "ui/I18n.h"
  6. #include "ui/Theme.h"
  7. #include "ui/WindowOwner.h"
  8. namespace lynx
  9. {
  10. namespace
  11. {
  12. juce::String u8 (const std::string& s) { return juce::String::fromUTF8 (s.c_str()); }
  13. // "Used by" names come from core/MissingFiles in English ("Audio clip: Hook", "Insert 3: effect", "Master: effect")
  14. juce::String userName (const std::string& user)
  15. {
  16. auto u = u8 (user);
  17. juce::String suffix;
  18. if (u.endsWith (": effect"))
  19. {
  20. u = u.dropLastCharacters (8);
  21. suffix = ": " + tr ("effect");
  22. }
  23. if (u.startsWith ("Audio clip: "))
  24. u = tr ("Audio clip") + ": " + u.substring (12);
  25. else if (u == "Master")
  26. u = tr ("Master");
  27. else if (u.startsWith ("Insert ") && u.substring (7).containsOnly ("0123456789"))
  28. u = tr ("Insert {0}", { u.substring (7) });
  29. return u + suffix;
  30. }
  31. juce::File searchFoldersFile() { return PluginHost::settingsFolder().getChildFile ("search-folders.txt"); }
  32. // Recursive search of folders for the missing files' names, off the UI thread.
  33. class SearchThread final : public juce::Thread
  34. {
  35. public:
  36. SearchThread (std::vector<MissingFile> m, juce::StringArray f, std::function<void (std::vector<std::string>, bool)> done)
  37. : juce::Thread ("LYNX missing-files search"), missing (std::move (m)), folders (std::move (f)), onDone (std::move (done))
  38. {
  39. }
  40. ~SearchThread() override { stopThread (4000); }
  41. std::atomic<int> scanned { 0 };
  42. void run() override
  43. {
  44. std::vector<std::string> hits;
  45. auto list = [this] (const std::string& folder, const std::function<bool (const std::string&, bool)>& onEntry) {
  46. #if JUCE_MAC
  47. // not JUCE's iterator on macOS: one name NSString rejects would end the app (issue #42)
  48. const juce::File dir (u8 (folder));
  49. for (const auto& name : search::listFolderNames (folder))
  50. {
  51. const auto f = dir.getChildFile (juce::String::fromUTF8 (name.data(), (int) name.size()).convertToPrecomposedUnicode());
  52. if (f.isHidden() || name[0] == '.')
  53. continue;
  54. ++scanned;
  55. if (! onEntry (f.getFullPathName().toStdString(), f.isDirectory()))
  56. return;
  57. }
  58. #else
  59. for (const auto& entry : juce::RangedDirectoryIterator (juce::File (u8 (folder)), false, "*",
  60. juce::File::findFilesAndDirectories | juce::File::ignoreHiddenFiles))
  61. {
  62. ++scanned;
  63. if (! onEntry (entry.getFile().getFullPathName().toStdString(), entry.isDirectory()))
  64. return;
  65. }
  66. #endif
  67. };
  68. for (const auto& folder : folders)
  69. {
  70. auto found = searchFolderForMissing (missing, folder.toStdString(), list, 2000000, [this] { return threadShouldExit(); });
  71. hits.insert (hits.end(), found.begin(), found.end());
  72. if (threadShouldExit())
  73. break;
  74. }
  75. const auto cancelled = threadShouldExit();
  76. juce::MessageManager::callAsync ([done = onDone, hits = std::move (hits), cancelled]() mutable { done (std::move (hits), cancelled); });
  77. }
  78. private:
  79. std::vector<MissingFile> missing;
  80. juce::StringArray folders;
  81. std::function<void (std::vector<std::string>, bool)> onDone;
  82. };
  83. class MissingFilesPanel final : public juce::Component,
  84. private juce::ListBoxModel,
  85. private juce::Timer
  86. {
  87. public:
  88. enum class Page { samples, plugins, found };
  89. MissingFilesPanel (MissingFilesInfo i, bool live) : info (std::move (i)), persistent (live)
  90. {
  91. title.setText (tr ("Missing files"), juce::dontSendNotification);
  92. title.setFont (theme::font (theme::type::display, true));
  93. addAndMakeVisible (title);
  94. summary.setFont (theme::font (theme::type::body));
  95. summary.setColour (juce::Label::textColourId, theme::colour::textSecondary);
  96. summary.setJustificationType (juce::Justification::topLeft);
  97. addAndMakeVisible (summary);
  98. for (auto* b : { &samplesTab, &pluginsTab, &foundTab })
  99. {
  100. b->setClickingTogglesState (true);
  101. b->setRadioGroupId (81);
  102. b->setColour (juce::TextButton::buttonOnColourId, theme::colour::accentMuted);
  103. b->setColour (juce::TextButton::textColourOnId, theme::colour::textPrimary);
  104. addAndMakeVisible (b);
  105. }
  106. samplesTab.onClick = [this] { showPage (Page::samples); };
  107. pluginsTab.onClick = [this] { showPage (Page::plugins); };
  108. foundTab.onClick = [this] { showPage (Page::found); };
  109. list.setModel (this);
  110. list.setRowHeight (46);
  111. list.setColour (juce::ListBox::backgroundColourId, theme::colour::bg0);
  112. list.setColour (juce::ListBox::outlineColourId, theme::colour::border);
  113. list.setOutlineThickness (1);
  114. list.setMultipleSelectionEnabled (true);
  115. addAndMakeVisible (list);
  116. searchButton.onClick = [this] { chooseSearchFolder(); };
  117. locateButton.onClick = [this] { locateSelected(); };
  118. skipButton.onClick = [this] { toggleSkipSelected(); };
  119. stopButton.onClick = [this] { stopSearch(); };
  120. for (auto* b : { &searchButton, &locateButton, &skipButton, &stopButton })
  121. addAndMakeVisible (b);
  122. stopButton.setVisible (false);
  123. status.setFont (theme::font (theme::type::small));
  124. status.setColour (juce::Label::textColourId, theme::colour::textSecondary);
  125. addAndMakeVisible (status);
  126. rememberToggle.setButtonText (tr ("Remember the folders I search"));
  127. rememberToggle.setToggleState (true, juce::dontSendNotification);
  128. addAndMakeVisible (rememberToggle);
  129. applyButton.setColour (juce::TextButton::buttonColourId, theme::colour::accent);
  130. applyButton.setColour (juce::TextButton::textColourOffId, theme::colour::onAccent);
  131. applyButton.onClick = [this] { apply(); };
  132. closeButton.onClick = [this] { close(); };
  133. addAndMakeVisible (applyButton);
  134. addAndMakeVisible (closeButton);
  135. if (persistent)
  136. folders = loadSearchFolders();
  137. showPage (! info.files.empty() ? Page::samples : ! info.plugins.empty() ? Page::plugins : Page::found);
  138. refresh();
  139. setSize (760, 560);
  140. }
  141. ~MissingFilesPanel() override
  142. {
  143. stopTimer();
  144. search.reset();
  145. }
  146. std::function<void (const std::map<std::string, std::string>&)> onApply;
  147. std::function<void()> onCloseRequest; // the window's; none in snapshots
  148. void showPageForSnapshot (int p, int row)
  149. {
  150. showPage (p == 1 ? Page::plugins : p == 2 ? Page::found : Page::samples);
  151. if (row >= 0)
  152. list.selectRow (row);
  153. refresh();
  154. if (p == 0)
  155. status.setText (tr ("{0} still missing, {1} found", { "2", "2" }), juce::dontSendNotification);
  156. }
  157. // the remembered search folders and the Browser's folders, searched without asking
  158. void searchRememberedFolders()
  159. {
  160. juce::StringArray all (info.searchFolders);
  161. for (const auto& f : folders)
  162. all.addIfNotAlreadyThere (u8 (f));
  163. all.addArray (browserSearchFolders());
  164. all.removeDuplicates (true);
  165. for (int i = all.size(); --i >= 0;)
  166. if (! juce::File (all[i]).isDirectory())
  167. all.remove (i);
  168. if (! all.isEmpty() && stillMissing() > 0)
  169. startSearch (all, false);
  170. }
  171. void paint (juce::Graphics& g) override
  172. {
  173. g.fillAll (theme::colour::bg2);
  174. // header band with the accent mark
  175. g.setColour (theme::colour::bg3);
  176. g.fillRect (header);
  177. g.setColour (theme::colour::accent);
  178. g.fillRect (header.withWidth (4));
  179. g.setColour (theme::colour::border);
  180. g.drawHorizontalLine (header.getBottom(), 0.0f, (float) getWidth());
  181. g.drawHorizontalLine (footer.getY() - 1, 0.0f, (float) getWidth());
  182. }
  183. void resized() override
  184. {
  185. auto area = getLocalBounds();
  186. header = area.removeFromTop (56 + 18 * juce::jmax (1, summaryLines));
  187. {
  188. auto h = header.reduced (20, 12);
  189. h.removeFromLeft (4);
  190. title.setBounds (h.removeFromTop (28));
  191. summary.setBounds (h);
  192. }
  193. footer = area.removeFromBottom (54);
  194. {
  195. auto f = footer.reduced (16, 12);
  196. closeButton.setBounds (f.removeFromRight (150));
  197. f.removeFromRight (8);
  198. applyButton.setBounds (f.removeFromRight (150));
  199. rememberToggle.setBounds (f.removeFromLeft (280));
  200. }
  201. area.reduce (16, 12);
  202. {
  203. auto tabs = area.removeFromTop (28);
  204. for (auto* b : { &samplesTab, &pluginsTab, &foundTab })
  205. {
  206. b->setBounds (tabs.removeFromLeft (juce::jmax (120, juce::GlyphArrangement::getStringWidthInt (juce::Font (theme::font (theme::type::body)), b->getButtonText()) + 28)));
  207. tabs.removeFromLeft (6);
  208. }
  209. }
  210. area.removeFromTop (10);
  211. auto actions = area.removeFromBottom (30);
  212. area.removeFromBottom (10);
  213. list.setBounds (area);
  214. if (page == Page::samples)
  215. {
  216. searchButton.setBounds (actions.removeFromLeft (150));
  217. actions.removeFromLeft (8);
  218. locateButton.setBounds (actions.removeFromLeft (110));
  219. actions.removeFromLeft (8);
  220. skipButton.setBounds (actions.removeFromLeft (110));
  221. actions.removeFromLeft (12);
  222. }
  223. stopButton.setBounds (actions.removeFromRight (80));
  224. status.setBounds (actions);
  225. }
  226. private:
  227. int stillMissing() const
  228. {
  229. return (int) std::count_if (info.files.begin(), info.files.end(), [] (const MissingFile& m) { return m.found.empty() && ! m.skipped; });
  230. }
  231. int foundCount() const
  232. {
  233. return (int) std::count_if (info.files.begin(), info.files.end(), [] (const MissingFile& m) { return ! m.found.empty() && ! m.skipped; });
  234. }
  235. void refresh()
  236. {
  237. const auto missing = stillMissing(), found = foundCount();
  238. juce::StringArray lines;
  239. if (! info.files.empty())
  240. lines.add (tr ("{0} sample(s) used by {1} could not be found on this PC.",
  241. { juce::String ((int) info.files.size()), info.projectName.isNotEmpty() ? info.projectName : tr ("this project") }));
  242. if (! info.plugins.empty())
  243. lines.add (tr ("{0} plugin(s) will not sound as in FL Studio (not installed, not loaded, or without their settings): see what LYNX SHARE did with each.",
  244. { juce::String ((int) info.plugins.size()) }));
  245. if (! info.autoRelocated.empty())
  246. lines.add (tr ("{0} file(s) were found automatically in another folder.", { juce::String ((int) info.autoRelocated.size()) }));
  247. if (lines.isEmpty())
  248. lines.add (tr ("Nothing is missing: every sample and plugin this project uses was found."));
  249. summaryLines = lines.size();
  250. summary.setText (lines.joinIntoString ("\n"), juce::dontSendNotification);
  251. samplesTab.setButtonText (tr ("Samples ({0})", { juce::String ((int) info.files.size()) }));
  252. pluginsTab.setButtonText (tr ("Plugins ({0})", { juce::String ((int) info.plugins.size()) }));
  253. foundTab.setButtonText (tr ("Found automatically ({0})", { juce::String ((int) info.autoRelocated.size()) }));
  254. const auto searching = search != nullptr;
  255. if (! searching && page == Page::samples)
  256. status.setText (info.files.empty() ? juce::String()
  257. : missing == 0 ? tr ("Every sample has a place. Apply to use them.")
  258. : tr ("{0} still missing, {1} found", { juce::String (missing), juce::String (found) }),
  259. juce::dontSendNotification);
  260. const auto samplesPage = page == Page::samples;
  261. for (auto* b : { &searchButton, &locateButton, &skipButton })
  262. b->setVisible (samplesPage);
  263. searchButton.setEnabled (! searching && missing > 0);
  264. locateButton.setEnabled (! searching && list.getNumSelectedRows() > 0);
  265. skipButton.setEnabled (list.getNumSelectedRows() > 0);
  266. stopButton.setVisible (searching && samplesPage);
  267. if (page == Page::plugins)
  268. status.setText (info.plugins.empty() ? juce::String() : tr ("Install them, scan for plugins (Options menu), then open the project again."), juce::dontSendNotification);
  269. else if (page == Page::found)
  270. status.setText (info.autoRelocated.empty() ? juce::String() : tr ("Already in use: nothing to do. Save the project to keep the new places."), juce::dontSendNotification);
  271. applyButton.setButtonText (found > 0 ? tr ("Apply ({0})", { juce::String (found) }) : tr ("Apply"));
  272. applyButton.setEnabled (found > 0 && ! searching);
  273. closeButton.setButtonText (found > 0 ? tr ("Close without changes") : tr ("Close"));
  274. rememberToggle.setVisible (! info.files.empty());
  275. list.updateContent();
  276. list.repaint();
  277. resized();
  278. }
  279. void showPage (Page p)
  280. {
  281. page = p;
  282. (p == Page::samples ? samplesTab : p == Page::plugins ? pluginsTab : foundTab).setToggleState (true, juce::dontSendNotification);
  283. list.deselectAllRows();
  284. list.setMultipleSelectionEnabled (p == Page::samples);
  285. refresh();
  286. }
  287. // --- list ---------------------------------------------------------------------------------
  288. int getNumRows() override
  289. {
  290. return page == Page::samples ? (int) info.files.size() : page == Page::plugins ? (int) info.plugins.size() : (int) info.autoRelocated.size();
  291. }
  292. void paintListBoxItem (int row, juce::Graphics& g, int width, int height, bool selected) override
  293. {
  294. if (selected)
  295. {
  296. g.setColour (theme::colour::accentMuted);
  297. g.fillRect (0, 0, width, height);
  298. g.setColour (theme::colour::accent);
  299. g.fillRect (0, 3, 3, height - 6);
  300. }
  301. else if (row % 2 == 1)
  302. {
  303. g.setColour (theme::colour::bg1);
  304. g.fillRect (0, 0, width, height);
  305. }
  306. juce::Colour dot;
  307. juce::String name, right, detail;
  308. juce::Colour detailColour = theme::colour::textDisabled;
  309. if (page == Page::samples)
  310. {
  311. const auto& m = info.files[(std::size_t) row];
  312. name = u8 (pathFileName (m.path));
  313. juce::StringArray users;
  314. for (const auto& u : m.usedBy)
  315. users.add (userName (u));
  316. right = users.joinIntoString (", ");
  317. if (m.skipped)
  318. {
  319. dot = theme::colour::textDisabled;
  320. detail = tr ("Skipped: stays silent") + " " + u8 (m.path);
  321. }
  322. else if (! m.found.empty())
  323. {
  324. dot = theme::colour::ledOn;
  325. detail = juce::String::fromUTF8 ("\xe2\x86\x92 ") + u8 (m.found);
  326. detailColour = theme::colour::ledOn.withAlpha (0.85f);
  327. }
  328. else
  329. {
  330. dot = theme::colour::warning;
  331. detail = u8 (m.path);
  332. }
  333. }
  334. else if (page == Page::plugins)
  335. {
  336. const auto& p = info.plugins[(std::size_t) row];
  337. dot = theme::colour::warning;
  338. name = u8 (p.name);
  339. juce::StringArray users;
  340. for (const auto& u : p.usedBy)
  341. users.add (userName (u));
  342. right = users.joinIntoString (", ");
  343. detail = tr ("Replaced by: {0}", { p.replacementArg.empty() ? tr (u8 (p.replacement)) : tr (p.replacement.c_str(), { u8 (p.replacementArg) }) });
  344. if (! p.replacementArg.empty())
  345. dot = theme::colour::info; // something plays in its place
  346. detailColour = theme::colour::textSecondary;
  347. }
  348. else
  349. {
  350. const auto& [from, to] = info.autoRelocated[(std::size_t) row];
  351. dot = theme::colour::info;
  352. name = u8 (pathFileName (to));
  353. detail = u8 (from) + juce::String::fromUTF8 (" \xe2\x86\x92 ") + u8 (to);
  354. }
  355. g.setColour (dot);
  356. g.fillEllipse (14.0f, 12.0f, 8.0f, 8.0f);
  357. const auto rightWidth = juce::jmin (width / 3, juce::GlyphArrangement::getStringWidthInt (juce::Font (theme::font (theme::type::small)), right) + 8);
  358. g.setFont (theme::font (theme::type::body, true));
  359. g.setColour (theme::colour::textPrimary);
  360. g.drawText (name, 32, 5, width - 44 - rightWidth, 18, juce::Justification::centredLeft, true);
  361. g.setFont (theme::font (theme::type::small));
  362. g.setColour (theme::colour::textSecondary);
  363. g.drawText (right, width - 12 - rightWidth, 5, rightWidth, 18, juce::Justification::centredRight, true);
  364. g.setColour (detailColour);
  365. g.drawText (detail, 32, 24, width - 44, 16, juce::Justification::centredLeft, true);
  366. }
  367. void selectedRowsChanged (int) override { refresh(); }
  368. void listBoxItemDoubleClicked (int row, const juce::MouseEvent&) override
  369. {
  370. if (page == Page::samples && search == nullptr)
  371. {
  372. list.selectRow (row);
  373. locateSelected();
  374. }
  375. }
  376. juce::String getTooltipForRow (int row) override
  377. {
  378. if (page == Page::samples && row < (int) info.files.size())
  379. return u8 (info.files[(std::size_t) row].path);
  380. return {};
  381. }
  382. // --- actions ------------------------------------------------------------------------------
  383. void chooseSearchFolder()
  384. {
  385. chooser = lynx::ui::makeFileChooser (tr ("Search a folder (and its sub-folders) for the missing samples"),
  386. folders.empty() ? juce::File::getSpecialLocation (juce::File::userHomeDirectory) : juce::File (u8 (folders.front())));
  387. lynx::ui::launchChooser (chooser, juce::FileBrowserComponent::openMode | juce::FileBrowserComponent::canSelectDirectories,
  388. [safe = juce::Component::SafePointer<MissingFilesPanel> (this)] (const juce::FileChooser& c) {
  389. if (safe == nullptr || ! c.getResult().isDirectory())
  390. return;
  391. safe->remember (c.getResult());
  392. safe->startSearch ({ c.getResult().getFullPathName() }, true);
  393. });
  394. }
  395. void locateSelected()
  396. {
  397. const auto row = list.getSelectedRow();
  398. if (page != Page::samples || row < 0 || row >= (int) info.files.size())
  399. return;
  400. const auto wanted = u8 (pathFileName (info.files[(std::size_t) row].path));
  401. const auto start = folders.empty() ? juce::File::getSpecialLocation (juce::File::userHomeDirectory) : juce::File (u8 (folders.front()));
  402. chooser = lynx::ui::makeFileChooser (tr ("Where is {0}?", { wanted }), start.getChildFile (wanted),
  403. "*" + juce::File (wanted).getFileExtension());
  404. lynx::ui::launchChooser (chooser, juce::FileBrowserComponent::openMode | juce::FileBrowserComponent::canSelectFiles,
  405. [safe = juce::Component::SafePointer<MissingFilesPanel> (this), row] (const juce::FileChooser& c) {
  406. if (safe == nullptr || ! c.getResult().existsAsFile())
  407. return;
  408. safe->located (row, c.getResult());
  409. });
  410. }
  411. // a file picked by hand: used for that row, and its folder is looked at for the others (as FL does)
  412. void located (int row, const juce::File& file)
  413. {
  414. auto& m = info.files[(std::size_t) row];
  415. m.found = file.getFullPathName().toStdString();
  416. m.skipped = false;
  417. std::vector<std::string> siblings;
  418. for (const auto& entry : juce::RangedDirectoryIterator (file.getParentDirectory(), false, "*", juce::File::findFiles))
  419. siblings.push_back (entry.getFile().getFullPathName().toStdString());
  420. const auto more = relocateByName (info.files, siblings);
  421. remember (file.getParentDirectory());
  422. refresh();
  423. if (more > 0)
  424. status.setText (tr ("{0} more found in the same folder", { juce::String (more) }), juce::dontSendNotification);
  425. }
  426. void toggleSkipSelected()
  427. {
  428. const auto rows = list.getSelectedRows();
  429. auto allSkipped = true;
  430. for (int i = 0; i < rows.size(); ++i)
  431. allSkipped = allSkipped && info.files[(std::size_t) rows[i]].skipped;
  432. for (int i = 0; i < rows.size(); ++i)
  433. {
  434. auto& m = info.files[(std::size_t) rows[i]];
  435. m.skipped = ! allSkipped;
  436. if (m.skipped)
  437. m.found.clear();
  438. }
  439. refresh();
  440. }
  441. void remember (const juce::File& folder)
  442. {
  443. if (! persistent || ! rememberToggle.getToggleState())
  444. return;
  445. rememberFolder (folders, folder.getFullPathName().toStdString());
  446. saveSearchFolders (folders);
  447. }
  448. void startSearch (const juce::StringArray& where, bool userPicked)
  449. {
  450. if (search != nullptr)
  451. return;
  452. searchedBy = userPicked;
  453. search = std::make_unique<SearchThread> (info.files, where,
  454. [safe = juce::Component::SafePointer<MissingFilesPanel> (this)] (std::vector<std::string> hits, bool cancelled) {
  455. if (safe != nullptr)
  456. safe->searchFinished (std::move (hits), cancelled);
  457. });
  458. searchedFolders = where;
  459. search->startThread();
  460. startTimerHz (8);
  461. refresh();
  462. timerCallback();
  463. }
  464. void stopSearch()
  465. {
  466. if (search != nullptr)
  467. search->signalThreadShouldExit();
  468. }
  469. void timerCallback() override
  470. {
  471. if (search != nullptr)
  472. status.setText (tr ("Searching {0}... {1} files looked at",
  473. { searchedFolders.size() == 1 ? searchedFolders[0] : tr ("your search folders"), juce::String (search->scanned.load()) }),
  474. juce::dontSendNotification);
  475. }
  476. void searchFinished (std::vector<std::string> hits, bool cancelled)
  477. {
  478. stopTimer();
  479. search.reset();
  480. const auto found = relocateByName (info.files, hits);
  481. refresh();
  482. status.setText ((cancelled ? tr ("Search stopped.") + " " : juce::String())
  483. + tr ("{0} found, {1} still missing", { juce::String (found), juce::String (stillMissing()) }),
  484. juce::dontSendNotification);
  485. }
  486. void apply()
  487. {
  488. const auto map = relocationMap (info.files);
  489. if (onApply && ! map.empty())
  490. onApply (map);
  491. close();
  492. }
  493. void close()
  494. {
  495. stopSearch();
  496. if (onCloseRequest)
  497. onCloseRequest();
  498. }
  499. MissingFilesInfo info;
  500. bool persistent = false, searchedBy = false;
  501. Page page = Page::samples;
  502. std::vector<std::string> folders;
  503. juce::StringArray searchedFolders;
  504. std::unique_ptr<SearchThread> search;
  505. std::unique_ptr<juce::FileChooser> chooser;
  506. juce::Rectangle<int> header, footer;
  507. int summaryLines = 1;
  508. juce::Label title, summary, status;
  509. juce::TextButton samplesTab, pluginsTab, foundTab;
  510. juce::ListBox list;
  511. juce::TextButton searchButton { tr ("Search folder...") }, locateButton { tr ("Locate...") }, skipButton { tr ("Skip") },
  512. stopButton { tr ("Stop") };
  513. juce::ToggleButton rememberToggle;
  514. juce::TextButton applyButton, closeButton;
  515. };
  516. // closes like the panel's buttons and reports when it goes away
  517. class MissingFilesWindow final : public juce::DocumentWindow
  518. {
  519. public:
  520. MissingFilesWindow (std::unique_ptr<MissingFilesPanel> panel, std::function<void()> closed)
  521. : juce::DocumentWindow (tr ("Missing files"), theme::colour::bg2, juce::DocumentWindow::closeButton, true), onClosed (std::move (closed))
  522. {
  523. panel->onCloseRequest = [this] { closeWindow(); };
  524. setUsingNativeTitleBar (true);
  525. setContentOwned (panel.release(), true);
  526. setResizable (true, false);
  527. setResizeLimits (620, 420, 1600, 1200);
  528. centreWithSize (getWidth(), getHeight());
  529. }
  530. void closeButtonPressed() override { closeWindow(); }
  531. bool keyPressed (const juce::KeyPress& key) override
  532. {
  533. if (key == juce::KeyPress::escapeKey)
  534. {
  535. closeWindow();
  536. return true;
  537. }
  538. return juce::DocumentWindow::keyPressed (key);
  539. }
  540. void closeWindow()
  541. {
  542. if (! isVisible())
  543. return;
  544. setVisible (false);
  545. if (onClosed)
  546. onClosed();
  547. juce::MessageManager::callAsync ([safe = juce::Component::SafePointer<juce::Component> (this)] { delete safe.getComponent(); });
  548. }
  549. private:
  550. std::function<void()> onClosed;
  551. };
  552. } // namespace
  553. std::vector<std::string> loadSearchFolders()
  554. {
  555. return parseFolderList (searchFoldersFile().loadFileAsString().toStdString());
  556. }
  557. void saveSearchFolders (const std::vector<std::string>& folders)
  558. {
  559. searchFoldersFile().replaceWithText (u8 (folderListText (folders)));
  560. }
  561. juce::StringArray browserSearchFolders()
  562. {
  563. juce::StringArray list;
  564. list.addLines (PluginHost::settingsFolder().getChildFile ("browser-folders.txt").loadFileAsString());
  565. list.trim();
  566. list.removeEmptyStrings();
  567. return list;
  568. }
  569. void showMissingFilesDialog (MissingFilesInfo info, std::function<void (const std::map<std::string, std::string>&)> onApply,
  570. std::function<void()> onClosed)
  571. {
  572. auto panel = std::make_unique<MissingFilesPanel> (std::move (info), true);
  573. panel->onApply = std::move (onApply);
  574. auto* raw = panel.get();
  575. auto* window = new MissingFilesWindow (std::move (panel), std::move (onClosed));
  576. window->setVisible (true);
  577. keepAboveMainWindow (*window);
  578. raw->searchRememberedFolders();
  579. }
  580. std::unique_ptr<juce::Component> makeMissingFilesPanel (MissingFilesInfo info, int page, int selectedRow)
  581. {
  582. auto panel = std::make_unique<MissingFilesPanel> (std::move (info), false);
  583. panel->showPageForSnapshot (page, selectedRow);
  584. return panel;
  585. }
  586. MissingFilesInfo missingFilesSnapshotInfo()
  587. {
  588. MissingFilesInfo info;
  589. info.projectName = "Night Drive";
  590. info.files = {
  591. { "C:\\Users\\Producer\\Samples\\Drums\\Kicks\\Kick Punchy 04.wav", { "Kick" }, "D:\\Library\\Drums\\Kicks\\Kick Punchy 04.wav", false },
  592. { "C:\\Users\\Producer\\Samples\\Drums\\Snares\\Snare Tight 12.wav", { "Snare", "Snare 2" }, {}, false },
  593. { "C:\\Users\\Producer\\Samples\\Vocals\\Hook take 3.wav", { "Audio clip: Hook take 3" }, {}, false },
  594. { "C:\\Users\\Producer\\Samples\\FX\\Riser long.wav", { "Riser" }, {}, true },
  595. { "E:\\Old drive\\Loops\\Pad texture 90bpm.wav", { "Pad", "Insert 4: Newtone" }, "D:\\Library\\Loops\\Pad texture 90bpm.wav", false },
  596. };
  597. info.plugins = {
  598. { "Serum", { "Lead", "Pluck" }, "Built-in synth (a preset chosen by the channel name)" },
  599. { "ValhallaRoom", { "Insert 3" }, "Nothing: the slot was left out of the mixer" },
  600. };
  601. info.autoRelocated = {
  602. { "C:\\Users\\Studio PC\\Documents\\Image-Line\\FL Studio\\Audio\\Sliced audio\\Break 2.wav",
  603. "C:\\Users\\me\\Documents\\Image-Line\\FL Studio\\Audio\\Sliced audio\\Break 2.wav" },
  604. { "C:\\Projects\\Night Drive\\Samples\\Chord stab.wav", "D:\\Music\\Night Drive\\Samples\\Chord stab.wav" },
  605. };
  606. return info;
  607. }
  608. } // namespace lynx