rewrite some things to use the new functions

This commit is contained in:
Superwhiskers 2018-03-14 18:29:13 -05:00
parent 75580296f6
commit a7715e27ed
2 changed files with 24 additions and 52 deletions

View file

@ -31,51 +31,47 @@ func main() {
if *doSetup == false {
// can't have that ugliness there
clear()
fmt.Printf("-- log\n")
// startup
fmt.Printf("= startup")
// i might include some os-specific code
fmt.Printf("loading 0%%: detecting os")
fmt.Printf("%s\n", padStrToMatchStr(fmt.Sprintf("\ros: %s", runtime.GOOS), "loading 0%%: detecting os", " "))
// file checking
fmt.Printf("loading 50%%: checking files.")
// map for holding file status
fileMap := make(map[string]string)
// config.json -- if nonexistent, it follows the user's instruction to create one, or use a builtin copy
fileMap["config"] = "ne"
if doesFileExist(*config) == false {
fmt.Printf("%s\n", padStrToMatchStr("\rconfig: nonexistent", "loading 50%%: checking files.", " "))
} else {
} doesFileExist(*config) != false {
// check if the file is valid JSON
if checkJSONValidity(*config) != true {
fmt.Printf("%s\n", padStrToMatchStr("\rconfig: invalid", "loading 50%%: checking files.", " "))
// set fileMap to have the correct status for the file
fileMap["config"] = "iv"
} else {
fmt.Printf("%s\n", padStrToMatchStr("\rconfig: valid", "loading 50%%: checking files.", " "))
// "ditto"
fileMap["config"] = "va"
}
}
// print final info
fmt.Printf("loaded..\n")
// do the setup function if the file isn't completely correct
if fileMap["config"] == "ne" {
// perform setup
setup(fileMap)
} else if fileMap["config"] == "iv" {
// i'm not just going to perform autosetup because they might have some stuff in there
fmt.Printf("your config is invalid.\n")
fmt.Printf("you have three different options:\n")
fmt.Printf(" 1. run this program with the --setup flag\n")
fmt.Printf(" 2. delete the config and run this program\n")
fmt.Printf(" 3. fix the config\n")
os.Exit(1)
} else {
} else {
startProxy(*config)
}

View file

@ -20,7 +20,6 @@ import (
"strings"
"time"
// externals
"github.com/shiena/ansicolor"
)
// setup function goes here now
@ -124,25 +123,14 @@ func setup(fileMap map[string]string) {
// handle the results
if (parsedRes.Server == resMap[test[x]]) && (err == nil) && (res != "") {
// things are different for windows
// *shrug*
if isWindows() {
Writer := ansicolor.NewAnsiColorWriter(os.Stdout)
fmt.Fprintf(Writer, "%s\n", padStrToMatchStr(fmt.Sprintf("\r %s%s%s%s %s -> %s", code("green"), code("bold"), utilIcons["success"], code("reset"), testEndpoints["ninty"][test[x]], testEndpoints["local"][test[x]]), fmt.Sprintf(" %s %s -> %s", utilIcons["uncertain"], testEndpoints["ninty"][test[x]], testEndpoints["local"][test[x]]), " "))
} else {
fmt.Printf("%s\n", padStrToMatchStr(fmt.Sprintf("\r %s%s%s%s %s -> %s", code("green"), code("bold"), utilIcons["success"], code("reset"), testEndpoints["ninty"][test[x]], testEndpoints["local"][test[x]]), fmt.Sprintf(" %s %s -> %s", utilIcons["uncertain"], testEndpoints["ninty"][test[x]], testEndpoints["local"][test[x]]), " "))
}
// MS, step your game up and support ansi escape codes
consoleSequence(fmt.Sprintf("%s\n", padStrToMatchStr(fmt.Sprintf("\r %s%s%s%s %s -> %s", code("green"), code("bold"), utilIcons["success"], code("reset"), testEndpoints["ninty"][test[x]], testEndpoints["local"][test[x]]), fmt.Sprintf(" %s %s -> %s", utilIcons["uncertain"], testEndpoints["ninty"][test[x]], testEndpoints["local"][test[x]]), " ")))
result[x] = true
} else {
// "ditto"
if isWindows() {
Writer := ansicolor.NewAnsiColorWriter(os.Stdout)
fmt.Fprintf(Writer, "%s\n", padStrToMatchStr(fmt.Sprintf("\r %s%s%s%s %s -> %s", code("red"), code("bold"), utilIcons["failiure"], code("reset"), testEndpoints["ninty"][test[x]], testEndpoints["local"][test[x]]), fmt.Sprintf(" %s %s -> %s", utilIcons["uncertain"], testEndpoints["ninty"][test[x]], testEndpoints["local"][test[x]]), " "))
} else {
fmt.Printf("%s\n", padStrToMatchStr(fmt.Sprintf("\r %s%s%s%s %s -> %s", code("red"), code("bold"), utilIcons["failiure"], code("reset"), testEndpoints["ninty"][test[x]], testEndpoints["local"][test[x]]), fmt.Sprintf(" %s %s -> %s", utilIcons["uncertain"], testEndpoints["ninty"][test[x]], testEndpoints["local"][test[x]]), " "))
}
// make windows great again (as if it ever was)
consoleSequence(fmt.Sprintf("%s\n", padStrToMatchStr(fmt.Sprintf("\r %s%s%s%s %s -> %s", code("red"), code("bold"), utilIcons["failiure"], code("reset"), testEndpoints["ninty"][test[x]], testEndpoints["local"][test[x]]), fmt.Sprintf(" %s %s -> %s", utilIcons["uncertain"], testEndpoints["ninty"][test[x]], testEndpoints["local"][test[x]]), " ")))
result[x] = false
}
@ -178,26 +166,14 @@ func setup(fileMap map[string]string) {
// handle the results
if (parsedRes2.Server == resMap[testOfficial[x]]) && (err3 == nil) && (res2 != "") {
// again, windows is just a pain to
// deal with
if isWindows() {
Writer := ansicolor.NewAnsiColorWriter(os.Stdout)
fmt.Fprintf(Writer, "%s\n", padStrToMatchStr(fmt.Sprintf("\r %s%s%s%s %s -> %s", code("green"), code("bold"), utilIcons["success"], code("reset"), testEndpoints["ninty"][testOfficial[x]], testEndpoints["official"][testOfficial[x]]), fmt.Sprintf(" %s %s -> %s", utilIcons["uncertain"], testEndpoints["ninty"][testOfficial[x]], testEndpoints["official"][testOfficial[x]]), " "))
} else {
fmt.Printf("%s\n", padStrToMatchStr(fmt.Sprintf("\r %s%s%s%s %s -> %s", code("green"), code("bold"), utilIcons["success"], code("reset"), testEndpoints["ninty"][testOfficial[x]], testEndpoints["official"][testOfficial[x]]), fmt.Sprintf(" %s %s -> %s", utilIcons["uncertain"], testEndpoints["ninty"][testOfficial[x]], testEndpoints["official"][testOfficial[x]]), " "))
}
// why is windows like this
consoleSequence(fmt.Sprintf("%s\n", padStrToMatchStr(fmt.Sprintf("\r %s%s%s%s %s -> %s", code("green"), code("bold"), utilIcons["success"], code("reset"), testEndpoints["ninty"][testOfficial[x]], testEndpoints["official"][testOfficial[x]]), fmt.Sprintf(" %s %s -> %s", utilIcons["uncertain"], testEndpoints["ninty"][testOfficial[x]], testEndpoints["official"][testOfficial[x]]), " ")))
resultOfficial[x] = true
} else {
// the amount of times i had to do this
// *sigh*
if isWindows() {
Writer := ansicolor.NewAnsiColorWriter(os.Stdout)
fmt.Fprintf(Writer, "%s\n", padStrToMatchStr(fmt.Sprintf("\r %s%s%s%s %s -> %s", code("red"), code("bold"), utilIcons["failiure"], code("reset"), testEndpoints["ninty"][testOfficial[x]], testEndpoints["official"][testOfficial[x]]), fmt.Sprintf(" %s %s -> %s", utilIcons["uncertain"], testEndpoints["ninty"][testOfficial[x]], testEndpoints["official"][testOfficial[x]]), " "))
} else {
fmt.Printf("%s\n", padStrToMatchStr(fmt.Sprintf("\r %s%s%s%s %s -> %s", code("red"), code("bold"), utilIcons["failiure"], code("reset"), testEndpoints["ninty"][testOfficial[x]], testEndpoints["official"][testOfficial[x]]), fmt.Sprintf(" %s %s -> %s", utilIcons["uncertain"], testEndpoints["ninty"][testOfficial[x]], testEndpoints["official"][testOfficial[x]]), " "))
}
// thank goodness for my shorthand function
consoleSequence(fmt.Sprintf("%s\n", padStrToMatchStr(fmt.Sprintf("\r %s%s%s%s %s -> %s", code("red"), code("bold"), utilIcons["failiure"], code("reset"), testEndpoints["ninty"][testOfficial[x]], testEndpoints["official"][testOfficial[x]]), fmt.Sprintf(" %s %s -> %s", utilIcons["uncertain"], testEndpoints["ninty"][testOfficial[x]], testEndpoints["official"][testOfficial[x]]), " ")))
resultOfficial[x] = false
}