diff --git a/config.go b/config.go new file mode 100644 index 0000000..2dc7f35 --- /dev/null +++ b/config.go @@ -0,0 +1,47 @@ +package main + +import ( + "fmt" + "gopkg.in/ini.v1" + "os" +) + +type Configuration struct { + file *ini.File + fileLocation string +} + +func NewConfig(fileLocation string) *Configuration { + conf := new(Configuration) + conf.fileLocation = fileLocation + return conf +} + +func (config *Configuration) Load() { + if _, err := os.Stat(config.fileLocation); err != nil { + file, err := os.Create(config.fileLocation) + if err != nil { + fmt.Printf("Failed to create configuration file: %v", err) + os.Exit(1) + } + _, err = file.WriteString("[General]\nserver = sfs.example.com\nport = 7392\nusername = user\nauth-token = token\n; http:// or https:// is necessary\n; port is optional\nhttp-server = http://sfs.example.com:80\npublic-key =\n\n[Share]\nsync-interval = 60") + if err != nil { + fmt.Printf("Error creating configuration file: %v", err) + os.Exit(1) + } + } + var err error + config.file, err = ini.Load(config.fileLocation) + if err != nil { + fmt.Printf("Failed to open configuration file: %v", err) + os.Exit(1) + } +} + +func (config *Configuration) Save() { + err := config.file.SaveTo(config.fileLocation) + if err != nil { + fmt.Printf("Failed to save configuration file: %v", err) + os.Exit(1) + } +} diff --git a/ezconf b/ezconf index e5bdaa6..50f3ea1 160000 --- a/ezconf +++ b/ezconf @@ -1 +1 @@ -Subproject commit e5bdaa67f6b2ad812b8aa5674316af02ae87e652 +Subproject commit 50f3ea10db20675313a7107665a49aa3135813ec diff --git a/go.mod b/go.mod index fea80b1..e184b2c 100644 --- a/go.mod +++ b/go.mod @@ -6,13 +6,12 @@ replace git.nevets.tech/Steven/ezconf v0.0.0-20230501190348-397365ddd2fa => ./ez require ( git.nevets.tech/Steven/ezconf v0.0.0-20230501190348-397365ddd2fa + github.com/TheTitanrain/w32 v0.0.0-20200114052255-2654d97dbd3d github.com/getlantern/systray v1.2.1 github.com/sqweek/dialog v0.0.0-20220809060634-e981b270ebbf ) require ( - github.com/TheTitanrain/w32 v0.0.0-20200114052255-2654d97dbd3d // indirect - github.com/gen2brain/beeep v0.0.0-20230307103607-6e717729cb4f // indirect github.com/getlantern/context v0.0.0-20190109183933-c447772a6520 // indirect github.com/getlantern/errors v0.0.0-20190325191628-abdb3e3e36f7 // indirect github.com/getlantern/golog v0.0.0-20190830074920-4ef2e798c2d7 // indirect @@ -20,11 +19,7 @@ require ( github.com/getlantern/hidden v0.0.0-20190325191715-f02dbb02be55 // indirect github.com/getlantern/ops v0.0.0-20190325191751-d70cb0d6f85f // indirect github.com/go-stack/stack v1.8.0 // indirect - github.com/go-toast/toast v0.0.0-20190211030409-01e6764cf0a4 // indirect - github.com/godbus/dbus/v5 v5.1.0 // indirect - github.com/nu7hatch/gouuid v0.0.0-20131221200532-179d4d0c4d8d // indirect github.com/oxtoacart/bpool v0.0.0-20190530202638-03653db5a59c // indirect - github.com/tadvi/systray v0.0.0-20190226123456-11a2b8fa57af // indirect golang.org/x/sys v0.8.0 // indirect gopkg.in/ini.v1 v1.67.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect diff --git a/go.sum b/go.sum index 473039e..cef22cb 100644 --- a/go.sum +++ b/go.sum @@ -1,11 +1,8 @@ -github.com/TheTitanrain/w32 v0.0.0-20180517000239-4f5cfb03fabf h1:FPsprx82rdrX2jiKyS17BH6IrTmUBYqZa/CXT4uvb+I= github.com/TheTitanrain/w32 v0.0.0-20180517000239-4f5cfb03fabf/go.mod h1:peYoMncQljjNS6tZwI9WVyQB3qZS6u79/N3mBOcnd3I= github.com/TheTitanrain/w32 v0.0.0-20200114052255-2654d97dbd3d h1:2xp1BQbqcDDaikHnASWpVZRjibOxu7y9LhAv04whugI= github.com/TheTitanrain/w32 v0.0.0-20200114052255-2654d97dbd3d/go.mod h1:peYoMncQljjNS6tZwI9WVyQB3qZS6u79/N3mBOcnd3I= github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/gen2brain/beeep v0.0.0-20230307103607-6e717729cb4f h1:oRm7Hy2dQWfHgOuOWRaYZf+kZcWJst7fxAlq+yjdLss= -github.com/gen2brain/beeep v0.0.0-20230307103607-6e717729cb4f/go.mod h1:0W7dI87PvXJ1Sjs0QPvWXKcQmNERY77e8l7GFhZB/s4= github.com/getlantern/context v0.0.0-20190109183933-c447772a6520 h1:NRUJuo3v3WGC/g5YiyF790gut6oQr5f3FBI88Wv0dx4= github.com/getlantern/context v0.0.0-20190109183933-c447772a6520/go.mod h1:L+mq6/vvYHKjCX2oez0CgEAJmbq1fbb/oNJIWQkBybY= github.com/getlantern/errors v0.0.0-20190325191628-abdb3e3e36f7 h1:6uJ+sZ/e03gkbqZ0kUG6mfKoqDb4XMAzMIwlajq19So= @@ -22,12 +19,6 @@ github.com/getlantern/systray v1.2.1 h1:udsC2k98v2hN359VTFShuQW6GGprRprw6kD6539J github.com/getlantern/systray v1.2.1/go.mod h1:AecygODWIsBquJCJFop8MEQcJbWFfw/1yWbVabNgpCM= github.com/go-stack/stack v1.8.0 h1:5SgMzNM5HxrEjV0ww2lTmX6E2Izsfxas4+YHWRs3Lsk= github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY= -github.com/go-toast/toast v0.0.0-20190211030409-01e6764cf0a4 h1:qZNfIGkIANxGv/OqtnntR4DfOY2+BgwR60cAcu/i3SE= -github.com/go-toast/toast v0.0.0-20190211030409-01e6764cf0a4/go.mod h1:kW3HQ4UdaAyrUCSSDR4xUzBKW6O2iA4uHhk7AtyYp10= -github.com/godbus/dbus/v5 v5.1.0 h1:4KLkAxT3aOY8Li4FRJe/KvhoNFFxo0m6fNuFUO8QJUk= -github.com/godbus/dbus/v5 v5.1.0/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA= -github.com/nu7hatch/gouuid v0.0.0-20131221200532-179d4d0c4d8d h1:VhgPp6v9qf9Agr/56bj7Y/xa04UccTW04VP0Qed4vnQ= -github.com/nu7hatch/gouuid v0.0.0-20131221200532-179d4d0c4d8d/go.mod h1:YUTz3bUH2ZwIWBy3CJBeOBEugqcmXREj14T+iG/4k4U= github.com/oxtoacart/bpool v0.0.0-20190530202638-03653db5a59c h1:rp5dCmg/yLR3mgFuSOe4oEnDDmGLROTvMragMUXpTQw= github.com/oxtoacart/bpool v0.0.0-20190530202638-03653db5a59c/go.mod h1:X07ZCGwUbLaax7L0S3Tw4hpejzu63ZrrQiUe6W0hcy0= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= @@ -37,11 +28,7 @@ github.com/sqweek/dialog v0.0.0-20220809060634-e981b270ebbf/go.mod h1:/qNPSY91qT github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= github.com/stretchr/testify v1.8.2 h1:+h33VjcLVPDHtOdpUCuF+7gSuG3yGIftsP1YvFihtJ8= -github.com/tadvi/systray v0.0.0-20190226123456-11a2b8fa57af h1:6yITBqGTE2lEeTPG04SN9W+iWHCRyHqlVYILiSXziwk= -github.com/tadvi/systray v0.0.0-20190226123456-11a2b8fa57af/go.mod h1:4F09kP5F+am0jAwlQLddpoMDM+iewkxxt6nxUQ5nq5o= -golang.org/x/sys v0.0.0-20200515095857-1151b9dac4a9 h1:YTzHMGlqJu67/uEo1lBv0n3wBXhXNeUbB1XfN2vmTm0= golang.org/x/sys v0.0.0-20200515095857-1151b9dac4a9/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.8.0 h1:EBmGv8NaZBZTWvrbjNoL6HVt+IVy3QDQpJs7VRIw3tU= golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= diff --git a/main.go b/main.go index 8c4d2eb..a52e8a7 100644 --- a/main.go +++ b/main.go @@ -14,9 +14,13 @@ var Config *ezconf.Configuration var Connection *tls.Conn func main() { - Config = ezconf.NewConfiguration("./config.ini") + Config.Load() + //Config = ezconf.NewConfiguration("./config.ini") + + Config.SetValue("Blah.blah.string", "asdfasdf") + //var err error - //Connection, err = NewConnection(Config.GetAsString("General.server"), Config.GetAsInt("General.port")) + //Connection, err = NewSFSConnection(Config.GetAsString("General.server"), Config.GetAsInt("General.port")) //if err != nil { // fmt.Printf("Error establishing connection: %v", err) // os.Exit(1) @@ -43,8 +47,6 @@ func main() { // os.Exit(1) //} - sendNotification("Notification", "This is the message displayed!") - systray.Run(onReady, onExit) } diff --git a/notifications.go b/notifications.go index 38785e0..a7ca9d3 100644 --- a/notifications.go +++ b/notifications.go @@ -1,7 +1,4 @@ package main -import "github.com/TheTitanrain/w32" - func sendNotification(title string, message string) { - w32.DialogBox() } diff --git a/serverconnection.go b/serverconnection.go index 40a491b..db0d29f 100644 --- a/serverconnection.go +++ b/serverconnection.go @@ -9,8 +9,9 @@ import ( "os" ) -type ClientConn struct { +type SFSConnection struct { tlsConn *tls.Conn + writing bool credentials Credentials isAuthed bool } @@ -20,7 +21,7 @@ type Credentials struct { pass string } -func NewConnection(host string, port int) (*tls.Conn, error) { +func NewSFSConnection(host string, port int) (*SFSConnection, error) { _, err := os.Stat("./public.cer") if err != nil { getPublicKey() @@ -47,7 +48,13 @@ func NewConnection(host string, port int) (*tls.Conn, error) { if err != nil { return nil, err } - return conn, nil + + return &SFSConnection{ + conn, + false, + Credentials{"", ""}, + true, + }, nil } func getPublicKey() {