Sync
This commit is contained in:
@@ -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() {
|
||||
|
||||
@@ -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 = "";
|
||||
|
||||
};
|
||||
|
||||
@@ -1736,5 +1736,11 @@ void PiPedalModel::SetSystemMidiBindings(std::vector<MidiBinding> &bindings)
|
||||
|
||||
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
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
+11
-6
@@ -1418,16 +1418,21 @@ std::vector<std::string> Storage::GetFileList(const PiPedalFileProperty&fileProp
|
||||
std::vector<std::string> 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;
|
||||
|
||||
Reference in New Issue
Block a user