syncer

package
v1.10.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 3, 2026 License: AGPL-3.0 Imports: 17 Imported by: 0

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

View Source
const MinVersion = "0.11.0"

MinVersion is the first Syncer release with the launcher API.

View Source
const Pipe = `\\.\pipe\syncer`

Pipe is where Syncer listens.

View Source
const Protocol = 1

Protocol is the API version this client speaks.

Variables

View Source
var ErrNotInstalled = errors.New("Syncer isn't installed")

ErrNotInstalled means Syncer isn't installed on this PC.

View Source
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 Installed

func Installed() (string, bool)

Installed returns Syncer.exe's path when Syncer is installed.

func UnknownMethod added in v1.8.0

func UnknownMethod(err error) bool

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

func Dial(ctx context.Context, start bool) (*Client, error)

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

func (c *Client) Accounts(ctx context.Context) (Accounts, error)

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) Call

func (c *Client) Call(ctx context.Context, method string, params, out any) error

Call calls a method and decodes its result into out (which may be nil).

func (*Client) Close

func (c *Client) Close() error

Close ends the connection.

func (*Client) Done

func (c *Client) Done() <-chan struct{}

Done is closed when the connection ends.

func (*Client) GameStatus

func (c *Client) GameStatus(ctx context.Context, g Game) (GameStatus, error)

GameStatus returns the save folders Syncer has for a game.

func (*Client) Games

func (c *Client) Games(ctx context.Context) ([]Folder, error)

Games lists every save folder Syncer looks after.

func (*Client) OnNotify

func (c *Client) OnNotify(fn func(method string))

OnNotify sets a function for notifications Syncer sends ("changed").

func (*Client) Open

func (c *Client) Open(ctx context.Context) error

Open shows Syncer's window.

func (*Client) RegisterGames

func (c *Client) RegisterGames(ctx context.Context, games []Game) error

RegisterGames tells Syncer which games this PC has, so it can match saves to games with unusual folder names (repacks, external copies).

func (*Client) Status

func (c *Client) Status(ctx context.Context) (Status, error)

Status returns Syncer's state.

func (*Client) Subscribe

func (c *Client) Subscribe(ctx context.Context) error

Subscribe asks for "changed" notifications (see OnNotify).

func (*Client) SwitchAccount added in v1.8.0

func (c *Client) SwitchAccount(ctx context.Context, id string) error

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

func (c *Client) SyncLauncherData(ctx context.Context, launcher, path string) (LauncherData, error)

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.

func (*Client) SyncNow

func (c *Client) SyncNow(ctx context.Context, ids []string, timeout time.Duration) ([]SyncResult, error)

SyncNow has Syncer bring the folders up to date with the other PCs, waiting at most timeout.

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

type GameStatus struct {
	Known   bool     `json:"known"`
	Folders []Folder `json:"folders"`
}

GameStatus is what Syncer knows about one game's saves.

type Install

type Install struct {
	Exe     string
	Version string // "" when unknown
}

Install is where Syncer is installed.

func Find

func Find() (Install, bool)

Find returns the installed Syncer.

func (Install) API

func (i Install) API() bool

API reports whether this Syncer can serve the launcher API.

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 RPCError

type RPCError struct {
	Code    int    `json:"code"`
	Message string `json:"message"`
}

RPCError is an error Syncer answered with.

func (*RPCError) Error

func (e *RPCError) Error() string

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.

type SyncResult

type SyncResult struct {
	ID        string `json:"id"`
	Done      bool   `json:"done"`
	State     string `json:"state"`
	NeedBytes int64  `json:"needBytes"`
}

SyncResult is the outcome of SyncNow for one folder.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL