diff --git a/.gitignore b/.gitignore index e06e4dc..6f6f5e6 100644 --- a/.gitignore +++ b/.gitignore @@ -20,5 +20,3 @@ # Go workspace file go.work go.work.sum - -TODO diff --git a/src/Picocrypt.go b/src/Picocrypt.go index 49addba..dcd25fe 100644 --- a/src/Picocrypt.go +++ b/src/Picocrypt.go @@ -651,13 +651,13 @@ func draw() { giu.Row( giu.Checkbox("Deniability", &deniability), - giu.Tooltip("Warning: only use this if you know what it does!"), + giu.Tooltip("Add plausible deniability to the volume\nIf enabled, comments will not be usable"), giu.Dummy(-170, 0), giu.Style().SetDisabled(!(len(allFiles) > 1 || len(onlyFolders) > 0)).To( giu.Checkbox("Recursively", &recursively).OnChange(func() { compress = false }), - giu.Tooltip("Warning: only use this if you know what it does!"), + giu.Tooltip("Encrypt and decrypt recursive files individually"), ), ).Build() @@ -690,7 +690,7 @@ func draw() { sameLevel = false } }), - giu.Tooltip("Extract .zip upon decryption (may overwrite files)"), + giu.Tooltip("Extract .zip upon decryption (may overwrite)"), ), giu.Dummy(-170, 0), giu.Style().SetDisabled(!autoUnzip).To( @@ -790,24 +790,8 @@ 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*int64(multiplier)) + " of disk space is free)"), + giu.Label("Ready (ensure " + sizeify(requiredFreeSpace) + " of disk space is free)"), ).Build() } else { giu.Style().SetColor(giu.StyleColorText, WHITE).To( @@ -874,12 +858,7 @@ func onDrop(names []string) { // One item dropped if len(names) == 1 { - stat, err := os.Stat(names[0]) - if err != nil { - mainStatus = "Failed to stat dropped item" - mainStatusColor = RED - return - } + stat, _ := os.Stat(names[0]) // A folder was dropped if stat.IsDir() { @@ -890,9 +869,14 @@ 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"} @@ -929,8 +913,8 @@ func onDrop(names []string) { } totalFiles++ compressTotal += stat.Size() + requiredFreeSpace += stat.Size() } - requiredFreeSpace = compressTotal } else { outputFile = names[0][:len(names[0])-4] } @@ -1033,7 +1017,7 @@ func onDrop(names []string) { allFiles = append(allFiles, name) compressTotal += stat.Size() - requiredFreeSpace += stat.Size() + requiredFreeSpace += 2 * stat.Size() inputLabel = fmt.Sprintf("Scanning files... (%s)", sizeify(compressTotal)) giu.Update() } @@ -1072,7 +1056,7 @@ func onDrop(names []string) { if err == nil && !stat.IsDir() { allFiles = append(allFiles, path) compressTotal += stat.Size() - requiredFreeSpace += stat.Size() + requiredFreeSpace += 2 * stat.Size() inputLabel = fmt.Sprintf("Scanning files... (%s)", sizeify(compressTotal)) giu.Update() } @@ -1117,7 +1101,7 @@ func work() { }() // Combine/compress all files into a .zip file if needed - if len(allFiles) > 1 || len(onlyFolders) > 0 { + if len(allFiles) > 1 || len(onlyFolders) > 0 || compress { // Consider case where compressing only one file files := allFiles if len(allFiles) == 0 { @@ -2569,6 +2553,20 @@ 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)