ae-send/main.go

76 lines
1.7 KiB
Go

package main
import (
"log"
"os"
"golang.org/x/sys/windows/registry"
)
func main() {
if len(os.Args) > 1 {
switch os.Args[1] {
case "install":
installContextMenuItem()
case "uninstall":
uninstallContextMenuItem()
default:
processFile(os.Args[1])
}
} else {
log.Println("No file provided")
}
}
func processFile(filePath string) {
log.Printf("Processing file: %s", filePath)
// Add your existing file processing logic here
}
func installContextMenuItem() {
exePath, _ := os.Executable()
keyPath := `Software\Classes\*\shell\AE Send`
command := "\"" + exePath + "\" \"%1\""
k, err := registry.OpenKey(registry.CURRENT_USER, keyPath, registry.ALL_ACCESS)
if err != nil {
k, _, err = registry.CreateKey(registry.CURRENT_USER, keyPath, registry.ALL_ACCESS)
if err != nil {
log.Fatalf("Failed to create registry key: %v", err)
return
}
}
defer k.Close()
err = k.SetStringValue("", "Send with AE Send")
if err != nil {
log.Fatalf("Failed to set registry value: %v", err)
return
}
commandKeyPath := keyPath + `\command`
commandKey, _, err := registry.CreateKey(registry.CURRENT_USER, commandKeyPath, registry.ALL_ACCESS)
if err != nil {
log.Fatalf("Failed to create command key: %v", err)
return
}
defer commandKey.Close()
err = commandKey.SetStringValue("", command)
if err != nil {
log.Fatalf("Failed to set command: %v", err)
}
log.Println("Context menu item installed successfully.")
}
func uninstallContextMenuItem() {
keyPath := `Software\Classes\*\shell\AE Send`
err := registry.DeleteKey(registry.CURRENT_USER, keyPath)
if err != nil {
log.Fatalf("Failed to remove context menu item: %v", err)
} else {
log.Println("Context menu item removed successfully.")
}
}