Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Development #168

Merged
merged 3 commits into from
Dec 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/src/chart/ChartManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1649,7 +1649,7 @@ export class ChartManager {
let error: string | null = null
if (
!this.loadedSM.usesChartTiming() &&
(await FileHandler.getFileHandle(this.getSMPath(".smebak")))
(await FileHandler.getFileHandle(this.getSMPath(".sm")))
) {
await FileHandler.writeFile(smPath, this.loadedSM.serialize("sm")).catch(
err => {
Expand Down
16 changes: 13 additions & 3 deletions app/src/gui/window/NewSongWindow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ export class NewSongWindow extends Window {
let folder = this.sm.properties.TITLE!
if (window.nw) {
const path = nw.require("path")
const process = nw.require("process")
const fileSelector = document.createElement("input")
fileSelector.type = "file"
fileSelector.nwsaveas = folder + ".sm"
Expand All @@ -153,9 +154,18 @@ export class NewSongWindow extends Window {
await FileHandler.writeFile(smPath, this.sm.serialize("sm"))
// Add the rest of the files
await Promise.all(
Object.entries(this.fileTable).map(entry =>
FileHandler.writeFile(folder + `/${entry[0]}`, entry[1])
)
Object.entries(this.fileTable).map(entry => {
const newPath = path.resolve(path.join(folder, entry[0]))
const filePath = path.resolve(entry[1].path!)
// Don't copy if they are the same path
if (
process.platform == "win32" &&
newPath.toLowerCase() === filePath.toLowerCase()
)
return
if (newPath === filePath) return
return FileHandler.writeFile(newPath, entry[1])
})
)
await this.app.chartManager.loadSM(smPath)
this.app.windowManager
Expand Down
8 changes: 7 additions & 1 deletion app/src/util/file-handler/NodeFileHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,9 +168,15 @@ export class NodeFileHandler implements BaseFileHandler {
}

private async writeHandle(handle: FileSystemFileHandle, data: Blob | string) {
let buf: ArrayBuffer
if (data instanceof Blob) {
buf = await data.arrayBuffer()
} else {
buf = new TextEncoder().encode(data).buffer
}
const writable = await handle.createWritable()
await writable.truncate(0)
await writable.write(data)
await writable.write(buf)
await writable.close()
}

Expand Down
Loading