aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2019-08-28 20:38:30 -0600
committerJason A. Donenfeld <Jason@zx2c4.com>2019-08-30 08:47:21 -0600
commit2f83e4df50d954decf9abe29197aaecb68a2da7b (patch)
tree8e4cc0d04e49e5a2bfc60c7dfd11434c05b13242
parentversion: bump (diff)
downloadwireguard-windows-2f83e4df50d954decf9abe29197aaecb68a2da7b.tar.xz
wireguard-windows-2f83e4df50d954decf9abe29197aaecb68a2da7b.zip
version: use ProductName and ProductVersion as strings
-rw-r--r--conf/path_windows.go5
-rw-r--r--ringlogger/dump.go4
-rw-r--r--ui/aboutdialog.go3
-rw-r--r--updater/versions.go3
-rw-r--r--version/debugging_linux.go4
-rw-r--r--version/useragent.go3
-rw-r--r--version/version_windows.go55
7 files changed, 31 insertions, 46 deletions
diff --git a/conf/path_windows.go b/conf/path_windows.go
index 3d0f2504..041afe84 100644
--- a/conf/path_windows.go
+++ b/conf/path_windows.go
@@ -10,6 +10,8 @@ import (
"path/filepath"
"golang.org/x/sys/windows"
+
+ "golang.zx2c4.com/wireguard/windows/version"
)
var cachedConfigFileDir string
@@ -41,7 +43,8 @@ func RootDirectory() (string, error) {
if err != nil {
return "", err
}
- c := filepath.Join(root, "WireGuard")
+ name, _ := version.RunningNameVersion()
+ c := filepath.Join(root, name)
err = os.MkdirAll(c, os.ModeDir|0700)
if err != nil {
return "", err
diff --git a/ringlogger/dump.go b/ringlogger/dump.go
index 552410e5..53e67eeb 100644
--- a/ringlogger/dump.go
+++ b/ringlogger/dump.go
@@ -13,6 +13,7 @@ import (
"golang.org/x/sys/windows"
"golang.org/x/sys/windows/registry"
"golang.zx2c4.com/wireguard/windows/conf"
+ "golang.zx2c4.com/wireguard/windows/version"
)
func DumpTo(out io.Writer, localSystem bool) error {
@@ -38,7 +39,8 @@ func DumpTo(out io.Writer, localSystem bool) error {
if err != nil {
return err
}
- path = filepath.Join(systemprofile, "AppData", "Local", "WireGuard", "log.bin")
+ name, _ := version.RunningNameVersion()
+ path = filepath.Join(systemprofile, "AppData", "Local", name, "log.bin")
}
file, err := os.Open(path)
if err != nil {
diff --git a/ui/aboutdialog.go b/ui/aboutdialog.go
index b56389bb..732531d4 100644
--- a/ui/aboutdialog.go
+++ b/ui/aboutdialog.go
@@ -83,7 +83,8 @@ func runAboutDialog(owner walk.Form) error {
return err
}
detailsLbl.SetTextAlignment(walk.AlignHCenterVNear)
- detailsLbl.SetText(fmt.Sprintf("App version: %s\nGo backend version: %s\nGo version: %s\nOperating system: %s\nArchitecture: %s", version.RunningVersion(), device.WireGuardGoVersion, strings.TrimPrefix(runtime.Version(), "go"), version.OsName(), runtime.GOARCH))
+ _, appVersion := version.RunningNameVersion()
+ detailsLbl.SetText(fmt.Sprintf("App version: %s\nGo backend version: %s\nGo version: %s\nOperating system: %s\nArchitecture: %s", appVersion, device.WireGuardGoVersion, strings.TrimPrefix(runtime.Version(), "go"), version.OsName(), runtime.GOARCH))
copyrightLbl, err := walk.NewTextLabel(dlg)
if err != nil {
diff --git a/updater/versions.go b/updater/versions.go
index 6ff73391..7292ce7e 100644
--- a/updater/versions.go
+++ b/updater/versions.go
@@ -17,7 +17,8 @@ import (
func versionNewerThanUs(candidate string) (bool, error) {
candidateParts := strings.Split(candidate, ".")
- ourParts := strings.Split(version.RunningVersion(), ".")
+ _, ver := version.RunningNameVersion()
+ ourParts := strings.Split(ver, ".")
if len(candidateParts) == 0 || len(ourParts) == 0 {
return false, errors.New("Empty version")
}
diff --git a/version/debugging_linux.go b/version/debugging_linux.go
index 4564b819..7c9c09c5 100644
--- a/version/debugging_linux.go
+++ b/version/debugging_linux.go
@@ -30,8 +30,8 @@ func OsName() string {
return fmt.Sprintf("%s %s %s", utsToStr(utsname.Sysname), utsToStr(utsname.Release), utsToStr(utsname.Version))
}
-func RunningVersion() string {
- return "0.0.0.0"
+func RunningNameVersion() (string, string) {
+ return "WireGuard", "0.0.0.0"
}
func VerifyAuthenticode(path string) bool {
diff --git a/version/useragent.go b/version/useragent.go
index 6fa62d40..52fb5c83 100644
--- a/version/useragent.go
+++ b/version/useragent.go
@@ -11,5 +11,6 @@ import (
)
func UserAgent() string {
- return fmt.Sprintf("WireGuard/%s (%s; %s)", RunningVersion(), OsName(), runtime.GOARCH)
+ name, ver := RunningNameVersion()
+ return fmt.Sprintf("%s/%s (%s; %s)", name, ver, OsName(), runtime.GOARCH)
}
diff --git a/version/version_windows.go b/version/version_windows.go
index b8775b7d..b583d160 100644
--- a/version/version_windows.go
+++ b/version/version_windows.go
@@ -6,11 +6,8 @@
package version
import (
- "errors"
- "fmt"
"os"
"runtime"
- "strings"
"unsafe"
"golang.org/x/sys/windows"
@@ -20,31 +17,12 @@ import (
//sys GetFileVersionInfo(filename *uint16, zero uint32, size uint32, block *byte) (err error) = version.GetFileVersionInfoW
//sys VerQueryValue(block *byte, section *uint16, value **byte, size *uint32) (err error) = version.VerQueryValueW
-type vsFixedFileInfo struct {
- Signature uint32
- StrucVersion uint32
- FileVersionMS uint32
- FileVersionLS uint32
- ProductVersionMS uint32
- ProductVersionLS uint32
- FileFlagsMask uint32
- FileFlags uint32
- FileOS uint32
- FileType uint32
- FileSubtype uint32
- FileDateMS uint32
- FileDateLS uint32
-}
-
-const vsFixedFileInfoSignature = 0xFEEF04BD
-
-var cachedVersion string
+var cachedVersion, cachedName string
-func RunningVersion() string {
- if len(cachedVersion) != 0 {
- return cachedVersion
+func RunningNameVersion() (name, version string) {
+ if len(cachedVersion) != 0 || len(cachedName) != 0 {
+ return cachedName, cachedVersion
}
- key16 := []uint16{'\\', 0x00}
self, err := os.Executable()
if err != nil {
panic(err)
@@ -63,22 +41,21 @@ func RunningVersion() string {
if err != nil {
panic(err)
}
- var fixedFileInfo *vsFixedFileInfo
- err = VerQueryValue(&buffer[0], &key16[0], (**byte)(unsafe.Pointer(&fixedFileInfo)), &size)
+
+ var val16 *uint16
+ err = VerQueryValue(&buffer[0], windows.StringToUTF16Ptr(`\StringFileInfo\040904b0\ProductName`), (**byte)(unsafe.Pointer(&val16)), &size)
if err != nil {
panic(err)
}
- if uintptr(size) < unsafe.Sizeof(vsFixedFileInfo{}) || fixedFileInfo == nil || fixedFileInfo.Signature != vsFixedFileInfoSignature {
- panic(errors.New("Incorrect return of VS_FIXEDFILEINFO"))
- }
- version := fmt.Sprintf("%d.%d.%d.%d", (fixedFileInfo.FileVersionMS>>16)&0xffff, (fixedFileInfo.FileVersionMS>>0)&0xffff, (fixedFileInfo.FileVersionLS>>16)&0xffff, (fixedFileInfo.FileVersionLS>>0)&0xffff)
- runtime.KeepAlive(buffer) // The win32 API aliases it in fixedFileInfo, but Go doesn't know that.
- if strings.HasSuffix(version, ".0") {
- version = version[:len(version)-2]
- }
- if strings.HasSuffix(version, ".0") {
- version = version[:len(version)-2]
+ name = windows.UTF16ToString((*[(1 << 30) - 1]uint16)(unsafe.Pointer(val16))[:size])
+ err = VerQueryValue(&buffer[0], windows.StringToUTF16Ptr(`\StringFileInfo\040904b0\ProductVersion`), (**byte)(unsafe.Pointer(&val16)), &size)
+ if err != nil {
+ panic(err)
}
+ version = windows.UTF16ToString((*[(1 << 30) - 1]uint16)(unsafe.Pointer(val16))[:size])
+ runtime.KeepAlive(buffer)
+
+ cachedName = name
cachedVersion = version
- return version
+ return
}