54 lines
1.8 KiB
Go
54 lines
1.8 KiB
Go
package installguide
|
|
|
|
import (
|
|
"fmt"
|
|
"syscall"
|
|
"unicode/utf16"
|
|
"unsafe"
|
|
|
|
"github.com/Nwflower/reims-go/internal/i18n"
|
|
)
|
|
|
|
// OPENFILENAMEW for the native chooser owned by the guest overlay.
|
|
type openFileName struct {
|
|
size uint32
|
|
owner, instance uintptr
|
|
filter, customFilter *uint16
|
|
maxCustomFilter, filterIndex uint32
|
|
file *uint16
|
|
maxFile uint32
|
|
fileTitle *uint16
|
|
maxFileTitle uint32
|
|
initialDir, title *uint16
|
|
flags uint32
|
|
fileOffset, fileExtension uint16
|
|
defaultExt *uint16
|
|
customData, hook uintptr
|
|
templateName *uint16
|
|
reserved uintptr
|
|
reservedCount, flagsEx uint32
|
|
}
|
|
|
|
func chooseImage(owner uintptr, locale i18n.Locale) (string, error) {
|
|
title := "Choose a macOS installer image"
|
|
label := "Installer images"
|
|
if locale == i18n.ZhCN {
|
|
title = "选择 macOS 安装镜像"
|
|
label = "安装镜像"
|
|
}
|
|
titleW, _ := syscall.UTF16PtrFromString(title)
|
|
filter := utf16.Encode([]rune(label + " (*.img, *.dmg)\x00*.img;*.dmg\x00\x00"))
|
|
file := make([]uint16, 32768)
|
|
opts := openFileName{owner: owner, filter: &filter[0], filterIndex: 1, file: &file[0], maxFile: uint32(len(file)), title: titleW,
|
|
flags: 0x80000 | 0x1000 | 0x800 | 0x8} // Explorer; existing path/file; preserve current directory.
|
|
opts.size = uint32(unsafe.Sizeof(opts))
|
|
dll := syscall.NewLazyDLL("comdlg32.dll")
|
|
if ok, _, _ := dll.NewProc("GetOpenFileNameW").Call(uintptr(unsafe.Pointer(&opts))); ok != 0 {
|
|
return syscall.UTF16ToString(file), nil
|
|
}
|
|
if code, _, _ := dll.NewProc("CommDlgExtendedError").Call(); code != 0 {
|
|
return "", fmt.Errorf("file dialog: %#x", code)
|
|
}
|
|
return "", nil
|
|
}
|