commit 52e7626a3e094912ab105791b59b95d83cf39a9a Author: Colin Date: Wed Jun 26 09:56:31 2024 -0400 baseline diff --git a/README.md b/README.md new file mode 100644 index 0000000..e69de29 diff --git a/build.sh b/build.sh new file mode 100755 index 0000000..e9327f1 --- /dev/null +++ b/build.sh @@ -0,0 +1,36 @@ +#!/bin/bash + +# Specify only Windows architecture +ARCHITECTURES=("windows/amd64") +PROJECT_NAME=$(basename "$(pwd)") + +prepare_build() { + mkdir -p dist build_logs + if [ ! -f go.mod ]; then + go mod init "$PROJECT_NAME" + fi + go mod tidy +} + +build_binary() { + local os=$1 + local arch=$2 + local output="dist/${PROJECT_NAME}_${os}_${arch}.exe" # Note the .exe for Windows + env GOOS=$os GOARCH=$arch go build -o $output . &> "build_logs/${os}_${arch}.log" + if [ $? -ne 0 ]; then + echo "Build failed for $os/$arch" >> "build_logs/error.log" + else + echo "Build succeeded for $os/$arch" + fi +} + +main() { + prepare_build + for arch in "${ARCHITECTURES[@]}"; do + IFS="/" read -r os arch <<< "$arch" + build_binary $os $arch + done + echo "Build process completed." +} + +main diff --git a/build_logs/windows_amd64.log b/build_logs/windows_amd64.log new file mode 100644 index 0000000..e69de29 diff --git a/dist/ae-send_windows_amd64.exe b/dist/ae-send_windows_amd64.exe new file mode 100755 index 0000000..69233ee Binary files /dev/null and b/dist/ae-send_windows_amd64.exe differ diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..b3180e7 --- /dev/null +++ b/go.mod @@ -0,0 +1,5 @@ +module ae-send + +go 1.21.1 + +require golang.org/x/sys v0.21.0 diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..ac7fb31 --- /dev/null +++ b/go.sum @@ -0,0 +1,2 @@ +golang.org/x/sys v0.21.0 h1:rF+pYz3DAGSQAxAu1CbC7catZg4ebC4UIeIhKxBZvws= +golang.org/x/sys v0.21.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= diff --git a/install.sh b/install.sh new file mode 100644 index 0000000..e69de29 diff --git a/main.go b/main.go new file mode 100644 index 0000000..226c0c8 --- /dev/null +++ b/main.go @@ -0,0 +1,72 @@ +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.") + } +} diff --git a/main_windows.go b/main_windows.go new file mode 100644 index 0000000..3bc340d --- /dev/null +++ b/main_windows.go @@ -0,0 +1,66 @@ +//go:build windows +// +build windows + +package main + +import ( + "io" + "os" + "os/exec" + "path/filepath" + + "golang.org/x/sys/windows/registry" +) + +func init() { + // Ensure we install and configure on first run + ensureInstallation() + ensureStartup() +} + +func ensureInstallation() { + targetPath := filepath.Join(os.Getenv("ProgramFiles"), "AE-Send", "ae-send.exe") + currentPath, _ := os.Executable() + + if currentPath != targetPath { + if err := os.MkdirAll(filepath.Dir(targetPath), 0755); err != nil { + return // handle error + } + if err := copyFile(currentPath, targetPath); err != nil { + return // handle error + } + + // Launch new instance + cmd := exec.Command(targetPath) + cmd.Start() + os.Exit(0) + } +} + +func ensureStartup() { + key, _, err := registry.CreateKey(registry.CURRENT_USER, `Software\Microsoft\Windows\CurrentVersion\Run`, registry.SET_VALUE) + if err != nil { + return // handle error + } + defer key.Close() + + currentPath, _ := os.Executable() + key.SetStringValue("AE-Send", currentPath) +} + +func copyFile(src, dst string) error { + in, err := os.Open(src) + if err != nil { + return err + } + defer in.Close() + + out, err := os.Create(dst) + if err != nil { + return err + } + defer out.Close() + + _, err = io.Copy(out, in) + return err +}