platform

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: 13 Imported by: 0

Documentation

Overview

Package platform wraps the Windows specifics the rest of Seaglass needs: known folders, the app's own data folders, drives and path checks.

Index

Constants

View Source
const OldName = "WaterLauncher"

OldName is what Seaglass was called before 1.5.

Variables

View Source
var (
	Roaming         = known(windows.FOLDERID_RoamingAppData)
	Local           = known(windows.FOLDERID_LocalAppData)
	ProgramData     = known(windows.FOLDERID_ProgramData)
	Public          = known(windows.FOLDERID_Public)
	Profile         = known(windows.FOLDERID_Profile)
	Documents       = known(windows.FOLDERID_Documents)
	Desktop         = known(windows.FOLDERID_Desktop)
	PublicDesktop   = known(windows.FOLDERID_PublicDesktop)
	StartMenu       = known(windows.FOLDERID_StartMenu)
	CommonStartMenu = known(windows.FOLDERID_CommonStartMenu)
	ProgramFiles    = known(windows.FOLDERID_ProgramFiles)
	ProgramFilesX86 = known(windows.FOLDERID_ProgramFilesX86)
	WindowsDir      = known(windows.FOLDERID_Windows)
)

Known folders, resolved once at start. "" when Windows doesn't know one.

View Source
var ErrNotSigned = errors.New("no valid signature")

ErrNotSigned means a file has no valid Authenticode signature.

Functions

func AppDir

func AppDir() string

AppDir is Seaglass's settings folder (%APPDATA%\Seaglass), created on demand.

func AppDirOverridden added in v1.6.1

func AppDirOverridden() bool

AppDirOverridden reports whether UseAppDir moved the data elsewhere (a test harness's own data): caches tied to that library belong with it.

func BringToFront added in v1.7.0

func BringToFront(hwnd uintptr) bool

BringToFront makes hwnd the window in front. Windows only lets the process the user last gave input to do that, and after a game closes that's the game, not Seaglass (a controller doesn't count): a plain SetForegroundWindow then only flashes the taskbar button, and the taskbar stays on top of a full-screen window that isn't in front. So it first sends an empty input (nothing moves or is typed), which makes Seaglass the process with the last input, and failing that joins the input of the window in front for a moment.

func CacheDir

func CacheDir(sub ...string) string

CacheDir is a folder under %LOCALAPPDATA%\Seaglass, created on demand.

func Crashed

func Crashed(code uint32) bool

Crashed reports whether an exit code is one Windows gives a process that crashed (an NTSTATUS error: an access violation, a stack overrun, heap corruption, an unhandled exception, …) rather than one that quit.

func EndProcess

func EndProcess(pid uint32, started uint64) error

