wine

package module
v0.0.0-...-167ad5e Latest Latest
Warning

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

Go to latest
Published: Dec 29, 2025 License: GPL-3.0 Imports: 21 Imported by: 1

README

wine

Godoc Reference

A Go package for managing a Wineprefix and running Wine. Includes goodies for serializing the registry.

Documentation

Overview

The wine package helps manage a Wineprefix and run Wine.

Index

Constants

View Source
const (
	ServerDebug      = "--debug"
	ServerForeground = "--foreground"
	ServerKill       = "--kill"
	ServerPersistent = "--persistent"
	ServerWait       = "--wait"
)
View Source
const (
	BootEndSession = "--end-session"
	BootForceExit  = "--force"
	BootInit       = "--init"
	BootKill       = "--kill"
	BootRestart    = "--restart"
	BootShutdown   = "--shutdown"
	BootUpdate     = "--update"
)

Variables

View Source
var ErrPrefixNotAbs = errors.New("prefix directory is not an absolute path")

Functions

func Escape

func Escape(src string, quote bool, raw bool) string

Quote determines if quotes are escaped. Raw determines if surrogates are to be encoded raw and escape sequences encoded as is.

func Unescape

func Unescape(src string) string

Types

type BinaryString

type BinaryString []byte // hex(1): REG_SZ

hex(8,a,0) are removed, as they are exclusive to Windows and unused by Wine.

hex(3) removed as it is unnecessary and does not appear in any real world registry data.

Wine internally stores REG_EXPAND_SZ and REG_MULTI_SZ as str(2) and str(7) and exports them as their hex(2) and hex(7) pairs respectively.

type Cmd

type Cmd struct {
	*exec.Cmd
	// contains filtered or unexported fields
}

Cmd is is a struct wrapper that overrides methods to better interact with a Wineprefix.

It is not reccomended to call any of the exec.Cmd's methods related to reading output such as StderrPipe, StdoutPipe, Output, among others. This is unfortunately due to a Wine bug that doesn't allow for easy interaction of Wine's output. If a method is unimplemented, it should use Cmd's method overrides.

For further information, refer to exec.Cmd.

func (*Cmd) CombinedOutput

func (c *Cmd) CombinedOutput() ([]byte, error)

Output runs the command and returns its standard output & error.

func (*Cmd) Output

func (c *Cmd) Output() ([]byte, error)

Output runs the command and returns its standard output. No error handling is performed on stderr.

func (*Cmd) Quiet

func (c *Cmd) Quiet() *Cmd

Quiet sets the command output to nil, used in contexts where errors are not to be expected.

func (*Cmd) Run

func (c *Cmd) Run() error

Refer to exec.Cmd.Run.

func (*Cmd) Start

func (c *Cmd) Start() error

Refer to exec.Cmd.Start.

func (*Cmd) Wait

func (c *Cmd) Wait() error

Refer to exec.Cmd.Wait.

type DwordBE

type DwordBE uint32 // hex(5): REG_DWORD_BIG_ENDIAN

type DwordLE

type DwordLE uint32 // hex(4): REG_DWORD_LITTLE_ENDIAN

type ExpandableString

type ExpandableString string // hex(2): REG_EXPAND_SZ

type Filetime

type Filetime int64

Filetime is a representation of Wine's FILETIME.

Routines are added and taken from golang.org/x/sys/windows package.

func FromBytes

func FromBytes(b []byte) Filetime

FromBytes converts a little endian []byte to Filetime.

func FromTime

func FromTime(t time.Time) Filetime

FromTime converts time.Time to Filetime.

func (Filetime) Bytes

func (ft Filetime) Bytes() []byte

Bytes converts Filetime to a []byte in little endian form.

func (Filetime) IsZero

func (ft Filetime) IsZero() bool

IsZero checks if Filetime represents 00:00:00 UTC, January 1, 1601.

func (Filetime) Time

func (ft Filetime) Time() time.Time

Time converts Filetime to time.Time.

