diff --git a/src/app/helpers.go b/src/app/helpers.go index 0a96a8e..0900575 100644 --- a/src/app/helpers.go +++ b/src/app/helpers.go @@ -3,7 +3,7 @@ package main import ( "fmt" "io/fs" - "path/filepath" + "log" "strconv" ) @@ -13,6 +13,10 @@ func delay() { } func inputselect_from_array(choses []string) int { + if len(choses) == 0 { + log.Fatal("empty list passed") + } + for { for i, label := range choses { fmt.Printf("%d: %s\n", i, label) @@ -31,7 +35,7 @@ func inputselect_from_array(choses []string) int { func getKeys() ([]fs.DirEntry, []string) { var list []string - keys, _ := resources.ReadDir(filepath.Join("resources", "keys")) + keys, _ := resources.ReadDir("resources/keys") for _, entry := range keys { list = append(list, entry.Name()) diff --git a/src/app/items.go b/src/app/items.go index 79ed2c0..a7ed591 100644 --- a/src/app/items.go +++ b/src/app/items.go @@ -22,6 +22,11 @@ func item_patch() { fmt.Println("Searching for *.vmoptions files ... ") files, appdataDirs := patcher.GetTool().FindDirectories() + if len(files) == 0 { + fmt.Println("No *.vmoptions files found") + return + } + fmt.Println("Choose what to patch:") selected := inputselect_from_array(files) diff --git a/src/app/patch.go b/src/app/patch.go index bc19561..6760741 100644 --- a/src/app/patch.go +++ b/src/app/patch.go @@ -26,7 +26,7 @@ func doPatch(vmoptionsPath string, destinationPath string, keyIndex int) { return } - jarfileContent, _ := resources.ReadFile(filepath.Join("resources", agentName)) + jarfileContent, _ := resources.ReadFile("resources/" + agentName) fpJarfile.Write(jarfileContent) fpJarfile.Close() } @@ -77,7 +77,7 @@ func doPatch(vmoptionsPath string, destinationPath string, keyIndex int) { keyPath := filepath.Join(destinationDir, key.Name()) fpKey, _ := os.Create(keyPath) - keyContent, _ := resources.ReadFile(filepath.Join("resources", "keys", key.Name())) + keyContent, _ := resources.ReadFile("resources/keys/" + key.Name()) fpKey.Write(keyContent) fpKey.Close() diff --git a/src/patchers/linux.go b/src/patchers/linux.go new file mode 100644 index 0000000..ac10a0d --- /dev/null +++ b/src/patchers/linux.go @@ -0,0 +1,12 @@ +package patchers + +type PatcherToolLinux struct { + PatcherTool +} + +func (p PatcherToolLinux) FindDirectories() ([]string, []string) { + files := findVmoptionsFiles([]string{"/home", "/opt"}) + appdataDirs := findLinuxAppdataDirs() + + return files, appdataDirs +} diff --git a/src/patchers/patcher.go b/src/patchers/patcher.go index 8686352..6994fe5 100644 --- a/src/patchers/patcher.go +++ b/src/patchers/patcher.go @@ -25,22 +25,3 @@ func (p Patcher) GetTool() PatcherTool { return p.Tool } - -type PatcherToolWindows struct { - PatcherTool -} - -func (p PatcherToolWindows) FindDirectories() ([]string, []string) { - panic("not implemented") -} - -type PatcherToolLinux struct { - PatcherTool -} - -func (p PatcherToolLinux) FindDirectories() ([]string, []string) { - files := findVmoptionsFiles([]string{"/home", "/opt"}) - appdataDirs := findLinuxAppdataDirs() - - return files, appdataDirs -} diff --git a/src/patchers/windows.go b/src/patchers/windows.go new file mode 100644 index 0000000..9b290d1 --- /dev/null +++ b/src/patchers/windows.go @@ -0,0 +1,27 @@ +package patchers + +import "os" + +type PatcherToolWindows struct { + PatcherTool +} + +func (p PatcherToolWindows) FindDirectories() ([]string, []string) { + configDir, _ := os.UserConfigDir() + var programfilesDirectories = []string{} + programfilesDir := os.Getenv("programfiles") + if programfilesDir != "" { + programfilesDirectories = append(programfilesDirectories, programfilesDir) + } + + programfilesDir = os.Getenv("programfiles(x86)") + if programfilesDir != "" { + programfilesDirectories = append(programfilesDirectories, programfilesDir) + } + + _ = programfilesDir + files := findVmoptionsFiles(programfilesDirectories) + appdata_dirs := findAppdataDirs(configDir) + + return files, appdata_dirs +}