change to zerolog

This commit is contained in:
2025-07-23 08:46:53 -07:00
parent 71f044e6e0
commit 8b5be228fe
17 changed files with 223 additions and 222 deletions

View File

@@ -5,15 +5,14 @@ import (
"errors"
"fmt"
"git.burkey.co/eburk/epochcli/pkg/epoch"
"github.com/rs/zerolog/log"
"io"
"log"
"os"
"os/exec"
"path/filepath"
"regexp"
"strings"
"epochsilicon/pkg/debug"
"epochsilicon/pkg/paths" // Corrected import path
"epochsilicon/pkg/utils" // Corrected import path
@@ -22,7 +21,7 @@ import (
)
func PatchEpoch(myWindow fyne.Window, updateAllStatuses func()) {
debug.Println("Patch Epoch clicked")
log.Debug().Msg("Patch Epoch clicked")
if paths.EpochPath == "" {
dialog.ShowError(fmt.Errorf("Epoch path not set. Please set it first."), myWindow)
return
@@ -38,25 +37,25 @@ func PatchEpoch(myWindow fyne.Window, updateAllStatuses func()) {
}
for resourceName, destPath := range filesToCopy {
debug.Printf("Processing resource: %s to %s", resourceName, destPath)
log.Debug().Msgf("Processing resource: %s to %s", resourceName, destPath)
// Check if file already exists and has correct size
if utils.PathExists(destPath) && utils.CompareFileWithBundledResource(destPath, resourceName) {
debug.Printf("File %s already exists with correct size, skipping copy", destPath)
log.Debug().Msgf("File %s already exists with correct size, skipping copy", destPath)
continue
}
if utils.PathExists(destPath) {
debug.Printf("File %s exists but has incorrect size, updating...", destPath)
log.Debug().Msgf("File %s exists but has incorrect size, updating...", destPath)
} else {
debug.Printf("File %s does not exist, creating...", destPath)
log.Debug().Msgf("File %s does not exist, creating...", destPath)
}
resource, err := fyne.LoadResourceFromPath(resourceName)
if err != nil {
errMsg := fmt.Sprintf("failed to open bundled resource %s: %v", resourceName, err)
dialog.ShowError(errors.New(errMsg), myWindow)
debug.Println(errMsg)
log.Debug().Msg(errMsg)
paths.PatchesAppliedEpoch = false
updateAllStatuses()
return
@@ -66,7 +65,7 @@ func PatchEpoch(myWindow fyne.Window, updateAllStatuses func()) {
if err != nil {
errMsg := fmt.Sprintf("failed to create destination file %s: %v", destPath, err)
dialog.ShowError(errors.New(errMsg), myWindow)
debug.Println(errMsg)
log.Debug().Msg(errMsg)
paths.PatchesAppliedEpoch = false
updateAllStatuses()
return
@@ -77,22 +76,22 @@ func PatchEpoch(myWindow fyne.Window, updateAllStatuses func()) {
if err != nil {
errMsg := fmt.Sprintf("failed to copy bundled resource %s to %s: %v", resourceName, destPath, err)
dialog.ShowError(errors.New(errMsg), myWindow)
debug.Println(errMsg)
log.Debug().Msg(errMsg)
paths.PatchesAppliedEpoch = false
updateAllStatuses()
return
}
debug.Printf("Successfully copied %s to %s", resourceName, destPath)
log.Debug().Msgf("Successfully copied %s to %s", resourceName, destPath)
}
debug.Printf("Preparing rosettax87 directory at: %s", targetRosettaX87Dir)
log.Debug().Msgf("Preparing rosettax87 directory at: %s", targetRosettaX87Dir)
if err := os.RemoveAll(targetRosettaX87Dir); err != nil {
debug.Printf("Warning: could not remove existing rosettax87 folder '%s': %v", targetRosettaX87Dir, err)
log.Debug().Msgf("Warning: could not remove existing rosettax87 folder '%s': %v", targetRosettaX87Dir, err)
}
if err := os.MkdirAll(targetRosettaX87Dir, 0755); err != nil {
errMsg := fmt.Sprintf("failed to create directory %s: %v", targetRosettaX87Dir, err)
dialog.ShowError(errors.New(errMsg), myWindow)
debug.Println(errMsg)
log.Debug().Msg(errMsg)
paths.PatchesAppliedEpoch = false
updateAllStatuses()
return
@@ -104,12 +103,12 @@ func PatchEpoch(myWindow fyne.Window, updateAllStatuses func()) {
}
for resourceName, destPath := range rosettaFilesToCopy {
debug.Printf("Processing rosetta resource: %s to %s", resourceName, destPath)
log.Debug().Msgf("Processing rosetta resource: %s to %s", resourceName, destPath)
resource, err := fyne.LoadResourceFromPath(resourceName)
if err != nil {
errMsg := fmt.Sprintf("failed to open bundled resource %s: %v", resourceName, err)
dialog.ShowError(errors.New(errMsg), myWindow)
debug.Println(errMsg)
log.Debug().Msg(errMsg)
paths.PatchesAppliedEpoch = false
updateAllStatuses()
return
@@ -119,7 +118,7 @@ func PatchEpoch(myWindow fyne.Window, updateAllStatuses func()) {
if err != nil {
errMsg := fmt.Sprintf("failed to create destination file %s: %v", destPath, err)
dialog.ShowError(errors.New(errMsg), myWindow)
debug.Println(errMsg)
log.Debug().Msg(errMsg)
paths.PatchesAppliedEpoch = false
updateAllStatuses()
return
@@ -130,7 +129,7 @@ func PatchEpoch(myWindow fyne.Window, updateAllStatuses func()) {
destinationFile.Close()
errMsg := fmt.Sprintf("failed to copy bundled resource %s to %s: %v", resourceName, destPath, err)
dialog.ShowError(errors.New(errMsg), myWindow)
debug.Println(errMsg)
log.Debug().Msg(errMsg)
paths.PatchesAppliedEpoch = false
updateAllStatuses()
return
@@ -138,31 +137,31 @@ func PatchEpoch(myWindow fyne.Window, updateAllStatuses func()) {
destinationFile.Close()
if filepath.Base(destPath) == "rosettax87" {
debug.Printf("Setting execute permission for %s", destPath)
log.Debug().Msgf("Setting execute permission for %s", destPath)
if err := os.Chmod(destPath, 0755); err != nil {
errMsg := fmt.Sprintf("failed to set execute permission for %s: %v", destPath, err)
dialog.ShowError(errors.New(errMsg), myWindow)
debug.Println(errMsg)
log.Debug().Msg(errMsg)
paths.PatchesAppliedEpoch = false
updateAllStatuses()
return
}
}
debug.Printf("Successfully copied %s to %s", resourceName, destPath)
log.Debug().Msgf("Successfully copied %s to %s", resourceName, destPath)
}
debug.Printf("Checking dlls.txt file at: %s", dllsTextFile)
log.Debug().Msgf("Checking dlls.txt file at: %s", dllsTextFile)
winerosettaEntry := "winerosetta.dll"
needsWinerosettaUpdate := true
if fileContentBytes, err := os.ReadFile(dllsTextFile); err == nil {
fileContent := string(fileContentBytes)
if strings.Contains(fileContent, winerosettaEntry) {
debug.Printf("dlls.txt already contains %s", winerosettaEntry)
log.Debug().Msgf("dlls.txt already contains %s", winerosettaEntry)
needsWinerosettaUpdate = false
}
} else {
debug.Printf("dlls.txt not found, will create a new one")
log.Debug().Msgf("dlls.txt not found, will create a new one")
}
if needsWinerosettaUpdate {
@@ -173,7 +172,7 @@ func PatchEpoch(myWindow fyne.Window, updateAllStatuses func()) {
if err != nil {
errMsg := fmt.Sprintf("failed to read dlls.txt for update: %v", err)
dialog.ShowError(errors.New(errMsg), myWindow)
debug.Println(errMsg)
log.Debug().Msg(errMsg)
}
}
@@ -187,20 +186,20 @@ func PatchEpoch(myWindow fyne.Window, updateAllStatuses func()) {
if needsWinerosettaUpdate {
if !strings.Contains(updatedContent, winerosettaEntry+"\n") {
updatedContent += winerosettaEntry + "\n"
debug.Printf("Adding %s to dlls.txt", winerosettaEntry)
log.Debug().Msgf("Adding %s to dlls.txt", winerosettaEntry)
}
}
if err := os.WriteFile(dllsTextFile, []byte(updatedContent), 0644); err != nil {
errMsg := fmt.Sprintf("failed to update dlls.txt: %v", err)
dialog.ShowError(errors.New(errMsg), myWindow)
debug.Println(errMsg)
log.Debug().Msg(errMsg)
} else {
debug.Printf("Successfully updated dlls.txt")
log.Debug().Msgf("Successfully updated dlls.txt")
}
}
debug.Println("Downloading updates from Project Epoch servers.")
log.Debug().Msg("Downloading updates from Project Epoch servers.")
// TODO: Change from dialog to pulsing animation
dialog.ShowInformation("Downloading patches", "Downloading patches for Project Epoch, this will take some time. Please wait until the status changes to \"Patched\"", myWindow)
@@ -213,10 +212,10 @@ func PatchEpoch(myWindow fyne.Window, updateAllStatuses func()) {
dialog.ShowError(errors.New(errMsg), myWindow)
})
paths.DownloadingPatches = false
log.Println(errMsg)
log.Error().Msg(errMsg)
}
log.Printf("Successfully updated %d Epoch files", stats.Updated)
debug.Println("Epoch patching with bundled resources completed successfully.")
log.Info().Msgf("Successfully updated %d Epoch files", stats.Updated)
log.Debug().Msg("Epoch patching with bundled resources completed successfully.")
fyne.Do(func() {
dialog.ShowInformation("Success", "Epoch patching process completed.", myWindow)
})
@@ -229,7 +228,7 @@ func PatchEpoch(myWindow fyne.Window, updateAllStatuses func()) {
}
func PatchCrossOver(myWindow fyne.Window, updateAllStatuses func()) {
debug.Println("Patch CrossOver clicked")
log.Debug().Msg("Patch CrossOver clicked")
if paths.CrossoverPath == "" {
dialog.ShowError(fmt.Errorf("CrossOver path not set. Please set it first."), myWindow)
return
@@ -246,7 +245,7 @@ func PatchCrossOver(myWindow fyne.Window, updateAllStatuses func()) {
return
}
debug.Printf("Copying %s to %s", wineloaderOrig, wineloaderCopy)
log.Debug().Msgf("Copying %s to %s", wineloaderOrig, wineloaderCopy)
if err := utils.CopyFile(wineloaderOrig, wineloaderCopy); err != nil {
errMsg := fmt.Sprintf("failed to copy wineloader: %v", err)
if strings.Contains(err.Error(), "operation not permitted") {
@@ -258,40 +257,40 @@ func PatchCrossOver(myWindow fyne.Window, updateAllStatuses func()) {
return
}
debug.Printf("Executing: codesign --remove-signature %s", wineloaderCopy)
log.Debug().Msgf("Executing: codesign --remove-signature %s", wineloaderCopy)
cmd := exec.Command("codesign", "--remove-signature", wineloaderCopy)
combinedOutput, err := cmd.CombinedOutput()
if err != nil {
derrMsg := fmt.Sprintf("failed to remove signature from %s: %v\nOutput: %s", wineloaderCopy, err, string(combinedOutput))
dialog.ShowError(errors.New(derrMsg), myWindow)
debug.Println(derrMsg)
log.Debug().Msg(derrMsg)
paths.PatchesAppliedCrossOver = false
if err := os.Remove(wineloaderCopy); err != nil {
debug.Printf("Warning: failed to cleanup wineloader2 after codesign failure: %v", err)
log.Debug().Msgf("Warning: failed to cleanup wineloader2 after codesign failure: %v", err)
}
updateAllStatuses()
return
}
debug.Printf("codesign output: %s", string(combinedOutput))
log.Debug().Msgf("codesign output: %s", string(combinedOutput))
debug.Printf("Setting execute permissions for %s", wineloaderCopy)
log.Debug().Msgf("Setting execute permissions for %s", wineloaderCopy)
if err := os.Chmod(wineloaderCopy, 0755); err != nil {
errMsg := fmt.Sprintf("failed to set executable permissions for %s: %v", wineloaderCopy, err)
dialog.ShowError(errors.New(errMsg), myWindow)
debug.Println(errMsg)
log.Debug().Msg(errMsg)
paths.PatchesAppliedCrossOver = false
updateAllStatuses()
return
}
debug.Println("CrossOver patching completed successfully.")
log.Debug().Msg("CrossOver patching completed successfully.")
paths.PatchesAppliedCrossOver = true
dialog.ShowInformation("Success", "CrossOver patching process completed.", myWindow)
updateAllStatuses()
}
func UnpatchEpoch(myWindow fyne.Window, updateAllStatuses func()) {
debug.Println("Unpatch Epoch clicked")
log.Debug().Msg("Unpatch Epoch clicked")
if paths.EpochPath == "" {
dialog.ShowError(fmt.Errorf("Epoch path not set. Please set it first."), myWindow)
return
@@ -305,13 +304,13 @@ func UnpatchEpoch(myWindow fyne.Window, updateAllStatuses func()) {
// Remove the rosettaX87 directory
if utils.DirExists(rosettaX87DirPath) {
debug.Printf("Removing directory: %s", rosettaX87DirPath)
log.Debug().Msgf("Removing directory: %s", rosettaX87DirPath)
if err := os.RemoveAll(rosettaX87DirPath); err != nil {
errMsg := fmt.Sprintf("failed to remove directory %s: %v", rosettaX87DirPath, err)
dialog.ShowError(errors.New(errMsg), myWindow)
debug.Println(errMsg)
log.Debug().Msg(errMsg)
} else {
debug.Printf("Successfully removed directory: %s", rosettaX87DirPath)
log.Debug().Msgf("Successfully removed directory: %s", rosettaX87DirPath)
}
}
@@ -319,25 +318,25 @@ func UnpatchEpoch(myWindow fyne.Window, updateAllStatuses func()) {
filesToRemove := []string{winerosettaDllPath, d3d9DllPath}
for _, file := range filesToRemove {
if utils.PathExists(file) {
debug.Printf("Removing file: %s", file)
log.Debug().Msgf("Removing file: %s", file)
if err := os.Remove(file); err != nil {
errMsg := fmt.Sprintf("failed to remove file %s: %v", file, err)
dialog.ShowError(errors.New(errMsg), myWindow)
debug.Println(errMsg)
log.Debug().Msg(errMsg)
} else {
debug.Printf("Successfully removed file: %s", file)
log.Debug().Msgf("Successfully removed file: %s", file)
}
}
}
// Update dlls.txt file - remove winerosetta.dll
if utils.PathExists(dllsTextFile) {
debug.Printf("Updating dlls.txt file: %s", dllsTextFile)
log.Debug().Msgf("Updating dlls.txt file: %s", dllsTextFile)
content, err := os.ReadFile(dllsTextFile)
if err != nil {
errMsg := fmt.Sprintf("failed to read dlls.txt file: %v", err)
dialog.ShowError(errors.New(errMsg), myWindow)
debug.Println(errMsg)
log.Debug().Msg(errMsg)
} else {
lines := strings.Split(string(content), "\n")
filteredLines := make([]string, 0, len(lines))
@@ -353,21 +352,21 @@ func UnpatchEpoch(myWindow fyne.Window, updateAllStatuses func()) {
if err := os.WriteFile(dllsTextFile, []byte(updatedContent), 0644); err != nil {
errMsg := fmt.Sprintf("failed to update dlls.txt file: %v", err)
dialog.ShowError(errors.New(errMsg), myWindow)
debug.Println(errMsg)
log.Debug().Msg(errMsg)
} else {
debug.Printf("Successfully updated dlls.txt file")
log.Debug().Msgf("Successfully updated dlls.txt file")
}
}
}
debug.Println("Epoch unpatching completed successfully.")
log.Debug().Msg("Epoch unpatching completed successfully.")
paths.PatchesAppliedEpoch = false
dialog.ShowInformation("Success", "Epoch unpatching process completed.", myWindow)
updateAllStatuses()
}
func UnpatchCrossOver(myWindow fyne.Window, updateAllStatuses func()) {
debug.Println("Unpatch CrossOver clicked")
log.Debug().Msg("Unpatch CrossOver clicked")
if paths.CrossoverPath == "" {
dialog.ShowError(fmt.Errorf("CrossOver path not set. Please set it first."), myWindow)
return
@@ -376,21 +375,21 @@ func UnpatchCrossOver(myWindow fyne.Window, updateAllStatuses func()) {
wineloaderCopy := filepath.Join(paths.CrossoverPath, "Contents", "SharedSupport", "CrossOver", "CrossOver-Hosted Application", "wineloader2")
if utils.PathExists(wineloaderCopy) {
debug.Printf("Removing file: %s", wineloaderCopy)
log.Debug().Msgf("Removing file: %s", wineloaderCopy)
if err := os.Remove(wineloaderCopy); err != nil {
errMsg := fmt.Sprintf("failed to remove file %s: %v", wineloaderCopy, err)
dialog.ShowError(errors.New(errMsg), myWindow)
debug.Println(errMsg)
log.Debug().Msg(errMsg)
updateAllStatuses()
return
} else {
debug.Printf("Successfully removed file: %s", wineloaderCopy)
log.Debug().Msgf("Successfully removed file: %s", wineloaderCopy)
}
} else {
debug.Printf("File not found to remove: %s", wineloaderCopy)
log.Debug().Msgf("File not found to remove: %s", wineloaderCopy)
}
debug.Println("CrossOver unpatching completed successfully.")
log.Debug().Msg("CrossOver unpatching completed successfully.")
paths.PatchesAppliedCrossOver = false
dialog.ShowInformation("Success", "CrossOver unpatching process completed.", myWindow)
updateAllStatuses()
@@ -407,14 +406,14 @@ func updateOrAddConfigSetting(configText, setting, value string) string {
if re.MatchString(configText) {
// Replace existing setting
configText = re.ReplaceAllString(configText, newSetting)
debug.Printf("Updated setting %s to %s", setting, value)
log.Debug().Msgf("Updated setting %s to %s", setting, value)
} else {
// Add new setting
if configText != "" && !strings.HasSuffix(configText, "\n") {
configText += "\n"
}
configText += newSetting + "\n"
debug.Printf("Added new setting %s with value %s", setting, value)
log.Debug().Msgf("Added new setting %s with value %s", setting, value)
}
return configText
@@ -428,7 +427,7 @@ func removeConfigSetting(configText, setting string) string {
if re.MatchString(configText) {
configText = re.ReplaceAllString(configText, "")
debug.Printf("Removed setting %s from config", setting)
log.Debug().Msgf("Removed setting %s from config", setting)
}
return configText