Skip to content

Commit

Permalink
create file - /issues/139
Browse files Browse the repository at this point in the history
  • Loading branch information
steam0r committed Oct 1, 2024
1 parent 9dea762 commit 26e956a
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 16 deletions.
21 changes: 8 additions & 13 deletions src/electron/electron_api.js
Original file line number Diff line number Diff line change
Expand Up @@ -1237,27 +1237,22 @@ class ElectronApi
return this.error("UNKNOWN_FILE");
}


const project = settings.getCurrentProject();
const newPath = path.join(projectsUtil.getAssetPath(project._id), "/");
const newPath = helper.fileURLToPath(data.fileName, true);
if (!fs.existsSync(newPath)) mkdirp.sync(newPath);

const sanitizedFileName = filesUtil.realSanitizeFilename(data.fileName);

try
{
if (fs.existsSync(newPath + sanitizedFileName))
if (fs.existsSync(newPath))
{
this._log.info("delete old file ", sanitizedFileName);
fs.unlinkSync(newPath + sanitizedFileName);
this._log.info("delete old file ", newPath);
fs.unlinkSync(newPath);
}
}
catch (e) {}

this._log.info("edit file", newPath + sanitizedFileName);
this._log.info("edit file", newPath);

fs.writeFileSync(newPath + sanitizedFileName, data.content);
return this.success("OK", { "filename": sanitizedFileName }, true);
fs.writeFileSync(newPath, data.content);
return this.success("OK", { "filename": newPath }, true);
}

getProjectOpDirs()
Expand Down Expand Up @@ -1519,7 +1514,7 @@ class ElectronApi
{
let file = data.name;
let pickedFileUrl = await electronApp.saveFileDialog(file);
if (pickedFileUrl && !fs.existsSync(pickedFileUrl)) fs.writeFileSync(pickedFileUrl, "");
if (pickedFileUrl) fs.writeFileSync(pickedFileUrl, "");
return this.success("OK", pickedFileUrl, true);
}

Expand Down
1 change: 1 addition & 0 deletions src/utils/helper_util.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ class HelperUtil extends SharedHelperUtil

pathToFileURL(thePath)
{
if (thePath && thePath.startsWith("file:")) return thePath;
return pathToFileURL(thePath).href;
}

Expand Down
2 changes: 1 addition & 1 deletion src/utils/projects_util.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ class ProjectsUtil extends SharedProjectsUtil
const fileNames = [];
if (!project || !project.ops) return [];
const assetPorts = this.getProjectAssetPorts(project, includeLibraryAssets);
let urls = assetPorts.map((assetPort) => { return assetPort.value; });
let urls = assetPorts.map((assetPort) => { return helper.pathToFileURL(assetPort.value); });
urls.forEach((url) =>
{
let fullPath = helper.fileURLToPath(url, true);
Expand Down
8 changes: 6 additions & 2 deletions src_client/electron_editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,10 +142,14 @@ export default class ElectronEditor

this._talker.addEventListener("createFile", (data, next) =>
{
this.api("createFile", data, (r) =>
this.api("createFile", data, (error, r) =>
{
const error = r && r.hasOwnProperty("error") ? r.error : null;
if (error) this._talker.send("logError", { "level": error.level, "message": error.msg || error });
if (window.standalone && window.standalone.gui)
{
window.standalone.gui.patchView.addAssetOpAuto(r);
window.standalone.gui.fileManagerEditor.editAssetTextFile("file:" + r, "text");
}
next(error, r);
});
});
Expand Down

0 comments on commit 26e956a

Please sign in to comment.