func (Filetime) Unix

func (ft Filetime) Unix() int64

Unix returns Filetime in Unix form, truncating nanoseconds.

type InternalBytes

type InternalBytes struct {
	Identifier uint32
	Data       []byte
}

InternalBytes represents a custom registry value type hex(i) where i is the Identifier. This is found in DEVPROP_TYPE_DEVPROPTYPE.

type Link string // hex(6): REG_LINK

type Prefix

type Prefix struct {
	// Path to a Wine or Proton installation.
	Root string

	// Stdout and Stderr specify the descendant Prefix's Command
	// Stdout and Stderr. This is mostly reserved for logging purposes.
	// By default, they will be set to their os counterparts.
	Stderr io.Writer
	Stdout io.Writer

	// Specifies additional environment variables for all
	// descendant Prefix commands. os.Environ()
	// will be appended when Env is used.
	Env []string
	// contains filtered or unexported fields
}

Prefix is a representation of a Wineprefix, which is where Wine stores its data and is equivalent to a C:\ drive.

func New

func New(dir string, root string) *Prefix

New returns a new Wineprefix.

The given directory, an optional path to the Wineprefix, must be owned by the current user, and must be an absolute path, otherwise running Wine will fail.

func (*Prefix) AppDataDir

func (p *Prefix) AppDataDir() (string, error)

AppDataDir returns the current user's AppData within the Prefix.

func (*Prefix) Boot

func (p *Prefix) Boot(args ...string) *Cmd

Boot returns a Cmd for wineboot.

func (*Prefix) Command

func (p *Prefix) Command(name string, arg ...string) *Cmd

Command returns the Cmd struct to execute the named program with the given arguments within the Wineprefix. It is reccomended to use Prefix.Wine to run wine as opposed to Command.

For further information, refer to exec.Command.

func (*Prefix) Dir

func (p *Prefix) Dir() string

Dir returns the directory of the Wineprefix.

func (*Prefix) Exists

func (p *Prefix) Exists() bool

IsSetup determines if the prefix exists and has been setup.

func (*Prefix) Init

func (p *Prefix) Init() error

Init returns a Cmd for initializating the Wineprefix.

This procedure is done automatically as necessary by invoking any Wine application or using Prefix.Start.

func (*Prefix) IsProton

func (p *Prefix) IsProton() bool

IsProton determines if the current Prefix Root is Proton.

func (*Prefix) Kill

func (p *Prefix) Kill() error

Kill kills the Wineprefix.

func (*Prefix) LibDir

func (p *Prefix) LibDir() string

func (*Prefix) NeedsUpdate

func (p *Prefix) NeedsUpdate() (bool, error)

NeedsUpdate reports whether the Wineprefix requires a full re-initialization, determined by the Wine installation.

Errors that can occur include failure to lookup installation and existence of the wineprefix directory.

func (*Prefix) Prepare

func (p *Prefix) Prepare() error

Prepare ensures the Wineprefix is up to date with the given wine root / installation and prepares it for running wine applications.

Wine applications automatically update the Prefix, but show a dialog window. Prepare hides it for the user and prints a log entry instead.

func (*Prefix) Registry

func (p *Prefix) Registry() (*Registry, error)

Registry parses and returns the registry for the given Wineprefix.

See the commment on Registry for more information.

func (*Prefix) RegistryAdd

func (p *Prefix) RegistryAdd(key string, value string, data RegistryData) error

RegistryAdd adds a new registry key to the Wineprefix with the named key, value, type, and data. The value parameter can be empty, to modify the (Default) value.

See RegistryData for more details about the type of data.

func (*Prefix) RegistryDelete

func (p *Prefix) RegistryDelete(key, value string) error

RegistryDelete deletes a registry key of the named key and value to be removed from the Wineprefix. The value parameter can be empty, if wanting to retrieving delete the entire key.

func (*Prefix) RegistryImportFile

func (p *Prefix) RegistryImportFile(name string) error

