fixed things lots of things

This commit is contained in:
2023-08-14 19:11:16 -05:00
parent ec40f2b695
commit a14fd98113
2 changed files with 13 additions and 44 deletions

1
build.cmd Normal file
View File

@@ -0,0 +1 @@
fyne package -os windows -icon .\cpms.png

54
main.go
View File

@@ -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 {
// delete any existing archive folder
_ = os.RemoveAll(archive)
// link the profile to the archive
err := os.Symlink(profile, archive)
if err != nil {
return err
}
err = os.Remove(path)
if err != nil {
fmt.Println(err)
}
return nil
})
if err != nil {
fmt.Println(err)
dialog.NewInformation("Error", "this program must be ran as administrator to allow linking", parent).Show()
return
}
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()
dialog.NewInformation("Success", fmt.Sprintf("linked files from %s to %s", filepath.Base(profile), archive), 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
}
return fn(path, info, err)
})
}