2 Commits
1.7.0 ... 1.8.0

Author SHA1 Message Date
1e17f76340 FIX: Fix bug version parse 2025-09-26 10:06:49 +07:00
1f9c95d6ac FIX: Fix bug hdiff 2025-09-09 08:47:16 +07:00
12 changed files with 57 additions and 100 deletions

Binary file not shown.

View File

@@ -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);
}

View File

@@ -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')

View File

@@ -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 {
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)
}
return true, "validated"
}
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()
}
patchBinFile := filepath.Join(constant.TempUrl, "BinaryVersion.bytes.hdiff")
sourceBinFile := filepath.Join(gamePath, "StarRail_Data\\StreamingAssets\\BinaryVersion.bytes")
tempBinFile := filepath.Join(constant.TempUrl, "BinaryVersion.bytes")
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()
}
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) {

View File

@@ -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) {

View File

@@ -98,7 +98,6 @@ func main() {
DevToolsEnabled: true,
})
err = app.Run()
if err != nil {
log.Fatal(err)

View File

@@ -10,7 +10,7 @@ const ProxyZipFile = "64bit.zip"
const LauncherFile = "firefly-launcher.exe"
const TempUrl = "./temp"
const CurrentLauncherVersion = "1.7.0"
const CurrentLauncherVersion = "1.8.0"
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 {

View File

@@ -6,7 +6,6 @@ import (
"os"
"regexp"
"strconv"
"strings"
)
type BinaryVersion struct {
@@ -24,45 +23,25 @@ func ParseBinaryVersion(path string) (*BinaryVersion, error) {
}
content := string(data)
fmt.Println(content)
lastDash := strings.LastIndex(content, "-")
if lastDash == -1 {
return nil, errors.New("no dash found in version string")
}
secondLastDash := strings.LastIndex(content[:lastDash], "-")
if secondLastDash == -1 {
return nil, errors.New("only one dash found in version string")
}
versionSlice := content[secondLastDash+1 : lastDash]
re := regexp.MustCompile(`^([A-Za-z]+)([\d\.]+)$`)
matches := re.FindStringSubmatch(versionSlice)
if len(matches) < 3 {
re := regexp.MustCompile(`([A-Za-z]+)(\d+)(?:\.(\d+))?(?:\.(\d+))?`)
matches := re.FindStringSubmatch(content)
if len(matches) < 2 {
return nil, errors.New("invalid version format")
}
binaryVersion := BinaryVersion{
Name: matches[1],
}
numbers := strings.Split(matches[2], ".")
if len(numbers) > 0 {
binaryVersion.Major, err = strconv.Atoi(numbers[0])
if err != nil {
return nil, err
if matches[2] != "" {
binaryVersion.Major, _ = strconv.Atoi(matches[2])
}
if len(matches) > 3 && matches[3] != "" {
binaryVersion.Minor, _ = strconv.Atoi(matches[3])
}
if len(numbers) > 1 {
binaryVersion.Minor, err = strconv.Atoi(numbers[1])
if err != nil {
return nil, err
}
}
if len(numbers) > 2 {
binaryVersion.Patch, err = strconv.Atoi(numbers[2])
if err != nil {
return nil, err
}
if len(matches) > 4 && matches[4] != "" {
binaryVersion.Patch, _ = strconv.Atoi(matches[4])
}
binaryVersion.Data = data