wine

package module
v0.0.0-...-874f01f Latest Latest
Warning

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

Go to latest
Published: Apr 2, 2024 License: GPL-3.0 Imports: 9 Imported by: 0

README

wine

Godoc Reference

A Go package for managing a Wineprefix and running Wine.

Example application client
package main

import (
	"os"
	"log"
	"io"
	"flag"
	"path/filepath"

	"github.com/apprehensions/wine"
)

func main() {
	root := flag.String("root", "", "Path to a wine install")
	dir := flag.String("dir",
		filepath.Join(os.Getenv("HOME"), ".wine"), "Path to a wineprefix")
	flag.Parse()

	logFile, err := os.CreateTemp(os.TempDir(), "wine-stderr.*.log")
	if err != nil {
		log.Fatal(err)
	}
	defer logFile.Close()
	log.Println("Log file at:", logFile.Name())

	pfx := wine.New(*dir, *root)
	pfx.Stderr = io.MultiWriter(os.Stderr, logFile)
	if err := pfx.Init(); err != nil {
		log.Fatal(err)
	}

	if err := pfx.SetDPI(96); err != nil {
		log.Fatal(err)
	}

	appData, err := pfx.AppDataDir()
	if err != nil {
		log.Fatal(err)
	}
	log.Println("User's AppData directory:", appData)

	err = pfx.RegistryAdd(`HKEY_CURRENT_USER\Software\Wine\Explorer\Desktops`,
		"Default", wine.REG_SZ, "1920x1080")
    if err != nil {
		log.Fatal(err)
	}

	err = pfx.RegistryDelete(`HKEY_CURRENT_USER\Software\Wine\Explorer\Desktops`,
		"Default")
	if err != nil {
		log.Fatal(err)
	}

	wineVer := pfx.Version()
	log.Println("Wine version:", wineVer)

	_ = pfx.Kill()
}

Documentation

Overview

The wine package helps manage a Wineprefix and run Wine.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrWineNotFound = errors.New("wine64 not found in $PATH or wineroot")
	ErrPrefixNotAbs = errors.New("prefix directory is not an absolute path")
)

Functions

This section is empty.

Types

type Cmd

type Cmd struct {
	*exec.Cmd
}

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

For further information, refer to exec.Cmd.

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.

type Prefix

type Prefix struct {
	// Path to a wine 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
	// 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 Prefix.

The given directory 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) 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 Prefix. It is reccomended to use [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 Prefix.

func (*Prefix) Init

func (p *Prefix) Init() error

Init preforms initialization for first Wine instance.

func (*Prefix) Kill

func (p *Prefix) Kill() error

Kill kills the Prefix's processes.

func (*Prefix) RegistryAdd

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

RegistryAdd adds a new registry key to the Wineprefix with the named key, value, type, and 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.

func (*Prefix) SetDPI

func (p *Prefix) SetDPI(dpi int) error

SetDPI sets the Prefix's DPI to the named DPI.

func (Prefix) String

func (p Prefix) String() string

String implements the Stringer interface.

func (*Prefix) Update

func (p *Prefix) Update() error

Update updates the wineprefix directory.

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 new Cmd with the prefix's Wine as the named program.

The Wine executable used is a path to the system or Prefix's Root's 'wine64' if present. an attempt to resolve for a ULWGL launcher will be made if it is present and necessary environment variables will be set to the command.

func (*Prefix) Winetricks

func (p *Prefix) Winetricks() error

Winetricks runs winetricks within the Prefix.

type RegistryType

type RegistryType string

RegistryType is the type of registry that the wine 'reg' program can accept.

const (
	REG_SZ        RegistryType = "REG_SZ"
	REG_MULTI_SZ  RegistryType = "REG_MULTI_SZ"
	REG_EXPAND_SZ RegistryType = "REG_EXPAND_SZ"
	REG_DWORD     RegistryType = "REG_DWORD"
	REG_QWORD     RegistryType = "REG_QWORD"
	REG_BINARY    RegistryType = "REG_BINARY"
	REG_NONE      RegistryType = "REG_NONE"
)

Jump to

Keyboard shortcuts

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