-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupdate_windows.go
58 lines (52 loc) · 1.14 KB
/
update_windows.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
//go:build windows
// +build windows
package updaterini
import (
"fmt"
"os"
"path/filepath"
"strings"
"syscall"
)
/*
for Windows OS executable should be stopped! USE ONLY WITH cur executable file stops functions
*/
func (uR *UpdateResult) deletePrevVersionFiles() (err error) {
var errFiles []string
for _, file := range uR.updateFilesInfo {
if !file.curFileRenamed {
continue
}
fPath := filepath.Join(uR.updateDir, file.replacement.FileName+oldVersionReplacedFilesExtension)
err = os.Remove(fPath)
if err != nil {
errFiles = append(errFiles, fPath)
}
}
if len(errFiles) == 0 {
return nil
}
var sI syscall.StartupInfo
var pI syscall.ProcessInformation
argv, tErr := syscall.UTF16PtrFromString(fmt.Sprintf(`%s\system32\cmd.exe /C PING -n 11 127.0.0.1>nul & DEL "%s"`,
os.Getenv("windir"), strings.Join(errFiles, `", "`))) // 11 equal 10 seconds, 31 equal 30 seconds etc.
if tErr != nil {
return tErr
}
err = syscall.CreateProcess(
nil,
argv,
nil,
nil,
true,
0,
nil,
nil,
&sI,
&pI)
return err
}
func (rF *updateFile) fillFileOwnerInfo(_ os.FileInfo) {
rF.curFileOwner = -1
rF.curFileGroup = -1
}