This commit is contained in:
Robin Davies
2023-03-21 14:34:13 -04:00
parent 15b4b19530
commit ed1dc75c53
5 changed files with 37 additions and 15 deletions
+14 -6
View File
@@ -74,7 +74,7 @@ export default class FilePropertyDialog extends ResizeResponsiveComponent<FilePr
fullScreen: false, fullScreen: false,
selectedFile: props.selectedFile, selectedFile: props.selectedFile,
hasSelection: false, hasSelection: false,
files: ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j"] files: []
}; };
this.requestFiles(); this.requestFiles();
@@ -83,7 +83,15 @@ export default class FilePropertyDialog extends ResizeResponsiveComponent<FilePr
private model: PiPedalModel; private model: PiPedalModel;
private requestFiles() { private requestFiles() {
this.model.requestFileList(this.props.fileProperty); this.model.requestFileList(this.props.fileProperty)
.then((files) => {
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 { onWindowSizeChanged(width: number, height: number): void {
@@ -118,11 +126,11 @@ export default class FilePropertyDialog extends ResizeResponsiveComponent<FilePr
} }
private isFileInList(selectedFile: string) { private isFileInList(files: string[],file: string) {
let hasSelection = false; let hasSelection = false;
for (var file of this.state.files) { for (var listFile of files) {
if (file === selectedFile) { if (listFile === file) {
hasSelection = true; hasSelection = true;
break; break;
} }
@@ -131,7 +139,7 @@ export default class FilePropertyDialog extends ResizeResponsiveComponent<FilePr
} }
onSelect(selectedFile: string) { onSelect(selectedFile: string) {
this.setState({ selectedFile: selectedFile, hasSelection: this.isFileInList(selectedFile) }) this.setState({ selectedFile: selectedFile, hasSelection: this.isFileInList(this.state.files,selectedFile) })
} }
render() { render() {
+2
View File
@@ -130,6 +130,7 @@ export class PiPedalFileProperty {
this.fileTypes = PiPedalFileType.deserialize_array(input.fileTypes); this.fileTypes = PiPedalFileType.deserialize_array(input.fileTypes);
this.patchProperty = input.patchProperty; this.patchProperty = input.patchProperty;
this.defaultFile = input.defaultFile; this.defaultFile = input.defaultFile;
this.directory = input.directory;
return this; return this;
} }
static deserialize_array(input: any): PiPedalFileProperty[] static deserialize_array(input: any): PiPedalFileProperty[]
@@ -145,6 +146,7 @@ export class PiPedalFileProperty {
name: string = ""; name: string = "";
fileTypes: PiPedalFileType[] = []; fileTypes: PiPedalFileType[] = [];
patchProperty: string = ""; patchProperty: string = "";
directory: string = "";
defaultFile: string = ""; defaultFile: string = "";
}; };
+7 -1
View File
@@ -1736,5 +1736,11 @@ void PiPedalModel::SetSystemMidiBindings(std::vector<MidiBinding> &bindings)
std::vector<std::string> PiPedalModel::GetFileList(const PiPedalFileProperty&fileProperty) std::vector<std::string> 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<std::string>(); // don't disclose to users what the problem is.
}
} }
+3 -2
View File
@@ -104,10 +104,10 @@ PiPedalFileProperty::PiPedalFileProperty(PiPedalHost *pHost, const LilvNode *nod
nullptr); nullptr);
if (directory) if (directory)
{ {
this->directory_ = name.AsString(); this->directory_ = directory.AsString();
if (!IsDirectoryNameValid(this->directory_)) 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 else
@@ -181,6 +181,7 @@ bool pipedal::IsAlphaNumeric(const std::string&value)
bool PiPedalFileProperty::IsDirectoryNameValid(const std::string&value) bool PiPedalFileProperty::IsDirectoryNameValid(const std::string&value)
{ {
if (value.length() == 0) return false;
return IsAlphaNumeric(value); return IsAlphaNumeric(value);
} }
+11 -6
View File
@@ -1418,16 +1418,21 @@ std::vector<std::string> Storage::GetFileList(const PiPedalFileProperty&fileProp
std::vector<std::string> result; std::vector<std::string> result;
std::filesystem::path audioFileDirectory = this->GetAudioFilesDirectory() / fileProperty.directory(); std::filesystem::path audioFileDirectory = this->GetAudioFilesDirectory() / fileProperty.directory();
for (auto const&dir_entry: std::filesystem::directory_iterator(audioFileDirectory)) try {
{ for (auto const&dir_entry: std::filesystem::directory_iterator(audioFileDirectory))
if (dir_entry.is_regular_file())
{ {
auto &path = dir_entry.path(); if (dir_entry.is_regular_file())
if (fileProperty.IsValidExtension(path.extension().string()))
{ {
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; return result;