From a14fd98113294707e8a1552db5d13954b9f5be82 Mon Sep 17 00:00:00 2001 From: Justin Harms Date: Mon, 14 Aug 2023 19:11:16 -0500 Subject: [PATCH] fixed things lots of things --- build.cmd | 1 + main.go | 56 ++++++++++++------------------------------------------- 2 files changed, 13 insertions(+), 44 deletions(-) create mode 100644 build.cmd diff --git a/build.cmd b/build.cmd new file mode 100644 index 0000000..6757e4e --- /dev/null +++ b/build.cmd @@ -0,0 +1 @@ +fyne package -os windows -icon .\cpms.png \ No newline at end of file diff --git a/main.go b/main.go index d48f743..83ba43a 100644 --- a/main.go +++ b/main.go @@ -2,10 +2,8 @@ package main import ( "fmt" - "io/fs" "os" "path/filepath" - "strings" "fyne.io/fyne/v2" "fyne.io/fyne/v2/app" @@ -14,8 +12,6 @@ import ( "fyne.io/fyne/v2/theme" "fyne.io/fyne/v2/widget" "gopkg.in/yaml.v3" - - cp "github.com/otiai10/copy" ) type Config struct { @@ -128,13 +124,13 @@ func fillGrid(grid *fyne.Container, parent fyne.Window) { defer grid.Show() grid.RemoveAll() for _, profile := range profiles { - profilename := strings.TrimSuffix(filepath.Base(profile), ".cpms") + profilename := filepath.Base(profile) grid.Add(widget.NewButton(profilename, makeIFunc(profile, archive, parent))) } } func scanProfiles(profilesroot string) []string { - dir := filepath.Join(profilesroot, "*.cpms/") + dir := filepath.Join(profilesroot, "*/") m, err := filepath.Glob(dir) if err != nil { fmt.Println(err) @@ -146,48 +142,20 @@ func scanProfiles(profilesroot string) []string { func makeIFunc(profile, archive string, parent fyne.Window) func() { return func() { if cfg.ArchiveRoot == "" || cfg.ProfilesRoot == "" { - d := dialog.NewInformation("Notice", "you must select a archive root and profiles root before", parent) - d.Show() - + dialog.NewInformation("Notice", "you must select a archive root and profiles root before", parent).Show() return } - dialog.NewConfirm("Are You Sure?", fmt.Sprintf("the current contents of %s will be lost", archive), func(b bool) { - if b { - err := walk(archive, func(path string, info fs.FileInfo, err error) error { - if err != nil { - return err - } - err = os.Remove(path) - if err != nil { - fmt.Println(err) - } - return nil - }) - if err != nil { - fmt.Println(err) - } + // delete any existing archive folder + _ = os.RemoveAll(archive) - err = cp.Copy(profile, archive) - if err != nil { - fmt.Println(err) - } - - dialog.NewInformation("Success", fmt.Sprintf("copied all files from %s to %s", filepath.Base(profile), archive), parent).Show() - } - }, parent).Show() - } -} - -func walk(root string, fn filepath.WalkFunc) error { - initial := false - - return filepath.Walk(root, func(path string, info fs.FileInfo, err error) error { - if !initial { - initial = true - return nil + // link the profile to the archive + err := os.Symlink(profile, archive) + if err != nil { + dialog.NewInformation("Error", "this program must be ran as administrator to allow linking", parent).Show() + return } - return fn(path, info, err) - }) + dialog.NewInformation("Success", fmt.Sprintf("linked files from %s to %s", filepath.Base(profile), archive), parent).Show() + } }