From 75c0a017f96b684d2379ced0b11a557d83f9c3e9 Mon Sep 17 00:00:00 2001 From: Evan Su <48808396+HACKERALERT@users.noreply.github.com> Date: Thu, 17 Apr 2025 23:37:36 -0400 Subject: [PATCH 1/6] Much more reliable free space estimator --- src/Picocrypt.go | 34 ++++++++++++++++++++++++++-------- 1 file changed, 26 insertions(+), 8 deletions(-) diff --git a/src/Picocrypt.go b/src/Picocrypt.go index dcd25fe..d616ae3 100644 --- a/src/Picocrypt.go +++ b/src/Picocrypt.go @@ -790,8 +790,21 @@ 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++ + } 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 +871,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() { @@ -873,10 +891,10 @@ func onDrop(names []string) { if err != nil { panic(err) } - requiredFreeSpace = 2 * size + requiredFreeSpace = 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 +931,8 @@ func onDrop(names []string) { } totalFiles++ compressTotal += stat.Size() - requiredFreeSpace += stat.Size() } + requiredFreeSpace = compressTotal } else { outputFile = names[0][:len(names[0])-4] } @@ -1017,7 +1035,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 +1074,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 +1119,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 { From ee2abd053c15e915f0be9fe19e4e0efc02a661e9 Mon Sep 17 00:00:00 2001 From: Evan Su <48808396+HACKERALERT@users.noreply.github.com> Date: Thu, 17 Apr 2025 23:46:04 -0400 Subject: [PATCH 2/6] remove duplicate single folder size counting --- src/Picocrypt.go | 20 +------------------- 1 file changed, 1 insertion(+), 19 deletions(-) diff --git a/src/Picocrypt.go b/src/Picocrypt.go index d616ae3..e27631f 100644 --- a/src/Picocrypt.go +++ b/src/Picocrypt.go @@ -803,6 +803,7 @@ func draw() { if recombine { multiplier++ } + fmt.Println(multiplier, requiredFreeSpace) giu.Style().SetColor(giu.StyleColorText, WHITE).To( giu.Label("Ready (ensure " + sizeify(requiredFreeSpace*int64(multiplier)) + " of disk space is free)"), ).Build() @@ -887,11 +888,6 @@ 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 = size } else { // A file was dropped files++ requiredFreeSpace = stat.Size() @@ -2571,20 +2567,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) From 99a04de2633eceac886414282202b5a59edd5961 Mon Sep 17 00:00:00 2001 From: Evan Su <48808396+HACKERALERT@users.noreply.github.com> Date: Thu, 17 Apr 2025 23:46:35 -0400 Subject: [PATCH 3/6] oops remove debug print statement --- src/Picocrypt.go | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Picocrypt.go b/src/Picocrypt.go index e27631f..6f28c92 100644 --- a/src/Picocrypt.go +++ b/src/Picocrypt.go @@ -803,7 +803,6 @@ func draw() { if recombine { multiplier++ } - fmt.Println(multiplier, requiredFreeSpace) giu.Style().SetColor(giu.StyleColorText, WHITE).To( giu.Label("Ready (ensure " + sizeify(requiredFreeSpace*int64(multiplier)) + " of disk space is free)"), ).Build() From 7a1d105a432603866f0d1468f2d175e65ff5b6bc Mon Sep 17 00:00:00 2001 From: Evan Su <48808396+HACKERALERT@users.noreply.github.com> Date: Thu, 17 Apr 2025 23:52:22 -0400 Subject: [PATCH 4/6] also increase multiplier if auto unzip --- src/Picocrypt.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/Picocrypt.go b/src/Picocrypt.go index 6f28c92..3994195 100644 --- a/src/Picocrypt.go +++ b/src/Picocrypt.go @@ -803,6 +803,9 @@ func draw() { if recombine { multiplier++ } + if autoUnzip { + multiplier++ + } giu.Style().SetColor(giu.StyleColorText, WHITE).To( giu.Label("Ready (ensure " + sizeify(requiredFreeSpace*int64(multiplier)) + " of disk space is free)"), ).Build() From 6140e2beb6bc79b1cfc0fb33253493ff47b54ea6 Mon Sep 17 00:00:00 2001 From: Evan Su <48808396+HACKERALERT@users.noreply.github.com> Date: Fri, 18 Apr 2025 00:06:01 -0400 Subject: [PATCH 5/6] 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. --- src/Picocrypt.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Picocrypt.go b/src/Picocrypt.go index 3994195..49addba 100644 --- a/src/Picocrypt.go +++ b/src/Picocrypt.go @@ -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( @@ -807,7 +807,7 @@ func draw() { multiplier++ } giu.Style().SetColor(giu.StyleColorText, WHITE).To( - giu.Label("Ready (ensure " + sizeify(requiredFreeSpace*int64(multiplier)) + " 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( From df5ef8e9ee7c57d87732fa16e6f2ca735635d565 Mon Sep 17 00:00:00 2001 From: Evan Su <48808396+HACKERALERT@users.noreply.github.com> Date: Fri, 18 Apr 2025 02:03:10 -0400 Subject: [PATCH 6/6] add TODO to .gitignore I store some TODOs locally and don't want them in vc --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitignore b/.gitignore index 6f6f5e6..e06e4dc 100644 --- a/.gitignore +++ b/.gitignore @@ -20,3 +20,5 @@ # Go workspace file go.work go.work.sum + +TODO