feat: finished basic functio

This commit is contained in:
2024-11-26 19:40:57 +08:00
parent 8f9dd089bc
commit b2e3930c10
15 changed files with 561 additions and 29 deletions

79
app.go
View File

@@ -2,7 +2,10 @@ package main
import (
"context"
"fmt"
"github.com/wailsapp/wails/v2/pkg/runtime"
"git.taurusxin.com/taurusxin/ncmdump-go/ncmcrypt"
)
// App struct
@@ -21,7 +24,75 @@ func (a *App) startup(ctx context.Context) {
a.ctx = ctx
}
// Greet returns a greeting for the given name
func (a *App) Greet(name string) string {
return fmt.Sprintf("Hello %s, It's show time!", name)
// select files to dump
func (a *App) SelectFiles() []string {
selection, err := runtime.OpenMultipleFilesDialog(a.ctx, runtime.OpenDialogOptions{
Title: "请选择文件",
Filters: []runtime.FileFilter{
{
DisplayName: "NCM Files",
Pattern: "*.ncm",
},
},
})
if err != nil {
return []string{}
}
return selection
}
func (a *App) SelectFolder() string {
folder, err := runtime.OpenDirectoryDialog(a.ctx, runtime.OpenDialogOptions{
Title: "请选择保存目录",
})
if err != nil {
return ""
}
return folder
}
type Status = string
const (
Pending Status = "pending"
Processing Status = "processing"
Done Status = "done"
Error Status = "error"
)
type NcmFile struct {
Name string
Status Status
}
// process single file
func (a *App) processFile(file string, index int, savePath string) {
runtime.EventsEmit(a.ctx, "file-status-changed", index, Processing)
ncm, err := ncmcrypt.NewNeteaseCloudMusic(file)
if err != nil {
runtime.EventsEmit(a.ctx, "file-status-changed", index, Error)
return
}
dumpResult, err := ncm.Dump(savePath)
if err != nil {
runtime.EventsEmit(a.ctx, "file-status-changed", index, Error)
return
}
if dumpResult {
_, err := ncm.FixMetadata(true)
if err != nil {
runtime.EventsEmit(a.ctx, "file-status-changed", index, Error)
return
}
runtime.EventsEmit(a.ctx, "file-status-changed", index, Done)
}
}
// process files
func (a *App) ProcessFiles(files []NcmFile, savePath string) {
for index, file := range files {
if file.Status == Pending {
go a.processFile(file.Name, index, savePath)
}
}
}