diff --git a/assets/7zip/7za.dll b/assets/7za.dll similarity index 100% rename from assets/7zip/7za.dll rename to assets/7za.dll diff --git a/assets/7zip/7za.exe b/assets/7za.exe similarity index 100% rename from assets/7zip/7za.exe rename to assets/7za.exe diff --git a/assets/7zip/7zxa.dll b/assets/7zxa.dll similarity index 100% rename from assets/7zip/7zxa.dll rename to assets/7zxa.dll diff --git a/assets/HDiffPatch/hdiffz.exe b/assets/HDiffPatch/hdiffz.exe deleted file mode 100644 index 9607bd0..0000000 Binary files a/assets/HDiffPatch/hdiffz.exe and /dev/null differ diff --git a/assets/HDiffPatch/hpatchz.exe b/assets/hpatchz.exe similarity index 100% rename from assets/HDiffPatch/hpatchz.exe rename to assets/hpatchz.exe diff --git a/frontend/bindings/firefly-launcher/internal/diff-service/diffservice.js b/frontend/bindings/firefly-launcher/internal/diff-service/diffservice.js index c50a802..a9eaec3 100644 --- a/frontend/bindings/firefly-launcher/internal/diff-service/diffservice.js +++ b/frontend/bindings/firefly-launcher/internal/diff-service/diffservice.js @@ -25,11 +25,10 @@ export function CutData(gamePath) { /** * @param {string} gamePath * @param {string} patchPath - * @param {boolean} isSkipVerify * @returns {$CancellablePromise<[boolean, string]>} */ -export function DataExtract(gamePath, patchPath, isSkipVerify) { - return $Call.ByID(2161622254, gamePath, patchPath, isSkipVerify); +export function DataExtract(gamePath, patchPath) { + return $Call.ByID(2161622254, gamePath, patchPath); } /** @@ -59,9 +58,8 @@ export function LDiffPatchData(gamePath) { /** * @param {string} gamePath * @param {string} patchPath - * @param {boolean} isNeedHDiff * @returns {$CancellablePromise<[boolean, string]>} */ -export function VersionValidate(gamePath, patchPath, isNeedHDiff) { - return $Call.ByID(2105077257, gamePath, patchPath, isNeedHDiff); +export function VersionValidate(gamePath, patchPath) { + return $Call.ByID(2105077257, gamePath, patchPath); } diff --git a/frontend/src/pages/diff/index.tsx b/frontend/src/pages/diff/index.tsx index 32cc9e8..32b7ad4 100644 --- a/frontend/src/pages/diff/index.tsx +++ b/frontend/src/pages/diff/index.tsx @@ -131,15 +131,13 @@ export default function DiffPage() { setStageType('Version Validate') setProgressUpdate(0) setMaxProgressUpdate(1) - const isNeedHDiff = validType !== 'hdiffmap.json' - const [validVersion, errorVersion] = await DiffService.VersionValidate(gameDir, diffDir, isNeedHDiff) + const [validVersion, errorVersion] = await DiffService.VersionValidate(gameDir, diffDir) if (!handleResult(validVersion, errorVersion)) return setProgressUpdate(1) } - const isSkipVerify = ['manifest', 'hdifffiles.txt', 'hdifffiles.json'].includes(validType) setStageType('Data Extract') - const [validData, errorData] = await DiffService.DataExtract(gameDir, diffDir, isSkipVerify) + const [validData, errorData] = await DiffService.DataExtract(gameDir, diffDir) if (!handleResult(validData, errorData)) return setStageType('Cut Data') diff --git a/internal/diff-service/hdiffz.go b/internal/diff-service/hdiffz.go index f8e5304..a48732c 100644 --- a/internal/diff-service/hdiffz.go +++ b/internal/diff-service/hdiffz.go @@ -35,13 +35,11 @@ func (h *DiffService) CheckTypeHDiff(patchPath string) (bool, string, string) { return false, "", "not found hdifffiles.txt or hdiffmap.json" } -func (h *DiffService) VersionValidate(gamePath, patchPath string, isNeedHDiff bool) (bool, string) { +func (h *DiffService) VersionValidate(gamePath, patchPath string) (bool, string) { oldBinPath := filepath.Join(gamePath, "StarRail_Data\\StreamingAssets\\BinaryVersion.bytes") - oldVersionData, err := models.ParseBinaryVersion(oldBinPath) - if err != nil { + if _, err := os.Stat(oldBinPath); err != nil { return false, err.Error() } - if _, err := os.Stat(patchPath); err != nil { return false, err.Error() } @@ -52,38 +50,33 @@ func (h *DiffService) VersionValidate(gamePath, patchPath string, isNeedHDiff bo } } - if !isNeedHDiff { + okFull, errFull := sevenzip.IsFileIn7z(patchPath, "StarRail_Data\\StreamingAssets\\BinaryVersion.bytes") + okDiff, errDiff := sevenzip.IsFileIn7z(patchPath, "StarRail_Data\\StreamingAssets\\BinaryVersion.bytes.hdiff") + + if (errFull != nil && errDiff != nil) || (!okFull && !okDiff) { + return false, "BinaryVersion file not found in patch" + } + + var tempBinFile string + + if okFull { if err := sevenzip.ExtractAFileFromZip(patchPath, "StarRail_Data\\StreamingAssets\\BinaryVersion.bytes", constant.TempUrl); err != nil { return false, err.Error() } - - binPath := filepath.Join(constant.TempUrl, "BinaryVersion.bytes") - newVersionData, err := models.ParseBinaryVersion(binPath) - if err != nil { + tempBinFile = filepath.Join(constant.TempUrl, "BinaryVersion.bytes") + } else { + if err := sevenzip.ExtractAFileFromZip(patchPath, "StarRail_Data\\StreamingAssets\\BinaryVersion.bytes.hdiff", constant.TempUrl); err != nil { return false, err.Error() } - defer os.Remove(binPath) - - v := newVersionData.Subtract(oldVersionData) - if v != 0 && v != 1 { - return false, fmt.Sprintf("the diff version %s not valid with game version %s", newVersionData, oldVersionData) + patchBinFile := filepath.Join(constant.TempUrl, "BinaryVersion.bytes.hdiff") + sourceBinFile := oldBinPath + tempBinFile = filepath.Join(constant.TempUrl, "BinaryVersion.bytes") + if err := hpatchz.ApplyPatch(sourceBinFile, patchBinFile, tempBinFile); err != nil { + os.Remove(patchBinFile) + return false, err.Error() } - - return true, "validated" - } - - if err := sevenzip.ExtractAFileFromZip(patchPath, "StarRail_Data\\StreamingAssets\\BinaryVersion.bytes.hdiff", constant.TempUrl); err != nil { - return false, err.Error() - } - - patchBinFile := filepath.Join(constant.TempUrl, "BinaryVersion.bytes.hdiff") - sourceBinFile := filepath.Join(gamePath, "StarRail_Data\\StreamingAssets\\BinaryVersion.bytes") - tempBinFile := filepath.Join(constant.TempUrl, "BinaryVersion.bytes") - if err := hpatchz.ApplyPatch(sourceBinFile, patchBinFile, tempBinFile); err != nil { os.Remove(patchBinFile) - return false, err.Error() } - os.Remove(patchBinFile) okFullPkg, err1 := sevenzip.IsFileIn7z(patchPath, "pkg_version") okDiffPkg, err2 := sevenzip.IsFileIn7z(patchPath, "pkg_version.hdiff") @@ -96,7 +89,6 @@ func (h *DiffService) VersionValidate(gamePath, patchPath string, isNeedHDiff bo } } if okDiffPkg { - if err := sevenzip.ExtractAFileFromZip(patchPath, "pkg_version.hdiff", constant.TempUrl); err != nil { return false, err.Error() } @@ -119,8 +111,11 @@ func (h *DiffService) VersionValidate(gamePath, patchPath string, isNeedHDiff bo } os.Remove(tempPkgFile) + // MD5 check BinaryVersion + flags := false for _, pkgData := range pkgDataList { if filepath.ToSlash(pkgData.RemoteFile) == "StarRail_Data/StreamingAssets/BinaryVersion.bytes" { + flags = true md5, err := verifier.FileMD5(tempBinFile) if err != nil { os.Remove(tempBinFile) @@ -134,15 +129,18 @@ func (h *DiffService) VersionValidate(gamePath, patchPath string, isNeedHDiff bo break } } - + if !flags { + os.Remove(tempBinFile) + return false, "BinaryVersion file not found in patch" + } _, err = models.ParseBinaryVersion(tempBinFile) if err != nil { os.Remove(tempBinFile) return false, err.Error() } + os.Remove(tempBinFile) return true, "validated" - } func (h *DiffService) HDiffPatchData(gamePath string) (bool, string) { diff --git a/internal/diff-service/utils.go b/internal/diff-service/utils.go index ece007e..9a5969c 100644 --- a/internal/diff-service/utils.go +++ b/internal/diff-service/utils.go @@ -2,15 +2,15 @@ package diffService import ( "firefly-launcher/pkg/constant" - "firefly-launcher/pkg/verifier" "firefly-launcher/pkg/sevenzip" - "github.com/wailsapp/wails/v3/pkg/application" + "io" "os" "path/filepath" - "io" + + "github.com/wailsapp/wails/v3/pkg/application" ) -func (h *DiffService) DataExtract(gamePath, patchPath string, isSkipVerify bool) (bool, string) { +func (h *DiffService) DataExtract(gamePath, patchPath string) (bool, string) { os.RemoveAll(constant.TempUrl) if _, err := os.Stat(gamePath); err != nil { return false, err.Error() @@ -30,20 +30,7 @@ func (h *DiffService) DataExtract(gamePath, patchPath string, isSkipVerify bool) os.RemoveAll(constant.TempUrl) return false, err.Error() } - - if !isSkipVerify { - validator, err := verifier.NewVerifier(gamePath, constant.TempUrl) - if err != nil { - os.RemoveAll(constant.TempUrl) - return false, err.Error() - } - - if err := validator.VerifyAll(); err != nil { - os.RemoveAll(constant.TempUrl) - return false, err.Error() - } - } - return true, "validated" + return true, "extract completed" } func (h *DiffService) CutData(gamePath string) (bool, string) { @@ -97,4 +84,4 @@ func (h *DiffService) CutData(gamePath string) (bool, string) { } os.RemoveAll(constant.TempUrl) return true, "cut completed" -} \ No newline at end of file +} diff --git a/main.go b/main.go index 1885c83..8b0071e 100644 --- a/main.go +++ b/main.go @@ -98,7 +98,6 @@ func main() { DevToolsEnabled: true, }) - err = app.Run() if err != nil { log.Fatal(err) diff --git a/pkg/constant/constant.go b/pkg/constant/constant.go index 1a5c2ae..5c58636 100644 --- a/pkg/constant/constant.go +++ b/pkg/constant/constant.go @@ -10,7 +10,7 @@ const ProxyZipFile = "64bit.zip" const LauncherFile = "firefly-launcher.exe" const TempUrl = "./temp" -const CurrentLauncherVersion = "1.7.0" +const CurrentLauncherVersion = "1.7.1" type ToolFile string @@ -19,15 +19,13 @@ const ( Tool7zaDLL ToolFile = "bin/7za.dll" Tool7zxaDLL ToolFile = "bin/7zxa.dll" ToolHPatchzExe ToolFile = "bin/hpatchz.exe" - ToolHDiffzExe ToolFile = "bin/hdiffz.exe" ) var RequiredFiles = map[ToolFile]string{ - Tool7zaExe: "assets/7zip/7za.exe", - Tool7zaDLL: "assets/7zip/7za.dll", - Tool7zxaDLL: "assets/7zip/7zxa.dll", - ToolHPatchzExe: "assets/HDiffPatch/hpatchz.exe", - ToolHDiffzExe: "assets/HDiffPatch/hdiffz.exe", + Tool7zaExe: "assets/7za.exe", + Tool7zaDLL: "assets/7za.dll", + Tool7zxaDLL: "assets/7zxa.dll", + ToolHPatchzExe: "assets/hpatchz.exe", } func (t ToolFile) GetEmbedPath() string {