mirror of
https://github.com/OpenDiablo2/OpenDiablo2
synced 2024-09-27 21:56:19 -04: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
|
var d2Engine *core.Engine
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
//runtime.LockOSThread()
|
||||||
|
//defer runtime.UnlockOSThread()
|
||||||
if len(GitBranch) == 0 {
|
if len(GitBranch) == 0 {
|
||||||
GitBranch = "Local Build"
|
GitBranch = "Local Build"
|
||||||
GitCommit = ""
|
GitCommit = ""
|
||||||
|
@ -238,7 +238,6 @@ func (v MPQ) getFileHashEntry(fileName string) (HashTableEntry, error) {
|
|||||||
|
|
||||||
// GetFileBlockData gets a block table entry
|
// GetFileBlockData gets a block table entry
|
||||||
func (v MPQ) getFileBlockData(fileName string) (BlockTableEntry, error) {
|
func (v MPQ) getFileBlockData(fileName string) (BlockTableEntry, error) {
|
||||||
fileName = strings.ReplaceAll(fileName, "{LANG}", resourcepaths.LanguageCode)
|
|
||||||
fileEntry, err := v.getFileHashEntry(fileName)
|
fileEntry, err := v.getFileHashEntry(fileName)
|
||||||
if err != nil || fileEntry.BlockIndex >= uint32(len(v.BlockTableEntries)) {
|
if err != nil || fileEntry.BlockIndex >= uint32(len(v.BlockTableEntries)) {
|
||||||
return BlockTableEntry{}, err
|
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
|
// ReadFile reads a file from the MPQ and returns a memory stream
|
||||||
func (v MPQ) ReadFile(fileName string) ([]byte, error) {
|
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]
|
cached := v.fileCache[fileName]
|
||||||
if cached != nil {
|
if cached != nil {
|
||||||
return cached, nil
|
return cached, nil
|
||||||
}
|
}
|
||||||
fileName = strings.ReplaceAll(fileName, "{LANG}", resourcepaths.LanguageCode)
|
|
||||||
fileBlockData, err := v.getFileBlockData(fileName)
|
fileBlockData, err := v.getFileBlockData(fileName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return []byte{}, err
|
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
|
// ReadTextFile reads a file and returns it as a string
|
||||||
func (v MPQ) ReadTextFile(fileName string) (string, error) {
|
func (v MPQ) ReadTextFile(fileName string) (string, error) {
|
||||||
fileName = strings.ReplaceAll(fileName, "{LANG}", resourcepaths.LanguageCode)
|
|
||||||
data, err := v.ReadFile(fileName)
|
data, err := v.ReadFile(fileName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
|
@ -1,19 +1,24 @@
|
|||||||
package tests
|
package tests
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"log"
|
||||||
"path"
|
"path"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/OpenDiablo2/OpenDiablo2/core"
|
||||||
|
|
||||||
"github.com/OpenDiablo2/OpenDiablo2/mpq"
|
"github.com/OpenDiablo2/OpenDiablo2/mpq"
|
||||||
|
|
||||||
"github.com/OpenDiablo2/OpenDiablo2/common"
|
"github.com/OpenDiablo2/OpenDiablo2/common"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestMPQScanPerformance(t *testing.T) {
|
func TestMPQScanPerformance(t *testing.T) {
|
||||||
|
log.SetFlags(log.Ldate | log.LUTC | log.Lmicroseconds | log.Llongfile)
|
||||||
mpq.InitializeCryptoBuffer()
|
mpq.InitializeCryptoBuffer()
|
||||||
common.ConfigBasePath = "../"
|
common.ConfigBasePath = "../"
|
||||||
config := common.LoadConfiguration()
|
config := common.LoadConfiguration()
|
||||||
|
engine := core.CreateEngine()
|
||||||
for _, fileName := range config.MpqLoadOrder {
|
for _, fileName := range config.MpqLoadOrder {
|
||||||
mpqFile := path.Join(config.MpqPath, fileName)
|
mpqFile := path.Join(config.MpqPath, fileName)
|
||||||
archive, _ := mpq.Load(mpqFile)
|
archive, _ := mpq.Load(mpqFile)
|
||||||
@ -26,6 +31,17 @@ func TestMPQScanPerformance(t *testing.T) {
|
|||||||
if strings.Contains(archiveFile, ".wav") || strings.Contains(archiveFile, ".pif") {
|
if strings.Contains(archiveFile, ".wav") || strings.Contains(archiveFile, ".pif") {
|
||||||
continue
|
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)
|
_, _ = archive.ReadFile(archiveFile)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user