Test updates. MPQ file name changes. (#119)

* Modified path logic to hopefully fix some issues
This commit is contained in:
Tim Sarbin 2019-11-08 19:52:49 -05:00 committed by GitHub
parent 7859b69da6
commit ed88d0e00d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 21 additions and 3 deletions

View File

@ -21,6 +21,8 @@ var GitCommit string
var d2Engine *core.Engine
func main() {
//runtime.LockOSThread()
//defer runtime.UnlockOSThread()
if len(GitBranch) == 0 {
GitBranch = "Local Build"
GitCommit = ""

View File

@ -238,7 +238,6 @@ func (v MPQ) getFileHashEntry(fileName string) (HashTableEntry, error) {
// GetFileBlockData gets a block table entry
func (v MPQ) getFileBlockData(fileName string) (BlockTableEntry, error) {
fileName = strings.ReplaceAll(fileName, "{LANG}", resourcepaths.LanguageCode)
fileEntry, err := v.getFileHashEntry(fileName)
if err != nil || fileEntry.BlockIndex >= uint32(len(v.BlockTableEntries)) {
return BlockTableEntry{}, err
@ -261,11 +260,13 @@ func (v MPQ) FileExists(fileName string) bool {
// ReadFile reads a file from the MPQ and returns a memory stream
func (v MPQ) ReadFile(fileName string) ([]byte, error) {
fileName = strings.ReplaceAll(fileName, "{LANG}", resourcepaths.LanguageCode)
fileName = strings.ToLower(fileName)
fileName = strings.ReplaceAll(fileName, `/`, "\\")
cached := v.fileCache[fileName]
if cached != nil {
return cached, nil
}
fileName = strings.ReplaceAll(fileName, "{LANG}", resourcepaths.LanguageCode)
fileBlockData, err := v.getFileBlockData(fileName)
if err != nil {
return []byte{}, err
@ -281,7 +282,6 @@ func (v MPQ) ReadFile(fileName string) ([]byte, error) {
// ReadTextFile reads a file and returns it as a string
func (v MPQ) ReadTextFile(fileName string) (string, error) {
fileName = strings.ReplaceAll(fileName, "{LANG}", resourcepaths.LanguageCode)
data, err := v.ReadFile(fileName)
if err != nil {
return "", err

View File

@ -1,19 +1,24 @@
package tests
import (
"log"
"path"
"strings"
"testing"
"github.com/OpenDiablo2/OpenDiablo2/core"
"github.com/OpenDiablo2/OpenDiablo2/mpq"
"github.com/OpenDiablo2/OpenDiablo2/common"
)
func TestMPQScanPerformance(t *testing.T) {
log.SetFlags(log.Ldate | log.LUTC | log.Lmicroseconds | log.Llongfile)
mpq.InitializeCryptoBuffer()
common.ConfigBasePath = "../"
config := common.LoadConfiguration()
engine := core.CreateEngine()
for _, fileName := range config.MpqLoadOrder {
mpqFile := path.Join(config.MpqPath, fileName)
archive, _ := mpq.Load(mpqFile)
@ -26,6 +31,17 @@ func TestMPQScanPerformance(t *testing.T) {
if strings.Contains(archiveFile, ".wav") || strings.Contains(archiveFile, ".pif") {
continue
}
parts := strings.Split(archiveFile, ".")
switch strings.ToLower(parts[len(parts)-1]) {
case "coff":
_ = common.LoadCof(archiveFile, engine)
case "dcc":
if strings.ContainsAny(archiveFile, "common") {
continue
}
_ = common.LoadDCC(archiveFile, engine)
}
_, _ = archive.ReadFile(archiveFile)
}
}