fixed things lots of things
This commit is contained in:
56
main.go
56
main.go
@@ -2,10 +2,8 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/fs"
|
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
|
||||||
|
|
||||||
"fyne.io/fyne/v2"
|
"fyne.io/fyne/v2"
|
||||||
"fyne.io/fyne/v2/app"
|
"fyne.io/fyne/v2/app"
|
||||||
@@ -14,8 +12,6 @@ import (
|
|||||||
"fyne.io/fyne/v2/theme"
|
"fyne.io/fyne/v2/theme"
|
||||||
"fyne.io/fyne/v2/widget"
|
"fyne.io/fyne/v2/widget"
|
||||||
"gopkg.in/yaml.v3"
|
"gopkg.in/yaml.v3"
|
||||||
|
|
||||||
cp "github.com/otiai10/copy"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type Config struct {
|
type Config struct {
|
||||||
@@ -128,13 +124,13 @@ func fillGrid(grid *fyne.Container, parent fyne.Window) {
|
|||||||
defer grid.Show()
|
defer grid.Show()
|
||||||
grid.RemoveAll()
|
grid.RemoveAll()
|
||||||
for _, profile := range profiles {
|
for _, profile := range profiles {
|
||||||
profilename := strings.TrimSuffix(filepath.Base(profile), ".cpms")
|
profilename := filepath.Base(profile)
|
||||||
grid.Add(widget.NewButton(profilename, makeIFunc(profile, archive, parent)))
|
grid.Add(widget.NewButton(profilename, makeIFunc(profile, archive, parent)))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func scanProfiles(profilesroot string) []string {
|
func scanProfiles(profilesroot string) []string {
|
||||||
dir := filepath.Join(profilesroot, "*.cpms/")
|
dir := filepath.Join(profilesroot, "*/")
|
||||||
m, err := filepath.Glob(dir)
|
m, err := filepath.Glob(dir)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
@@ -146,48 +142,20 @@ func scanProfiles(profilesroot string) []string {
|
|||||||
func makeIFunc(profile, archive string, parent fyne.Window) func() {
|
func makeIFunc(profile, archive string, parent fyne.Window) func() {
|
||||||
return func() {
|
return func() {
|
||||||
if cfg.ArchiveRoot == "" || cfg.ProfilesRoot == "" {
|
if cfg.ArchiveRoot == "" || cfg.ProfilesRoot == "" {
|
||||||
d := dialog.NewInformation("Notice", "you must select a archive root and profiles root before", parent)
|
dialog.NewInformation("Notice", "you must select a archive root and profiles root before", parent).Show()
|
||||||
d.Show()
|
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
dialog.NewConfirm("Are You Sure?", fmt.Sprintf("the current contents of %s will be lost", archive), func(b bool) {
|
// delete any existing archive folder
|
||||||
if b {
|
_ = os.RemoveAll(archive)
|
||||||
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)
|
|
||||||
}
|
|
||||||
|
|
||||||
err = cp.Copy(profile, archive)
|
// link the profile to the archive
|
||||||
if err != nil {
|
err := os.Symlink(profile, archive)
|
||||||
fmt.Println(err)
|
if err != nil {
|
||||||
}
|
dialog.NewInformation("Error", "this program must be ran as administrator to allow linking", parent).Show()
|
||||||
|
return
|
||||||
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
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return fn(path, info, err)
|
dialog.NewInformation("Success", fmt.Sprintf("linked files from %s to %s", filepath.Base(profile), archive), parent).Show()
|
||||||
})
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user