mirror of
https://github.com/Mrs4s/go-cqhttp.git
synced 2025-05-05 19:43:49 +08:00
feat double click check.
This commit is contained in:
parent
604a05b625
commit
93da16897a
7
global/terminal/double_click.go
Normal file
7
global/terminal/double_click.go
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
// +build !windows
|
||||||
|
|
||||||
|
package terminal
|
||||||
|
|
||||||
|
func RunningByDoubleClick() bool {
|
||||||
|
return false
|
||||||
|
}
|
23
global/terminal/double_click_windows.go
Normal file
23
global/terminal/double_click_windows.go
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
// +build windows
|
||||||
|
|
||||||
|
package terminal
|
||||||
|
|
||||||
|
import (
|
||||||
|
"syscall"
|
||||||
|
"unsafe"
|
||||||
|
)
|
||||||
|
|
||||||
|
// RunningByDoubleClick 检查是否通过双击直接运行
|
||||||
|
func RunningByDoubleClick() bool {
|
||||||
|
kernel32 := syscall.NewLazyDLL("kernel32.dll")
|
||||||
|
lp := kernel32.NewProc("GetConsoleProcessList")
|
||||||
|
if lp != nil {
|
||||||
|
var ids [2]uint32
|
||||||
|
var maxCount uint32 = 2
|
||||||
|
ret, _, _ := lp.Call(uintptr(unsafe.Pointer(&ids)), uintptr(maxCount))
|
||||||
|
if ret > 1 {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
17
main.go
17
main.go
@ -8,6 +8,7 @@ import (
|
|||||||
"encoding/base64"
|
"encoding/base64"
|
||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"github.com/Mrs4s/go-cqhttp/global/terminal"
|
||||||
rotatelogs "github.com/lestrrat-go/file-rotatelogs"
|
rotatelogs "github.com/lestrrat-go/file-rotatelogs"
|
||||||
easy "github.com/t-tomalak/logrus-easy-formatter"
|
easy "github.com/t-tomalak/logrus-easy-formatter"
|
||||||
"io"
|
"io"
|
||||||
@ -53,6 +54,11 @@ func init() {
|
|||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
conf = getConfig()
|
||||||
|
if conf == nil {
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
|
||||||
// 在debug模式下,将在标准输出中打印当前执行行数
|
// 在debug模式下,将在标准输出中打印当前执行行数
|
||||||
if conf.Debug {
|
if conf.Debug {
|
||||||
log.SetReportCaller(true)
|
log.SetReportCaller(true)
|
||||||
@ -90,11 +96,6 @@ func init() {
|
|||||||
_ = os.Remove("cqhttp.json")
|
_ = os.Remove("cqhttp.json")
|
||||||
}
|
}
|
||||||
|
|
||||||
conf = getConfig()
|
|
||||||
if conf == nil {
|
|
||||||
os.Exit(1)
|
|
||||||
}
|
|
||||||
|
|
||||||
if !global.PathExists(global.ImagePath) {
|
if !global.PathExists(global.ImagePath) {
|
||||||
if err := os.MkdirAll(global.ImagePath, 0755); err != nil {
|
if err := os.MkdirAll(global.ImagePath, 0755); err != nil {
|
||||||
log.Fatalf("创建图片缓存文件夹失败: %v", err)
|
log.Fatalf("创建图片缓存文件夹失败: %v", err)
|
||||||
@ -118,7 +119,11 @@ func init() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
if terminal.RunningByDoubleClick() {
|
||||||
|
log.Warning("警告: 强烈不推荐通过双击直接运行本程序, 这将导致一些非预料的后果.")
|
||||||
|
log.Warning("将等待10s后启动")
|
||||||
|
time.Sleep(time.Second * 10)
|
||||||
|
}
|
||||||
var byteKey []byte
|
var byteKey []byte
|
||||||
arg := os.Args
|
arg := os.Args
|
||||||
if len(arg) > 1 {
|
if len(arg) > 1 {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user