From 3fbceec8de833416bf1ae049f959f222c3f1a4a0 Mon Sep 17 00:00:00 2001
From: Ariver <shanghai3168@gmail.com>
Date: Tue, 02 Jun 2026 14:05:59 +0800
Subject: [PATCH] Prepare Round 1 model profile QA baseline
---
privatevoice.src/internal/paths/paths.go | 50 ++++++++++++++++++++++++++++++++++++++++++--------
1 files changed, 42 insertions(+), 8 deletions(-)
diff --git a/VoiceSnapGo/internal/paths/paths.go b/privatevoice.src/internal/paths/paths.go
similarity index 70%
rename from VoiceSnapGo/internal/paths/paths.go
rename to privatevoice.src/internal/paths/paths.go
index 2b1ce20..5c311dd 100644
--- a/VoiceSnapGo/internal/paths/paths.go
+++ b/privatevoice.src/internal/paths/paths.go
@@ -7,19 +7,25 @@
"path/filepath"
)
-const appDirName = "VoiceSnap"
+const appDirName = "PrivateVoice Input"
+
+var legacyAppDirNames = []string{"VoiceSnap"}
// AppSupportDir returns the per-user persistent data directory.
func AppSupportDir() string {
+ return appSupportDir(appDirName)
+}
+
+func appSupportDir(dirName string) string {
base, err := os.UserConfigDir()
if err != nil || base == "" {
home, homeErr := os.UserHomeDir()
if homeErr != nil || home == "" {
- return appDirName
+ return dirName
}
base = filepath.Join(home, "Library", "Application Support")
}
- return filepath.Join(base, appDirName)
+ return filepath.Join(base, dirName)
}
// File returns a path inside the persistent app data directory.
@@ -27,7 +33,7 @@
return filepath.Join(AppSupportDir(), name)
}
-// ModelDir returns the persistent SenseVoice model directory.
+// ModelDir returns the legacy persistent SenseVoice model directory.
func ModelDir() string {
return filepath.Join(AppSupportDir(), "models", "sensevoice")
}
@@ -37,16 +43,36 @@
return filepath.Join(AppSupportDir(), "models")
}
+// ModelInstallDir returns the persistent install directory for a model profile.
+func ModelInstallDir(name string) string {
+ return filepath.Join(ModelsRoot(), name)
+}
+
+// ModelStatePath returns the persistent model install state file path.
+func ModelStatePath() string {
+ return filepath.Join(ModelsRoot(), "state.json")
+}
+
// Ensure creates the app data directory.
func Ensure() error {
return os.MkdirAll(AppSupportDir(), 0755)
}
-// MigrateFromLegacyExecutableDir copies old user data from beside the executable
-// into Application Support. Existing new-location files are never overwritten.
+// MigrateFromLegacyExecutableDir copies old user data into the current app
+// support directory. Existing new-location files are never overwritten.
func MigrateFromLegacyExecutableDir() error {
if err := Ensure(); err != nil {
return err
+ }
+
+ for _, dirName := range legacyAppDirNames {
+ legacyDir := appSupportDir(dirName)
+ if samePath(legacyDir, AppSupportDir()) {
+ continue
+ }
+ if err := copyUserDataFromDir(legacyDir); err != nil {
+ return fmt.Errorf("migrate %s: %w", dirName, err)
+ }
}
legacyDir, err := legacyExecutableDir()
@@ -57,13 +83,21 @@
return nil
}
+ if err := copyUserDataFromDir(legacyDir); err != nil {
+ return err
+ }
+
+ return nil
+}
+
+func copyUserDataFromDir(sourceDir string) error {
for _, name := range []string{"config.json", "userdict.json", "history.json"} {
- if err := copyFileIfMissing(filepath.Join(legacyDir, name), File(name)); err != nil {
+ if err := copyFileIfMissing(filepath.Join(sourceDir, name), File(name)); err != nil {
return fmt.Errorf("migrate %s: %w", name, err)
}
}
- if err := copyDirIfMissing(filepath.Join(legacyDir, "models"), ModelsRoot()); err != nil {
+ if err := copyDirIfMissing(filepath.Join(sourceDir, "models"), ModelsRoot()); err != nil {
return fmt.Errorf("migrate models: %w", err)
}
--
Gitblit v1.9.3