~hristoast/openmw-validator

b17a08124de73b57472f49bbee38b96d76192570 — Hristos N. Triantafillou 28 days ago 87cd8a2
Unbreak path checking, show fully replaced paths too
4 files changed, 35 insertions(+), 33 deletions(-)

M config.go
M files.go
M paths.go
M validations.go
M config.go => config.go +3 -1
@@ 6,6 6,7 @@ import (
	"log"
	"os"
	"os/user"
	"path/filepath"
	"runtime"
	"strings"
	"time"


@@ 54,8 55,9 @@ func (g *gameConfig) registerReplacement(new *dataFile, old *dataFile) {
		localPath:  new.localPath,
		replacedBy: new.dDir,
	})
	old.dDir.replaced += 1
	if !g.runCfg.noReplace {
		log.Printf("Replaced: %s", old.dDir.path)
		log.Printf("Replaced: %s", filepath.Join(old.dDir.path, new.localPath))
	}
}


M files.go => files.go +1 -6
@@ 55,12 55,7 @@ type replacedFile struct {

func checkContentFile(cf string, order int, gc *gameConfig) bool {
	// Format the file...
	c := strings.Replace(cf, "content=", "", -1)
	c = strings.TrimPrefix(c, "'")
	c = strings.TrimPrefix(c, "\"")
	c = strings.TrimSuffix(c, "\r")
	c = strings.TrimSuffix(c, "'")
	c = strings.TrimSuffix(c, "\"")
	c := sanitizePath(cf, "content=")

	if !gc.runCfg.quiet {
		log.Printf("Checking: %v", c)

M paths.go => paths.go +7 -24
@@ 51,7 51,6 @@ func (d *dataDir) checkDataDirs(gc *gameConfig) error {
						oldf, ok := df.alreadySaved(gc.dataFiles)
						if ok {
							gc.registerReplacement(df, oldf)
							d.replaced += 1
						}
						gc.dataFiles[localPath] = df



@@ 73,7 72,6 @@ func (d *dataDir) checkDataDirs(gc *gameConfig) error {
				oldf, ok := df.alreadySaved(gc.dataFiles)
				if ok {
					gc.registerReplacement(df, oldf)
					d.replaced += 1
				}

				if df.isPlugin() {


@@ 97,40 95,25 @@ func (d *dataDir) alreadyFound(found map[string]bool) bool {

// Verify that a dataDir is real, then scan it for files.
func (d *dataDir) check(dataOrder int, gc *gameConfig) error {
	// Format the path...
	p := strings.Replace(d.path, "data=", "", -1)
	p = strings.TrimPrefix(p, "'")
	p = strings.TrimPrefix(p, "\"")
	p = strings.TrimSuffix(p, "\r")
	p = strings.TrimSuffix(p, "'")
	p = strings.TrimSuffix(p, "\"")

	if !gc.runCfg.quiet {
		log.Printf("Checking: %v", p)
		log.Printf("Checking: %v", d.path)
	}

	found := d.alreadyFound(gc.foundPaths)
	if found {
		log.Printf("Path already configured: %s", p)
		gc.duplicatePaths = append(gc.duplicatePaths, p)
		log.Printf("Path already configured: %s", d.path)
		gc.duplicatePaths = append(gc.duplicatePaths, d.path)
	} else {
		gc.foundPaths[p] = true
		gc.foundPaths[d.path] = true
	}

	_, err := os.Stat(p)
	_, err := os.Stat(d.path)
	if os.IsNotExist(err) {
		gc.badPaths = append(gc.badPaths, p)
		gc.badPaths = append(gc.badPaths, d.path)
		return err
	}

	dd := &dataDir{
		files:    []*dataFile{},
		plugins:  []*dataFile{},
		order:    dataOrder,
		path:     p,
		replaced: 0,
	}
	dd.checkDataDirs(gc)
	d.checkDataDirs(gc)

	return err
}

M validations.go => validations.go +24 -2
@@ 2,8 2,21 @@ package main

import (
	"log"
	"strings"
)

// Get just the path from a string read directly from an openmw.cfg file,
// hopefully in a way that doesn't upset all the OSes.
func sanitizePath(path string, prefix string) string {
	p := strings.Replace(path, prefix, "", -1)
	p = strings.TrimPrefix(p, "'")
	p = strings.TrimPrefix(p, "\"")
	p = strings.TrimSuffix(p, "\r")
	p = strings.TrimSuffix(p, "'")
	p = strings.TrimSuffix(p, "\"")
	return p
}

// Given the raw cfg data and program config, do validating on the cfg file (and
// all related work).
func runValidations(runCfg *runConfig) {


@@ 38,6 51,7 @@ func runValidations(runCfg *runConfig) {
		log.Println()
	}
	for _, p := range d.dataPaths {
		p = sanitizePath(p, "data=")
		dd := &dataDir{
			files:    []*dataFile{},
			plugins:  []*dataFile{},


@@ 104,7 118,7 @@ func runValidations(runCfg *runConfig) {
			}
			log.Printf("Data path #%d \"%s\" has %d %s and %d %s. %d %s %s replaced.", p.order, p.path, fileCount, fileWord, pluginCount, pluginWord, p.replaced, fWord, wWord)

			if len(p.files) >= p.replaced {
			if p.replaced > 0 && p.replaced >= len(p.files) {
				g.fullyReplaced = append(g.fullyReplaced, p)
			}
		}


@@ 175,7 189,15 @@ func runValidations(runCfg *runConfig) {
		log.Println()
	}

	//TODO: report on fully replaced
	if haveFullyReplaced {
		log.Printf("Fully replaced data path count: %v", len(g.fullyReplaced))
		log.Println("The following data paths are fully replaced:")
		log.Println()
		for _, fr := range g.fullyReplaced {
			log.Println(fr.path)
		}
		log.Println()
	}

	if !haveBadPaths && !haveEmptyPaths && !haveDupedPaths && !haveBunkContent && !haveFullyReplaced {
		log.Println("Great Job! No problems detected.")