diff --git a/go.mod b/go.mod index 1fad4b3..ac2ad2f 100644 --- a/go.mod +++ b/go.mod @@ -1,8 +1,9 @@ module github.com/starkers/safer-eve require ( + fyne.io/fyne v1.2.1 github.com/ChimeraCoder/gojson v1.1.0 // indirect - github.com/fsnotify/fsnotify v1.4.7 // indirect + github.com/coreos/etcd v3.3.18+incompatible github.com/hpcloud/tail v1.0.0 github.com/leaanthony/mewn v0.10.7 github.com/papertrail/go-tail v0.0.0-20180509224916-973c153b0431 @@ -13,3 +14,5 @@ require ( gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 // indirect gopkg.in/yaml.v2 v2.2.7 // indirect ) + +go 1.13 diff --git a/go.sum b/go.sum index 518238a..3d78fda 100644 --- a/go.sum +++ b/go.sum @@ -1,5 +1,7 @@ fyne.io/fyne v1.1.2 h1:a9YLFXxqN7lKNqTrk+ocw3/3ROrn6aFiofix8ATVOBc= fyne.io/fyne v1.1.2/go.mod h1:ukZVsvlHO29NK4HARH2B4rqgVqgx6WbtWKfEUOz4ZNo= +fyne.io/fyne v1.2.1 h1:0hicR1E+hZGwZUwN5LheR5SoPr/ror8fGzQR2qJcZkA= +fyne.io/fyne v1.2.1/go.mod h1:Ab+3DIB/FVteW0y4DXfmZv4N3JdnCBh2lHkINI02BOU= github.com/ChimeraCoder/gojson v1.1.0 h1:/6S8djl/jColpJGTYniA3xrqJWuKeyEozzPtpr5L4Pw= github.com/ChimeraCoder/gojson v1.1.0/go.mod h1:nYbTQlu6hv8PETM15J927yM0zGj3njIldp72UT1MqSw= github.com/Jeffail/gabs/v2 v2.2.0 h1:7touC+WzbQ7LO5+mwgxT44miyTqAVCOlIWLA6PiIB5w= @@ -11,6 +13,8 @@ github.com/Netflix/go-expect v0.0.0-20180615182759-c93bf25de8e8/go.mod h1:oX5x61 github.com/abadojack/whatlanggo v1.0.1 h1:19N6YogDnf71CTHm3Mp2qhYfkRdyvbgwWdd2EPxJRG4= github.com/abadojack/whatlanggo v1.0.1/go.mod h1:66WiQbSbJBIlOZMsvbKe5m6pzQovxCH9B/K8tQB2uoc= github.com/akavel/rsrc v0.8.0/go.mod h1:uLoCtb9J+EyAqh+26kdrTgmzRBFPGOolLWKpdxkKq+c= +github.com/coreos/etcd v3.3.18+incompatible h1:Zz1aXgDrFFi1nadh58tA9ktt06cmPTwNNP3dXwIq1lE= +github.com/coreos/etcd v3.3.18+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc32PjwdhPthX9715RE= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/dchest/cssmin v0.0.0-20151210170030-fb8d9b44afdc h1:VBS1z48BFEe00G81z8MKOtwX7f/ISkuH38NscT8iVPw= @@ -25,6 +29,8 @@ github.com/fsnotify/fsnotify v1.4.7 h1:IXs+QLmnXW2CcXuY+8Mzv/fWEsPGWxqefPtCP5CnV github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= github.com/go-gl/gl v0.0.0-20181026044259-55b76b7df9d2 h1:78Hza2KHn2PX1jdydQnffaU2A/xM0g3Nx1xmMdep9Gk= github.com/go-gl/gl v0.0.0-20181026044259-55b76b7df9d2/go.mod h1:482civXOzJJCPzJ4ZOX/pwvXBWSnzD4OKMdH4ClKGbk= +github.com/go-gl/gl v0.0.0-20190320180904-bf2b1f2f34d7 h1:SCYMcCJ89LjRGwEa0tRluNRiMjZHalQZrVrvTbPh+qw= +github.com/go-gl/gl v0.0.0-20190320180904-bf2b1f2f34d7/go.mod h1:482civXOzJJCPzJ4ZOX/pwvXBWSnzD4OKMdH4ClKGbk= github.com/go-gl/glfw v0.0.0-20181213070059-819e8ce5125f h1:7MsFMbSn8Lcw0blK4+NEOf8DuHoOBDhJsHz04yh13pM= github.com/go-gl/glfw v0.0.0-20181213070059-819e8ce5125f/go.mod h1:vR7hzQXu2zJy9AVAgeJqvqgH9Q5CA+iKCZ2gyEVpxRU= github.com/go-playground/colors v1.2.0 h1:0EdjTXKrr2g1L/LQTYtIqabeHpZuGZz1U4osS1T8+5M= @@ -101,8 +107,13 @@ github.com/wailsapp/wails v0.19.0/go.mod h1:CEmTAETH2Z9/mW6rf8pqWcMajql2AKi789uB golang.org/x/crypto v0.0.0-20190123085648-057139ce5d2b/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= +golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/image v0.0.0-20181116024801-cd38e8056d9b h1:VHyIDlv3XkfCa5/a81uzaoDkHH4rr81Z62g+xlnO8uM= golang.org/x/image v0.0.0-20181116024801-cd38e8056d9b/go.mod h1:ux5Hcp/YLpHSI86hEcLt0YII63i6oz57MZXIpbrjZUs= +golang.org/x/image v0.0.0-20190227222117-0694c2d4d067/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js= +golang.org/x/image v0.0.0-20190802002840-cff245a6509b h1:+qEpEAPhDZ1o0x3tHzZTQDArnOixOzGD9HUJfcg0mb4= +golang.org/x/image v0.0.0-20190802002840-cff245a6509b/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0= +golang.org/x/mobile v0.0.0-20190719004257-d2bd2a29d028/go.mod h1:E/iHnbuqvinMTCcRqshq8CkpyQDoeVncDDYHnLhea+o= golang.org/x/net v0.0.0-20181220203305-927f97764cc3/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20190509222800-a4d6f7feada5 h1:6M3SDHlHHDCx2PcQw3S4KsR170vGqDhJDOmpVd4Hjak= @@ -112,9 +123,12 @@ golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5h golang.org/x/sys v0.0.0-20181228144115-9a3f9b0469bb/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190312061237-fead79001313/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190509141414-a5b02f93d862 h1:rM0ROo5vb9AdYJi1110yjWGMej9ITfKddS89P3Fkhug= golang.org/x/sys v0.0.0-20190509141414-a5b02f93d862/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190626221950-04f50cda93cb h1:fgwFCsaw9buMuxNd6+DQfAuSFqbNiQZpcgJQAgJsK6k= +golang.org/x/sys v0.0.0-20190626221950-04f50cda93cb/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= gopkg.in/AlecAivazis/survey.v1 v1.8.4/go.mod h1:iBNOmqKz/NUbZx3bA+4hAGLRC7fSK7tgtVDT4tB22XA= diff --git a/main.go b/main.go index 447a19e..6d39085 100644 --- a/main.go +++ b/main.go @@ -1,41 +1,12 @@ package main import ( - "fmt" "github.com/starkers/safer-eve/pkg/eve" - "time" ) func main() { - fmt.Println("searching") - - //logDirs := eve.PathSearch() - //fmt.Println(a) - fileList := eve.FileSearchUnix() - - //List := eve.GetActiveChannels(fileList) - //for _, name := range List{ - // fmt.Println(name) - //} - - //for _, d := range logDirs { - // fmt.Println(d) - // go eve.WatchPath(d) - //} - - - for _, f := range fileList{ - if eve.IsCurrentLog(f) { - //if strings.Contains(f, "delve.imperium") { - // fmt.Printf("tailing file: %v\n", f) - go eve.Tail(f) - //} - } - //else { - // fmt.Println(f) - //} - } - time.Sleep(9999 * time.Hour) + //Think about some cli params that might be useful later. + eve.Init() } diff --git a/pkg/eve/FileSearch.go b/pkg/eve/FileSearch.go index 94541e8..fff185f 100644 --- a/pkg/eve/FileSearch.go +++ b/pkg/eve/FileSearch.go @@ -50,43 +50,3 @@ func FileSearchUnix() []string { } return filesPotential } - -// returns paths with eve chat log files -func PathSearch() []string { - var pathsWithLogs []string - fmt.Println("PathSearch looking for chat log files..") - - searchPath = append(searchPath, "~/.local/share/Steam/steamapps/compatdata/8500/pfx/drive_c/users/steamuser/My Documents/EVE/logs/Chatlogs") - - userName, _ := user.Current() - homeDir := userName.HomeDir - - for _, d := range searchPath { - - // if has trailing slash, remove it - d = strings.TrimSuffix(d, "/") - - // do a unix like expansion if the path starts like `~/` - if strings.HasPrefix(d, "~/") { - d = filepath.Join(homeDir, d[2:]) - } - f, err := os.Open(d) - if err != nil { - log.Fatal(err) - } - files, err := f.Readdir(-1) - if err != nil { - log.Fatal(err) - } - err = f.Close() - if err != nil { - log.Fatal(err) - } - if len(files) > 0 { - pathsWithLogs = append(pathsWithLogs, d) - } - fmt.Println(len(files)) - - } - return pathsWithLogs -} diff --git a/pkg/eve/Init.go b/pkg/eve/Init.go new file mode 100644 index 0000000..583835c --- /dev/null +++ b/pkg/eve/Init.go @@ -0,0 +1,60 @@ +package eve + +import ( + "fmt" + "log" + + "github.com/starkers/safer-eve/pkg/evelogs" +) + +type logDirs []*evelogs.LogDir +type logfiles []*evelogs.LogFile + +func Init() error { + fmt.Println("searching") + + //fmt.Println(a) + //fileList := FileSearchUnix() + dirlist, err := GetLogDirectories() + if err != nil { + log.Fatal(fmt.Sprintf("Failed getting log directories %v", err)) + } + logDirs, err := evelogs.DirsToLogDirs(dirlist) + if err != nil { + log.Fatal(err) + } + log.Println("Found logdirs: ") + for _, logdir := range logDirs { + log.Println(logdir.Path) + } + + //List := eve.GetActiveChannels(fileList) + var logfiles []*evelogs.LogFile + for _, logdir := range logDirs { + logfilelist, err := logdir.GetLogFiles() + if err != nil { + log.Printf("Warning: %s", err) + } + logfiles = append(logfiles, logfilelist...) + + } + + //for _, d := range logDirs { + // fmt.Println(d) + // go eve.WatchPath(d) + //} + + // for _, f := range fileList { + // if eve.IsCurrentLog(f) { + // //if strings.Contains(f, "delve.imperium") { + // // fmt.Printf("tailing file: %v\n", f) + // go eve.Tail(f) + // //} + // } + // //else { + // // fmt.Println(f) + // //} + // } + // time.Sleep(9999 * time.Hour) + return nil +} diff --git a/pkg/eve/LogDirectories.go b/pkg/eve/LogDirectories.go new file mode 100644 index 0000000..3877b2d --- /dev/null +++ b/pkg/eve/LogDirectories.go @@ -0,0 +1,37 @@ +package eve + +import ( + "io/ioutil" + "os/user" + "path/filepath" + "strings" +) + +func GetLogDirectories() ([]string, error) { + // Given assumptions about log directories in the eve application + // installatin layout, simple method to retrieve folders for eve. + // We can extend this to branch for or register platform later + linuxPath := "~/.local/share/Steam/steamapps/compatdata/8500/pfx/drive_c/users/steamuser/My Documents/EVE/logs/" + // linuxPath := "~/.local/share/Steam/steamapps/compatdata/8500/pfx/drive_c/users/steamuser/My Documents/EVE/notreal/" + //TODO: if not linux + // load ini or settings file of locations? + // get result by probing install path for file system a bit. + path := linuxPath + var paths []string + + if strings.HasPrefix(path, "~/") { + userName, _ := user.Current() + path = filepath.Join(userName.HomeDir, path[2:]) + } + files, err := ioutil.ReadDir(path) + if err != nil { + return nil, err + } + for _, f := range files { + + if f.IsDir() { + paths = append(paths, f.Name()) + } + } + return paths, nil +} diff --git a/pkg/evelogs/logDir.go b/pkg/evelogs/logDir.go new file mode 100644 index 0000000..bad53e1 --- /dev/null +++ b/pkg/evelogs/logDir.go @@ -0,0 +1,71 @@ +package evelogs + +import ( + "fmt" + "io/ioutil" + "log" + "os" + "os/user" + "path/filepath" + "strings" +) + +type LogDir struct { + Path string +} + +func NewLogDir(path string) (*LogDir, error) { + // do a unix like expansion if the path starts like `~/` + if strings.HasPrefix(path, "~/") { + userName, _ := user.Current() + path = filepath.Join(userName.HomeDir, path[2:]) + } + ld := &LogDir{Path: path} + if !ld.DExists() { + return nil, fmt.Errorf("Path %s does not exist or is a regular file", ld.Path) + } + return ld, nil +} + +func (ld *LogDir) DExists() bool { + info, err := os.Stat(ld.Path) + if os.IsNotExist(err) { + return false + } + return info.IsDir() +} + +func (ld *LogDir) GetLogFiles() ([]*LogFile, error) { + //TODO: iterate through the directory looking for logs + + files, err := ioutil.ReadDir(ld.Path) + var paths []string + if err != nil { + log.Fatal(err) + return nil, err + } + for _, f := range files { + if !f.IsDir() { + paths = append(paths, ld.Path+string(os.PathSeparator)+f.Name()) + } + } + logfiles, err := PathsToLogFiles(paths) + if err != nil { + log.Fatal(err) + return nil, err + } + return logfiles, nil +} + +// Generate logDir instances from log dir paths +func DirsToLogDirs(paths []string) ([]*LogDir, error) { + var logDirs []*LogDir + for _, dirpath := range paths { + newLogDir, err := NewLogDir(dirpath) + if err != nil { + return nil, err + } + logDirs = append(logDirs, newLogDir) + } + return logDirs, nil +} diff --git a/pkg/evelogs/logFile.go b/pkg/evelogs/logFile.go new file mode 100644 index 0000000..bc8762a --- /dev/null +++ b/pkg/evelogs/logFile.go @@ -0,0 +1,48 @@ +package evelogs + +import ( + "fmt" + "log" + "os" +) + +type LogFile struct { + Path string +} + +// create a lofFile instance, if it's a file. +func NewLogFile(path string) (*LogFile, error) { + lf := &LogFile{Path: path} + exists := lf.FileExists() + if !exists { + return nil, fmt.Errorf("File %s not found or is directory", lf.Path) + } + return lf, nil +} + +func (lf *LogFile) FileExists() bool { + info, err := os.Stat(lf.Path) + if os.IsNotExist(err) { + return false + } + return !info.IsDir() +} + +func (lf *LogFile) TailFile() error { + //lets start a goroutine to tail the file here + return nil +} + +//create logFile instances from a list of paths +func PathsToLogFiles(paths []string) ([]*LogFile, error) { + var logFiles []*LogFile + for _, f := range paths { + nLogFile, err := NewLogFile(f) + if err != nil { + log.Printf("Error with %s: %s", f, err) + return nil, err + } + logFiles = append(logFiles, nLogFile) + } + return logFiles, nil +}