diff --git a/react/src/FilePropertyDialog.tsx b/react/src/FilePropertyDialog.tsx index 2c03d46..5ca8465 100644 --- a/react/src/FilePropertyDialog.tsx +++ b/react/src/FilePropertyDialog.tsx @@ -74,7 +74,7 @@ export default class FilePropertyDialog extends ResizeResponsiveComponent { + if (this.mounted) + { + this.setState({files: files,hasSelection: this.isFileInList(files,this.state.selectedFile)}); + } + }).catch((error)=>{ + this.model.showAlert(error.toString()) + }); } onWindowSizeChanged(width: number, height: number): void { @@ -118,11 +126,11 @@ export default class FilePropertyDialog extends ResizeResponsiveComponent &bindings) std::vector PiPedalModel::GetFileList(const PiPedalFileProperty&fileProperty) { - return this->storage.GetFileList(fileProperty); + try { + return this->storage.GetFileList(fileProperty); + } catch (const std::exception & e) + { + Lv2Log::warning("GetFileList() failed: (%s)", e.what()); + return std::vector(); // don't disclose to users what the problem is. + } } diff --git a/src/PiPedalUI.cpp b/src/PiPedalUI.cpp index ac27669..6f0d18a 100644 --- a/src/PiPedalUI.cpp +++ b/src/PiPedalUI.cpp @@ -104,10 +104,10 @@ PiPedalFileProperty::PiPedalFileProperty(PiPedalHost *pHost, const LilvNode *nod nullptr); if (directory) { - this->directory_ = name.AsString(); + this->directory_ = directory.AsString(); if (!IsDirectoryNameValid(this->directory_)) { - throw std::logic_error("Pipedal FileProperty::director must have only alpha-numeric characters."); + throw std::logic_error("Pipedal FileProperty::directory must have only alpha-numeric characters."); } } else @@ -181,6 +181,7 @@ bool pipedal::IsAlphaNumeric(const std::string&value) bool PiPedalFileProperty::IsDirectoryNameValid(const std::string&value) { + if (value.length() == 0) return false; return IsAlphaNumeric(value); } diff --git a/src/Storage.cpp b/src/Storage.cpp index cd6f68b..6b55303 100644 --- a/src/Storage.cpp +++ b/src/Storage.cpp @@ -1418,16 +1418,21 @@ std::vector Storage::GetFileList(const PiPedalFileProperty&fileProp std::vector result; std::filesystem::path audioFileDirectory = this->GetAudioFilesDirectory() / fileProperty.directory(); - for (auto const&dir_entry: std::filesystem::directory_iterator(audioFileDirectory)) - { - if (dir_entry.is_regular_file()) + try { + for (auto const&dir_entry: std::filesystem::directory_iterator(audioFileDirectory)) { - auto &path = dir_entry.path(); - if (fileProperty.IsValidExtension(path.extension().string())) + if (dir_entry.is_regular_file()) { - result.push_back(fileProperty.directory() / path.filename()); + auto &path = dir_entry.path(); + if (fileProperty.IsValidExtension(path.extension().string())) + { + result.push_back(fileProperty.directory() / path.filename()); + } } } + } catch(const std::exception&error) + { + throw std::logic_error("Directory not found: " + audioFileDirectory.string()); } return result;