MCPcopy Create free account
hub / github.com/ElyPrismLauncher/Launcher / getPathFromBookmark

Method getPathFromBookmark

launcher/settings/SettingsObject.cpp:121–165  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

119
120#ifdef Q_OS_MACOS
121QString SettingsObject::getPathFromBookmark(const QString& id)
122{
123 auto setting = getSetting(id);
124 if (!setting) {
125 qCritical() << QString("Error changing setting %1. Setting doesn't exist.").arg(id);
126 return "";
127 }
128
129 // there is no need to use bookmarks if the default value is used or the directory is within the data directory (already can access)
130 if (setting->get() == setting->defValue() ||
131 QDir(setting->get().toString()).absolutePath().startsWith(QDir::current().absolutePath())) {
132 return setting->get().toString();
133 }
134
135 auto bookmarkId = id + "Bookmark";
136 auto bookmarkSetting = getSetting(bookmarkId);
137 if (!bookmarkSetting) {
138 qCritical() << QString("Error changing setting %1. Bookmark setting doesn't exist.").arg(id);
139 return "";
140 }
141
142 QByteArray bookmark = bookmarkSetting->get().toByteArray();
143 if (bookmark.isEmpty()) {
144 qDebug() << "Creating bookmark for" << id << "at" << setting->get().toString();
145 setPathWithBookmark(id, setting->get().toString());
146 return setting->get().toString();
147 }
148 bool stale;
149 QUrl url = m_sandboxedFileAccess.securityScopedBookmarkToURL(bookmark, stale);
150 if (url.isValid()) {
151 if (stale) {
152 setting->set(url.path());
153 bookmarkSetting->set(bookmark);
154 }
155
156 m_sandboxedFileAccess.startUsingSecurityScopedBookmark(bookmark, stale);
157 // already did a stale check, no need to do it again
158
159 // convert to relative path to current directory if `url` is a descendant of the current directory
160 QDir currentDir = QDir::current().absolutePath();
161 return url.path().startsWith(currentDir.absolutePath()) ? currentDir.relativeFilePath(url.path()) : url.path();
162 }
163
164 return setting->get().toString();
165}
166
167bool SettingsObject::setPathWithBookmark(const QString& id, const QString& path)
168{

Callers

nothing calls this directly

Calls 9

QStringClass · 0.50
QDirClass · 0.50
getMethod · 0.45
defValueMethod · 0.45
toStringMethod · 0.45
isEmptyMethod · 0.45
isValidMethod · 0.45
setMethod · 0.45
pathMethod · 0.45

Tested by

no test coverage detected