1
0
mirror of https://github.com/duke-git/lancet.git synced 2026-02-12 08:42:29 +08:00

单独剥离出来一个为windows的,增加RandNumLen为取指定长度随机数.

This commit is contained in:
guanren
2024-10-18 13:23:04 +08:00
parent 1ecb016969
commit fc5ca5e39e
6 changed files with 131 additions and 38 deletions

View File

@@ -1,3 +1,6 @@
//go:build windows
// +build windows
// Copyright 2021 dudaodong@gmail.com. All rights reserved.
// Use of this source code is governed by MIT license.
@@ -15,7 +18,6 @@ import (
"errors"
"fmt"
"github.com/duke-git/lancet/v2/validator"
"golang.org/x/sys/windows"
"io"
"io/fs"
"net/http"
@@ -25,7 +27,6 @@ import (
"sort"
"strings"
"sync"
"unsafe"
)
// FileReader is a reader supporting offset seeking and reading one
@@ -948,32 +949,3 @@ func ParallelChunkRead(filePath string, linesCh chan<- []string, chunkSizeMB, ma
return nil
}
// GetExeDllVersion 获取exe或dll文件的版本信息
func GetExeDllVersion(filePath string) (string, error) {
// 获取版本信息大小
size, err := windows.GetFileVersionInfoSize(filePath, nil)
if err != nil {
return "", fmt.Errorf("无法获取版本信息大小: %w", err)
}
// 读取版本信息
data := make([]byte, size)
err = windows.GetFileVersionInfo(filePath, 0, size, unsafe.Pointer(&data[0]))
if err != nil {
return "", fmt.Errorf("无法获取版本信息: %w", err)
}
// 查询版本信息
var fixedInfo *windows.VS_FIXEDFILEINFO
var fixedInfoLen uint32
err = windows.VerQueryValue(unsafe.Pointer(&data[0]), `\`, unsafe.Pointer(&fixedInfo), &fixedInfoLen)
if err != nil {
return "", fmt.Errorf("无法查询版本信息: %w", err)
}
// 提取版本号
major := fixedInfo.FileVersionMS >> 16
minor := fixedInfo.FileVersionMS & 0xFFFF
build := fixedInfo.FileVersionLS >> 16
revision := fixedInfo.FileVersionLS & 0xFFFF
return fmt.Sprintf("%d.%d.%d.%d", major, minor, build, revision), nil
}