RegistryImport imports keys, values and data from a given registry file data into the Wineprefix's registry.

func (*Prefix) RegistryImportKey

func (p *Prefix) RegistryImportKey(key *RegistryKey) error

RegistryKeyImport imports the given key to the Wineprefix. If the root key is not a toplevel registry key, an error will be shown to the user as a GUI.

func (*Prefix) RegistryQuery

func (p *Prefix) RegistryQuery(path string) (*RegistryKey, error)

RegistryQuery finds the registry key located at path. If the named registry key is not found, nil will be returned.

func (*Prefix) Running

func (p *Prefix) Running() bool

Running reports whether the Wineserver is already running for this Wineprefix on the host system.

func (*Prefix) Server

func (p *Prefix) Server(args ...string) error

Server runs wineserver with the given arguments.

func (*Prefix) Start

func (p *Prefix) Start() error

Start ensures the Wineprefix's server is running and is prepared to run any Wine application. The persistence is automatically set to 32. If the Wineserver is already running, this will return nil.

Wine applications will do this by default, but will have a few seconds to run as to prepare the environment, which Start could fulfill prior to running applications.

func (Prefix) String

func (p Prefix) String() string

String implements the Stringer interface, returning the directory of the Wineprefix.

func (*Prefix) Update

func (p *Prefix) Update() error

Update fully re-initalizes the Wineprefix data using Wineboot.

This procedure is done automatically as necessary by invoking any Wine application or using Prefix.Start.

func (*Prefix) Version

func (p *Prefix) Version() string

Version returns the Wineprefix's Wine version.

func (*Prefix) Wine

func (p *Prefix) Wine(exe string, arg ...string) *Cmd

Wine returns a Cmd for usage of calling WINE.

type Registry

type Registry struct {
	CurrentUser *RegistryKey
	Machine     *RegistryKey
	// contains filtered or unexported fields
}

Registry represents the Wineprefix's root registry keys at the state it was retrieved. It is not equal to the Wineprefix's actual registry files unless it was exported.

To export a registry to a Wineprefix, the Registry must have come from [Registry()], which requires an initialized wineprefix, and the Wineserver must be killed as to not conflict with Wineserver's internal registry.

To write a RegistryKey to a Wineprefix, you can use either Prefix.RegistryAdd or Prefix.RegistryImportKey.

Only HKEY_CURRENT_USER and HKEY_LOCAL_MACHINE are supported and queryable.

func (*Registry) Query

func (r *Registry) Query(path string) *RegistryKey

Query finds the given registry key path in r. nil will be returned if no such key was found. The path must be prefixed with only HKLM or HKCU (and their full counterparts), as they are the only root keys available in Registry.

func (*Registry) Save

func (r *Registry) Save() error

Save exports and writes r to the Wineprefix's registry files. It is assumed that the Registry is serialized from the same registry files and must exist.

See the commment on Registry for what is exported.

type RegistryData

type RegistryData any

RegistryData represents a RegistryValue's data.

Setting the data to nil will effectively delete the data during exporting, but will not delete the registry key.

Known registry types and their Go types:

  • REG_SZ = string
  • REG_MULTI_SZ aka hex(7) = []string
  • REG_DWORD = uint32
  • REG_QWORD aka hex(b) = uint64
  • REG_BINARY aka hex = []byte
  • REG_NONE = []byte length 0
  • REG_LINK = Link
  • REG_EXPAND_SZ aka hex(2)= ExpandableString
  • REG_DWORD_LITTLE_ENDIAN aka hex(4) = DwordLE
  • REG_DWORD_BIG_ENDIAN aka hex(5) = DwordBE
  • DEVPROP_TYPE_DEVPROPTYPE aka hex(ffff????) = [InternalByte]

type RegistryKey

type RegistryKey struct {
	Name    string
	Values  []RegistryValue
	Subkeys []*RegistryKey
	// contains filtered or unexported fields
}

RegistryKey represents a relative, offline Wine registry key with its known values and subkeys.

