diff --git a/main.go b/main.go index 079b622..4fcd914 100644 --- a/main.go +++ b/main.go @@ -4,21 +4,32 @@ package main import ( "os" + "path" "github.com/portapps/portapps/v2" "github.com/portapps/portapps/v2/pkg/log" "github.com/portapps/portapps/v2/pkg/utl" ) +type config struct { + Cleanup bool `yaml:"cleanup" mapstructure:"cleanup"` +} + var ( app *portapps.App + cfg *config ) func init() { var err error + // Default config + cfg = &config{ + Cleanup: false, + } + // Init app - if app, err = portapps.New("transmission-portable", "Transmission"); err != nil { + if app, err = portapps.NewWithCfg("transmission-portable", "Transmission", cfg); err != nil { log.Fatal().Err(err).Msg("Cannot initialize application. See log file for more info.") } } @@ -27,6 +38,15 @@ func main() { utl.CreateFolder(app.DataPath) app.Process = utl.PathJoin(app.AppPath, "transmission-qt.exe") + // Cleanup on exit + if cfg.Cleanup { + defer func() { + utl.Cleanup([]string{ + path.Join(os.Getenv("APPDATA"), "transmission"), + }) + }() + } + utl.OverrideEnv("TRANSMISSION_HOME", app.DataPath) defer app.Close()