-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Using winrt api to register sync root
- Loading branch information
1 parent
6fb3be7
commit b65069d
Showing
19 changed files
with
389 additions
and
285 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,98 +1,32 @@ | ||
package main | ||
|
||
import ( | ||
"io" | ||
"os" | ||
"path/filepath" | ||
|
||
"github.com/rs/zerolog" | ||
"github.com/rs/zerolog/log" | ||
|
||
"github.com/balazsgrill/potatodrive/bindings" | ||
"golang.org/x/sys/windows/registry" | ||
) | ||
|
||
func initLogger() (zerolog.Logger, io.Closer) { | ||
cachedir, err := os.UserCacheDir() | ||
if err != nil { | ||
panic(err) | ||
} | ||
logfolder := filepath.Join(cachedir, "PotatoDrive") | ||
err = os.MkdirAll(logfolder, 0777) | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
logfile := "potatodrive.log" | ||
logf, err := os.OpenFile(filepath.Join(logfolder, logfile), os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0666) | ||
if err != nil { | ||
panic(err) | ||
} | ||
return log.Output(logf).With().Timestamp().Logger(), logf | ||
} | ||
|
||
func startInstance(parentkey registry.Key, keyname string) (io.Closer, error) { | ||
key, err := registry.OpenKey(parentkey, keyname, registry.QUERY_VALUE) | ||
if err != nil { | ||
log.Printf("Open key: %v", err) | ||
return nil, err | ||
} | ||
|
||
var basec bindings.BaseConfig | ||
err = bindings.ReadConfigFromRegistry(key, &basec) | ||
if err != nil { | ||
log.Printf("Get base config: %v", err) | ||
return nil, err | ||
} | ||
config := bindings.CreateConfigByType(basec.Type) | ||
bindings.ReadConfigFromRegistry(key, config) | ||
err = config.Validate() | ||
if err != nil { | ||
log.Printf("Validate config: %v", err) | ||
return nil, err | ||
} | ||
fs, err := config.ToFileSystem() | ||
if err != nil { | ||
log.Printf("Create file system: %v", err) | ||
return nil, err | ||
} | ||
|
||
log.Printf("Starting %s on %s", keyname, basec.LocalPath) | ||
c, err := bindings.BindVirtualizationInstance(basec.LocalPath, fs) | ||
if err != nil { | ||
log.Print(err) | ||
} | ||
log.Printf("%s started", keyname) | ||
return c, nil | ||
} | ||
|
||
func main() { | ||
var logf io.Closer | ||
log.Logger, logf = initLogger() | ||
defer logf.Close() | ||
|
||
parentkey, err := registry.OpenKey(registry.LOCAL_MACHINE, "SOFTWARE\\PotatoDrive", registry.QUERY_VALUE|registry.READ) | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
keys, err := parentkey.ReadSubKeyNames(0) | ||
mgr, err := New() | ||
if err != nil { | ||
panic(err) | ||
log.Print(err) | ||
return | ||
} | ||
ui := createUI(mgr.Logger) | ||
defer ui.ni.Dispose() | ||
|
||
var instances []io.Closer | ||
|
||
keys, _ := mgr.InstanceList() | ||
for _, keyname := range keys { | ||
c, err := startInstance(parentkey, keyname) | ||
err := mgr.StartInstance(keyname, ui.Logger, func(err error) { | ||
if err != nil { | ||
ui.Logger.Err(err).Msgf("%s is offline %v", keyname, err) | ||
} | ||
}) | ||
if err != nil { | ||
log.Printf("Start instance: %v", err) | ||
} else { | ||
instances = append(instances, c) | ||
ui.Logger.Err(err).Msgf("Failed to start %s", keyname) | ||
} | ||
} | ||
|
||
bindings.CloseOnSigTerm(instances...) | ||
|
||
select {} | ||
go bindings.CloseOnSigTerm(mgr) | ||
ui.Run() | ||
} |
Oops, something went wrong.