]> 127.0.0.1 Git - part/.git/commitdiff
fix
authorqydysky <qydysky@foxmail.com>
Sun, 8 May 2022 02:58:05 +0000 (10:58 +0800)
committerqydysky <qydysky@foxmail.com>
Sun, 8 May 2022 02:58:05 +0000 (10:58 +0800)
Sys.go
linuxwin/win.go

diff --git a/Sys.go b/Sys.go
index 699bf73bb38fb159a77e9de4f254887b1611fb80..2fb76aa5303f2233d982c7ab0528ad17eac72ef9 100644 (file)
--- a/Sys.go
+++ b/Sys.go
@@ -11,7 +11,6 @@ import (
        "strconv"
        "strings"
        "sync"
-       "syscall"
        "time"
 
        Ppart "github.com/qydysky/part/linuxwin"
@@ -192,29 +191,5 @@ func (this *sys) PreventSleep() (stop *signal.Signal) {
                return
        }
 
-       const (
-               EsSystemRequired = 0x00000001
-               EsContinuous     = 0x80000000
-       )
-
-       var pulseTime = 10 * time.Second
-
-       kernel32 := syscall.NewLazyDLL("kernel32.dll")
-       setThreadExecStateProc := kernel32.NewProc("SetThreadExecutionState")
-
-       pulse := time.NewTicker(pulseTime)
-
-       stop = signal.Init()
-
-       go func() {
-               defer setThreadExecStateProc.Call(uintptr(EsContinuous))
-               for stop.Islive() {
-                       select {
-                       case <-pulse.C:
-                               setThreadExecStateProc.Call(uintptr(EsSystemRequired | EsContinuous))
-                       }
-               }
-       }()
-
-       return
+       return Ppart.PreventSleep()
 }
index f0e78e5dc6866ef66f1cd0d612d5498c746cf099..ed1ae78f55d0857c9b29f7f04fed28e7c3d63bf4 100755 (executable)
+//go:build !linux
 // +build !linux
 
-
 package Ppart
 
 import (
-    "syscall"
-    "unsafe"
-    "os"
-    "os/exec"
-    "path/filepath"
+       "os"
+       "os/exec"
+       "path/filepath"
+       "syscall"
+       "time"
+       "unsafe"
+
+       signal "github.com/qydysky/part/signal"
 )
 
 type ulong int32
 type ulong_ptr uintptr
 
 type PROCESSENTRY32 struct {
-    dwSize ulong
-    cntUsage ulong
-    th32ProcessID ulong
-    th32DefaultHeapID ulong_ptr
-    th32ModuleID ulong
-    cntThreads ulong
-    th32ParentProcessID ulong
-    pcPriClassBase ulong
-    dwFlags ulong
-    szExeFile [260]byte
+       dwSize              ulong
+       cntUsage            ulong
+       th32ProcessID       ulong
+       th32DefaultHeapID   ulong_ptr
+       th32ModuleID        ulong
+       cntThreads          ulong
+       th32ParentProcessID ulong
+       pcPriClassBase      ulong
+       dwFlags             ulong
+       szExeFile           [260]byte
 }
 
