github.com/xml-comp/xml-comp@v0.0.42-0.20180719122048-292fe466b944/main.go (about) 1 package main 2 3 import ( 4 "flag" 5 "fmt" 6 "log" 7 "os" 8 "path/filepath" 9 10 "os/user" 11 "runtime" 12 13 "github.com/XML-Comp/XML-Comp/comparer" 14 ) 15 16 const ver = "v0.4" 17 18 func main() { 19 var ( 20 original = flag.String("original", getOriginalDir(), "Full path directory of your RimWorld English folder (required)") 21 translation = flag.String("translation", "", "Full path directory of your RimWorld Translation folder (required)") 22 docType = flag.String("doc", "xml", "Type of the Doc that you want to compare (not required)") 23 multipleMsg = "Considers the translation flag as a collection of translations, enabling 1:N comparison" 24 multiple = flag.Bool("multiple", false, multipleMsg) 25 version = flag.Bool("version", false, "Prints current version") 26 docs, lines, inNeed int 27 ) 28 flag.Parse() 29 args := os.Args 30 switch { 31 case len(args) < 2 || args[1] == "-h": 32 flag.Usage() 33 os.Exit(1) 34 case *version: 35 fmt.Println(ver) 36 os.Exit(0) 37 case len(*original) == 0 || len(*translation) == 0: 38 flag.Usage() 39 os.Exit(1) 40 } 41 fmt.Println("Creating instance ...") 42 fmt.Print("Output:- ") 43 comparer.DocType = *docType 44 if *multiple { 45 dir, err := comparer.ReadDir(*translation) 46 if err != nil { 47 log.Fatal(err) 48 } 49 for _, d := range dir { 50 if d.IsDir() { 51 err := comparer.Compare(*original, filepath.Join(*translation, d.Name())) 52 if err != nil { 53 log.Fatal(err) 54 } 55 } 56 docs += comparer.Docs 57 lines += comparer.Lines 58 inNeed += comparer.InNeed 59 } 60 } else { 61 err := comparer.Compare(*original, *translation) 62 if err != nil { 63 log.Fatal(err) 64 } 65 docs = comparer.Docs 66 lines = comparer.Lines 67 inNeed = comparer.InNeed 68 } 69 fmt.Println("Docs comparisons are DONE!") 70 fmt.Printf("Documents scanned: %v | Lines scanned: %v | Translations needed: %v\n", docs, lines, inNeed) 71 os.Exit(0) 72 } 73 74 // getOriginalDir gets the default Steam installation directory. 75 // Returns empty string if directory is not found. 76 func getOriginalDir() string { 77 rimWorldDir := "" 78 // https://support.steampowered.com/kb_article.php?ref=7710-tdlc-0426 79 if runtime.GOOS == "windows" && runtime.GOARCH == "386" { 80 rimWorldDir = `C:\Program Files\Steam\steamapps\common\RimWorld` 81 } else if runtime.GOOS == "windows" && runtime.GOARCH == "amd64" { 82 rimWorldDir = `C:\Program Files (x86)\Steam\steamapps\common\RimWorld` 83 } else if runtime.GOOS == "darwin" { 84 // https://gaming.stackexchange.com/a/219537 85 currentUser, err := user.Current() 86 if err != nil { 87 return "" 88 } 89 // safe to use *nix path sep since we are in the darwin runtime 90 rimWorldDir = filepath.Join(currentUser.HomeDir, 91 `/Library/Application Support/Steam/steamapps/common/RimWorld/RimWorldMac.app`) 92 } 93 // we're in all runtimes here, use os dependent separator 94 englishTrans := filepath.Join(rimWorldDir, "Mods", "Core", "Languages", "English") 95 // do one final check to make sure the English dir exists 96 _, err := os.Stat(englishTrans) 97 if err != nil { 98 englishTrans = "" 99 } 100 return englishTrans 101 }