Start button show "Zip and Encrypt" if temp zip needed

This commit is contained in:
Evan Su 2025-04-13 15:15:43 -04:00
parent 6a8fdeaa53
commit c63cf92672
2 changed files with 35 additions and 16 deletions

View file

@ -6,6 +6,8 @@
# v1.48 (Released 04/15/2025) # v1.48 (Released 04/15/2025)
<ul> <ul>
<li>✓ Allow pressing 'Enter' key to press Start/Process button</li> <li>✓ Allow pressing 'Enter' key to press Start/Process button</li>
<li>✓ Update "Encrypt" button to "Zip and Encrypt" if multiple files</li>
<li>✓ Give user estimated required free disk space in status label</li>
<li>✓ Encrypt previously unencrypted temporary zip files</li> <li>✓ Encrypt previously unencrypted temporary zip files</li>
<li>✓ Add `.incomplete` to filenames while work is in progress</li> <li>✓ Add `.incomplete` to filenames while work is in progress</li>
<li>✓ Use `encrypted-*.zip.pcv` output name instead of `Encrypted.zip.pcv`</li> <li>✓ Use `encrypted-*.zip.pcv` output name instead of `Encrypted.zip.pcv`</li>

View file

@ -131,6 +131,7 @@ var mainStatus = "Ready"
var mainStatusColor = WHITE var mainStatusColor = WHITE
var popupStatus string var popupStatus string
var usingTempZip bool var usingTempZip bool
var requiredFreeSpace int64
// Progress variables // Progress variables
var progress float32 var progress float32
@ -635,15 +636,7 @@ func draw() {
giu.Tooltip("Provides the highest level of security attainable"), giu.Tooltip("Provides the highest level of security attainable"),
giu.Dummy(-170, 0), giu.Dummy(-170, 0),
giu.Style().SetDisabled(recursively || !(len(allFiles) > 1 || len(onlyFolders) > 0)).To( giu.Style().SetDisabled(recursively || !(len(allFiles) > 1 || len(onlyFolders) > 0)).To(
giu.Checkbox("Compress files", &compress).OnChange(func() { giu.Checkbox("Compress files", &compress),
if !(len(allFiles) > 1 || len(onlyFolders) > 0) {
if compress {
outputFile = filepath.Join(filepath.Dir(outputFile), "Encrypted") + ".zip.pcv"
} else {
outputFile = filepath.Join(filepath.Dir(outputFile), filepath.Base(inputFile)) + ".pcv"
}
}
}),
giu.Tooltip("Compress files with Deflate before encrypting"), giu.Tooltip("Compress files with Deflate before encrypting"),
), ),
).Build() ).Build()
@ -747,7 +740,7 @@ func draw() {
tmp := strings.TrimSuffix(filepath.Base(outputFile), ".pcv") tmp := strings.TrimSuffix(filepath.Base(outputFile), ".pcv")
f.SetInitFilename(strings.TrimSuffix(tmp, filepath.Ext(tmp))) f.SetInitFilename(strings.TrimSuffix(tmp, filepath.Ext(tmp)))
if mode == "encrypt" && (len(allFiles) > 1 || len(onlyFolders) > 0 || compress) { if mode == "encrypt" && (len(allFiles) > 1 || len(onlyFolders) > 0 || compress) {
f.SetInitFilename("Encrypted") f.SetInitFilename("encrypted-" + strconv.Itoa(int(time.Now().Unix())))
} }
// Get the chosen file path // Get the chosen file path
@ -796,12 +789,12 @@ func draw() {
).Build() ).Build()
return return
} }
if usingTempZip { if requiredFreeSpace > 0 {
giu.Style().SetColor(giu.StyleColorText, WHITE).To( giu.Style().SetColor(giu.StyleColorText, WHITE).To(
giu.Label("Ready (info: will create a temporary zip file)"), giu.Label("Ready (ensure " + sizeify(requiredFreeSpace) + " of disk space is free)"),
).Build() ).Build()
} else { } else {
giu.Style().SetColor(giu.StyleColorText, mainStatusColor).To( giu.Style().SetColor(giu.StyleColorText, WHITE).To(
giu.Label("Ready"), giu.Label("Ready"),
).Build() ).Build()
} }
@ -872,12 +865,18 @@ func onDrop(names []string) {
folders++ folders++
mode = "encrypt" mode = "encrypt"
inputLabel = "1 folder" inputLabel = "1 folder"
startLabel = "Encrypt" startLabel = "Zip and Encrypt"
onlyFolders = append(onlyFolders, names[0]) onlyFolders = append(onlyFolders, names[0])
inputFile = filepath.Join(filepath.Dir(names[0]), "Encrypted") + ".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()
// 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"}
@ -914,6 +913,7 @@ func onDrop(names []string) {
} }
totalFiles++ totalFiles++
compressTotal += stat.Size() compressTotal += stat.Size()
requiredFreeSpace += stat.Size()
} }
} else { } else {
outputFile = names[0][:len(names[0])-4] outputFile = names[0][:len(names[0])-4]
@ -1003,7 +1003,7 @@ func onDrop(names []string) {
} }
} else { // There are multiple dropped items } else { // There are multiple dropped items
mode = "encrypt" mode = "encrypt"
startLabel = "Encrypt" startLabel = "Zip and Encrypt"
// Go through each dropped item and add to corresponding slices // Go through each dropped item and add to corresponding slices
for _, name := range names { for _, name := range names {
@ -1017,6 +1017,7 @@ func onDrop(names []string) {
allFiles = append(allFiles, name) allFiles = append(allFiles, name)
compressTotal += stat.Size() compressTotal += 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()
} }
@ -1055,6 +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 += 2 * stat.Size()
inputLabel = fmt.Sprintf("Scanning files... (%s)", sizeify(compressTotal)) inputLabel = fmt.Sprintf("Scanning files... (%s)", sizeify(compressTotal))
giu.Update() giu.Update()
} }
@ -2339,6 +2341,7 @@ func resetUI() {
mainStatusColor = WHITE mainStatusColor = WHITE
popupStatus = "" popupStatus = ""
usingTempZip = false usingTempZip = false
requiredFreeSpace = 0
progress = 0 progress = 0
progressInfo = "" progressInfo = ""
@ -2550,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)