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() {
	keyPath := `Software\Classes\*\shell\AE Send`
	commandPath := `Software\Classes\*\shell\AE Send\command`

	k, _, err := registry.CreateKey(registry.CURRENT_USER, keyPath, registry.SET_VALUE)
	if err != nil {
		log.Fatalf("Unable to create registry key: %v", err)
	}
	defer k.Close()

	err = k.SetStringValue("", "Send with AE Send")
	if err != nil {
		log.Fatalf("Unable to set registry value: %v", err)
	}

	exePath, err := os.Executable()
	if err != nil {
		log.Fatalf("Unable to get executable path: %v", err)
	}

	k, _, err = registry.CreateKey(registry.CURRENT_USER, commandPath, registry.SET_VALUE)
	if err != nil {
		log.Fatalf("Unable to create command registry key: %v", err)
	}
	defer k.Close()

	err = k.SetStringValue("", "\""+exePath+"\" \"%1\"")
	if err != nil {
		log.Fatalf("Unable 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.")
	}
}
