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
- Variables
- func AppDir() string
- func AppDirOverridden() bool
- func BringToFront(hwnd uintptr) bool
- func CacheDir(sub ...string) string
- func Crashed(code uint32) bool
- func EndProcess(pid uint32, started uint64) error
- func FixedDrives() []string
- func ForegroundPID() uint32
- func InstanceRunning(uniqueID string) bool
- func IsDir(p string) bool
- func IsFile(p string) bool
- func IsForeground(hwnd uintptr) bool
- func Key(dir string) string
- func LoadSecret(name string) string
- func MarkFullscreen(hwnd uintptr, on bool) error
- func MoveOldData(oldRunning bool) []string
- func MoveOldStartup(exe string) bool
- func OpenFile(p string) error
- func OpenURI(uri string) error
- func OpenWebPage(url string) error
- func ProcessImage(pid uint32) (path string, started uint64, err error)
- func ProcessRunning(name string) bool
- func Protect(data []byte) ([]byte, error)
- func RealCase(p string) string
- func RepairStartup(exe string) bool
- func SaveSecret(name, value string) error
- func SetStartup(exe string, on bool) error
- func ShowInExplorer(dir string) error
- func Signer(path string) (string, error)
- func StartProcess(exe, args, workDir string) (int, error)
- func StartupCommand(exe string) string
- func SystemPath(p string) bool
- func Unprotect(enc []byte) ([]byte, error)
- func UseAppDir(dir string)
- func WaitInstanceGone(uniqueID string, d time.Duration) bool
- func WatchForeground(fn func(pid uint32)) (stop func(), err error)
- func Within(parent, child string) bool
- type ExitWatch
- type Proc
- type Startup
Constants ¶
const OldName = "WaterLauncher"
OldName is what Seaglass was called before 1.5.
Variables ¶
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.
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
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 Crashed ¶
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 ¶
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 ¶
InstanceRunning reports whether a Seaglass with this id already runs in this Windows session.
func IsForeground ¶ added in v1.7.0
IsForeground reports whether hwnd is the window in front.
func LoadSecret ¶
LoadSecret reads a secret stored with SaveSecret; "" when there is none.
func MarkFullscreen ¶ added in v1.7.0
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 ¶
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 ¶
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 OpenURI ¶
OpenURI hands a URI (steam://…, com.epicgames.launcher://…, shell:…) to Windows, the way Explorer would open it.
func OpenWebPage ¶
OpenWebPage opens an https page in the default browser. Only pages Seaglass itself links to are passed here.
func ProcessImage ¶
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 ¶
ProcessRunning reports whether a process with this exe name runs.
func RealCase ¶
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 ¶
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 ¶
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 ¶
SetStartup registers (or removes) the exe to start at sign-in, in the tray.
func Signer ¶
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 ¶
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 ¶
StartupCommand is the command Windows runs at sign-in: the exe, in the tray.
func SystemPath ¶
SystemPath reports whether p lies in a folder no game installs into (Windows itself, Common Files, WindowsApps).
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 ¶
WaitInstanceGone waits until the running instance has exited, at most d.
func WatchForeground ¶
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.
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).
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.