| 122 | void RecentFilesController::clearPlatformRecentFiles() {} |
| 123 | |
| 124 | void RecentFilesController::loadRecentFilesList() |
| 125 | { |
| 126 | RecentFilesList newList; |
| 127 | |
| 128 | DEFER { |
| 129 | setRecentFilesList(newList, false); |
| 130 | }; |
| 131 | |
| 132 | RetVal<ByteArray> data; |
| 133 | { |
| 134 | mi::ReadResourceLockGuard lock_guard(multiInstancesProvider(), RECENT_FILES_RESOURCE_NAME); |
| 135 | data = fileSystem()->readFile(configuration()->recentFilesJsonPath()); |
| 136 | } |
| 137 | |
| 138 | if (!data.ret || data.val.empty()) { |
| 139 | data.val = configuration()->compatRecentFilesData(); |
| 140 | } |
| 141 | |
| 142 | if (data.val.empty()) { |
| 143 | return; |
| 144 | } |
| 145 | |
| 146 | std::string err; |
| 147 | const JsonDocument json = JsonDocument::fromJson(data.val, &err); |
| 148 | if (!err.empty()) { |
| 149 | LOGE() << "Loading JSON failed: " << err; |
| 150 | return; |
| 151 | } |
| 152 | |
| 153 | if (!json.isArray()) { |
| 154 | return; |
| 155 | } |
| 156 | |
| 157 | const JsonArray array = json.rootArray(); |
| 158 | for (size_t i = 0; i < array.size(); ++i) { |
| 159 | const JsonValue val = array.at(i); |
| 160 | |
| 161 | if (val.isString()) { |
| 162 | newList.emplace_back(muse::io::path_t(val.toStdString())); |
| 163 | } else if (val.isObject()) { |
| 164 | const JsonObject obj = val.toObject(); |
| 165 | RecentFile file; |
| 166 | file.path = obj["path"].toStdString(); |
| 167 | file.displayNameOverride = QString::fromStdString(obj["displayName"].toStdString()); |
| 168 | newList.emplace_back(std::move(file)); |
| 169 | } else { |
| 170 | continue; |
| 171 | } |
| 172 | } |
| 173 | } |
| 174 | |
| 175 | void RecentFilesController::removeNonexistentFiles() |
| 176 | { |
no test coverage detected