FIX: Fix bug hdiff
This commit is contained in:
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user