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,
selectedFile: props.selectedFile,
hasSelection: false,
files: ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j"]
files: []
};
this.requestFiles();
@@ -83,7 +83,15 @@ export default class FilePropertyDialog extends ResizeResponsiveComponent<FilePr
private model: PiPedalModel;
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 {
@@ -118,11 +126,11 @@ export default class FilePropertyDialog extends ResizeResponsiveComponent<FilePr
}
private isFileInList(selectedFile: string) {
private isFileInList(files: string[],file: string) {
let hasSelection = false;
for (var file of this.state.files) {
if (file === selectedFile) {
for (var listFile of files) {
if (listFile === file) {
hasSelection = true;
break;
}
@@ -131,7 +139,7 @@ export default class FilePropertyDialog extends ResizeResponsiveComponent<FilePr
}
onSelect(selectedFile: string) {
this.setState({ selectedFile: selectedFile, hasSelection: this.isFileInList(selectedFile) })
this.setState({ selectedFile: selectedFile, hasSelection: this.isFileInList(this.state.files,selectedFile) })
}
render() {
+2
View File
@@ -130,6 +130,7 @@ export class PiPedalFileProperty {
this.fileTypes = PiPedalFileType.deserialize_array(input.fileTypes);
this.patchProperty = input.patchProperty;
this.defaultFile = input.defaultFile;
this.directory = input.directory;
return this;
}
static deserialize_array(input: any): PiPedalFileProperty[]
@@ -145,6 +146,7 @@ export class PiPedalFileProperty {
name: string = "";
fileTypes: PiPedalFileType[] = [];
patchProperty: string = "";
directory: string = "";
defaultFile: string = "";
};
+6
View File
@@ -1736,5 +1736,11 @@ void PiPedalModel::SetSystemMidiBindings(std::vector<MidiBinding> &bindings)
std::vector<std::string> PiPedalModel::GetFileList(const PiPedalFileProperty&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);
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);
}
+5
View File
@@ -1418,6 +1418,7 @@ std::vector<std::string> Storage::GetFileList(const PiPedalFileProperty&fileProp
std::vector<std::string> result;
std::filesystem::path audioFileDirectory = this->GetAudioFilesDirectory() / fileProperty.directory();
try {
for (auto const&dir_entry: std::filesystem::directory_iterator(audioFileDirectory))
{
if (dir_entry.is_regular_file())
@@ -1429,6 +1430,10 @@ std::vector<std::string> Storage::GetFileList(const PiPedalFileProperty&fileProp
}
}
}
} catch(const std::exception&error)
{
throw std::logic_error("Directory not found: " + audioFileDirectory.string());
}
return result;
}