Compare commits

..

1 commit

Author SHA1 Message Date
Evan Su
504e908195
Merge 9b2b69e442 into f0bfe3ba03 2025-04-14 00:06:28 +00:00
2 changed files with 29 additions and 33 deletions

2
.gitignore vendored
View file

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

View file

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