comment the shit outta this
This commit is contained in:
parent
7f7d2ff393
commit
b6587e58d3
5 changed files with 67 additions and 35 deletions
10
go.mod
10
go.mod
|
@ -1,9 +1,11 @@
|
|||
module wanna-goon
|
||||
|
||||
go 1.22.5
|
||||
go 1.23.1
|
||||
|
||||
toolchain go1.24.0
|
||||
|
||||
require (
|
||||
github.com/Merith-TK/utils v0.0.0-20240919202228-115b4d33f5d8
|
||||
github.com/Merith-TK/utils v0.0.0-20241022045459-1018f4b81f87
|
||||
github.com/ncruces/zenity v0.10.14
|
||||
)
|
||||
|
||||
|
@ -12,6 +14,6 @@ require (
|
|||
github.com/dchest/jsmin v0.0.0-20220218165748-59f39799265f // indirect
|
||||
github.com/josephspurrier/goversioninfo v1.4.1 // indirect
|
||||
github.com/randall77/makefat v0.0.0-20210315173500-7ddd0e42c844 // indirect
|
||||
golang.org/x/image v0.20.0 // indirect
|
||||
golang.org/x/sys v0.25.0 // indirect
|
||||
golang.org/x/image v0.21.0 // indirect
|
||||
golang.org/x/sys v0.26.0 // indirect
|
||||
)
|
||||
|
|
12
go.sum
12
go.sum
|
@ -1,5 +1,5 @@
|
|||
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=
|
||||
github.com/Merith-TK/utils v0.0.0-20241022045459-1018f4b81f87 h1:z6UI46B9lUzCUAHs+VjURdBDelL524gCTNybZCRsn/8=
|
||||
github.com/Merith-TK/utils v0.0.0-20241022045459-1018f4b81f87/go.mod h1:gLvM19iu7i+cnsQMBq98rZa98tv9DCxecmFXuHQS9kc=
|
||||
github.com/akavel/rsrc v0.10.2 h1:Zxm8V5eI1hW4gGaYsJQUhxpjkENuG91ki8B4zCrvEsw=
|
||||
github.com/akavel/rsrc v0.10.2/go.mod h1:uLoCtb9J+EyAqh+26kdrTgmzRBFPGOolLWKpdxkKq+c=
|
||||
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
|
||||
|
@ -19,10 +19,10 @@ github.com/stretchr/testify v1.6.1 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd
|
|||
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||
go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto=
|
||||
go.uber.org/goleak v1.3.0/go.mod h1:CoHD4mav9JJNrW/WLlf7HGZPjdw8EucARQHekz1X6bE=
|
||||
golang.org/x/image v0.20.0 h1:7cVCUjQwfL18gyBJOmYvptfSHS8Fb3YUDtfLIZ7Nbpw=
|
||||
golang.org/x/image v0.20.0/go.mod h1:0a88To4CYVBAHp5FXJm8o7QbUl37Vd85ply1vyD8auM=
|
||||
golang.org/x/sys v0.25.0 h1:r+8e+loiHxRqhXVl6ML1nO3l1+oFoWbnlu2Ehimmi34=
|
||||
golang.org/x/sys v0.25.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
||||
golang.org/x/image v0.21.0 h1:c5qV36ajHpdj4Qi0GnE0jUc/yuo33OLFaa0d+crTD5s=
|
||||
golang.org/x/image v0.21.0/go.mod h1:vUbsLavqK/W303ZroQQVKQ+Af3Yl6Uz1Ppu5J/cLz78=
|
||||
golang.org/x/sys v0.26.0 h1:KHjCJyddX0LoSTb3J+vWpupP9p0oznkqVk/IfjymZbo=
|
||||
golang.org/x/sys v0.26.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
|
||||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
|
|
23
goon.go
23
goon.go
|
@ -10,17 +10,23 @@ import (
|
|||
"github.com/Merith-TK/utils/debug"
|
||||
)
|
||||
|
||||
// goonFiles moves files from the specified source path to the `.wanna-goon` directory.
|
||||
// This is a "soft punishment" for users who break the rules.
|
||||
func goonFiles(src string) error {
|
||||
debug.SetTitle("goonFiles")
|
||||
defer debug.ResetTitle()
|
||||
debug.SetTitle("goonFiles") // Set the debug title to "goonFiles"
|
||||
defer debug.ResetTitle() // Reset the debug title when the function exits
|
||||
|
||||
var goonError error
|
||||
var goonDest string
|
||||
|
||||
// Get the absolute path of the source file/directory
|
||||
src, goonError = filepath.Abs(src)
|
||||
if goonError != nil {
|
||||
return goonError
|
||||
}
|
||||
goonDest = filepath.ToSlash(src)
|
||||
|
||||
// Check if the source path exists
|
||||
_, err := os.Stat(src)
|
||||
if os.IsNotExist(err) {
|
||||
return fmt.Errorf("source path does not exist: %s", src)
|
||||
|
@ -29,6 +35,7 @@ func goonFiles(src string) error {
|
|||
return fmt.Errorf("could not stat source path: %v", err)
|
||||
}
|
||||
|
||||
// Prepare the destination path within the `.wanna-goon` directory
|
||||
goonDest = strings.TrimPrefix(goonDest, "C:/")
|
||||
userProfile := os.Getenv("USERPROFILE")
|
||||
if userProfile == "" {
|
||||
|
@ -38,11 +45,14 @@ func goonFiles(src string) error {
|
|||
goonDestPath := filepath.Join("C:/", ".wanna-goon", goonDest)
|
||||
debug.Print("gooning:", src)
|
||||
debug.Print("to:", goonDestPath)
|
||||
|
||||
// Create the necessary directories in the `.wanna-goon` directory
|
||||
goonError = os.MkdirAll(filepath.Dir(goonDestPath), os.ModePerm)
|
||||
if goonError != nil {
|
||||
return fmt.Errorf("could not create directory %s: %v", goonDestPath, goonError)
|
||||
}
|
||||
|
||||
// Move the file/directory to the `.wanna-goon` directory
|
||||
goonError = os.Rename(src, goonDestPath)
|
||||
if goonError != nil {
|
||||
return fmt.Errorf("could not move file from %s to %s: %v", src, goonDestPath, goonError)
|
||||
|
@ -51,11 +61,16 @@ func goonFiles(src string) error {
|
|||
return goonError
|
||||
}
|
||||
|
||||
// goonProgram kills a running process by its executable name.
|
||||
// This is used to stop programs that are running against the rules.
|
||||
func goonProgram(exeName string) error {
|
||||
var err error
|
||||
debug.SetTitle("cooming")
|
||||
defer debug.ResetTitle()
|
||||
debug.SetTitle("cooming") // Set the debug title to "cooming"
|
||||
defer debug.ResetTitle() // Reset the debug title when the function exits
|
||||
|
||||
debug.Print("gooning:", exeName)
|
||||
|
||||
// Execute a command to forcefully kill the process by its name
|
||||
cmdKill := exec.Command("cmd", "/C", "taskkill /IM", exeName, "/F")
|
||||
err = cmdKill.Run()
|
||||
if err != nil {
|
||||
|
|
34
main.go
34
main.go
|
@ -10,45 +10,55 @@ import (
|
|||
"github.com/ncruces/zenity"
|
||||
)
|
||||
|
||||
var recovery bool
|
||||
var recovery bool // Flag to determine if the program should restore files
|
||||
|
||||
// init initializes the command-line flags.
|
||||
func init() {
|
||||
flag.BoolVar(&recovery, "recovery", false, "Undo Fuckery")
|
||||
flag.BoolVar(&recovery, "recovery", false, "Undo Fuckery") // Define a flag for recovery mode
|
||||
}
|
||||
|
||||
// main is the entry point of the program.
|
||||
func main() {
|
||||
flag.Parse()
|
||||
flag.Parse() // Parse the command-line flags
|
||||
|
||||
// If recovery mode is enabled, restore files and notify the user
|
||||
if recovery {
|
||||
restoreFiles()
|
||||
zenity.Info("You have been a good goon-slut and earned your files back!")
|
||||
restoreFiles() // Restore files from the `.wanna-goon` directory
|
||||
zenity.Info("You have been a good goon-slut and earned your files back!") // Show a success message
|
||||
return
|
||||
}
|
||||
|
||||
// Get the user's profile directory from the environment variable
|
||||
userdata := os.Getenv("USERPROFILE")
|
||||
debug.Print(fmt.Sprintf("USERPROFILE: %s", userdata))
|
||||
debug.Print(fmt.Sprintf("USERPROFILE: %s", userdata)) // Log the user's profile directory
|
||||
|
||||
// Get the local application data directory from the environment variable
|
||||
localAppData := os.Getenv("LOCALAPPDATA")
|
||||
debug.Print(fmt.Sprintf("LOCALAPPDATA: %s", localAppData))
|
||||
debug.Print(fmt.Sprintf("LOCALAPPDATA: %s", localAppData)) // Log the local application data directory
|
||||
|
||||
// Define a map of programs and their corresponding directories to "goon"
|
||||
programFiles := map[string]string{
|
||||
"Discord.exe": fmt.Sprintf("%s\\Discord", localAppData),
|
||||
"Discord.exe": fmt.Sprintf("%s\\Discord", localAppData), // Example: Discord executable and its directory
|
||||
}
|
||||
|
||||
debug.Println(programFiles)
|
||||
debug.Println(programFiles) // Log the program files map
|
||||
|
||||
// Iterate over the programs and their directories
|
||||
for program, files := range programFiles {
|
||||
// Kill the running program
|
||||
err := goonProgram(program)
|
||||
if err != nil {
|
||||
debug.Print(err)
|
||||
debug.Print(err) // Log any errors that occur while killing the program
|
||||
}
|
||||
time.Sleep(5 * time.Second)
|
||||
time.Sleep(5 * time.Second) // Wait for 5 seconds to ensure the program is fully terminated
|
||||
|
||||
// Move the program's files to the `.wanna-goon` directory
|
||||
err = goonFiles(files)
|
||||
if err != nil {
|
||||
debug.Print(err)
|
||||
debug.Print(err) // Log any errors that occur while moving the files
|
||||
}
|
||||
}
|
||||
|
||||
// Notify the user that they have been "punished"
|
||||
zenity.Warning("You have been a naughty gooner, face the punishment like a good goon-slut")
|
||||
}
|
||||
|
|
23
recover.go
23
recover.go
|
@ -9,30 +9,31 @@ import (
|
|||
"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/".
|
||||
// restoreFiles is a duplicate function that performs the same operation as in `main.go`.
|
||||
// It restores files from the `.wanna-goon` directory back to their original locations.
|
||||
func restoreFiles() error {
|
||||
debug.SetTitle("Restore")
|
||||
defer debug.ResetTitle()
|
||||
debug.SetTitle("Restore") // Set the debug title to "Restore"
|
||||
defer debug.ResetTitle() // Reset the debug title when the function exits
|
||||
|
||||
// Get the user's profile directory from the environment variable
|
||||
userProfile := os.Getenv("USERPROFILE")
|
||||
if userProfile == "" {
|
||||
return fmt.Errorf("could not get USERPROFILE environment variable")
|
||||
}
|
||||
|
||||
// Get the absolute path to the `.wanna-goon` directory
|
||||
wannaGoonPath, wannaGoonErr := filepath.Abs("C:/.wanna-goon")
|
||||
if wannaGoonErr != nil {
|
||||
return fmt.Errorf("could not get absolute path for .wanna-goon: %v", wannaGoonErr)
|
||||
}
|
||||
|
||||
// Walk through the `.wanna-goon` directory to restore files
|
||||
err := filepath.Walk(wannaGoonPath, func(path string, info os.FileInfo, err error) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// If the current path is a directory, recreate it in the original location
|
||||
if info.IsDir() {
|
||||
destPath := filepath.Join("C:/", strings.TrimPrefix(path, wannaGoonPath))
|
||||
debug.Print("creating directory:", destPath)
|
||||
|
@ -40,6 +41,7 @@ func restoreFiles() error {
|
|||
return fmt.Errorf("could not create directory %s: %v", destPath, err)
|
||||
}
|
||||
} else {
|
||||
// If the current path is a file, move it back to the original location
|
||||
destPath := filepath.Join("C:/", strings.TrimPrefix(path, wannaGoonPath))
|
||||
debug.Print("moving file:", path, "to:", destPath)
|
||||
if err := os.Rename(path, destPath); err != nil {
|
||||
|
@ -48,10 +50,13 @@ func restoreFiles() error {
|
|||
}
|
||||
return nil
|
||||
})
|
||||
|
||||
// Handle any errors that occurred during the file restoration process
|
||||
if err != nil {
|
||||
return fmt.Errorf("error restoring files: %v", err)
|
||||
} else {
|
||||
debug.Print("files restored successfully")
|
||||
// Remove the `.wanna-goon` directory after all files have been restored
|
||||
if err := os.RemoveAll(wannaGoonPath); err != nil {
|
||||
return fmt.Errorf("could not remove wanna-goon directory: %v", err)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue