-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.go
74 lines (57 loc) · 1.2 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
package main
import (
"cloakcrypt/internal/encryption"
"cloakcrypt/internal/filesystem"
"context"
"log"
"path/filepath"
"github.com/wailsapp/wails/v2/pkg/runtime"
)
// Wails default
type App struct {
ctx context.Context
}
func NewApp() *App {
return &App{}
}
func (a *App) startup(ctx context.Context) {
a.ctx = ctx
}
////
var CloakFile string
var EncryptFilePath string
var EncryptedFile string
func (a *App) SelectFile(mode int) string {
var err error
var vari *string
if mode == 0 {
vari = &CloakFile
} else if mode == 1 {
vari = &EncryptFilePath
} else {
vari = &EncryptedFile
}
*vari, err = runtime.OpenFileDialog(a.ctx, runtime.OpenDialogOptions{})
if err != nil {
log.Fatal(err)
}
return filepath.Base(*vari)
}
func (a *App) EncryptFile(password string) bool {
encryption.Key = password
err := filesystem.Write(CloakFile, EncryptFilePath, a.ctx)
if err != nil {
log.Println("Error while encrypting file:", err)
return false
}
return true
}
func (a *App) DecryptFile(password string) bool {
encryption.Key = password
err := filesystem.Read(EncryptedFile, a.ctx)
if err != nil {
log.Println("Error while decrypting file:", err)
return false
}
return true
}