@@ -2,18 +2,17 @@ package patching
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"epochsilicon/pkg/log"
|
||||
"errors"
|
||||
"fmt"
|
||||
"git.burkey.co/eburk/epochcli/pkg/epoch"
|
||||
"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("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.Debugf("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.Debugf("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.Debugf("File %s exists but has incorrect size, updating...", destPath)
|
||||
} else {
|
||||
debug.Printf("File %s does not exist, creating...", destPath)
|
||||
log.Debugf("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(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(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(errMsg)
|
||||
paths.PatchesAppliedEpoch = false
|
||||
updateAllStatuses()
|
||||
return
|
||||
}
|
||||
debug.Printf("Successfully copied %s to %s", resourceName, destPath)
|
||||
log.Debugf("Successfully copied %s to %s", resourceName, destPath)
|
||||
}
|
||||
|
||||
debug.Printf("Preparing rosettax87 directory at: %s", targetRosettaX87Dir)
|
||||
log.Debugf("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.Debugf("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(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.Debugf("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(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(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(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.Debugf("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(errMsg)
|
||||
paths.PatchesAppliedEpoch = false
|
||||
updateAllStatuses()
|
||||
return
|
||||
}
|
||||
}
|
||||
debug.Printf("Successfully copied %s to %s", resourceName, destPath)
|
||||
log.Debugf("Successfully copied %s to %s", resourceName, destPath)
|
||||
}
|
||||
|
||||
debug.Printf("Checking dlls.txt file at: %s", dllsTextFile)
|
||||
log.Debugf("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.Debugf("dlls.txt already contains %s", winerosettaEntry)
|
||||
needsWinerosettaUpdate = false
|
||||
}
|
||||
} else {
|
||||
debug.Printf("dlls.txt not found, will create a new one")
|
||||
log.Debugf("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(errMsg)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -187,39 +186,43 @@ 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.Debugf("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(errMsg)
|
||||
} else {
|
||||
debug.Printf("Successfully updated dlls.txt")
|
||||
log.Debugf("Successfully updated dlls.txt")
|
||||
}
|
||||
}
|
||||
|
||||
debug.Println("Downloading updates from Project Epoch servers.")
|
||||
log.Debug("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)
|
||||
paths.DownloadingPatches = true
|
||||
log.Debug("Attempting to download Epoch patches...")
|
||||
go func() {
|
||||
stats, err := epoch.Update(paths.EpochPath, true, true, false)
|
||||
if err != nil {
|
||||
errMsg := fmt.Sprintf("failed to update Epoch files: %v", err)
|
||||
stats := epoch.Update(paths.EpochPath, true, true, false)
|
||||
if stats.Error != nil {
|
||||
errMsg := fmt.Sprintf("failed to update Epoch files: %v", stats.Error)
|
||||
fyne.Do(func() {
|
||||
dialog.ShowError(errors.New(errMsg), myWindow)
|
||||
})
|
||||
paths.DownloadingPatches = false
|
||||
log.Println(errMsg)
|
||||
log.Error(errMsg)
|
||||
} else {
|
||||
for _, msg := range stats.LogMessages {
|
||||
log.Debug(msg)
|
||||
}
|
||||
log.Infof("Successfully updated %d Epoch files", stats.Updated)
|
||||
log.Debug("Epoch patching with bundled resources completed successfully.")
|
||||
fyne.Do(func() {
|
||||
dialog.ShowInformation("Success", "Epoch patching process completed.", myWindow)
|
||||
})
|
||||
}
|
||||
log.Printf("Successfully updated %d Epoch files", stats.Updated)
|
||||
debug.Println("Epoch patching with bundled resources completed successfully.")
|
||||
fyne.Do(func() {
|
||||
dialog.ShowInformation("Success", "Epoch patching process completed.", myWindow)
|
||||
})
|
||||
fyne.DoAndWait(func() {
|
||||
paths.DownloadingPatches = false
|
||||
updateAllStatuses()
|
||||
@@ -229,7 +232,7 @@ func PatchEpoch(myWindow fyne.Window, updateAllStatuses func()) {
|
||||
}
|
||||
|
||||
func PatchCrossOver(myWindow fyne.Window, updateAllStatuses func()) {
|
||||
debug.Println("Patch CrossOver clicked")
|
||||
log.Debug("Patch CrossOver clicked")
|
||||
if paths.CrossoverPath == "" {
|
||||
dialog.ShowError(fmt.Errorf("CrossOver path not set. Please set it first."), myWindow)
|
||||
return
|
||||
@@ -246,7 +249,7 @@ func PatchCrossOver(myWindow fyne.Window, updateAllStatuses func()) {
|
||||
return
|
||||
}
|
||||
|
||||
debug.Printf("Copying %s to %s", wineloaderOrig, wineloaderCopy)
|
||||
log.Debugf("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 +261,40 @@ func PatchCrossOver(myWindow fyne.Window, updateAllStatuses func()) {
|
||||
return
|
||||
}
|
||||
|
||||
debug.Printf("Executing: codesign --remove-signature %s", wineloaderCopy)
|
||||
log.Debugf("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(derrMsg)
|
||||
paths.PatchesAppliedCrossOver = false
|
||||
if err := os.Remove(wineloaderCopy); err != nil {
|
||||
debug.Printf("Warning: failed to cleanup wineloader2 after codesign failure: %v", err)
|
||||
log.Debugf("Warning: failed to cleanup wineloader2 after codesign failure: %v", err)
|
||||
}
|
||||
updateAllStatuses()
|
||||
return
|
||||
}
|
||||
debug.Printf("codesign output: %s", string(combinedOutput))
|
||||
log.Debugf("codesign output: %s", string(combinedOutput))
|
||||
|
||||
debug.Printf("Setting execute permissions for %s", wineloaderCopy)
|
||||
log.Debugf("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(errMsg)
|
||||
paths.PatchesAppliedCrossOver = false
|
||||
updateAllStatuses()
|
||||
return
|
||||
}
|
||||
|
||||
debug.Println("CrossOver patching completed successfully.")
|
||||
log.Debug("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("Unpatch Epoch clicked")
|
||||
if paths.EpochPath == "" {
|
||||
dialog.ShowError(fmt.Errorf("Epoch path not set. Please set it first."), myWindow)
|
||||
return
|
||||
@@ -305,13 +308,13 @@ func UnpatchEpoch(myWindow fyne.Window, updateAllStatuses func()) {
|
||||
|
||||
// Remove the rosettaX87 directory
|
||||
if utils.DirExists(rosettaX87DirPath) {
|
||||
debug.Printf("Removing directory: %s", rosettaX87DirPath)
|
||||
log.Debugf("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(errMsg)
|
||||
} else {
|
||||
debug.Printf("Successfully removed directory: %s", rosettaX87DirPath)
|
||||
log.Debugf("Successfully removed directory: %s", rosettaX87DirPath)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -319,25 +322,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.Debugf("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(errMsg)
|
||||
} else {
|
||||
debug.Printf("Successfully removed file: %s", file)
|
||||
log.Debugf("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.Debugf("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(errMsg)
|
||||
} else {
|
||||
lines := strings.Split(string(content), "\n")
|
||||
filteredLines := make([]string, 0, len(lines))
|
||||
@@ -353,21 +356,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(errMsg)
|
||||
} else {
|
||||
debug.Printf("Successfully updated dlls.txt file")
|
||||
log.Debugf("Successfully updated dlls.txt file")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
debug.Println("Epoch unpatching completed successfully.")
|
||||
log.Debug("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("Unpatch CrossOver clicked")
|
||||
if paths.CrossoverPath == "" {
|
||||
dialog.ShowError(fmt.Errorf("CrossOver path not set. Please set it first."), myWindow)
|
||||
return
|
||||
@@ -376,21 +379,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.Debugf("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(errMsg)
|
||||
updateAllStatuses()
|
||||
return
|
||||
} else {
|
||||
debug.Printf("Successfully removed file: %s", wineloaderCopy)
|
||||
log.Debugf("Successfully removed file: %s", wineloaderCopy)
|
||||
}
|
||||
} else {
|
||||
debug.Printf("File not found to remove: %s", wineloaderCopy)
|
||||
log.Debugf("File not found to remove: %s", wineloaderCopy)
|
||||
}
|
||||
|
||||
debug.Println("CrossOver unpatching completed successfully.")
|
||||
log.Debug("CrossOver unpatching completed successfully.")
|
||||
paths.PatchesAppliedCrossOver = false
|
||||
dialog.ShowInformation("Success", "CrossOver unpatching process completed.", myWindow)
|
||||
updateAllStatuses()
|
||||
@@ -407,14 +410,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.Debugf("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.Debugf("Added new setting %s with value %s", setting, value)
|
||||
}
|
||||
|
||||
return configText
|
||||
@@ -428,7 +431,7 @@ func removeConfigSetting(configText, setting string) string {
|
||||
|
||||
if re.MatchString(configText) {
|
||||
configText = re.ReplaceAllString(configText, "")
|
||||
debug.Printf("Removed setting %s from config", setting)
|
||||
log.Debugf("Removed setting %s from config", setting)
|
||||
}
|
||||
|
||||
return configText
|
||||
|
Reference in New Issue
Block a user