syncer

package
v1.6.0 Latest Latest
Warning

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

Go to latest
Published: Sep 27, 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.

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

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) 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, unofficial 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) 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"`
}

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