Compare commits
6 Commits
36fd04f975
...
6f5f739059
Author | SHA1 | Date | |
---|---|---|---|
6f5f739059 | |||
b0bfb3e606 | |||
4df7df678b | |||
33d9b91c52 | |||
f7a7a7b401 | |||
7402e35d66 |
@ -12,6 +12,8 @@ ncmdump-gui 基于 [ncmdump-go](https://git.taurusxin.com/taurusxin/ncmdump-go)
|
||||
|
||||
前往[Releases](https://git.taurusxin.com/taurusxin/ncmdump-gui/releases)下载最新版本。
|
||||
|
||||
请注意:绝大多数较新版本的 Windows 都自带了 Webview 2 运行时,如果遇到了软件无法启动的问题,请前往微软官网下载:<https://developer.microsoft.com/zh-cn/microsoft-edge/webview2/>
|
||||
|
||||
## Bug 及建议
|
||||
|
||||
如有任何问题或建议,请直接通过 [Issue](https://git.taurusxin.com/taurusxin/ncmdump-gui/issues) 反馈,本站已开放注册。
|
||||
|
@ -1,4 +1,4 @@
|
||||
import React, { useEffect } from 'react'
|
||||
import React, { useEffect, useMemo } from 'react'
|
||||
import { useState } from 'react'
|
||||
import {
|
||||
Button,
|
||||
@ -35,12 +35,17 @@ import {
|
||||
CheckmarkRegular,
|
||||
DismissRegular,
|
||||
DocumentArrowRightRegular,
|
||||
DocumentAddRegular,
|
||||
DeleteRegular,
|
||||
DeleteDismissRegular,
|
||||
WindowPlayRegular,
|
||||
} from '@fluentui/react-icons'
|
||||
|
||||
import { Status, Item, SaveTo } from './types'
|
||||
import { SelectFiles, SelectFolder, ProcessFiles } from '../wailsjs/go/main/App'
|
||||
import { Load, Save } from '../wailsjs/go/utils/ConfigManager'
|
||||
import { main } from '../wailsjs/go/models'
|
||||
import { EventsOn } from '../wailsjs/runtime/runtime'
|
||||
import { EventsOn, OnFileDrop } from '../wailsjs/runtime/runtime'
|
||||
|
||||
const columnsDef: TableColumnDefinition<Item>[] = [
|
||||
createTableColumn<Item>({
|
||||
@ -51,6 +56,10 @@ const columnsDef: TableColumnDefinition<Item>[] = [
|
||||
columnId: 'file',
|
||||
renderHeaderCell: () => <>文件</>,
|
||||
}),
|
||||
createTableColumn<Item>({
|
||||
columnId: 'operation',
|
||||
renderHeaderCell: () => <>操作</>,
|
||||
}),
|
||||
]
|
||||
|
||||
const useStyles = makeStyles({
|
||||
@ -69,10 +78,9 @@ export const App = () => {
|
||||
const styles = useStyles()
|
||||
|
||||
const [items, setItems] = useState<Item[]>([])
|
||||
const [isProcessing, setIsProcessing] = useState(false)
|
||||
|
||||
const [totalFilesNeedToProcess, setTotalFilesNeedToProcess] = useState(0)
|
||||
const [finishedCount, setFinishedCount] = useState(0)
|
||||
const isProcessing = useMemo(() => {
|
||||
return items.some(item => item.status === 'processing')
|
||||
}, [items])
|
||||
|
||||
const [saveTo, setSaveTo] = useState<SaveTo>('original')
|
||||
const [savePath, setSavePath] = useState('')
|
||||
@ -87,9 +95,13 @@ export const App = () => {
|
||||
minWidth: 100,
|
||||
},
|
||||
file: {
|
||||
idealWidth: 150,
|
||||
idealWidth: 1000,
|
||||
minWidth: 150,
|
||||
},
|
||||
operation: {
|
||||
idealWidth: 80,
|
||||
minWidth: 80,
|
||||
},
|
||||
})
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/naming-convention
|
||||
@ -131,11 +143,13 @@ export const App = () => {
|
||||
}
|
||||
|
||||
const selectFiles = () => {
|
||||
if (isProcessing) {
|
||||
return
|
||||
}
|
||||
SelectFiles().then(files => {
|
||||
for (const file of files) {
|
||||
setItems(prev => [...prev, { file, status: 'pending' }])
|
||||
}
|
||||
setTotalFilesNeedToProcess(files.length)
|
||||
})
|
||||
}
|
||||
|
||||
@ -162,7 +176,10 @@ export const App = () => {
|
||||
showDialog('当前文件列表已全部处理完毕,请重新添加新的文件。')
|
||||
return
|
||||
}
|
||||
setIsProcessing(true)
|
||||
if(saveTo === 'custom' && savePath === '') {
|
||||
showDialog('保存路径为空,请先设置保存路径。')
|
||||
return
|
||||
}
|
||||
const ncmFiles: main.NcmFile[] = []
|
||||
items.forEach(item => {
|
||||
ncmFiles.push({
|
||||
@ -175,24 +192,37 @@ export const App = () => {
|
||||
|
||||
useEffect(() => {
|
||||
EventsOn('file-status-changed', (index: number, status: Status) => {
|
||||
if (status == 'done' || status === 'error') {
|
||||
setFinishedCount(prev => prev + 1)
|
||||
}
|
||||
setItems(prev => {
|
||||
const newItems = [...prev]
|
||||
newItems[index].status = status
|
||||
return newItems
|
||||
})
|
||||
})
|
||||
Load().then(res => {
|
||||
console.log(res)
|
||||
setSaveTo(res.save_to as SaveTo)
|
||||
setSavePath(res.path)
|
||||
})
|
||||
}, [])
|
||||
|
||||
useEffect(() => {
|
||||
if (finishedCount === totalFilesNeedToProcess) {
|
||||
setFinishedCount(0)
|
||||
setTotalFilesNeedToProcess(0)
|
||||
setIsProcessing(false)
|
||||
Save({
|
||||
save_to: saveTo,
|
||||
path: savePath,
|
||||
}).then(_ => {})
|
||||
}, [saveTo, savePath])
|
||||
|
||||
OnFileDrop((_x, _y, paths) => {
|
||||
let length = paths.length
|
||||
for (const path of paths) {
|
||||
// only end with ncm
|
||||
if (!path.endsWith('.ncm')) {
|
||||
length--
|
||||
continue
|
||||
}
|
||||
setItems(prev => [...prev, { file: path, status: 'pending' }])
|
||||
}
|
||||
}, [finishedCount])
|
||||
}, false)
|
||||
|
||||
return (
|
||||
<div className="p-3">
|
||||
@ -217,10 +247,22 @@ export const App = () => {
|
||||
</DialogSurface>
|
||||
</Dialog>
|
||||
<div className="flex space-between gap-3">
|
||||
<Button onClick={selectFiles}>添加文件</Button>
|
||||
<Button onClick={() => setItems([])}>清除列表</Button>
|
||||
<Button onClick={selectFiles} icon={<DocumentAddRegular />}>
|
||||
添加文件
|
||||
</Button>
|
||||
<Button
|
||||
onClick={() => {
|
||||
if (!isProcessing) {
|
||||
setItems([])
|
||||
}
|
||||
}}
|
||||
icon={<DeleteDismissRegular />}
|
||||
>
|
||||
清除列表
|
||||
</Button>
|
||||
<Button
|
||||
appearance="primary"
|
||||
icon={<WindowPlayRegular />}
|
||||
onClick={() => {
|
||||
startProcess()
|
||||
}}
|
||||
@ -289,6 +331,18 @@ export const App = () => {
|
||||
</TableCellLayout>
|
||||
</TableCell>
|
||||
<TableCell>{file.file}</TableCell>
|
||||
<TableCell>
|
||||
<Button
|
||||
size="small"
|
||||
icon={<DeleteRegular />}
|
||||
appearance="transparent"
|
||||
onClick={() => {
|
||||
setItems(prev => prev.filter((_, i) => i !== index))
|
||||
}}
|
||||
>
|
||||
移除
|
||||
</Button>
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
))}
|
||||
</TableBody>
|
||||
|
2
go.mod
2
go.mod
@ -5,7 +5,7 @@ go 1.23.0
|
||||
toolchain go1.23.3
|
||||
|
||||
require (
|
||||
git.taurusxin.com/taurusxin/ncmdump-go v1.7.3
|
||||
git.taurusxin.com/taurusxin/ncmdump-go v1.7.4
|
||||
github.com/wailsapp/wails/v2 v2.9.2
|
||||
)
|
||||
|
||||
|
4
go.sum
4
go.sum
@ -1,5 +1,5 @@
|
||||
git.taurusxin.com/taurusxin/ncmdump-go v1.7.3 h1:UbaWVqWpCHJxle2ud631TzNavhSi7cuwu6+MudG3/tQ=
|
||||
git.taurusxin.com/taurusxin/ncmdump-go v1.7.3/go.mod h1:6kRSwUFM9BZwvDrg6MEPBn+29+Q2131QjK/URWO7seg=
|
||||
git.taurusxin.com/taurusxin/ncmdump-go v1.7.4 h1:Uk7tP58yNMOMqH1e9+BOFwwQ/lqScK3F10mAIFB/jtM=
|
||||
git.taurusxin.com/taurusxin/ncmdump-go v1.7.4/go.mod h1:6kRSwUFM9BZwvDrg6MEPBn+29+Q2131QjK/URWO7seg=
|
||||
github.com/TwiN/go-color v1.4.1 h1:mqG0P/KBgHKVqmtL5ye7K0/Gr4l6hTksPgTgMk3mUzc=
|
||||
github.com/TwiN/go-color v1.4.1/go.mod h1:WcPf/jtiW95WBIsEeY1Lc/b8aaWoiqQpu5cf8WFxu+s=
|
||||
github.com/bep/debounce v1.2.1 h1:v67fRdBA9UQu2NhLFXrSg0Brw7CexQekrBwDMM8bzeY=
|
||||
|
14
main.go
14
main.go
@ -6,6 +6,8 @@ import (
|
||||
"github.com/wailsapp/wails/v2"
|
||||
"github.com/wailsapp/wails/v2/pkg/options"
|
||||
"github.com/wailsapp/wails/v2/pkg/options/assetserver"
|
||||
|
||||
"git.taurusxin.com/taurusxin/ncmdump-gui/utils"
|
||||
)
|
||||
|
||||
//go:embed all:frontend/dist
|
||||
@ -15,8 +17,13 @@ func main() {
|
||||
// Create an instance of the app structure
|
||||
app := NewApp()
|
||||
|
||||
config_manager, err := utils.NewConfigManager("config.json")
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
// Create application with options
|
||||
err := wails.Run(&options.App{
|
||||
err = wails.Run(&options.App{
|
||||
Title: "ncmdump-gui",
|
||||
Width: 750,
|
||||
Height: 500,
|
||||
@ -27,6 +34,11 @@ func main() {
|
||||
OnStartup: app.startup,
|
||||
Bind: []interface{}{
|
||||
app,
|
||||
config_manager,
|
||||
},
|
||||
DragAndDrop: &options.DragAndDrop{
|
||||
EnableFileDrop: true,
|
||||
DisableWebViewDrop: true,
|
||||
},
|
||||
})
|
||||
|
||||
|
83
utils/config_manager.go
Normal file
83
utils/config_manager.go
Normal file
@ -0,0 +1,83 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
)
|
||||
|
||||
type SaveToType = string
|
||||
|
||||
const (
|
||||
Original SaveToType = "original"
|
||||
Custom SaveToType = "custom"
|
||||
)
|
||||
|
||||
type Preference struct {
|
||||
SaveTo SaveToType `json:"save_to"`
|
||||
Path string `json:"path"`
|
||||
}
|
||||
|
||||
type ConfigManager struct {
|
||||
FilePath string
|
||||
}
|
||||
|
||||
// NewConfigManager 创建一个新的配置管理器,自动适配不同操作系统的用户目录
|
||||
func NewConfigManager(filename string) (*ConfigManager, error) {
|
||||
configDir, err := os.UserConfigDir() // 获取用户配置目录
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
dirPath := filepath.Join(configDir, "ncmdump-gui")
|
||||
err = os.MkdirAll(dirPath, os.ModePerm)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
filePath := filepath.Join(dirPath, filename)
|
||||
|
||||
configManager := &ConfigManager{FilePath: filePath}
|
||||
// if not exist, create it with default value
|
||||
if _, err := os.Stat(filePath); os.IsNotExist(err) {
|
||||
defaultConfig := &Preference{
|
||||
SaveTo: Original,
|
||||
Path: "",
|
||||
}
|
||||
configManager.Save(defaultConfig)
|
||||
}
|
||||
return &ConfigManager{FilePath: filePath}, nil
|
||||
}
|
||||
|
||||
// Save 将配置保存到文件
|
||||
func (cm *ConfigManager) Save(preference *Preference) bool {
|
||||
file, err := os.Create(cm.FilePath)
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
defer file.Close()
|
||||
|
||||
encoder := json.NewEncoder(file)
|
||||
encoder.SetIndent("", " ") // 格式化输出
|
||||
err = encoder.Encode(preference)
|
||||
return err == nil
|
||||
}
|
||||
|
||||
// Load 从文件读取配置
|
||||
func (cm *ConfigManager) Load() *Preference {
|
||||
file, err := os.Open(cm.FilePath)
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
defer file.Close()
|
||||
|
||||
var preference *Preference = nil
|
||||
decoder := json.NewDecoder(file)
|
||||
err = decoder.Decode(&preference)
|
||||
fmt.Println(preference)
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
return preference
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user