From a17e0f0e2c879bcbe96406cee19d7fbe2e3036f1 Mon Sep 17 00:00:00 2001 From: zsliu98 Date: Thu, 28 Sep 2023 11:38:29 -0400 Subject: [PATCH] fix: create property directory when needed --- Source/State/property.cpp | 32 +++++++++++++++++++++++--------- Source/State/property.h | 26 +++++++++++++++++++------- 2 files changed, 42 insertions(+), 16 deletions(-) diff --git a/Source/State/property.cpp b/Source/State/property.cpp index e0e38ae..90990de 100644 --- a/Source/State/property.cpp +++ b/Source/State/property.cpp @@ -2,10 +2,16 @@ // Copyright (C) 2023 - zsliu98 // This file is part of ZLEComp // -// ZLEComp is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. -// ZLEComp is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. +// ZLEComp is free software: you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the Free Software +// Foundation, either version 3 of the License, or (at your option) any later +// version. ZLEComp is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more +// details. // -// You should have received a copy of the GNU General Public License along with ZLEComp. If not, see . +// You should have received a copy of the GNU General Public License along with +// ZLEComp. If not, see . // ============================================================================== #include "property.h" @@ -13,27 +19,35 @@ namespace zlstate { Property::Property() { - uiFile = std::make_unique(juce::File(uiPath), juce::PropertiesFile::Options()); + if (!path.isDirectory()) { + path.createDirectory(); + } + uiFile = std::make_unique( + uiPath, juce::PropertiesFile::Options()); } Property::Property(juce::AudioProcessorValueTreeState &apvts) { - uiFile = std::make_unique(juce::File(uiPath), juce::PropertiesFile::Options()); + if (!path.isDirectory()) { + path.createDirectory(); + } + uiFile = std::make_unique( + uiPath, juce::PropertiesFile::Options()); loadAPVTS(apvts); } void Property::loadAPVTS(juce::AudioProcessorValueTreeState &apvts) { - const juce::ScopedReadLock myScopedLock (readWriteLock); + const juce::ScopedReadLock myScopedLock(readWriteLock); auto file = uiFile->getFile(); - if (auto xml = juce::XmlDocument::parse (file)) { + if (auto xml = juce::XmlDocument::parse(file)) { apvts.replaceState(juce::ValueTree::fromXml(*xml)); } } void Property::saveAPVTS(juce::AudioProcessorValueTreeState &apvts) { - const juce::ScopedWriteLock myScopedLock (readWriteLock); + const juce::ScopedWriteLock myScopedLock(readWriteLock); auto file = uiFile->getFile(); if (auto xml = apvts.copyState().createXml()) { xml->writeTo(file); } } -} // zlstate \ No newline at end of file +} // namespace zlstate \ No newline at end of file diff --git a/Source/State/property.h b/Source/State/property.h index ceaaa86..b4154f6 100644 --- a/Source/State/property.h +++ b/Source/State/property.h @@ -2,10 +2,16 @@ // Copyright (C) 2023 - zsliu98 // This file is part of ZLEComp // -// ZLEComp is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. -// ZLEComp is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. +// ZLEComp is free software: you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the Free Software +// Foundation, either version 3 of the License, or (at your option) any later +// version. ZLEComp is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more +// details. // -// You should have received a copy of the GNU General Public License along with ZLEComp. If not, see . +// You should have received a copy of the GNU General Public License along with +// ZLEComp. If not, see . // ============================================================================== #ifndef ZLECOMP_PROPERTY_H @@ -30,10 +36,16 @@ namespace zlstate { std::unique_ptr uiFile; juce::ReadWriteLock readWriteLock; - inline auto static const path = juce::File::getSpecialLocation(juce::File::userApplicationDataDirectory).getFullPathName(); - inline auto static const uiPath = path + "/Audio/Presets/" + JucePlugin_Manufacturer + "/" + JucePlugin_Name + "/ui.xml"; + inline auto static const path = + juce::File::getSpecialLocation(juce::File::userApplicationDataDirectory) + .getChildFile("Audio") + .getChildFile("Presets") + .getChildFile(JucePlugin_Manufacturer) + .getChildFile(JucePlugin_Name); + inline auto static const uiPath = + path.getChildFile("ui.xml"); }; -} // zlstate +} // namespace zlstate -#endif //ZLECOMP_PROPERTY_H +#endif // ZLECOMP_PROPERTY_H