diff --git a/main.go b/code/main/main.go similarity index 98% rename from main.go rename to code/main/main.go index 5dd9281..e246427 100644 --- a/main.go +++ b/code/main/main.go @@ -1,4 +1,4 @@ -package tank +package main import ( "fmt" diff --git a/code/tool/util/util_path.go b/code/tool/util/util_path.go index e83d89c..2d94404 100644 --- a/code/tool/util/util_path.go +++ b/code/tool/util/util_path.go @@ -9,6 +9,7 @@ import ( "os" "os/user" "path/filepath" + "runtime" "strings" ) @@ -31,6 +32,22 @@ func GetGoPath() string { } +//获取开发时的Home目录 +func GetDevHomePath() string { + + _, file, _, ok := runtime.Caller(0) + if !ok { + panic("cannot get dev home path.") + } + + dir := GetDirOfPath(file) + dir = GetDirOfPath(dir) + dir = GetDirOfPath(dir) + dir = GetDirOfPath(dir) + + return dir +} + //获取该应用可执行文件的位置。 //例如:C:\Users\lishuang\AppData\Local\Temp func GetHomePath() string { @@ -43,14 +60,14 @@ func GetHomePath() string { //如果exPath中包含了 /private/var/folders 我们认为是在Mac的开发环境中 macDev := strings.HasPrefix(exPath, "/private/var/folders") if macDev { - exPath = GetGoPath() + "/src/github.com/eyebluecn/tank/tmp" + exPath = GetDevHomePath() + "/tmp" } //如果exPath中包含了 \\AppData\\Local\\Temp 我们认为是在Win的开发环境中 systemUser, err := user.Current() winDev := strings.HasPrefix(exPath, systemUser.HomeDir+"\\AppData\\Local\\Temp") if winDev { - exPath = GetGoPath() + "/src/github.com/eyebluecn/tank/tmp" + exPath = GetDevHomePath() + "/tmp" } return exPath