-func PCheck(pros []string) []int{
+func PCheck(pros []string) []int {
        kernel32 := syscall.NewLazyDLL("kernel32.dll")
-    pHandle,_,_  := kernel32.NewProc("CreateToolhelp32Snapshot").Call(uintptr(0x2),uintptr(0x0))
-    res:=[]int{}
-    _pros:=[][]byte{}
-    if int(pHandle)==-1 {return res}
-    for _,v:= range pros{
-        if v=="" {return res}
-        _pros=append(_pros,[]byte(v))
-        res=append(res,0)
-    }
-    // fmt.Println(string(_pros[0]))
-    pp:= kernel32.NewProc("Process32Next")
-    var proc PROCESSENTRY32;
-    var a [260]byte;
-    proc.dwSize = ulong(unsafe.Sizeof(proc));
-    
-    for {
-        proc.szExeFile=a;
-        rt,_,_ := pp.Call(uintptr(pHandle),uintptr(unsafe.Pointer(&proc)))
-        
-        if int(rt)!=1 {break}
-        // fmt.Println(string(proc.szExeFile[0:]))
-        for j,i :=range _pros{
-            // fmt.Println(string(proc.szExeFile[0:len(_pros[i])]))
-            // if len(_pros[i])!=len(proc.szExeFile){continue}
-            
-            for q,v:=range i{
-                if proc.szExeFile[q]!=v {break}
-                if q+1==len(i) {res[j]+=1}
-            }
-            // fmt.Println("")
-
-            
-            // if proc.szExeFile[:len(_pros[i])]==_pros[i] {res[i]+=1}
-        }
-    }
-    kernel32.NewProc("CloseHandle").Call(pHandle);
-    // fmt.Println(time.Since(t))
+       pHandle, _, _ := kernel32.NewProc("CreateToolhelp32Snapshot").Call(uintptr(0x2), uintptr(0x0))
+       res := []int{}
+       _pros := [][]byte{}
+       if int(pHandle) == -1 {
+               return res
+       }
+       for _, v := range pros {
+               if v == "" {
+                       return res
+               }
+               _pros = append(_pros, []byte(v))
+               res = append(res, 0)
+       }
+       // fmt.Println(string(_pros[0]))
+       pp := kernel32.NewProc("Process32Next")
+       var proc PROCESSENTRY32
+       var a [260]byte
+       proc.dwSize = ulong(unsafe.Sizeof(proc))
+
+       for {
+               proc.szExeFile = a
+               rt, _, _ := pp.Call(uintptr(pHandle), uintptr(unsafe.Pointer(&proc)))
+
+               if int(rt) != 1 {
+                       break
+               }
+               // fmt.Println(string(proc.szExeFile[0:]))
+               for j, i := range _pros {
+                       // fmt.Println(string(proc.szExeFile[0:len(_pros[i])]))
+                       // if len(_pros[i])!=len(proc.szExeFile){continue}
+
+                       for q, v := range i {
+                               if proc.szExeFile[q] != v {
+                                       break
+                               }
+                               if q+1 == len(i) {
+                                       res[j] += 1
+                               }
+                       }
+                       // fmt.Println("")
+
+                       // if proc.szExeFile[:len(_pros[i])]==_pros[i] {res[i]+=1}
+               }
+       }
+       kernel32.NewProc("CloseHandle").Call(pHandle)
+       // fmt.Println(time.Since(t))
        return res
 }
 
-func PStartf(pro []*exec.Cmd){
-    for i := range pro {
-        pro[i].SysProcAttr = &syscall.SysProcAttr{HideWindow: true}
-        pro[i].Start()
-    }
+func PStartf(pro []*exec.Cmd) {
+       for i := range pro {
+               pro[i].SysProcAttr = &syscall.SysProcAttr{HideWindow: true}
+               pro[i].Start()
+       }
 }
 
-func PRun(hide bool,prog string,cmd ...string) error {
-    p:=exec.Command(prog,cmd...)
-    if hide {p.SysProcAttr = &syscall.SysProcAttr{HideWindow: true}}
-    return p.Run()
+func PRun(hide bool, prog string, cmd ...string) error {
+       p := exec.Command(prog, cmd...)
+       if hide {
+               p.SysProcAttr = &syscall.SysProcAttr{HideWindow: true}
+       }
+       return p.Run()
 }
 
 func PProxy(s, pacUrl string) error {
-    if s=="off"{
-        return PRun(true,Cdir()+"/ref/sysproxy64.exe","off")
-    }else{
-        return PRun(true,Cdir()+"/ref/sysproxy64.exe","pac",pacUrl)
-    }
-    return nil
+       if s == "off" {
+               return PRun(true, Cdir()+"/ref/sysproxy64.exe", "off")
+       } else {
+               return PRun(true, Cdir()+"/ref/sysproxy64.exe", "pac", pacUrl)
+       }
+       return nil
+}
+
+func Cdir() string {
+       dir, _ := os.Executable()
+       exPath := filepath.Dir(dir)
+       return exPath
 }
 
-func Cdir()string{
-    dir, _ := os.Executable()
-    exPath := filepath.Dir(dir)
-    return exPath
+func FileMove(src, trg string) error {
+       from, err := syscall.UTF16PtrFromString(src)
+       if err != nil {
+               return err
+       }
+       to, err := syscall.UTF16PtrFromString(trg)
+       if err != nil {
+               return err
+       }
+       return syscall.MoveFile(from, to)
 }
 
-func FileMove(src,trg string) error {
-    from, err := syscall.UTF16PtrFromString(src)
-    if err != nil {
-        return err
-    }
-    to, err := syscall.UTF16PtrFromString(trg)
-    if err != nil {
-        return err
-    }
-    return syscall.MoveFile(from, to)
-}
\ No newline at end of file
+func PreventSleep() (stop *signal.Signal) {
+       const (
+               EsSystemRequired = 0x00000001
+               EsContinuous     = 0x80000000
+       )
+
+       var pulseTime = 10 * time.Second
+
+       kernel32 := syscall.NewLazyDLL("kernel32.dll")
+       setThreadExecStateProc := kernel32.NewProc("SetThreadExecutionState")
+
+       pulse := time.NewTicker(pulseTime)
+
+       stop = signal.Init()
+
+       go func() {
+               defer setThreadExecStateProc.Call(uintptr(EsContinuous))
+               for stop.Islive() {
+                       select {
+                       case <-pulse.C:
+                               setThreadExecStateProc.Call(uintptr(EsSystemRequired | EsContinuous))
+                       }
+               }
+       }()
+
+       return
+}