VideoConcat/wails3-app/services/file_service.go
2026-01-06 19:35:21 +08:00

77 lines
1.9 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package services
import (
"context"
"os"
"path/filepath"
)
// FileService 文件服务
type FileService struct{}
// NewFileService 创建文件服务实例
func NewFileService() *FileService {
return &FileService{}
}
// SelectFolder 选择文件夹(返回路径)
func (s *FileService) SelectFolder(ctx context.Context) (string, error) {
// 在 Wails3 中,文件选择需要通过前端实现
// 这里只是占位,实际应该通过前端调用系统对话框
return "", nil
}
// SelectFile 选择文件(返回路径)
func (s *FileService) SelectFile(ctx context.Context, filter string) (string, error) {
// 在 Wails3 中,文件选择需要通过前端实现
return "", nil
}
// OpenFolder 打开文件夹
func (s *FileService) OpenFolder(ctx context.Context, folderPath string) error {
// Windows 下打开文件夹
cmd := "explorer"
args := []string{folderPath}
// 这里需要使用 exec.Command但为了简化我们返回路径让前端处理
// 或者使用系统调用
return nil
}
// FileExists 检查文件是否存在
func (s *FileService) FileExists(ctx context.Context, filePath string) (bool, error) {
_, err := os.Stat(filePath)
if err == nil {
return true, nil
}
if os.IsNotExist(err) {
return false, nil
}
return false, err
}
// GetFileSize 获取文件大小(字节)
func (s *FileService) GetFileSize(ctx context.Context, filePath string) (int64, error) {
info, err := os.Stat(filePath)
if err != nil {
return 0, err
}
return info.Size(), nil
}
// EnsureDirectory 确保目录存在
func (s *FileService) EnsureDirectory(ctx context.Context, dirPath string) error {
return os.MkdirAll(dirPath, 0755)
}
// ListFiles 列出目录中的文件
func (s *FileService) ListFiles(ctx context.Context, dirPath string, pattern string) ([]string, error) {
patternPath := filepath.Join(dirPath, pattern)
matches, err := filepath.Glob(patternPath)
if err != nil {
return nil, err
}
return matches, nil
}