-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
121 lines (101 loc) · 3.73 KB
/
main.go
File metadata and controls
121 lines (101 loc) · 3.73 KB
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
package main
import (
"iod/crypto"
"iod/functions"
"os"
"atomicgo.dev/keyboard/keys"
"github.com/pterm/pterm"
"golang.org/x/sys/windows/registry"
)
// main runs an interactive shell allowing the user to list the files and directories in
// their current directory, change directories, create new files, delete files, and quit.
func main() {
currentDir, err := os.Getwd()
if err != nil {
pterm.Error.Println("Error getting current directory:", err)
return
}
var options []string
options = append(options, "1. List files and dirs")
options = append(options, "2. Change directory")
options = append(options, "3. Create new file")
options = append(options, "4. Delete file")
options = append(options, "5. Copy file")
options = append(options, "6. List sorted files and dirs")
options = append(options, "7. Open file (read-only mode)")
options = append(options, "8. AES encryption")
options = append(options, "9. Find file in computer with pattern")
options = append(options, "10. Quit")
pterm.FgCyan.Printf("Current directory: %s\n", currentDir)
printer := pterm.DefaultInteractiveMultiselect.WithOptions(options)
printer.Filter = false
printer.TextStyle.Add(*pterm.NewStyle(pterm.FgGreen))
printer.KeyConfirm = keys.Enter
for {
selectedOptions, _ := pterm.DefaultInteractiveSelect.WithOptions(options).Show()
switch selectedOptions {
case "1. List files and dirs":
functions.ListFiles(currentDir)
case "2. Change directory":
currentDir = functions.ChangeDirectory(currentDir)
pterm.FgCyan.Printf("Current directory: %s\n", currentDir)
case "3. Create new file":
functions.CreateFile(currentDir)
case "4. Delete file":
functions.DeleteFile(currentDir)
case "5. Copy file":
functions.CopyFile(currentDir)
case "6. List sorted files and dirs":
var sortBy []string
sortBy = append(sortBy, "1. Sort by name")
sortBy = append(sortBy, "2. Sort by change date")
printer := pterm.DefaultInteractiveMultiselect.WithOptions(sortBy)
printer.Filter = false
printer.TextStyle.Add(*pterm.NewStyle(pterm.FgGreen))
printer.KeyConfirm = keys.Enter
selectedOptions, _ := pterm.DefaultInteractiveSelect.WithOptions(sortBy).Show()
switch selectedOptions {
case "1. Sort by name":
functions.ListSortedFilesAndDirs(currentDir)
case "2. Sort by change date":
functions.ListSortedFilesAndDirsByChangeDate(currentDir)
}
case "7. Open file (read-only mode)":
functions.OpenFile(currentDir)
case "8. AES encryption":
var encryptionOptions []string
encryptionOptions = append(encryptionOptions, "1. Encrypt file")
encryptionOptions = append(encryptionOptions, "2. Decrypt file")
printer := pterm.DefaultInteractiveMultiselect.WithOptions(encryptionOptions)
printer.Filter = false
printer.TextStyle.Add(*pterm.NewStyle(pterm.FgGreen))
printer.KeyConfirm = keys.Enter
selectedOptions, _ := pterm.DefaultInteractiveSelect.WithOptions(encryptionOptions).Show()
switch selectedOptions {
case "1. Encrypt file":
if !crypto.CheckAviailableKey() {
crypto.CreateSettingsToRegedit("key", crypto.GenerateKey())
crypto.EncryptFileTUI(currentDir, crypto.GenerateKey())
return
}
key, err := crypto.ReadRegistryValue(registry.CURRENT_USER, "Software\\iod", "key")
if err != nil {
pterm.Error.Println("Error reading key:", err)
return
}
crypto.EncryptFileTUI(currentDir, key)
case "2. Decrypt file":
readKey, err := crypto.ReadRegistryValue(registry.CURRENT_USER, "Software\\iod", "key")
if err != nil {
pterm.Error.Println("Error reading key:", err)
return
}
crypto.DecryptFileTUI(currentDir, readKey)
}
case "9. Find file in computer with pattern":
functions.GlobalFinderFile()
case "10. Quit":
return
}
}
}