|
34 | 34 | #include "project/iprojectconfiguration.h" |
35 | 35 | #include "notation/inotationconfiguration.h" |
36 | 36 | #include "audio/main/iaudioconfiguration.h" |
| 37 | +#include "engraving/infrastructure/mscio.h" |
| 38 | +#include "context/iglobalcontext.h" |
37 | 39 |
|
38 | 40 | using namespace muse; |
39 | 41 |
|
@@ -120,6 +122,52 @@ static QStringList getUserSoundFontDirectories() |
120 | 122 | return paths; |
121 | 123 | } |
122 | 124 |
|
| 125 | +// Path of project file (ex: .../Desktop/project.mscz) |
| 126 | +static QString getProjectPath() |
| 127 | +{ |
| 128 | + auto globalContext = muse::modularity::globalIoc()->resolve<context::IGlobalContext>("project"); |
| 129 | + if (!globalContext) { |
| 130 | + LOGE() << "Failed to resolve IGlobalContext"; |
| 131 | + return QString(); |
| 132 | + } |
| 133 | + |
| 134 | + auto project = globalContext->currentProject(); |
| 135 | + if (!project) { |
| 136 | + return QString(); |
| 137 | + } |
| 138 | + |
| 139 | + muse::io::path_t projectPath = project->path(); |
| 140 | + if (projectPath.empty()) { |
| 141 | + return QString(); |
| 142 | + } |
| 143 | + |
| 144 | + return QString::fromStdString(projectPath.toStdString()); |
| 145 | +} |
| 146 | + |
| 147 | +// Is the project a folder with a .mscx file |
| 148 | +static bool isProjectDirectory() { |
| 149 | + QString projectPath = getProjectPath(); |
| 150 | + if (projectPath.isEmpty()) { |
| 151 | + return false; |
| 152 | + } |
| 153 | + |
| 154 | + std::string suffix = muse::io::suffix(projectPath); |
| 155 | + |
| 156 | + return mscIoModeBySuffix(suffix) == MscIoMode::Dir; |
| 157 | +} |
| 158 | + |
| 159 | +// Path of project's containing folder |
| 160 | +static QString getProjectDirectoryPath() |
| 161 | +{ |
| 162 | + QString projectPath = getProjectPath(); |
| 163 | + if (projectPath.isEmpty()) { |
| 164 | + return QString(); |
| 165 | + } |
| 166 | + |
| 167 | + QString directoryPath = QString::fromStdString(io::dirpath(projectPath).toStdString()); |
| 168 | + return directoryPath; |
| 169 | +} |
| 170 | + |
123 | 171 | //--------------------------------------------------------- |
124 | 172 | // isPathAllowed |
125 | 173 | // Check if the file path is within allowed directories |
@@ -178,6 +226,11 @@ static bool isPathAllowed(const QString& filePath) |
178 | 226 | // 7. User-configured SoundFonts directories (Preferences → Folders → SoundFonts) |
179 | 227 | allowedPaths << getUserSoundFontDirectories(); |
180 | 228 |
|
| 229 | + // 8. Project path if it's a folder (with a .mscx file) instead of a .mscz file |
| 230 | + if (isProjectDirectory()) { |
| 231 | + allowedPaths << getProjectDirectoryPath(); |
| 232 | + } |
| 233 | + |
181 | 234 | // Check if the canonical path starts with any allowed base path |
182 | 235 | bool allowed = false; |
183 | 236 | for (const QString& basePath : allowedPaths) { |
@@ -229,6 +282,14 @@ QStringList FileIO::userSoundFontDirectories() { |
229 | 282 | return getUserSoundFontDirectories(); |
230 | 283 | } |
231 | 284 |
|
| 285 | +bool FileIO::isProjectStoredAsDirectory() { |
| 286 | + return isProjectDirectory(); |
| 287 | +} |
| 288 | + |
| 289 | +QString FileIO::projectDirectoryPath() { |
| 290 | + return getProjectDirectoryPath(); |
| 291 | +} |
| 292 | + |
232 | 293 | // The running plugin's directory |
233 | 294 | QString FileIO::pluginDirectoryPath() { |
234 | 295 | QQmlContext* context = QQmlEngine::contextForObject(this); |
|
0 commit comments