|
|
@ -225,23 +225,25 @@ class FileManager extends Plugin { |
|
|
|
* @param {string} folderPath base folder path |
|
|
|
* @param {string} folderPath base folder path |
|
|
|
* @returns {void} |
|
|
|
* @returns {void} |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
async writeMultipleFiles(filePaths, fileData, folderPath) { |
|
|
|
async writeMultipleFiles(filePaths: string[], fileData: string[], folderPath: string) { |
|
|
|
|
|
|
|
if (this.currentRequest) { |
|
|
|
|
|
|
|
const canCall = await this.askUserPermission(`writeFile`, `will write multiple files to ${folderPath}...`) |
|
|
|
|
|
|
|
const required = this.appManager.isRequired(this.currentRequest.from) |
|
|
|
|
|
|
|
if (canCall && !required) { |
|
|
|
|
|
|
|
this.call('notification', 'toast', fileChangedToastMsg(this.currentRequest.from, folderPath)) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
try { |
|
|
|
try { |
|
|
|
let alert = true |
|
|
|
|
|
|
|
for (let i = 0; i < filePaths.length; i++) { |
|
|
|
for (let i = 0; i < filePaths.length; i++) { |
|
|
|
const installPath = folderPath + "/" + filePaths[i] |
|
|
|
const installPath = folderPath + "/" + filePaths[i] |
|
|
|
|
|
|
|
|
|
|
|
let path = this.normalize(installPath) |
|
|
|
let path = this.normalize(installPath) |
|
|
|
path = this.limitPluginScope(path) |
|
|
|
path = this.limitPluginScope(path) |
|
|
|
|
|
|
|
|
|
|
|
if (await this.exists(path)) { |
|
|
|
if (!await this.exists(path)) { |
|
|
|
await this._handleIsFile(path, `Cannot write file ${path}`) |
|
|
|
await this._setFileInternal(path, fileData[i]) |
|
|
|
await this.setMultipleFileContent(path, fileData[i], folderPath, alert) |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
await this.setMultipleFileContent(path, fileData[i], folderPath, alert) |
|
|
|
|
|
|
|
this.emit('fileAdded', path) |
|
|
|
this.emit('fileAdded', path) |
|
|
|
} |
|
|
|
} |
|
|
|
alert = false |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} catch (e) { |
|
|
|
} catch (e) { |
|
|
|
throw new Error(e) |
|
|
|
throw new Error(e) |
|
|
@ -603,18 +605,6 @@ class FileManager extends Plugin { |
|
|
|
return await this._setFileInternal(path, content) |
|
|
|
return await this._setFileInternal(path, content) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
async setMultipleFileContent(path, content, folderPath, alert) { |
|
|
|
|
|
|
|
if (this.currentRequest) { |
|
|
|
|
|
|
|
const canCall = await this.askUserPermission(`writeFile`, `modifying ${folderPath} ...`) |
|
|
|
|
|
|
|
const required = this.appManager.isRequired(this.currentRequest.from) |
|
|
|
|
|
|
|
if (canCall && !required && alert) { |
|
|
|
|
|
|
|
// inform the user about modification after permission is granted and even if permission was saved before
|
|
|
|
|
|
|
|
this.call('notification', 'toast', fileChangedToastMsg(this.currentRequest.from, folderPath)) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return await this._setFileInternal(path, content) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
_setFileInternal(path, content) { |
|
|
|
_setFileInternal(path, content) { |
|
|
|
const provider = this.fileProviderOf(path) |
|
|
|
const provider = this.fileProviderOf(path) |
|
|
|
if (!provider) throw createError({ code: 'ENOENT', message: `${path} not available` }) |
|
|
|
if (!provider) throw createError({ code: 'ENOENT', message: `${path} not available` }) |
|
|
|