From f9c4c1c7cfc4b3ed745c2689337131fa58675aaf Mon Sep 17 00:00:00 2001 From: TaurusXin Date: Fri, 14 Feb 2025 16:17:24 +0800 Subject: [PATCH] feat: list folder recursively --- app.go | 16 ++++++++++++++++ frontend/src/App.tsx | 17 +++++++++++++++-- utils/file_util.go | 30 ++++++++++++++++++++++++++++++ 3 files changed, 61 insertions(+), 2 deletions(-) create mode 100644 utils/file_util.go diff --git a/app.go b/app.go index 806257d..767fe83 100644 --- a/app.go +++ b/app.go @@ -6,6 +6,7 @@ import ( "github.com/wailsapp/wails/v2/pkg/runtime" "git.taurusxin.com/taurusxin/ncmdump-go/ncmcrypt" + "git.taurusxin.com/taurusxin/ncmdump-gui/utils" ) // App struct @@ -51,6 +52,21 @@ func (a *App) SelectFolder() string { return folder } +func (a *App) SelectFilesFromFolder(ext string) []string { + folder, err := runtime.OpenDirectoryDialog(a.ctx, runtime.OpenDialogOptions{ + Title: "请选择文件夹", + }) + if err != nil { + return []string{} + } else { + files, err := utils.ListFilesFromFolder(folder, ext) + if err != nil { + return []string{} + } + return files + } +} + type Status = string const ( diff --git a/frontend/src/App.tsx b/frontend/src/App.tsx index f9010cc..7e08880 100644 --- a/frontend/src/App.tsx +++ b/frontend/src/App.tsx @@ -38,11 +38,12 @@ import { DocumentAddRegular, DeleteRegular, DeleteDismissRegular, + FolderAddRegular, WindowPlayRegular, } from '@fluentui/react-icons' import { Status, Item, SaveTo } from './types' -import { SelectFiles, SelectFolder, ProcessFiles } from '../wailsjs/go/main/App' +import { SelectFiles, SelectFolder, SelectFilesFromFolder, ProcessFiles } from '../wailsjs/go/main/App' import { Load, Save } from '../wailsjs/go/utils/ConfigManager' import { main } from '../wailsjs/go/models' import { EventsOn, OnFileDrop } from '../wailsjs/runtime/runtime' @@ -155,6 +156,17 @@ export const App = () => { }) } + const selectFilesFromFolder = () => { + if (isProcessing) { + return + } + SelectFilesFromFolder('ncm').then(files => { + for (const file of files) { + setItems(prev => [...prev, { file, status: 'pending' }]) + } + }) + } + const showDialog = (message: string) => { setMessage(message) setOpen(true) @@ -178,7 +190,7 @@ export const App = () => { showDialog('当前文件列表已全部处理完毕,请重新添加新的文件。') return } - if(saveTo === 'custom' && savePath === '') { + if (saveTo === 'custom' && savePath === '') { showDialog('保存路径为空,请先设置保存路径。') return } @@ -254,6 +266,7 @@ export const App = () => { +