EndProcess stops a process right away (like Task Manager's End task). started must match, so a process id Windows handed out again is left alone.

func FixedDrives

func FixedDrives() []string

FixedDrives returns the roots of local fixed drives ("C:\", "D:\", …).

func ForegroundPID

func ForegroundPID() uint32

ForegroundPID is the process whose window is in front, 0 when none is.

func InstanceRunning

func InstanceRunning(uniqueID string) bool

InstanceRunning reports whether a Seaglass with this id already runs in this Windows session.

func IsDir

func IsDir(p string) bool

IsDir reports whether p is an existing folder.

func IsFile

func IsFile(p string) bool

IsFile reports whether p is an existing regular file.

func IsForeground added in v1.7.0

func IsForeground(hwnd uintptr) bool

IsForeground reports whether hwnd is the window in front.

func Key

func Key(dir string) string

Key is a folder's identity: cleaned and lower-cased.

func LoadSecret

func LoadSecret(name string) string

LoadSecret reads a secret stored with SaveSecret; "" when there is none.

func MarkFullscreen added in v1.7.0

func MarkFullscreen(hwnd uintptr, on bool) error

MarkFullscreen tells the taskbar hwnd is a full-screen window, so it steps behind it whenever it's in front, rather than going by the window's size alone (which it checks only now and then).

func MoveOldData

func MoveOldData(oldRunning bool) []string

MoveOldData moves WaterLauncher's data (%APPDATA%\WaterLauncher and %LOCALAPPDATA%\WaterLauncher) into Seaglass's folders: whatever Seaglass doesn't have yet, so its own data wins, and nothing is deleted. While WaterLauncher itself still runs (oldRunning), its folders are used where they are and moved another time. Call it before anything is opened; what it did is returned for the log.

func MoveOldStartup

func MoveOldStartup(exe string) bool

MoveOldStartup turns WaterLauncher's "start with Windows" entry into Seaglass's, keeping whether it's turned off in Task Manager. It reports whether there was one.

func OpenFile

func OpenFile(p string) error

OpenFile opens a text file Seaglass wrote in the user's editor.

func OpenURI

func OpenURI(uri string) error

OpenURI hands a URI (steam://…, com.epicgames.launcher://…, shell:…) to Windows, the way Explorer would open it.

func OpenWebPage

func OpenWebPage(url string) error

OpenWebPage opens an https page in the default browser. Only pages Seaglass itself links to are passed here.

func ProcessImage

func ProcessImage(pid uint32) (path string, started uint64, err error)

ProcessImage returns the full path of a process's exe and when it started (a FILETIME, to tell a reused process id apart). It works for elevated processes of the same user too.

func ProcessRunning

func ProcessRunning(name string) bool

ProcessRunning reports whether a process with this exe name runs.

func Protect

func Protect(data []byte) ([]byte, error)

Protect encrypts data with Windows DPAPI for this Windows user.

func RealCase

func RealCase(p string) string

RealCase returns p with the capitalisation the file system uses (Steam keeps its path lower-cased in the registry). p is returned unchanged when it can't be opened or resolves somewhere else (a junction).

func RepairStartup

func RepairStartup(exe string) bool

RepairStartup points an existing Run entry at exe when the program it names is gone (Seaglass was moved). It reports whether it changed.

func SaveSecret

func SaveSecret(name, value string) error

SaveSecret stores a secret (an API key) encrypted with Windows DPAPI, so only this Windows user on this PC can read it back. An empty value deletes it.

func SetStartup

func SetStartup(exe string, on bool) error

SetStartup registers (or removes) the exe to start at sign-in, in the tray.

func ShowInExplorer

func ShowInExplorer(dir string) error

ShowInExplorer opens Explorer at dir.

func Signer

func Signer(path string) (string, error)

Signer returns the name of the publisher whose valid Authenticode signature a file carries (the signing certificate's display name). It checks the signature first; revocation is only checked from cache.

func StartProcess

func StartProcess(exe, args, workDir string) (int, error)

StartProcess starts exe with a raw argument string in workDir, detached from Seaglass. It never goes through a shell. When the game asks for administrator rights, Windows shows its UAC prompt.

func StartupCommand

func StartupCommand(exe string) string

StartupCommand is the command Windows runs at sign-in: the exe, in the tray.

func SystemPath

func SystemPath(p string) bool

SystemPath reports whether p lies in a folder no game installs into (Windows itself, Common Files, WindowsApps).

func Unprotect

func Unprotect(enc []byte) ([]byte, error)

Unprotect decrypts what Protect encrypted.

func UseAppDir

func UseAppDir(dir string)

UseAppDir puts the library, settings and log in dir instead (a test harness's own data). Call it before anything is opened.

func WaitInstanceGone

func WaitInstanceGone(uniqueID string, d time.Duration) bool

WaitInstanceGone waits until the running instance has exited, at most d.

func WatchForeground

func WatchForeground(fn func(pid uint32)) (stop func(), err error)

WatchForeground calls fn with the process id of each window that comes to the front, other than Seaglass's own. Windows tells it (a WinEvent hook, out of context): nothing is polled and nothing is injected into other processes. fn runs on the watcher's thread and must return quickly. stop ends the watch.

func Within

func Within(parent, child string) bool

Within reports whether child is parent or lies below it (case-insensitive).

Types

type ExitWatch

type ExitWatch struct {
	// contains filtered or unexported fields
}

ExitWatch holds a process open so its exit code can be read after it ends (Windows keeps it for as long as a handle is open).

func WatchExit

func WatchExit(pid uint32, started uint64) (*ExitWatch, error)

WatchExit opens a process for its exit code. started must match, so a process id Windows handed out again isn't watched instead.

func (*ExitWatch) Close

func (w *ExitWatch) Close()

Close lets go of the process.

func (*ExitWatch) Code

func (w *ExitWatch) Code() (uint32, bool)

Code returns the exit code once the process has ended.

type Proc

type Proc struct {
	PID, PPID uint32
	Name      string // exe file name, as Windows lists it
}

Proc is one running process.

func Processes

func Processes() ([]Proc, error)

Processes lists the running processes.

type Startup

type Startup struct {
	On bool `json:"on"`
	// Off in Task Manager's Startup apps: Windows skips it even though
	// it's registered.
	DisabledByUser bool `json:"disabledByUser"`
}

Startup is whether Seaglass starts when you sign in to Windows.

func GetStartup

func GetStartup() Startup

GetStartup reads the current user's Run entry for Seaglass.

Jump to

Keyboard shortcuts

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