mirror of
https://git.um-react.app/um/cli.git
synced 2025-11-28 03:33:02 +00:00
refactor: improve mmkv logic
This commit is contained in:
65
algo/qmc/key_mmkv_loader_darwin.go
Normal file
65
algo/qmc/key_mmkv_loader_darwin.go
Normal file
@@ -0,0 +1,65 @@
|
||||
package qmc
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
"go.uber.org/zap"
|
||||
"unlock-music.dev/cli/algo/common"
|
||||
)
|
||||
|
||||
func LoadMMKVOrDefault(path string, key string, logger *zap.Logger) (result common.QMCKeys, err error) {
|
||||
key1, err := loadMacKeysV8(logger)
|
||||
if err != nil {
|
||||
key1 = nil
|
||||
logger.Warn("LoadMMKVOrDefault: could not read QQMusic v8.8.0 keys", zap.Error(err))
|
||||
}
|
||||
|
||||
key2, err := loadMacKeysV10(logger)
|
||||
if err != nil {
|
||||
key2 = nil
|
||||
logger.Warn("LoadMMKVOrDefault: could not read QQMusic v10.x keys", zap.Error(err))
|
||||
}
|
||||
|
||||
userKeys := make(common.QMCKeys)
|
||||
if path != "" {
|
||||
logger.Info("Using user mmkv")
|
||||
userKeys, err = LoadMMKV(path, key, logger)
|
||||
if err != nil {
|
||||
userKeys = nil
|
||||
logger.Warn("LoadMMKVOrDefault: could not read user keys", zap.Error(err))
|
||||
}
|
||||
}
|
||||
|
||||
allKeys := mergeMMKVKeys(key1, key2, userKeys)
|
||||
|
||||
logger.Debug("Keys loaded", zap.Any("keys", allKeys), zap.Int("len", len(allKeys)))
|
||||
|
||||
return allKeys, nil
|
||||
}
|
||||
|
||||
func loadMacKeysV8(logger *zap.Logger) (keys common.QMCKeys, err error) {
|
||||
homeDir, err := os.UserHomeDir()
|
||||
if err != nil {
|
||||
logger.Warn("Failed to get home dir")
|
||||
return nil, fmt.Errorf("loadMacKeysV8: failed to get home: %w", err)
|
||||
}
|
||||
p := filepath.Join(
|
||||
homeDir,
|
||||
"Library/Containers/com.tencent.QQMusicMac/Data",
|
||||
"Library/Application Support/QQMusicMac/mmkv",
|
||||
"MMKVStreamEncryptId",
|
||||
)
|
||||
if f, err := os.Stat(p); err == nil && !f.IsDir() {
|
||||
logger.Info("Using QQMusic 8.x mmkv", zap.String("mmkv", p))
|
||||
return LoadMMKV(p, "", logger)
|
||||
}
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func loadMacKeysV10(logger *zap.Logger) (common.QMCKeys, error) {
|
||||
// TODO: stub only
|
||||
var _ = logger
|
||||
return nil, nil
|
||||
}
|
||||
Reference in New Issue
Block a user