Skip to content

Commit

Permalink
Move config & icon file in .dl directory
Browse files Browse the repository at this point in the history
  • Loading branch information
thedevsaddam committed Oct 30, 2021
1 parent 17b6196 commit 96546c1
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
26 changes: 24 additions & 2 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,12 @@ import (
)

const (
configFileName = ".dl.config.json"
configDirectory = ".dl"
configFileName = configDirectory + "/config.json"
)

var (
defaultConfig Config
)

// Config represent configurations for the download manager
Expand All @@ -21,7 +26,13 @@ type Config struct {
SubDirMap values.MapStrSliceString `json:"sub_dir_map"`
}

var defaultConfig Config
func getConfigDir() (string, error) {
homeDir, err := os.UserHomeDir()
if err != nil {
return "", err
}
return filepath.Join(homeDir, configDirectory), nil
}

func getConfigFileName() (string, error) {
homeDir, err := os.UserHomeDir()
Expand Down Expand Up @@ -71,10 +82,21 @@ func CreateConfig(c Config) error {
if err != nil {
return err
}

configDir, err := getConfigDir()
if err != nil {
return err
}

if err := os.MkdirAll(configDir, 0777); err != nil {
return err
}

fn, err := getConfigFileName()
if err != nil {
return err
}

return ioutil.WriteFile(fn, bb, 0644)
}

Expand Down
3 changes: 2 additions & 1 deletion notifier/icon.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ import (
)

const (
icon = ".dl101.png"
configDirectory = ".dl"
icon = ".dl" + "/icon.png"
)

func getIconPath() (string, error) {
Expand Down

0 comments on commit 96546c1

Please sign in to comment.