11 String presetString = preset.loadFileAsString();
12 ValueTree presetData = ValueTree::fromXml(presetString);
20 if (presetData.isValid() ==
false)
34 bool bundleCreated(
false);
37 if (fileStructureExists ==
false)
39 errors =
"Failed to create bundle. Unable to make temp file " +
getExportBundleRoot().getFullPathName();
43 if (bundleAssetsTooBig)
46 errors =
"Audio files are too large - preset size over the size limit by " +
52 if (anyMissingFiles.isNotEmpty())
54 errors =
"Files used in this preset could not be found:\n" + anyMissingFiles;
64 if (bundleFile.getFullPathName().isNotEmpty() && bundleFile.exists())
70 errors =
"\nThe export bundle could not be created, "
71 "this might be caused by the chosen output folder becoming inaccessible or by lack of "
83 jassert(bundleFile.existsAsFile());
85 ZipFile bundleZip(bundleFile);
87 bundleRoot.deleteRecursively();
88 auto uncompressResult = bundleZip.uncompressTo(bundleRoot);
89 if (uncompressResult.failed())
91 throw PresetException(
"Krotos Studio was unable to open the bundle file.",
92 uncompressResult.getErrorMessage());
97 throw PresetException(
"The file does not appear to be a valid Krotos Studio preset bundle.",
"openBundle");
104 bool validBundle(
false);
105 if (bundleDirectory.isDirectory())
111 validBundle |= presetDir.isDirectory();
114 validBundle |= audioAssetsDir.isDirectory();
121 File presetFile = bundleRoot.getChildFile(
PresetSubdirectory).findChildFiles(File::findFiles,
true)[0];
129 File presetFileDestination(
131 if (presetDirectory.isDirectory())
133 m_presetFile.createXml()->writeTo(presetFileDestination);
135 return presetFileDestination;
141 if (audioAssetDirectory.isDirectory())
145 const File fileSource(asset.assetPath);
146 const File fileDestination(audioAssetDirectory.getFullPathName() + File::getSeparatorChar() +
148 if (fileSource.existsAsFile())
150 if (fileDestination.getParentDirectory().createDirectory().wasOk())
152 fileSource.copyFileTo(fileDestination);
161 const File root(File::getSpecialLocation(File::SpecialLocationType::tempDirectory));
171 const bool structureOkay(presetDir.createDirectory().wasOk() && audioAssetsDir.createDirectory().wasOk());
172 return structureOkay;
178 if (bundleRoot.exists())
180 bundleRoot.deleteRecursively();
186 bool isAudioFile(
false);
187 StringArray audioFileTypes;
189 for (
auto type : audioFileTypes)
191 if (value.toLowerCase().endsWith(type))
202 int64 cumulativeSizeBytes(0);
205 File file(asset.assetPath);
206 cumulativeSizeBytes += file.getSize();
208 const int sizeInMB(cumulativeSizeBytes / (1024 * 1024));
214 for (
auto* kwidget : kwidgetElement.getChildIterator())
224 if (anotherKwidgetsElem !=
nullptr)
229 if (customParamsElem !=
nullptr)
238 const int attributes = customParamsElement.getNumAttributes();
239 for (
int i = 0; i < attributes; i++)
241 String value = customParamsElement.getAttributeValue(i);
247 StringArray values = StringArray::fromLines(value);
248 for (
auto singleValue : values)
251 listOfFiles.addIfNotAlreadyThere(singleValue);
257 listOfFiles.addIfNotAlreadyThere(value);
262 for (
auto* customParamElem : customParamsElement.getChildIterator())
270 std::vector<AudioAsset> assetsFound;
271 StringArray audioAssetsPaths;
273 if (presetDataElem !=
nullptr)
276 if (kwidgetsElem !=
nullptr)
283 for (String path : audioAssetsPaths)
287 String slash = File::getSeparatorString();
288 newAsset.
assetID =
"Asset" + String(++assetId) + slash + File(path).getFileName();
289 assetsFound.push_back(newAsset);
297 if (exportPreset.existsAsFile())
299 auto presetDataElem = XmlDocument::parse(exportPreset);
301 if (kwidgetsElem !=
nullptr)
304 presetDataElem->writeTo(exportPreset);
311 for (
auto* kwidgetIterator : kwidgetElement.getChildIterator())
315 if (anotherKwidgetsElem !=
nullptr)
320 if (customParamsElem !=
nullptr)
328 const int attributes = customParamsElement.getNumAttributes();
329 for (
int i = 0; i < attributes; i++)
331 String value = customParamsElement.getAttributeValue(i);
338 const String attributeName = customParamsElement.getAttributeName(i);
342 customParamsElement.setAttribute(attributeName, asset.assetID);
348 for (
auto* customParamChild : customParamsElement.getChildIterator())
356 File archiveFile(outputFilePath);
357 if (archiveFile.exists())
359 archiveFile.deleteFile();
361 const int compressionLevel(0);
362 ZipFile::Builder zipBuilder;
365 for (
auto file : files)
367 zipBuilder.addFile(file, compressionLevel, file.getRelativePathFrom(
getExportBundleRoot()));
370 FileOutputStream archiveStream(archiveFile);
371 bool success = zipBuilder.writeToStream(archiveStream,
nullptr);
372 return success ? archiveFile : File();
377 String missingAssets;
382 if (file.existsAsFile() ==
false)
384 missingAssets += filePath +
"\n";
387 return missingAssets;
394 String subfolder = asset.assetID.upToFirstOccurrenceOf(File::getSeparatorString(),
396 String filename = asset.assetID.fromLastOccurrenceOf(File::getSeparatorString(),
399 asset.assetID = subfolder + File::createLegalFileName(filename);
412 return getSandboxDirectory().getChildFile(File::createLegalFileName(bundleFile.getFileNameWithoutExtension()));
435 if (File file(filepathFromPreset); file.existsAsFile() ==
false)
438 String subPath(filepathFromPreset.fromFirstOccurrenceOf(
"Factory Assets" + File::getSeparatorString(),
441 File customFile(customAssetFilepath);
442 const String kafFile{
".kaf"};
443 if (customFile.existsAsFile())
445 filepathFromPreset = customAssetFilepath;
448 else if (customFile.withFileExtension(kafFile).existsAsFile())
450 filepathFromPreset = customFile.withFileExtension(kafFile).getFullPathName();
453 return filepathFromPreset;
static String convertFilePathString(const String &)
Definition AssetManager.cpp:583
static File getUserDataDirectory()
Returns the user data directory, this will be a named manufacturer / plugin subfolder under the File:...
Definition AssetManager.cpp:402
static const String SupportedAudioTypes
Definition AssetManager.h:112
static File getAssetDirectory()
Definition AssetManager.cpp:383
void copyAudioAssetsForExport()
Definition PresetBundler.cpp:138
static File getAudioAssetDirectoryForBundle(const File &bundleFile)
Returns the path to the audio assets directory for a particular bundle based on the name of the file ...
Definition PresetBundler.cpp:415
static const String AudioAssetsSubdirectory
Definition PresetBundler.h:144
static File getSandboxDirectory()
Returns the path to the sandbox directory where the preset bundles are temporarily stored.
Definition PresetBundler.cpp:405
void initialise(ValueTree presetData)
Definition PresetBundler.cpp:18
static File openBundle(File bundleArchive)
Extracts the contents of a bundle archive to the temporary "sandbox" directory.
Definition PresetBundler.cpp:80
static File getSandboxDirectoryForBundle(const File &bundleFile)
Returns the path to the sandbox directory for a particular bundle based on the name of the file being...
Definition PresetBundler.cpp:410
void getPresetFilepaths(StringArray &listOfFiles, XmlElement widgetElement)
Definition PresetBundler.cpp:212
static File getPresetFromBundleDirectory(File bundleDirectory)
Locates the preset file within a given bundle directory.
Definition PresetBundler.cpp:119
String m_bundleRootId
Definition PresetBundler.h:193
void cleanUpFileStructure()
Definition PresetBundler.cpp:175
std::vector< AudioAsset > m_assetFilepaths
Definition PresetBundler.h:195
int getEstimatedAssetsSizeMB()
Definition PresetBundler.cpp:200
void processExportedPresetFile(File exportPreset)
Definition PresetBundler.cpp:295
int m_maxSizeMegaBytes
Definition PresetBundler.h:196
File copyPresetForExport(String nameForPresetFile)
Definition PresetBundler.cpp:126
bool createBundle(File outputLocation, String &errors)
Definition PresetBundler.cpp:32
bool isValueMultipleFiles(String value)
Definition PresetBundler.cpp:430
void clenseExportIDs()
Definition PresetBundler.cpp:390
std::vector< AudioAsset > getAssetsListFromPreset()
Definition PresetBundler.cpp:268
void replacePaths(XmlElement &widgetElement)
Definition PresetBundler.cpp:309
PresetBundler(File preset)
Definition PresetBundler.cpp:9
static bool isABundlePreset(const File &preset)
Returns whether this preset file is part of a bundle. This is just a simple check for that the provid...
Definition PresetBundler.cpp:425
static const String BundleFileExtension
The file extension for the bundle archive.
Definition PresetBundler.h:47
String convertFilepath(String filepathFromPreset)
Definition PresetBundler.cpp:432
File buildBundleArchive(String outputDirectoryPath)
Definition PresetBundler.cpp:354
String listMissingFiles()
Definition PresetBundler.cpp:375
void findPathAttributesRecursive(StringArray &listOfFiles, XmlElement customParamsElement)
Definition PresetBundler.cpp:236
static bool validateBundleDirectory(File bundleDirectory)
Validates that a given directory is a valid bundle directory by checking it is a child file of the sa...
Definition PresetBundler.cpp:102
void replacePathRecursive(XmlElement &widgetElement)
Definition PresetBundler.cpp:326
static File getPresetDirectoryForBundle(const File &bundleFile)
Returns the path to the preset directory for a particular bundle based on the name of the file being ...
Definition PresetBundler.cpp:420
ValueTree m_presetFile
Definition PresetBundler.h:194
static String m_presetFileExtension
Definition PresetBundler.h:192
void setPresetFileExtension(String fileExtension)
Definition PresetBundler.cpp:403
String m_factoryAssetsDirectory
Definition PresetBundler.h:171
static const String PresetSubdirectory
Definition PresetBundler.h:142
bool isValueAudioFile(String value)
Definition PresetBundler.cpp:184
bool createBundleFileStructure()
Definition PresetBundler.cpp:166
File getExportBundleRoot()
Definition PresetBundler.cpp:159
An exception for preset manager.
Definition PresetManager.h:148
String StringsIntoPath(Args... args)
Joins multiple string arguments into a path string.
Definition helpers.h:25
Definition AirAbsorptionFilter.cpp:2
Definition PresetBundler.h:50
String assetPath
Definition PresetBundler.h:52
String assetID
Definition PresetBundler.h:54
static const Identifier id
Definition XmlType.h:41
static const Identifier kwidgets
Definition XmlType.h:22
static const Identifier customParams
Definition XmlType.h:20