change to zerolog
This commit is contained in:
@@ -2,8 +2,8 @@ package utils
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
|
||||
"github.com/rs/zerolog/log"
|
||||
"github.com/zalando/go-keyring"
|
||||
)
|
||||
|
||||
@@ -23,7 +23,7 @@ func SaveSudoPassword(password string) error {
|
||||
return fmt.Errorf("failed to save password to keychain: %v", err)
|
||||
}
|
||||
|
||||
log.Println("Password saved securely to keychain")
|
||||
log.Info().Msg("Password saved securely to keychain")
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -52,7 +52,7 @@ func DeleteSudoPassword() error {
|
||||
return fmt.Errorf("failed to delete password from keychain: %v", err)
|
||||
}
|
||||
|
||||
log.Println("Password removed from keychain")
|
||||
log.Info().Msg("Password removed from keychain")
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@@ -4,6 +4,7 @@ import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"github.com/rs/zerolog/log"
|
||||
"io"
|
||||
"net/http"
|
||||
"os"
|
||||
@@ -11,8 +12,6 @@ import (
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"epochsilicon/pkg/debug"
|
||||
|
||||
"fyne.io/fyne/v2"
|
||||
"fyne.io/fyne/v2/dialog"
|
||||
)
|
||||
@@ -104,16 +103,16 @@ func CopyDir(src string, dst string) error {
|
||||
|
||||
// RunOsascript runs an AppleScript command using osascript.
|
||||
func RunOsascript(scriptString string, myWindow fyne.Window) bool {
|
||||
debug.Printf("Executing AppleScript: %s", scriptString)
|
||||
log.Debug().Msgf("Executing AppleScript: %s", scriptString)
|
||||
cmd := exec.Command("osascript", "-e", scriptString)
|
||||
output, err := cmd.CombinedOutput()
|
||||
if err != nil {
|
||||
errMsg := fmt.Sprintf("AppleScript failed: %v\nOutput: %s", err, string(output))
|
||||
dialog.ShowError(errors.New(errMsg), myWindow)
|
||||
debug.Println(errMsg)
|
||||
log.Debug().Msg(errMsg)
|
||||
return false
|
||||
}
|
||||
debug.Printf("osascript output: %s", string(output))
|
||||
log.Debug().Msgf("osascript output: %s", string(output))
|
||||
return true
|
||||
}
|
||||
|
||||
@@ -264,14 +263,14 @@ func InstallUpdate(dmgPath string) error {
|
||||
}
|
||||
|
||||
// Mount the DMG and parse the mount point from plist output
|
||||
debug.Printf("Mounting DMG: %s", dmgPath)
|
||||
log.Debug().Msgf("Mounting DMG: %s", dmgPath)
|
||||
mountCmd := exec.Command("hdiutil", "attach", dmgPath, "-nobrowse", "-plist")
|
||||
mountOutput, err := mountCmd.CombinedOutput()
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to mount DMG: %v, output: %s", err, string(mountOutput))
|
||||
}
|
||||
|
||||
debug.Printf("Mount output: %s", string(mountOutput))
|
||||
log.Debug().Msgf("Mount output: %s", string(mountOutput))
|
||||
|
||||
mountPoint := ""
|
||||
|
||||
@@ -292,7 +291,7 @@ func InstallUpdate(dmgPath string) error {
|
||||
end := strings.Index(nextLine, "</string>")
|
||||
if start >= 8 && end > start {
|
||||
mountPoint = nextLine[start:end]
|
||||
debug.Printf("Found mount point in plist: %s", mountPoint)
|
||||
log.Debug().Msgf("Found mount point in plist: %s", mountPoint)
|
||||
break
|
||||
}
|
||||
}
|
||||
@@ -301,7 +300,7 @@ func InstallUpdate(dmgPath string) error {
|
||||
|
||||
// Fallback: try without -plist flag for simpler output
|
||||
if mountPoint == "" {
|
||||
debug.Printf("Plist parsing failed, trying simple mount")
|
||||
log.Debug().Msgf("Plist parsing failed, trying simple mount")
|
||||
// Unmount first if something was mounted
|
||||
exec.Command("hdiutil", "detach", dmgPath, "-force").Run()
|
||||
|
||||
@@ -321,7 +320,7 @@ func InstallUpdate(dmgPath string) error {
|
||||
for i := len(parts) - 1; i >= 0; i-- {
|
||||
if strings.HasPrefix(parts[i], "/Volumes/") {
|
||||
mountPoint = parts[i]
|
||||
debug.Printf("Found mount point in simple output: %s", mountPoint)
|
||||
log.Debug().Msgf("Found mount point in simple output: %s", mountPoint)
|
||||
break
|
||||
}
|
||||
}
|
||||
@@ -336,11 +335,11 @@ func InstallUpdate(dmgPath string) error {
|
||||
return fmt.Errorf("could not find mount point. Mount output: %s", string(mountOutput))
|
||||
}
|
||||
|
||||
debug.Printf("Using mount point: %s", mountPoint)
|
||||
log.Debug().Msgf("Using mount point: %s", mountPoint)
|
||||
|
||||
defer func() {
|
||||
// Unmount the DMG
|
||||
debug.Printf("Unmounting DMG from: %s", mountPoint)
|
||||
log.Debug().Msgf("Unmounting DMG from: %s", mountPoint)
|
||||
unmountCmd := exec.Command("hdiutil", "detach", mountPoint, "-force")
|
||||
unmountCmd.Run()
|
||||
}()
|
||||
@@ -354,7 +353,7 @@ func InstallUpdate(dmgPath string) error {
|
||||
newAppPath = exactPath
|
||||
} else {
|
||||
// Search for any .app bundle in the mount point
|
||||
debug.Printf("EpochSilicon.app not found at exact path, searching for .app bundles")
|
||||
log.Debug().Msgf("EpochSilicon.app not found at exact path, searching for .app bundles")
|
||||
entries, err := os.ReadDir(mountPoint)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to read DMG contents: %v", err)
|
||||
@@ -363,7 +362,7 @@ func InstallUpdate(dmgPath string) error {
|
||||
for _, entry := range entries {
|
||||
if entry.IsDir() && strings.HasSuffix(entry.Name(), ".app") {
|
||||
candidatePath := filepath.Join(mountPoint, entry.Name())
|
||||
debug.Printf("Found .app bundle: %s", candidatePath)
|
||||
log.Debug().Msgf("Found .app bundle: %s", candidatePath)
|
||||
newAppPath = candidatePath
|
||||
break
|
||||
}
|
||||
@@ -374,11 +373,11 @@ func InstallUpdate(dmgPath string) error {
|
||||
return fmt.Errorf("no .app bundle found in DMG at %s", mountPoint)
|
||||
}
|
||||
|
||||
debug.Printf("Found app to install: %s", newAppPath)
|
||||
log.Debug().Msgf("Found app to install: %s", newAppPath)
|
||||
|
||||
// Create backup of current app
|
||||
backupPath := currentAppPath + ".backup"
|
||||
debug.Printf("Creating backup: %s -> %s", currentAppPath, backupPath)
|
||||
log.Debug().Msgf("Creating backup: %s -> %s", currentAppPath, backupPath)
|
||||
|
||||
// Remove old backup if it exists
|
||||
if PathExists(backupPath) {
|
||||
@@ -390,16 +389,16 @@ func InstallUpdate(dmgPath string) error {
|
||||
}
|
||||
|
||||
// Remove current app
|
||||
debug.Printf("Removing current app: %s", currentAppPath)
|
||||
log.Debug().Msgf("Removing current app: %s", currentAppPath)
|
||||
if err := os.RemoveAll(currentAppPath); err != nil {
|
||||
return fmt.Errorf("failed to remove current app: %v", err)
|
||||
}
|
||||
|
||||
// Copy new app
|
||||
debug.Printf("Installing new app: %s -> %s", newAppPath, currentAppPath)
|
||||
log.Debug().Msgf("Installing new app: %s -> %s", newAppPath, currentAppPath)
|
||||
if err := CopyDir(newAppPath, currentAppPath); err != nil {
|
||||
// Try to restore backup on failure
|
||||
debug.Printf("Installation failed, restoring backup")
|
||||
log.Debug().Msgf("Installation failed, restoring backup")
|
||||
os.RemoveAll(currentAppPath)
|
||||
CopyDir(backupPath, currentAppPath)
|
||||
return fmt.Errorf("failed to install new app: %v", err)
|
||||
@@ -408,25 +407,25 @@ func InstallUpdate(dmgPath string) error {
|
||||
// Fix executable permissions for the main binary
|
||||
executablePath := filepath.Join(currentAppPath, "Contents", "MacOS", "epochsilicon")
|
||||
if PathExists(executablePath) {
|
||||
debug.Printf("Setting executable permissions for: %s", executablePath)
|
||||
log.Debug().Msgf("Setting executable permissions for: %s", executablePath)
|
||||
if err := os.Chmod(executablePath, 0755); err != nil {
|
||||
debug.Printf("Warning: failed to set executable permissions: %v", err)
|
||||
log.Debug().Msgf("Warning: failed to set executable permissions: %v", err)
|
||||
// Don't fail the entire update for this, but log it
|
||||
}
|
||||
} else {
|
||||
debug.Printf("Warning: executable not found at expected path: %s", executablePath)
|
||||
log.Debug().Msgf("Warning: executable not found at expected path: %s", executablePath)
|
||||
}
|
||||
|
||||
// Remove backup on success
|
||||
os.RemoveAll(backupPath)
|
||||
|
||||
debug.Printf("Update installed successfully")
|
||||
log.Debug().Msgf("Update installed successfully")
|
||||
return nil
|
||||
}
|
||||
|
||||
// TestDMGMount tests DMG mounting and returns mount point and app path for debugging
|
||||
func TestDMGMount(dmgPath string) (string, string, error) {
|
||||
debug.Printf("Testing DMG mount: %s", dmgPath)
|
||||
log.Debug().Msgf("Testing DMG mount: %s", dmgPath)
|
||||
|
||||
// Mount the DMG with verbose output to better parse mount point
|
||||
mountCmd := exec.Command("hdiutil", "attach", dmgPath, "-nobrowse", "-plist")
|
||||
@@ -435,7 +434,7 @@ func TestDMGMount(dmgPath string) (string, string, error) {
|
||||
return "", "", fmt.Errorf("failed to mount DMG: %v, output: %s", err, string(mountOutput))
|
||||
}
|
||||
|
||||
debug.Printf("Mount output: %s", string(mountOutput))
|
||||
log.Debug().Msgf("Mount output: %s", string(mountOutput))
|
||||
|
||||
// Parse mount output to get mount point
|
||||
mountPoint := ""
|
||||
@@ -460,7 +459,7 @@ func TestDMGMount(dmgPath string) (string, string, error) {
|
||||
|
||||
// Second try: use hdiutil info to get mount points if first method failed
|
||||
if mountPoint == "" {
|
||||
debug.Printf("First mount point detection failed, trying hdiutil info")
|
||||
log.Debug().Msgf("First mount point detection failed, trying hdiutil info")
|
||||
infoCmd := exec.Command("hdiutil", "info", "-plist")
|
||||
infoOutput, infoErr := infoCmd.CombinedOutput()
|
||||
if infoErr == nil {
|
||||
@@ -481,7 +480,7 @@ func TestDMGMount(dmgPath string) (string, string, error) {
|
||||
return "", "", fmt.Errorf("could not find mount point. Mount output: %s", string(mountOutput))
|
||||
}
|
||||
|
||||
debug.Printf("Using mount point: %s", mountPoint)
|
||||
log.Debug().Msgf("Using mount point: %s", mountPoint)
|
||||
|
||||
// Find the app in the mounted DMG
|
||||
var newAppPath string
|
||||
@@ -492,7 +491,7 @@ func TestDMGMount(dmgPath string) (string, string, error) {
|
||||
newAppPath = exactPath
|
||||
} else {
|
||||
// Search for any .app bundle in the mount point
|
||||
debug.Printf("EpochSilicon.app not found at exact path, searching for .app bundles")
|
||||
log.Debug().Msgf("EpochSilicon.app not found at exact path, searching for .app bundles")
|
||||
entries, err := os.ReadDir(mountPoint)
|
||||
if err != nil {
|
||||
// Unmount before returning error
|
||||
@@ -503,7 +502,7 @@ func TestDMGMount(dmgPath string) (string, string, error) {
|
||||
for _, entry := range entries {
|
||||
if entry.IsDir() && strings.HasSuffix(entry.Name(), ".app") {
|
||||
candidatePath := filepath.Join(mountPoint, entry.Name())
|
||||
debug.Printf("Found .app bundle: %s", candidatePath)
|
||||
log.Debug().Msgf("Found .app bundle: %s", candidatePath)
|
||||
newAppPath = candidatePath
|
||||
break
|
||||
}
|
||||
@@ -511,7 +510,7 @@ func TestDMGMount(dmgPath string) (string, string, error) {
|
||||
}
|
||||
|
||||
// Unmount after testing
|
||||
debug.Printf("Unmounting test DMG from: %s", mountPoint)
|
||||
log.Debug().Msgf("Unmounting test DMG from: %s", mountPoint)
|
||||
exec.Command("hdiutil", "detach", mountPoint, "-force").Run()
|
||||
|
||||
if newAppPath == "" {
|
||||
@@ -531,14 +530,14 @@ func CompareFileWithBundledResource(filePath, resourceName string) bool {
|
||||
// Get file info for the existing file
|
||||
fileInfo, err := os.Stat(filePath)
|
||||
if err != nil {
|
||||
debug.Printf("Failed to stat file %s: %v", filePath, err)
|
||||
log.Debug().Msgf("Failed to stat file %s: %v", filePath, err)
|
||||
return false
|
||||
}
|
||||
|
||||
// Load the bundled resource
|
||||
resource, err := fyne.LoadResourceFromPath(resourceName)
|
||||
if err != nil {
|
||||
debug.Printf("Failed to load bundled resource %s: %v", resourceName, err)
|
||||
log.Debug().Msgf("Failed to load bundled resource %s: %v", resourceName, err)
|
||||
return false
|
||||
}
|
||||
|
||||
@@ -546,7 +545,7 @@ func CompareFileWithBundledResource(filePath, resourceName string) bool {
|
||||
fileSize := fileInfo.Size()
|
||||
resourceSize := int64(len(resource.Content()))
|
||||
|
||||
debug.Printf("Comparing file sizes - %s: %d bytes vs bundled %s: %d bytes",
|
||||
log.Debug().Msgf("Comparing file sizes - %s: %d bytes vs bundled %s: %d bytes",
|
||||
filePath, fileSize, resourceName, resourceSize)
|
||||
|
||||
return fileSize == resourceSize
|
||||
|
@@ -2,7 +2,7 @@ package utils
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"github.com/rs/zerolog/log"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
@@ -74,7 +74,7 @@ reg add "%s" /v "RightOptionIsAlt" /t REG_SZ /d "Y" /f
|
||||
return fmt.Errorf("batch registry add failed: %v, output: %s", err, string(output))
|
||||
}
|
||||
|
||||
log.Printf("Successfully enabled Option-as-Alt mapping in Wine registry (optimized)")
|
||||
log.Info().Msgf("Successfully enabled Option-as-Alt mapping in Wine registry (optimized)")
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -102,7 +102,7 @@ reg delete "%s" /v "RightOptionIsAlt" /f 2>nul
|
||||
return fmt.Errorf("batch registry delete failed: %v, output: %s", err, string(output))
|
||||
}
|
||||
|
||||
log.Printf("Successfully disabled Option-as-Alt mapping in Wine registry (optimized)")
|
||||
log.Info().Msgf("Successfully disabled Option-as-Alt mapping in Wine registry (optimized)")
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -110,7 +110,7 @@ reg delete "%s" /v "RightOptionIsAlt" /f 2>nul
|
||||
func CheckOptionAsAltEnabled() bool {
|
||||
homeDir, err := os.UserHomeDir()
|
||||
if err != nil {
|
||||
log.Printf("Failed to get user home directory: %v", err)
|
||||
log.Info().Msgf("Failed to get user home directory: %v", err)
|
||||
return false
|
||||
}
|
||||
|
||||
@@ -118,7 +118,7 @@ func CheckOptionAsAltEnabled() bool {
|
||||
|
||||
// Check if CrossOver wine loader exists
|
||||
if !PathExists(wineLoaderPath) {
|
||||
log.Printf("CrossOver wine loader not found at: %s", wineLoaderPath)
|
||||
log.Info().Msgf("CrossOver wine loader not found at: %s", wineLoaderPath)
|
||||
return false
|
||||
}
|
||||
|
||||
@@ -133,18 +133,18 @@ func CheckOptionAsAltEnabled() bool {
|
||||
func CheckOptionAsAltEnabledFast() bool {
|
||||
regPath, err := GetWineUserRegPath()
|
||||
if err != nil {
|
||||
log.Printf("Failed to get Wine registry path: %v", err)
|
||||
log.Info().Msgf("Failed to get Wine registry path: %v", err)
|
||||
return false
|
||||
}
|
||||
|
||||
if !PathExists(regPath) {
|
||||
log.Printf("Wine user.reg file not found at: %s", regPath)
|
||||
log.Info().Msgf("Wine user.reg file not found at: %s", regPath)
|
||||
return false
|
||||
}
|
||||
|
||||
content, err := os.ReadFile(regPath)
|
||||
if err != nil {
|
||||
log.Printf("Failed to read Wine registry file: %v", err)
|
||||
log.Info().Msgf("Failed to read Wine registry file: %v", err)
|
||||
return false
|
||||
}
|
||||
|
||||
@@ -191,12 +191,12 @@ func SetOptionAsAltEnabled(enabled bool) error {
|
||||
} else {
|
||||
err := setRegistryValuesOptimized(winePrefix, false)
|
||||
if err != nil {
|
||||
log.Printf("Wine registry disable failed: %v", err)
|
||||
log.Info().Msgf("Wine registry disable failed: %v", err)
|
||||
}
|
||||
|
||||
err2 := setRegistryValuesFast(false)
|
||||
if err2 != nil {
|
||||
log.Printf("File-based cleanup failed: %v", err2)
|
||||
log.Info().Msgf("File-based cleanup failed: %v", err2)
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
@@ -334,7 +334,7 @@ func addOptionAsAltSettingsFast(regPath string, lines []string) error {
|
||||
return fmt.Errorf("failed to write registry file: %v", err)
|
||||
}
|
||||
|
||||
log.Printf("Successfully enabled Option-as-Alt mapping in Wine registry (fast method)")
|
||||
log.Info().Msgf("Successfully enabled Option-as-Alt mapping in Wine registry (fast method)")
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -342,7 +342,7 @@ func addOptionAsAltSettingsFast(regPath string, lines []string) error {
|
||||
func removeOptionAsAltSettingsFast(regPath string, lines []string) error {
|
||||
if !PathExists(regPath) {
|
||||
// File doesn't exist, nothing to remove
|
||||
log.Printf("Successfully disabled Option-as-Alt mapping in Wine registry (no file to modify)")
|
||||
log.Info().Msgf("Successfully disabled Option-as-Alt mapping in Wine registry (no file to modify)")
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -369,7 +369,7 @@ func removeOptionAsAltSettingsFast(regPath string, lines []string) error {
|
||||
return fmt.Errorf("failed to write registry file: %v", err)
|
||||
}
|
||||
|
||||
log.Printf("Successfully disabled Option-as-Alt mapping in Wine registry (fast method)")
|
||||
log.Info().Msgf("Successfully disabled Option-as-Alt mapping in Wine registry (fast method)")
|
||||
return nil
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user