github.com/shogo82148/std@v1.22.1-0.20240327122250-4e474527810c/internal/syscall/windows/registry/value.go (about)

     1  // Copyright 2015 The Go Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  //go:build windows
     6  
     7  package registry
     8  
     9  import (
    10  	"github.com/shogo82148/std/errors"
    11  	"github.com/shogo82148/std/syscall"
    12  )
    13  
    14  const (
    15  	// Registry value types.
    16  	NONE                       = 0
    17  	SZ                         = 1
    18  	EXPAND_SZ                  = 2
    19  	BINARY                     = 3
    20  	DWORD                      = 4
    21  	DWORD_BIG_ENDIAN           = 5
    22  	LINK                       = 6
    23  	MULTI_SZ                   = 7
    24  	RESOURCE_LIST              = 8
    25  	FULL_RESOURCE_DESCRIPTOR   = 9
    26  	RESOURCE_REQUIREMENTS_LIST = 10
    27  	QWORD                      = 11
    28  )
    29  
    30  var (
    31  	// ErrShortBuffer is returned when the buffer was too short for the operation.
    32  	ErrShortBuffer = syscall.ERROR_MORE_DATA
    33  
    34  	// ErrNotExist is returned when a registry key or value does not exist.
    35  	ErrNotExist = syscall.ERROR_FILE_NOT_FOUND
    36  
    37  	// ErrUnexpectedType is returned by Get*Value when the value's type was unexpected.
    38  	ErrUnexpectedType = errors.New("unexpected key value type")
    39  )
    40  
    41  // GetValue retrieves the type and data for the specified value associated
    42  // with an open key k. It fills up buffer buf and returns the retrieved
    43  // byte count n. If buf is too small to fit the stored value it returns
    44  // ErrShortBuffer error along with the required buffer size n.
    45  // If no buffer is provided, it returns true and actual buffer size n.
    46  // If no buffer is provided, GetValue returns the value's type only.
    47  // If the value does not exist, the error returned is ErrNotExist.
    48  //
    49  // GetValue is a low level function. If value's type is known, use the appropriate
    50  // Get*Value function instead.
    51  func (k Key) GetValue(name string, buf []byte) (n int, valtype uint32, err error)
    52  
    53  // GetStringValue retrieves the string value for the specified
    54  // value name associated with an open key k. It also returns the value's type.
    55  // If value does not exist, GetStringValue returns ErrNotExist.
    56  // If value is not SZ or EXPAND_SZ, it will return the correct value
    57  // type and ErrUnexpectedType.
    58  func (k Key) GetStringValue(name string) (val string, valtype uint32, err error)
    59  
    60  // GetMUIStringValue retrieves the localized string value for
    61  // the specified value name associated with an open key k.
    62  // If the value name doesn't exist or the localized string value
    63  // can't be resolved, GetMUIStringValue returns ErrNotExist.
    64  func (k Key) GetMUIStringValue(name string) (string, error)
    65  
    66  // ExpandString expands environment-variable strings and replaces
    67  // them with the values defined for the current user.
    68  // Use ExpandString to expand EXPAND_SZ strings.
    69  func ExpandString(value string) (string, error)
    70  
    71  // GetStringsValue retrieves the []string value for the specified
    72  // value name associated with an open key k. It also returns the value's type.
    73  // If value does not exist, GetStringsValue returns ErrNotExist.
    74  // If value is not MULTI_SZ, it will return the correct value
    75  // type and ErrUnexpectedType.
    76  func (k Key) GetStringsValue(name string) (val []string, valtype uint32, err error)
    77  
    78  // GetIntegerValue retrieves the integer value for the specified
    79  // value name associated with an open key k. It also returns the value's type.
    80  // If value does not exist, GetIntegerValue returns ErrNotExist.
    81  // If value is not DWORD or QWORD, it will return the correct value
    82  // type and ErrUnexpectedType.
    83  func (k Key) GetIntegerValue(name string) (val uint64, valtype uint32, err error)
    84  
    85  // GetBinaryValue retrieves the binary value for the specified
    86  // value name associated with an open key k. It also returns the value's type.
    87  // If value does not exist, GetBinaryValue returns ErrNotExist.
    88  // If value is not BINARY, it will return the correct value
    89  // type and ErrUnexpectedType.
    90  func (k Key) GetBinaryValue(name string) (val []byte, valtype uint32, err error)
    91  
    92  // SetDWordValue sets the data and type of a name value
    93  // under key k to value and DWORD.
    94  func (k Key) SetDWordValue(name string, value uint32) error
    95  
    96  // SetQWordValue sets the data and type of a name value
    97  // under key k to value and QWORD.
    98  func (k Key) SetQWordValue(name string, value uint64) error
    99  
   100  // SetStringValue sets the data and type of a name value
   101  // under key k to value and SZ. The value must not contain a zero byte.
   102  func (k Key) SetStringValue(name, value string) error
   103  
   104  // SetExpandStringValue sets the data and type of a name value
   105  // under key k to value and EXPAND_SZ. The value must not contain a zero byte.
   106  func (k Key) SetExpandStringValue(name, value string) error
   107  
   108  // SetStringsValue sets the data and type of a name value
   109  // under key k to value and MULTI_SZ. The value strings
   110  // must not contain a zero byte.
   111  func (k Key) SetStringsValue(name string, value []string) error
   112  
   113  // SetBinaryValue sets the data and type of a name value
   114  // under key k to value and BINARY.
   115  func (k Key) SetBinaryValue(name string, value []byte) error
   116  
   117  // DeleteValue removes a named value from the key k.
   118  func (k Key) DeleteValue(name string) error
   119  
   120  // ReadValueNames returns the value names of key k.
   121  func (k Key) ReadValueNames() ([]string, error)