| 4 | #include "juce_core/juce_core.h" |
| 5 | |
| 6 | void UpdateUserData(std::string destDirPath) |
| 7 | { |
| 8 | juce::File bundledDataDir(ofToResourcePath("userdata_original")); |
| 9 | juce::File destDataDir(destDirPath); |
| 10 | juce::File bundledDataVersionFile(bundledDataDir.getChildFile("userdata_version.txt")); |
| 11 | juce::File destDataVersionFile(destDataDir.getChildFile("userdata_version.txt")); |
| 12 | |
| 13 | if (!bundledDataVersionFile.exists()) |
| 14 | return; |
| 15 | |
| 16 | bool needCopy = false; |
| 17 | std::vector<juce::String> preserveOldFileList; |
| 18 | std::vector<juce::String> leaveAloneFileList; |
| 19 | |
| 20 | if (!destDataVersionFile.exists()) |
| 21 | { |
| 22 | needCopy = true; |
| 23 | } |
| 24 | else |
| 25 | { |
| 26 | juce::StringArray bundledVersionLines; |
| 27 | juce::StringArray destVersionLines; |
| 28 | bundledDataVersionFile.readLines(bundledVersionLines); |
| 29 | destDataVersionFile.readLines(destVersionLines); |
| 30 | if (bundledVersionLines.isEmpty()) |
| 31 | return; |
| 32 | if (destVersionLines.isEmpty()) |
| 33 | { |
| 34 | needCopy = true; |
| 35 | } |
| 36 | else |
| 37 | { |
| 38 | int bundledDataVersion = ofToInt(bundledVersionLines[0].toStdString()); |
| 39 | int destDataVersion = ofToInt(destVersionLines[0].toStdString()); |
| 40 | needCopy = destDataVersion < bundledDataVersion; |
| 41 | //I can use the data version in the future to see if special accommodations need to be made for copy/overwriting any specific files |
| 42 | |
| 43 | preserveOldFileList.push_back(juce::String(destDirPath) + "/layouts/blank.json"); |
| 44 | leaveAloneFileList.push_back(juce::String(destDirPath) + "/drums/drums.json"); |
| 45 | } |
| 46 | } |
| 47 | |
| 48 | if (needCopy) |
| 49 | { |
| 50 | ofLog() << "copying data from " + bundledDataDir.getFullPathName().toStdString() + " to " + destDirPath; |
| 51 | destDataDir.createDirectory(); |
| 52 | |
| 53 | for (const auto& entry : juce::RangedDirectoryIterator{ bundledDataDir, true, "*", juce::File::findDirectories }) |
| 54 | { |
| 55 | juce::String destDirName = juce::String(destDirPath) + "/" + entry.getFile().getRelativePathFrom(bundledDataDir); |
| 56 | juce::File(destDirName).createDirectory(); |
| 57 | } |
| 58 | |
| 59 | for (const auto& entry : juce::RangedDirectoryIterator{ bundledDataDir, true }) |
| 60 | { |
| 61 | juce::String sourceFileName = entry.getFile().getFullPathName(); |
| 62 | juce::String destFileName = juce::String(destDirPath) + "/" + entry.getFile().getRelativePathFrom(bundledDataDir).replaceCharacter('\\', '/'); |
| 63 |
no test coverage detected