Compare commits

...

6 commits

Author SHA1 Message Date
Evan Su
df5ef8e9ee add TODO to .gitignore
Some checks are pending
CodeQL / Analyze (push) Waiting to run
I store some TODOs locally and don't want them in vc
2025-04-18 02:03:10 -04:00
Evan Su
6140e2beb6 change tooltips for deniability and recursively to a warning
Average user should never need to use these options. Better warn them against it or at least to read the README about the features to understand what they do. These two options can cause funky/unexpected/unintuitive behaviour unless the user understands what they do.
2025-04-18 00:06:01 -04:00
Evan Su
7a1d105a43 also increase multiplier if auto unzip 2025-04-17 23:52:22 -04:00
Evan Su
99a04de263 oops remove debug print statement 2025-04-17 23:46:35 -04:00
Evan Su
ee2abd053c remove duplicate single folder size counting 2025-04-17 23:46:04 -04:00
Evan Su
75c0a017f9 Much more reliable free space estimator 2025-04-17 23:37:36 -04:00
2 changed files with 33 additions and 29 deletions

2
.gitignore vendored
View file

@ -20,3 +20,5 @@
# Go workspace file
go.work
go.work.sum
TODO

View file

@ -651,13 +651,13 @@ func draw() {
giu.Row(
giu.Checkbox("Deniability", &deniability),
giu.Tooltip("Add plausible deniability to the volume\nIf enabled, comments will not be usable"),
giu.Tooltip("Warning: only use this if you know what it does!"),
giu.Dummy(-170, 0),
giu.Style().SetDisabled(!(len(allFiles) > 1 || len(onlyFolders) > 0)).To(
giu.Checkbox("Recursively", &recursively).OnChange(func() {
compress = false
}),
giu.Tooltip("Encrypt and decrypt recursive files individually"),
giu.Tooltip("Warning: only use this if you know what it does!"),
),
).Build()
@ -690,7 +690,7 @@ func draw() {
sameLevel = false
}
}),
giu.Tooltip("Extract .zip upon decryption (may overwrite)"),
giu.Tooltip("Extract .zip upon decryption (may overwrite files)"),
),
giu.Dummy(-170, 0),
giu.Style().SetDisabled(!autoUnzip).To(
@ -790,8 +790,24 @@ func draw() {
return
}
if requiredFreeSpace > 0 {
multiplier := 1
if len(allFiles) > 1 || len(onlyFolders) > 0 { // need a temporary zip file
multiplier++
}
if deniability {
multiplier++
}
if split {
multiplier++
}
if recombine {
multiplier++
}
if autoUnzip {
multiplier++
}
giu.Style().SetColor(giu.StyleColorText, WHITE).To(
giu.Label("Ready (ensure " + sizeify(requiredFreeSpace) + " of disk space is free)"),
giu.Label("Ready (ensure >" + sizeify(requiredFreeSpace*int64(multiplier)) + " of disk space is free)"),
).Build()
} else {
giu.Style().SetColor(giu.StyleColorText, WHITE).To(
@ -858,7 +874,12 @@ func onDrop(names []string) {
// One item dropped
if len(names) == 1 {
stat, _ := os.Stat(names[0])
stat, err := os.Stat(names[0])
if err != nil {
mainStatus = "Failed to stat dropped item"
mainStatusColor = RED
return
}
// A folder was dropped
if stat.IsDir() {
@ -869,14 +890,9 @@ func onDrop(names []string) {
onlyFolders = append(onlyFolders, names[0])
inputFile = filepath.Join(filepath.Dir(names[0]), "encrypted-"+strconv.Itoa(int(time.Now().Unix()))) + ".zip"
outputFile = inputFile + ".pcv"
size, err := dirSize(names[0])
if err != nil {
panic(err)
}
requiredFreeSpace = 2 * size
} else { // A file was dropped
files++
requiredFreeSpace += stat.Size()
requiredFreeSpace = stat.Size()
// Is the file a part of a split volume?
nums := []string{"0", "1", "2", "3", "4", "5", "6", "7", "8", "9"}
@ -913,8 +929,8 @@ func onDrop(names []string) {
}
totalFiles++
compressTotal += stat.Size()
requiredFreeSpace += stat.Size()
}
requiredFreeSpace = compressTotal
} else {
outputFile = names[0][:len(names[0])-4]
}
@ -1017,7 +1033,7 @@ func onDrop(names []string) {
allFiles = append(allFiles, name)
compressTotal += stat.Size()
requiredFreeSpace += 2 * stat.Size()
requiredFreeSpace += stat.Size()
inputLabel = fmt.Sprintf("Scanning files... (%s)", sizeify(compressTotal))
giu.Update()
}
@ -1056,7 +1072,7 @@ func onDrop(names []string) {
if err == nil && !stat.IsDir() {
allFiles = append(allFiles, path)
compressTotal += stat.Size()
requiredFreeSpace += 2 * stat.Size()
requiredFreeSpace += stat.Size()
inputLabel = fmt.Sprintf("Scanning files... (%s)", sizeify(compressTotal))
giu.Update()
}
@ -1101,7 +1117,7 @@ func work() {
}()
// Combine/compress all files into a .zip file if needed
if len(allFiles) > 1 || len(onlyFolders) > 0 || compress {
if len(allFiles) > 1 || len(onlyFolders) > 0 {
// Consider case where compressing only one file
files := allFiles
if len(allFiles) == 0 {
@ -2553,20 +2569,6 @@ func unpackArchive(zipPath string) error {
return nil
}
func dirSize(path string) (int64, error) {
var size int64
err := filepath.Walk(path, func(_ string, info os.FileInfo, err error) error {
if err != nil {
return err
}
if !info.IsDir() {
size += info.Size()
}
return err
})
return size, err
}
func main() {
// Create the main window
window = giu.NewMasterWindow("Picocrypt "+version[1:], 318, 507, giu.MasterWindowFlagsNotResizable)