Documentation
¶
Overview ¶
Package syncer talks to Syncer (github.com/ApolloF/syncer), which keeps game saves in sync between PCs and backs them up. Syncer serves a local JSON-RPC 2.0 API on the named pipe \\.\pipe\syncer, one JSON message per line; only the current Windows user can connect. When Syncer's window isn't open, "Syncer.exe --api" serves it until it's idle.
Index ¶
- Constants
- Variables
- func Installed() (string, bool)
- type BackupResult
- type Client
- func (c *Client) BackupNow(ctx context.Context, wait bool, timeout time.Duration) (BackupResult, error)
- func (c *Client) Call(ctx context.Context, method string, params, out any) error
- func (c *Client) Close() error
- func (c *Client) Done() <-chan struct{}
- func (c *Client) GameStatus(ctx context.Context, g Game) (GameStatus, error)
- func (c *Client) Games(ctx context.Context) ([]Folder, error)
- func (c *Client) OnNotify(fn func(method string))
- func (c *Client) Open(ctx context.Context) error
- func (c *Client) RegisterGames(ctx context.Context, games []Game) error
- func (c *Client) Status(ctx context.Context) (Status, error)
- func (c *Client) Subscribe(ctx context.Context) error
- func (c *Client) SyncNow(ctx context.Context, ids []string, timeout time.Duration) ([]SyncResult, error)
- type Folder
- type Game
- type GameStatus
- type Install
- type RPCError
- type Status
- type SyncResult
Constants ¶
const MinVersion = "0.11.0"
MinVersion is the first Syncer release with the launcher API.
const Pipe = `\\.\pipe\syncer`
Pipe is where Syncer listens.
const Protocol = 1
Protocol is the API version this client speaks.
Variables ¶
var ErrNotInstalled = errors.New("Syncer isn't installed")
ErrNotInstalled means Syncer isn't installed on this PC.
var ErrOutdated = errors.New("Syncer needs an update (version " + MinVersion + " or newer)")
ErrOutdated means the installed Syncer is too old for the launcher API.
Functions ¶
Types ¶
type BackupResult ¶
type BackupResult struct {
Started bool `json:"started"`
Finished bool `json:"finished"`
OK bool `json:"ok"`
At time.Time `json:"at"`
Copied int `json:"copied"`
Errors []string `json:"errors"`
}
BackupResult is the outcome of BackupNow.
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is one connection to Syncer. Safe for concurrent use.
func Dial ¶
Dial connects to Syncer. With start, it starts "Syncer.exe --api" when Syncer isn't serving the API yet.
func (*Client) BackupNow ¶
func (c *Client) BackupNow(ctx context.Context, wait bool, timeout time.Duration) (BackupResult, error)
BackupNow starts a backup; with wait it returns once it has finished (or timeout has passed).
func (*Client) Done ¶
func (c *Client) Done() <-chan struct{}
Done is closed when the connection ends.
func (*Client) GameStatus ¶
GameStatus returns the save folders Syncer has for a game.
func (*Client) RegisterGames ¶
RegisterGames tells Syncer which games this PC has, so it can match saves to games with unusual folder names (repacks, unofficial copies).
type Folder ¶
type Folder struct {
ID string `json:"id"`
Label string `json:"label"`
Path string `json:"path"`
Sync bool `json:"sync"`
Backup bool `json:"backup"`
State string `json:"state"`
NeedBytes int64 `json:"needBytes"`
Errors int `json:"errors"`
Conflicts int `json:"conflicts"`
Exists bool `json:"exists"`
Modified time.Time `json:"modified"`
BackedUp time.Time `json:"backedUp"`
NewerOn string `json:"newerOn"`
NewerAt time.Time `json:"newerAt"`
}
Folder is one save folder Syncer looks after.
type Game ¶
type Game struct {
Title string `json:"title"`
Dir string `json:"dir,omitempty"`
SteamAppID int `json:"steamAppId,omitempty"`
GogID string `json:"gogId,omitempty"`
}
Game identifies a game to Syncer.
type GameStatus ¶
GameStatus is what Syncer knows about one game's saves.
type Status ¶
type Status struct {
Protocol int `json:"protocol"`
Version string `json:"version"`
Window bool `json:"window"`
Syncthing bool `json:"syncthing"`
Paused bool `json:"paused"`
PausedTill time.Time `json:"pausedUntil"`
BackingUp bool `json:"backingUp"`
LastBackup time.Time `json:"lastBackup"`
Games int `json:"games"`
Conflicts int `json:"conflicts"`
}
Status is Syncer's overall state.