mirror of
https://github.com/OpenDiablo2/OpenDiablo2
synced 2024-06-19 21:55:24 +00:00
Test updates. MPQ file name changes. (#119)
* Modified path logic to hopefully fix some issues
This commit is contained in:
parent
7859b69da6
commit
ed88d0e00d
2
main.go
2
main.go
|
@ -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 = ""
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user