From 830dc74ff06f7190e7126903470acd07fa1be11e Mon Sep 17 00:00:00 2001 From: Kai Blaschke Date: Sun, 4 Dec 2022 21:53:36 +0100 Subject: [PATCH] Catch directory access exceptions in Playlist class. No error handling or feedback mechanism yet. --- src/playlist/Playlist.cpp | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/src/playlist/Playlist.cpp b/src/playlist/Playlist.cpp index 8c83d211f..73526f9e9 100644 --- a/src/playlist/Playlist.cpp +++ b/src/playlist/Playlist.cpp @@ -86,21 +86,29 @@ auto Playlist::AddPath(const std::string& path, uint32_t index, bool recursive, m_presetHistory.clear(); if (recursive) { - for (const auto& entry : recursive_directory_iterator(path)) + try { - if (is_regular_file(entry) && entry.path().extension() == ".milk") + for (const auto& entry : recursive_directory_iterator(path)) { - uint32_t currentIndex{InsertAtEnd}; - if (index < InsertAtEnd) + if (is_regular_file(entry) && entry.path().extension() == ".milk") { - currentIndex = index + presetsAdded; - } - if (AddItem(entry.path().string(), currentIndex, allowDuplicates)) - { - presetsAdded++; + uint32_t currentIndex{InsertAtEnd}; + if (index < InsertAtEnd) + { + currentIndex = index + presetsAdded; + } + if (AddItem(entry.path().string(), currentIndex, allowDuplicates)) + { + presetsAdded++; + } } } } + catch (std::exception&) + { + // Todo: Add failure feedback + return presetsAdded; + } } else {