Skip to content

Commit

Permalink
Windows patcher
Browse files Browse the repository at this point in the history
  • Loading branch information
p1ratrulezzz committed Apr 28, 2022
1 parent 3fafcaf commit b1c2760
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 23 deletions.
8 changes: 6 additions & 2 deletions src/app/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package main
import (
"fmt"
"io/fs"
"path/filepath"
"log"
"strconv"
)

Expand All @@ -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)
Expand All @@ -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())
Expand Down
5 changes: 5 additions & 0 deletions src/app/items.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
4 changes: 2 additions & 2 deletions src/app/patch.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Expand Down Expand Up @@ -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()

Expand Down
12 changes: 12 additions & 0 deletions src/patchers/linux.go
Original file line number Diff line number Diff line change
@@ -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
}
19 changes: 0 additions & 19 deletions src/patchers/patcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
27 changes: 27 additions & 0 deletions src/patchers/windows.go
Original file line number Diff line number Diff line change
@@ -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
}

0 comments on commit b1c2760

Please sign in to comment.