Skip to content

Commit

Permalink
fix: create property directory when needed
Browse files Browse the repository at this point in the history
  • Loading branch information
zsliu98 committed Sep 28, 2023
1 parent 19b2b21 commit a17e0f0
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 16 deletions.
32 changes: 23 additions & 9 deletions Source/State/property.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,38 +2,52 @@
// 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 <https://www.gnu.org/licenses/>.
// You should have received a copy of the GNU General Public License along with
// ZLEComp. If not, see <https://www.gnu.org/licenses/>.
// ==============================================================================

#include "property.h"

namespace zlstate {

Property::Property() {
uiFile = std::make_unique<juce::PropertiesFile>(juce::File(uiPath), juce::PropertiesFile::Options());
if (!path.isDirectory()) {
path.createDirectory();
}
uiFile = std::make_unique<juce::PropertiesFile>(
uiPath, juce::PropertiesFile::Options());
}

Property::Property(juce::AudioProcessorValueTreeState &apvts) {
uiFile = std::make_unique<juce::PropertiesFile>(juce::File(uiPath), juce::PropertiesFile::Options());
if (!path.isDirectory()) {
path.createDirectory();
}
uiFile = std::make_unique<juce::PropertiesFile>(
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
} // namespace zlstate
26 changes: 19 additions & 7 deletions Source/State/property.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 <https://www.gnu.org/licenses/>.
// You should have received a copy of the GNU General Public License along with
// ZLEComp. If not, see <https://www.gnu.org/licenses/>.
// ==============================================================================

#ifndef ZLECOMP_PROPERTY_H
Expand All @@ -30,10 +36,16 @@ namespace zlstate {
std::unique_ptr<juce::PropertiesFile> 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

0 comments on commit a17e0f0

Please sign in to comment.