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)
- func UnknownMethod(err error) bool
- type Account
- type Accounts
- type BackupResult
- type Client
- func (c *Client) Accounts(ctx context.Context) (Accounts, error)
- 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) SwitchAccount(ctx context.Context, id string) error
- func (c *Client) SyncLauncherData(ctx context.Context, launcher, path string) (LauncherData, error)
- func (c *Client) SyncNow(ctx context.Context, ids []string, timeout time.Duration) ([]SyncResult, error)
- type Folder
- type Game
- type GameStatus
- type Install
- type LauncherData
- 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 ¶
func UnknownMethod ¶ added in v1.8.0
UnknownMethod reports whether Syncer answered that it doesn't have the method: it's older than the feature.
Types ¶
type Account ¶ added in v1.8.0
type Account struct {
ID string `json:"id"`
Name string `json:"name"`
Color string `json:"color,omitempty"`
Active bool `json:"active"`
}
Account is one person with their own saves in Syncer.
type Accounts ¶ added in v1.8.0
type Accounts struct {
Enabled bool `json:"enabled"`
Active string `json:"active,omitempty"` // the account playing on this PC
Accounts []Account `json:"accounts"`
Split []struct {
Game string `json:"game"`
Label string `json:"label"`
Accounts []string `json:"accounts"`
} `json:"split"`
}
Accounts are Syncer's accounts: with them on, each person keeps their own saves of the games they split.
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) Accounts ¶ added in v1.8.0
Accounts returns Syncer's accounts. Syncer before accounts answers with an error UnknownMethod recognises.
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, external copies).
func (*Client) SwitchAccount ¶ added in v1.8.0
SwitchAccount puts an account's saves in place on this PC. It fails while a game runs, or when that account's saves haven't arrived yet.
func (*Client) SyncLauncherData ¶ added in v1.8.0
SyncLauncherData asks Syncer to sync and back up a launcher's own data folder (it must be in the user's AppData). Asking again is harmless.
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"`
// Account: the game has separate saves per account, and this folder
// holds the saves of the account playing on this PC.
Account string `json:"account,omitempty"`
}
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 LauncherData ¶ added in v1.8.0
type LauncherData struct {
ID string `json:"id"`
Label string `json:"label"`
Sync bool `json:"sync"`
Backup bool `json:"backup"`
Added bool `json:"added"` // added by this call
// Dismissed: someone stopped syncing it in Syncer, and it stays that way.
Dismissed bool `json:"dismissed"`
}
LauncherData is a launcher's own data folder that Syncer syncs and backs up like a 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.