It is not reccomended to iterate over the Subkeys field to modify it, use RegistryKey.Add and RegistryKey.Delete.

Symlinked registry keys are unsupported. They always contain a subkey with the name SymbolicLinkValue and an absolute registry path such as '\Registry\Machine\Software\Classes\AppsId' encoded in UTF16LE.

func NewRegistryKey

func NewRegistryKey(path string) *RegistryKey

NewRegistryKey creates a registry key and its parents based on the absolute registry path. The path must contain a backslash, even if it is the root key.

func ParseRegistryFile

func ParseRegistryFile(name string) (*RegistryKey, error)

ParseRegistryFile is a helper for ParseRegistry to parse from a registry file.

func (*RegistryKey) Add

func (k *RegistryKey) Add(path string) *RegistryKey

Add will find the registry key located at path, relative to k, and creates any parent key if necesary.

func (*RegistryKey) AddKey

func (k *RegistryKey) AddKey(a *RegistryKey) *RegistryKey

AddKey will resolve the key a to k, adding its full path and parent path, including all of the subkeys.

func (*RegistryKey) Delete

func (k *RegistryKey) Delete(path string) bool

Delete removes the named registry key path relative to k. If deletion was successful and the key was found in k, true will be returned, otherwise false will be returned.

func (*RegistryKey) DeleteValue

func (k *RegistryKey) DeleteValue(name string) bool

DeleteValue deletes the named value from k and reports whether the value was found and successfully deleted.

func (*RegistryKey) Equal

func (k *RegistryKey) Equal(b *RegistryKey) bool

This is preferred over reflect.DeepEqual as there are private pointer properties.

func (*RegistryKey) Export

func (k *RegistryKey) Export(w io.Writer) error

Export writes the regedit export of k to w. Any error regarding formatting a type will not be returned if k's origin was serialized from ParseRegistry.

If there are any registry keys with no values and subkeys, it will be marked as deleted.

Registry keys that are links to other keys will not be exported here.

func (*RegistryKey) GetValue

func (k *RegistryKey) GetValue(name string) *RegistryValue

GetValue finds the a registry value with the given name in k. If it is not found, nil will be returned.

func (*RegistryKey) Import

func (k *RegistryKey) Import(r io.Reader) error

Import parses the registry file from r and serializes it into a k. If parsing from Wine's internal .reg files, the root registry will be named, but if parsing from a exported .reg file, the root registry key will have no name.

func (*RegistryKey) Parent

func (k *RegistryKey) Parent() *RegistryKey

Parent returns k's parent registry key. The parent can be null if k is a root registry key such as HKEY_CURRENT_USER.

func (*RegistryKey) Path

func (k *RegistryKey) Path() string

Path returns the path to itself up to the root registry key.

func (*RegistryKey) Query

func (k *RegistryKey) Query(path string) *RegistryKey

Query finds the given registry key path relative to k. nil will be returned if no key was found.

func (*RegistryKey) Root

func (k *RegistryKey) Root() (parent *RegistryKey)

Parent returns k's root registry key (greatest parent).

func (*RegistryKey) SetValue

func (k *RegistryKey) SetValue(name string, data RegistryData) (ret *RegistryValue)

SetValue sets a named value in k with the specified data. The name may be an empty string to specify the (Default) key. See RegistryData for more information.

If the named value already exists in k, only the data will be set, otherwise a new value will be added to k with the given name and data.

type RegistryValue

type RegistryValue struct {
	Name string
	Data RegistryData
}

RegistryValue represents a known registry key's value pairs.

The (Default) key will have the name as empty.

Directories

Path Synopsis
cmd
dxvk command
Package dxvk manages DXVK for a Wineprefix.
Package dxvk manages DXVK for a Wineprefix.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
Package webview abstracts Edge WebView 2 updates for a Wineprefix.
Package webview abstracts Edge WebView 2 updates for a Wineprefix.

Jump to

Keyboard shortcuts

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