-
Notifications
You must be signed in to change notification settings - Fork 0
/
gohOptions.go
288 lines (234 loc) · 9.48 KB
/
gohOptions.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
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
// gohOptions.go
/*
Source file auto-generated on Tue, 06 Apr 2021 22:04:43 using Gotk3 Objects Handler v1.7.5 ©2018-21 hfmrow
This software use gotk3 that is licensed under the ISC License:
https://github.com/gotk3/gotk3/blob/master/LICENSE
Copyright ©2020-21 hfmrow - Hash Me v1.2 github.com/hfmrow/hash-me
This program comes with absolutely no warranty. See the The MIT License (MIT) for details:
https://opensource.org/licenses/mit-license.php
*/
package main
import (
"bytes"
"encoding/json"
"io/ioutil"
"github.com/gotk3/gotk3/gtk"
glco "github.com/hfmrow/genLib/crypto"
glfs "github.com/hfmrow/genLib/files"
glfssf "github.com/hfmrow/genLib/files/scanFileDir"
glss "github.com/hfmrow/genLib/slices"
glsg "github.com/hfmrow/genLib/strings"
gltscj "github.com/hfmrow/genLib/tools/concurrentJob"
gltsle "github.com/hfmrow/genLib/tools/log2file"
gltsushe "github.com/hfmrow/genLib/tools/units/human_readable"
gimc "github.com/hfmrow/gtk3Import/misc"
gitsww "github.com/hfmrow/gtk3Import/tools/window"
gitw "github.com/hfmrow/gtk3Import/treeview"
)
// Application infos. Only this section could be [modified during an update].
// Except for "Descr" variable, it is not recommended to manualy change
// options values relative to the project. Use GOH instead to doing this,
// or respect strictly the original applied format.
var (
Name = "Hash Me"
Vers = "v1.2"
Descr = "Create hash checksum for given files, allow to create .SUM files corresponding to each file. Includes Md4, Md5, Sha1, Sha256, Sha384, Sha512, Sha3_256, Sha3_384, Sha3_512, Blake2b256, Blake2b384, Blake2b512 methods."
Creat = "hfmrow"
YearCreat = "2020-21"
LicenseShort = "This program comes with absolutely no warranty.\nSee the The MIT License (MIT) for details:\nhttps://opensource.org/licenses/mit-license.php"
LicenseAbrv = "License (MIT)"
Repository = "github.com/hfmrow/hash-me"
// Internal var declarations
mainOptions *MainOpt
devMode,
doTempDir bool
absoluteRealPath,
optFilename,
tempDir string
/*
* Library mapping
*/
// Window decoration
wds *gitsww.WinDecorationStructure
WinDecorationStructureNew = gitsww.WinDecorationStructureNew
// Treeview
tvs *gitw.TreeViewStructure
TreeViewStructureNew = gitw.TreeViewStructureNew
columns [][]string
colmap map[string]int
// Errors handling
Log2FileStructNew = gltsle.Log2FileStructNew
Logger *gltsle.Log2FileStruct
// D&D
dndWindow,
dndTextView *gimc.DragNDropStruct
DragNDropNew = gimc.DragNDropNew
// Clipboard / Css / Statusbar
clipboard *gimc.Clipboard
ClipboardNew = gimc.ClipboardNew
CssWdgScnBytes = gimc.CssWdgScnBytes
mainStatusbar *gimc.StatusBar
StatusBarStructureNew = gimc.StatusBarStructureNew
// Concurrent job
ccs *gltscj.ConcurrentCalcStruc
ConcurrentCalcStrucNew = gltscj.ConcurrentCalcStrucNew
// Files
HumanReadableSize = gltsushe.HumanReadableSize
HR_UNIT_DEFAULT = gltsushe.UNIT_DEFAULT
HR_UNIT_DECIMAL = gltsushe.UNIT_DECIMAL
ExtEnsure = glfs.ExtEnsure
HashMe = glco.HashMe
GetOsLineEnd = glsg.GetOsLineEnd
ScanDirDepth = glfssf.ScanDirDepth
// Slice
IsExistSl = glss.IsExistSl
// Misc
files []string
filesChanged bool
// TextView buffer
buff *gtk.TextBuffer
// Progressbar
pbs *gimc.ProgressBarStruct
ProgressGifNew = gimc.ProgressGifNew
FormatText = glsg.FormatText
resultsHash []*entry
)
// MainOpt: This structure contains all the variables of the application, they
// will be saved when exiting and reloaded at launch.
type MainOpt struct {
// File signature
FileSign []string
// Window position
MainWinWidth,
MainWinHeight,
MainWinPosX,
MainWinPosY int
LanguageFilename string // In case where GOTranslate is used.
ShowSplash,
MakeOutputFile,
RecursiveScan,
ConcurrentOp,
ShowFilename,
AppendDroppedFiles,
UseDecimal,
Reminder,
Md4, Md5,
Sha1, Sha256, Sha384, Sha512,
Sha3_256, Sha3_384, Sha3_512,
Blake2b256, Blake2b384, Blake2b512 bool
ReminderMessage,
CurrentStackPage string
SwitchStackPage,
SwitchExpandState bool
}
// Init: Main options initialisation, Put here default values for your application.
func (opt *MainOpt) Init() {
opt.FileSign = []string{Name, Vers, "©" + YearCreat, Creat, Repository, LicenseAbrv}
opt.LanguageFilename = "assets/lang/eng.lang"
opt.MainWinWidth = 800
opt.MainWinHeight = 600
opt.ShowSplash = true
opt.ShowFilename = true
opt.Reminder = true
opt.Md5 = true
// opt.Sha256 = true
opt.Sha512 = true
opt.ReminderMessage = `HowTo: Open a command prompt and use these commands regarding your OS,
according to desired checksum type, MD5 | SHA256 | SHA512 ...
Win: CertUtil -hashfile filename MD5 | SHA1 | SHA256 | SHA384 | SHA512
Linux: md5sum filename | sha256sum filename | shasum384 filename | sha512sum filename | b2sum -l256 filename | b2sum -l512 filename
OS X: md5 filename | shasum -a256 filename | shasum -a384 filename | shasum -a512 filename
`
}
// UpdateObjects: Options -> Objects. Put here options to assign to gtk3 objects at start
func (opt *MainOpt) UpdateObjects() {
// With GtkApplicationWindow (does not happen with GtkWindow) I have strange behavior
// when updating window size and position, sometimes width, height is not restored
// successfully, I have tried to figure it out but after a few (long) times I resigned
// myself to using a workaround method, right now I am using a timer that runs 'count'
// times the same commands to finally get the desired result (set window's size with
// the previously saved values).
// count := 5
// glib.TimeoutAdd(uint(64), func() bool {
mainObjects.MainWindow.Resize(opt.MainWinWidth, opt.MainWinHeight)
mainObjects.MainWindow.Move(opt.MainWinPosX, opt.MainWinPosY)
// count--
// return count > 0
// })
mainObjects.CheckbuttonAddReminder.SetActive(opt.Reminder)
mainObjects.CheckbuttonMd4.SetActive(opt.Md4)
mainObjects.CheckbuttonMd5.SetActive(opt.Md5)
mainObjects.CheckbuttonSha1.SetActive(opt.Sha1)
mainObjects.CheckbuttonSha256.SetActive(opt.Sha256)
mainObjects.CheckbuttonSha384.SetActive(opt.Sha384)
mainObjects.CheckbuttonSha512.SetActive(opt.Sha512)
mainObjects.CheckbuttonSha3_256.SetActive(opt.Sha3_256)
mainObjects.CheckbuttonSha3_384.SetActive(opt.Sha3_384)
mainObjects.CheckbuttonSha3_512.SetActive(opt.Sha3_512)
mainObjects.CheckbuttonBlake2b256.SetActive(opt.Blake2b256)
mainObjects.CheckbuttonBlake2b384.SetActive(opt.Blake2b384)
mainObjects.CheckbuttonBlake2b512.SetActive(opt.Blake2b512)
mainObjects.CheckbuttonShowFilename.SetActive(opt.ShowFilename)
mainObjects.CheckbuttonAppendFiles.SetActive(opt.AppendDroppedFiles)
mainObjects.CheckbuttonUseDecimal.SetActive(opt.UseDecimal)
mainObjects.CheckbuttonConcurrentOp.SetActive(opt.ConcurrentOp)
mainObjects.CheckbuttonRecursiveScan.SetActive(opt.RecursiveScan)
mainObjects.CheckbuttonCreateFile.SetActive(opt.MakeOutputFile)
if len(opt.CurrentStackPage) > 0 {
mainObjects.Stack.SetVisibleChildName(opt.CurrentStackPage)
}
mainObjects.SwitchTreeView.SetActive(opt.SwitchStackPage)
mainObjects.SwitchExpand.SetActive(opt.SwitchExpandState)
SwitchExpandStateSet(mainObjects.SwitchExpand)
mainObjects.CheckbuttonShowSplash.SetActive(opt.ShowSplash)
}
// UpdateOptions: Objects -> Options. Put here the gtk3 objects whose
// values you want to save in the options structure on exit.
func (opt *MainOpt) UpdateOptions() {
opt.MainWinWidth, opt.MainWinHeight = mainObjects.MainWindow.GetSize()
opt.MainWinPosX, opt.MainWinPosY = mainObjects.MainWindow.GetPosition()
opt.Reminder = mainObjects.CheckbuttonAddReminder.GetActive()
opt.Md4 = mainObjects.CheckbuttonMd4.GetActive()
opt.Md5 = mainObjects.CheckbuttonMd5.GetActive()
opt.Sha1 = mainObjects.CheckbuttonSha1.GetActive()
opt.Sha256 = mainObjects.CheckbuttonSha256.GetActive()
opt.Sha384 = mainObjects.CheckbuttonSha384.GetActive()
opt.Sha512 = mainObjects.CheckbuttonSha512.GetActive()
opt.Sha3_256 = mainObjects.CheckbuttonSha3_256.GetActive()
opt.Sha3_384 = mainObjects.CheckbuttonSha3_384.GetActive()
opt.Sha3_512 = mainObjects.CheckbuttonSha3_512.GetActive()
opt.Blake2b256 = mainObjects.CheckbuttonBlake2b256.GetActive()
opt.Blake2b384 = mainObjects.CheckbuttonBlake2b384.GetActive()
opt.Blake2b512 = mainObjects.CheckbuttonBlake2b512.GetActive()
opt.ShowFilename = mainObjects.CheckbuttonShowFilename.GetActive()
opt.AppendDroppedFiles = mainObjects.CheckbuttonAppendFiles.GetActive()
opt.UseDecimal = mainObjects.CheckbuttonUseDecimal.GetActive()
opt.ConcurrentOp = mainObjects.CheckbuttonConcurrentOp.GetActive()
opt.RecursiveScan = mainObjects.CheckbuttonRecursiveScan.GetActive()
opt.MakeOutputFile = mainObjects.CheckbuttonCreateFile.GetActive()
opt.CurrentStackPage = mainObjects.Stack.GetVisibleChildName()
opt.SwitchStackPage = mainObjects.SwitchTreeView.GetActive()
opt.SwitchExpandState = mainObjects.SwitchExpand.GetActive()
opt.ShowSplash = mainObjects.CheckbuttonShowSplash.GetActive()
}
// Read: Options from file.
func (opt *MainOpt) Read() (err error) {
opt.Init() // Init options with defaults values
textFileBytes, err := ioutil.ReadFile(optFilename)
if err != nil {
return err
}
return json.Unmarshal(textFileBytes, &opt)
}
// Write: Options to file
func (opt *MainOpt) Write() error {
var out bytes.Buffer
opt.UpdateOptions()
jsonData, err := json.Marshal(&opt)
if err != nil {
return err
} else if err = json.Indent(&out, jsonData, "", "\t"); err == nil {
return ioutil.WriteFile(optFilename, out.Bytes(), 0644)
}
return err
}