diff --git a/pkg/patching/patching.go b/pkg/patching/patching.go index ad76af3..0f65914 100644 --- a/pkg/patching/patching.go +++ b/pkg/patching/patching.go @@ -38,6 +38,19 @@ func PatchTurtleWoW(myWindow fyne.Window, updateAllStatuses func()) { for resourceName, destPath := range filesToCopy { log.Printf("Processing resource: %s to %s", resourceName, destPath) + + // Check if file already exists and has correct size + if utils.PathExists(destPath) && utils.CompareFileWithBundledResource(destPath, resourceName) { + log.Printf("File %s already exists with correct size, skipping copy", destPath) + continue + } + + if utils.PathExists(destPath) { + log.Printf("File %s exists but has incorrect size, updating...", destPath) + } else { + log.Printf("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) diff --git a/pkg/ui/status.go b/pkg/ui/status.go index 5ebc44e..6dd6e16 100644 --- a/pkg/ui/status.go +++ b/pkg/ui/status.go @@ -92,9 +92,18 @@ func updateTurtleWoWStatus() { } } + // Check if patched files have the correct size (matches bundled versions) + winerosettaDllCorrectSize := utils.CompareFileWithBundledResource(winerosettaDllPath, "winerosetta/winerosetta.dll") + d3d9DllCorrectSize := utils.CompareFileWithBundledResource(d3d9DllPath, "winerosetta/d3d9.dll") + libSiliconPatchCorrectSize := utils.CompareFileWithBundledResource(libSiliconPatchDllPath, "winerosetta/libSiliconPatch.dll") + rosettaX87CorrectSize := utils.CompareFileWithBundledResource(rosettaX87ExePath, "rosettax87/rosettax87") + libRuntimeRosettaX87CorrectSize := utils.CompareFileWithBundledResource(libRuntimeRosettaX87Path, "rosettax87/libRuntimeRosettax87") + if utils.PathExists(winerosettaDllPath) && utils.PathExists(d3d9DllPath) && utils.PathExists(libSiliconPatchDllPath) && utils.DirExists(rosettaX87DirPath) && utils.PathExists(rosettaX87ExePath) && - utils.PathExists(libRuntimeRosettaX87Path) && dllsFileValid { + utils.PathExists(libRuntimeRosettaX87Path) && dllsFileValid && + winerosettaDllCorrectSize && d3d9DllCorrectSize && libSiliconPatchCorrectSize && + rosettaX87CorrectSize && libRuntimeRosettaX87CorrectSize { paths.PatchesAppliedTurtleWoW = true } } diff --git a/pkg/utils/utils.go b/pkg/utils/utils.go index 7a64588..96e33b6 100644 --- a/pkg/utils/utils.go +++ b/pkg/utils/utils.go @@ -138,3 +138,37 @@ func CheckForUpdate(currentVersion string) (latestVersion, releaseNotes string, latest := strings.TrimPrefix(data.TagName, "v") return latest, data.Body, latest != currentVersion, nil } + +// GetBundledResourceSize returns the size of a bundled resource +func GetBundledResourceSize(resourcePath string) (int64, error) { + resource, err := fyne.LoadResourceFromPath(resourcePath) + if err != nil { + return 0, fmt.Errorf("failed to load bundled resource %s: %v", resourcePath, err) + } + return int64(len(resource.Content())), nil +} + +// CompareFileWithBundledResource compares the size of a file with a bundled resource +func CompareFileWithBundledResource(filePath, resourcePath string) bool { + if !PathExists(filePath) { + return false + } + + // Get file size + fileInfo, err := os.Stat(filePath) + if err != nil { + log.Printf("Failed to get file info for %s: %v", filePath, err) + return false + } + fileSize := fileInfo.Size() + + // Get bundled resource size + resourceSize, err := GetBundledResourceSize(resourcePath) + if err != nil { + log.Printf("Failed to get bundled resource size for %s: %v", resourcePath, err) + return false + } + + log.Printf("Comparing file sizes: %s (%d bytes) vs %s (%d bytes)", filePath, fileSize, resourcePath, resourceSize) + return fileSize == resourceSize +}