forked from o0x1024/IMiniCrack
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.go
190 lines (167 loc) · 3.66 KB
/
app.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
package main
import (
"IMiniCrack/pkg/model"
"IMiniCrack/pkg/scan"
"context"
"github.com/wailsapp/wails"
"github.com/wailsapp/wails/v2/pkg/runtime"
"os"
"os/exec"
"os/user"
runtime2 "runtime"
)
// App struct
type App struct {
rt *wails.Runtime
ctx context.Context
}
// NewApp creates a new App application struct
func NewApp() *App {
return &App{}
}
// startup is called when the app starts. The context is saved
// so we can call the runtime methods
func (a *App) startup(ctx context.Context) {
a.ctx = ctx
runtime.WindowSetBackgroundColour(a.ctx, 255, 255, 255, 255)
}
// 保存正则信息
func (a *App) beforeClose(ctx context.Context) (prevent bool) {
resp := scan.Sc.SaveRegex()
if resp.Err != "" {
dialog, err := runtime.MessageDialog(ctx, runtime.MessageDialogOptions{
Type: runtime.QuestionDialog,
Title: "Quit?",
Message: "正则保存失败,原因:" + resp.Err + ",确定要关闭么?",
})
if err != nil {
return false
}
return dialog != "Yes"
}
return false
}
func (a *App) OpenDecDir(path string) string {
osType := runtime2.GOOS
curPath, err := os.Getwd()
if err != nil {
return err.Error()
}
switch osType {
case "windows":
exec.Command(`cmd`, `/c`, `explorer`, path).Start()
//case "linux":
// dd = "/"
case "darwin":
exec.Command(`open`, curPath).Start()
}
return ""
}
func (a *App) SelectOpenFile() (resp model.Response) {
user, _ := user.Current()
path, err := runtime.OpenFileDialog(a.ctx, runtime.OpenDialogOptions{
Title: "Select Directory",
DefaultDirectory: user.HomeDir + "\\Documents",
ShowHiddenFiles: true,
})
if err != nil {
resp.Err = err.Error()
return resp
}
resp.Data = path
return resp
}
func (a *App) OpenDisFile(path string) (resp model.Response) {
data, err := os.ReadFile(path)
if err != nil {
resp.Err = err.Error()
return resp
}
resp.Data = string(data)
return resp
}
func (a *App) OpenWxPackDir(curPath string) string {
//file := p.rt.Dialog.SelectFile()
//curPath, err := os.Getwd()
user, err := user.Current()
if err != nil {
return "OpenWxPackDir" + err.Error()
}
if err != nil {
return err.Error()
}
wxPath := ""
osType := runtime2.GOOS
switch osType {
case "windows":
wxPath = user.HomeDir + "\\Documents\\WeChat Files\\Applet"
case "linux":
wxPath = user.HomeDir
case "darwin":
wxPath = user.HomeDir
}
file, err := runtime.OpenDirectoryDialog(a.ctx, runtime.OpenDialogOptions{
Title: "Select wxpack Dir",
DefaultDirectory: wxPath,
})
if err != nil {
panic(err)
}
return file
}
func (a *App) GetDefaultOutPath() string {
user, err := user.Current()
if err != nil {
return "OpenWxPackDir" + err.Error()
}
return user.HomeDir + "\\Documents"
}
func (a *App) OpenDir() string {
user, err := user.Current()
if err != nil {
return "OpenWxPackDir" + err.Error()
}
dd := ""
osType := runtime2.GOOS
switch osType {
case "windows":
dd = user.HomeDir + "\\Documents"
case "linux":
dd = user.HomeDir
case "darwin":
dd = user.HomeDir
}
dir, err := runtime.OpenDirectoryDialog(a.ctx, runtime.OpenDialogOptions{
Title: "Select Directory",
DefaultDirectory: dd,
})
if err != nil {
panic(err)
}
return dir
}
func (a *App) OpenScanDir(path string) string {
if path == "" {
osType := runtime2.GOOS
switch osType {
case "windows":
path = "C:\\"
case "linux":
path = "/"
case "darwin":
path = "/"
}
}
dir, err := runtime.OpenDirectoryDialog(a.ctx, runtime.OpenDialogOptions{
Title: "Select Directory",
DefaultDirectory: path,
})
if err != nil {
panic(err)
}
return dir
}
func (p *App) WailsInit(runtime *wails.Runtime) error {
p.rt = runtime
return nil
}