Skip to content

Commit

Permalink
Add cleanup config
Browse files Browse the repository at this point in the history
  • Loading branch information
crazy-max committed Sep 29, 2020
1 parent 01c7f63 commit 9a45658
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.")
}
}
Expand All @@ -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()
Expand Down

0 comments on commit 9a45658

Please sign in to comment.