feat: ConvertGUI v2.0 (Wails + preview/trim + NSIS + Gitea CI)
Build Windows Installer / build (push) Successful in 4m11s
Build Windows Installer / build (push) Successful in 4m11s
This commit is contained in:
40 files changed
+6084
-266
No files matched your search
@@ -0,0 +1,84 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"os"
|
||||
"path/filepath"
|
||||
)
|
||||
|
||||
type AppConfig struct {
|
||||
Language string `json:"language"` // "ru" or "en"
|
||||
FFmpegPath string `json:"ffmpegPath"`
|
||||
FFprobePath string `json:"ffprobePath"`
|
||||
DefaultEncoder string `json:"defaultEncoder"` // libx264, h264_nvenc, libx265, hevc_nvenc
|
||||
DefaultHwDecode string `json:"defaultHwDecode"`
|
||||
DefaultPreset string `json:"defaultPreset"`
|
||||
DefaultCRF int `json:"defaultCrf"`
|
||||
DefaultFPS int `json:"defaultFps"` // 0 = original, 60 = 60fps
|
||||
DefaultTune string `json:"defaultTune"`
|
||||
DefaultMergeAudio bool `json:"defaultMergeAudio"`
|
||||
OutputSuffix string `json:"outputSuffix"`
|
||||
}
|
||||
|
||||
func Default() AppConfig {
|
||||
return AppConfig{
|
||||
Language: "ru",
|
||||
DefaultEncoder: "libx264",
|
||||
DefaultHwDecode: "none",
|
||||
DefaultPreset: "slow",
|
||||
DefaultCRF: 20,
|
||||
DefaultFPS: 60,
|
||||
DefaultTune: "film",
|
||||
DefaultMergeAudio: true,
|
||||
OutputSuffix: "_converted",
|
||||
}
|
||||
}
|
||||
|
||||
func ConfigPath() (string, error) {
|
||||
dir, err := os.UserConfigDir()
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
return filepath.Join(dir, "ConvertGUI", "config.json"), nil
|
||||
}
|
||||
|
||||
func Load() AppConfig {
|
||||
cfg := Default()
|
||||
path, err := ConfigPath()
|
||||
if err != nil {
|
||||
return cfg
|
||||
}
|
||||
data, err := os.ReadFile(path)
|
||||
if err != nil {
|
||||
return cfg
|
||||
}
|
||||
_ = json.Unmarshal(data, &cfg)
|
||||
if cfg.Language == "" {
|
||||
cfg.Language = "ru"
|
||||
}
|
||||
if cfg.DefaultEncoder == "" {
|
||||
cfg.DefaultEncoder = "libx264"
|
||||
}
|
||||
if cfg.DefaultPreset == "" {
|
||||
cfg.DefaultPreset = "slow"
|
||||
}
|
||||
if cfg.DefaultCRF < 0 || cfg.DefaultCRF > 51 {
|
||||
cfg.DefaultCRF = 20
|
||||
}
|
||||
return cfg
|
||||
}
|
||||
|
||||
func Save(cfg AppConfig) error {
|
||||
path, err := ConfigPath()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if err := os.MkdirAll(filepath.Dir(path), 0o755); err != nil {
|
||||
return err
|
||||
}
|
||||
data, err := json.MarshalIndent(cfg, "", " ")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return os.WriteFile(path, data, 0o644)
|
||||
}
|
||||
Reference in new issue
Block a user