Skip to content

Commit 797f6c7

Browse files
Add the current project's path to the write whitelist if the project's MscIoMode is Dir (the project is stored as a folder containing a mscx file)
1 parent 156fc94 commit 797f6c7

File tree

2 files changed

+65
-0
lines changed

2 files changed

+65
-0
lines changed

src/engraving/api/v1/util.cpp

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@
3434
#include "project/iprojectconfiguration.h"
3535
#include "notation/inotationconfiguration.h"
3636
#include "audio/main/iaudioconfiguration.h"
37+
#include "engraving/infrastructure/mscio.h"
38+
#include "context/iglobalcontext.h"
3739

3840
using namespace muse;
3941

@@ -120,6 +122,52 @@ static QStringList getUserSoundFontDirectories()
120122
return paths;
121123
}
122124

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+
123171
//---------------------------------------------------------
124172
// isPathAllowed
125173
// Check if the file path is within allowed directories
@@ -178,6 +226,11 @@ static bool isPathAllowed(const QString& filePath)
178226
// 7. User-configured SoundFonts directories (Preferences → Folders → SoundFonts)
179227
allowedPaths << getUserSoundFontDirectories();
180228

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+
181234
// Check if the canonical path starts with any allowed base path
182235
bool allowed = false;
183236
for (const QString& basePath : allowedPaths) {
@@ -229,6 +282,14 @@ QStringList FileIO::userSoundFontDirectories() {
229282
return getUserSoundFontDirectories();
230283
}
231284

285+
bool FileIO::isProjectStoredAsDirectory() {
286+
return isProjectDirectory();
287+
}
288+
289+
QString FileIO::projectDirectoryPath() {
290+
return getProjectDirectoryPath();
291+
}
292+
232293
// The running plugin's directory
233294
QString FileIO::pluginDirectoryPath() {
234295
QQmlContext* context = QQmlEngine::contextForObject(this);

src/engraving/api/v1/util.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,10 @@ class FileIO : public QObject
109109
Q_INVOKABLE QStringList userSoundFontDirectories();
110110
// Returns the plugin's folder's path
111111
Q_INVOKABLE QString pluginDirectoryPath();
112+
// Returns whether or not the project is stored as a folder (with a .mscx file)
113+
Q_INVOKABLE bool isProjectStoredAsDirectory();
114+
// Returns the project's folder's path
115+
Q_INVOKABLE QString projectDirectoryPath();
112116

113117
/// muse::Returns the file's last modification time
114118
Q_INVOKABLE int modifiedTime();

0 commit comments

Comments
 (0)