Fix language dropdown

This commit is contained in:
Evan Su 2021-08-19 20:20:11 -04:00 committed by GitHub
parent 2d01835223
commit 5e9a3554c1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -64,7 +64,7 @@ import (
"github.com/HACKERALERT/infectious" // v0.0.0-20210818221523-92bdec168696 "github.com/HACKERALERT/infectious" // v0.0.0-20210818221523-92bdec168696
// Helpers // Helpers
"github.com/cloudfoundry-attic/jibber_jabber" "github.com/HACKERALERT/jibber_jabber" // v0.0.0-20210819210536-54a4d27b5376
"github.com/HACKERALERT/clipboard" // v0.1.5-0.20210716140604-61d96bf4fc94 "github.com/HACKERALERT/clipboard" // v0.1.5-0.20210716140604-61d96bf4fc94
"github.com/HACKERALERT/dialog" // v0.0.0-20210716143851-223edea1d840 "github.com/HACKERALERT/dialog" // v0.0.0-20210716143851-223edea1d840
"github.com/HACKERALERT/browser" // v0.0.0-20210818221535-991cc324ab76 "github.com/HACKERALERT/browser" // v0.0.0-20210818221535-991cc324ab76
@ -94,10 +94,21 @@ type locale struct{
var locales []locale var locales []locale
var selectedLocale = "en" var selectedLocale = "en"
var allLocales = []string{
"en",
"es",
"lt",
"pt-BR",
"tr",
}
// Languages // Languages
var languages = []string{ var languages = []string{
"English", "English",
"Español",
"Lietuvių",
"Português-BR",
"Türkçe",
} }
var languageSelected int32 var languageSelected int32
@ -214,7 +225,10 @@ func startUI(){
pos := giu.GetCursorPos() pos := giu.GetCursorPos()
giu.Row( giu.Row(
giu.Dummy(-108,0), giu.Dummy(-108,0),
giu.Combo("##language",languages[languageSelected],languages,&languageSelected).Size(100), giu.Combo("##language",languages[languageSelected],languages,&languageSelected).OnChange(func(){
selectedLocale = allLocales[languageSelected]
shredding = s(shredding)
}).Size(100),
).Build() ).Build()
giu.SetCursorPos(pos) giu.SetCursorPos(pos)
@ -390,13 +404,13 @@ func startUI(){
}), }),
giu.Tooltip(s("Clear both password fields.")), giu.Tooltip(s("Clear both password fields.")),
giu.Button(passwordStateLabel).OnClick(func(){ giu.Button(s(passwordStateLabel)).OnClick(func(){
if passwordState==giu.InputTextFlagsPassword{ if passwordState==giu.InputTextFlagsPassword{
passwordState = giu.InputTextFlagsNone passwordState = giu.InputTextFlagsNone
passwordStateLabel = s("Hide") passwordStateLabel = "Hide"
}else{ }else{
passwordState = giu.InputTextFlagsPassword passwordState = giu.InputTextFlagsPassword
passwordStateLabel = s("Show") passwordStateLabel = "Show"
} }
}), }),
giu.Tooltip(s("Click to toggle the password state.")), giu.Tooltip(s("Click to toggle the password state.")),
@ -441,7 +455,7 @@ func startUI(){
giu.Dummy(12,0), giu.Dummy(12,0),
giu.Custom(func(){ giu.Custom(func(){
if !(mode=="decrypt"&&!keyfile){ if !(mode=="decrypt"&&!keyfile){
giu.Button(keyfileLabel).OnClick(func(){ giu.Button(s(keyfileLabel)).OnClick(func(){
filename,err := dialog.File().Load() filename,err := dialog.File().Load()
if err!=nil{ if err!=nil{
return return
@ -456,7 +470,7 @@ func startUI(){
if keyfile&&mode=="encrypt"{ if keyfile&&mode=="encrypt"{
giu.Button(s("Clear")).OnClick(func(){ giu.Button(s("Clear")).OnClick(func(){
keyfile = false keyfile = false
keyfileLabel = s("Keyfile") keyfileLabel = "Keyfile"
keyfilePath = "" keyfilePath = ""
}).Build() }).Build()
} }
@ -557,14 +571,14 @@ func startUI(){
}), }),
// Start button // Start button
giu.Button("Start").Size(-0.0000001,35).OnClick(func(){ giu.Button(s("Start")).Size(-0.0000001,35).OnClick(func(){
if mode=="encrypt"&&password!=cPassword{ if mode=="encrypt"&&password!=cPassword{
_status = s("Passwords don't match.") _status = "Passwords don't match."
_status_color = color.RGBA{0xff,0x00,0x00,255} _status_color = color.RGBA{0xff,0x00,0x00,255}
return return
} }
if keyfile&&keyfilePath==""{ if keyfile&&keyfilePath==""{
_status = s("Please select a keyfile.") _status = "Please select a keyfile."
_status_color = color.RGBA{0xff,0x00,0x00,255} _status_color = color.RGBA{0xff,0x00,0x00,255}
return return
} }
@ -595,7 +609,7 @@ func startUI(){
}), }),
giu.Style().SetColor(giu.StyleColorText,_status_color).To( giu.Style().SetColor(giu.StyleColorText,_status_color).To(
giu.Label(_status), giu.Label(s(_status)),
), ),
), ),
@ -771,13 +785,15 @@ func startUI(){
giu.Label(" - Phil P."), giu.Label(" - Phil P."),
giu.Label(" - E. Zahard"), giu.Label(" - E. Zahard"),
giu.Label(s("Translators:")), giu.Label(s("Translators:")),
giu.Label(" - umitseyhan75 (Turkish)"), giu.Label(" - umitseyhan75"),
giu.Label(" - digitalblossom (German)"), giu.Label(" - digitalblossom"),
giu.Label(" - maguszeal (Brazilian Portuguese)"), giu.Label(" - zeeaall"),
giu.Label(" - francirc"),
giu.Label(" - kurpau"),
giu.Label(s("Other:")), giu.Label(s("Other:")),
giu.Label(" - Fuderal for setting up Picocrypt's Discord server"), giu.Label(" - Fuderal"),
giu.Label(" - u/greenreddits for constant feedback and support"), giu.Label(" - u/greenreddits"),
giu.Label(" - u/Tall_Escape for helping me test Picocrypt"), giu.Label(" - u/Tall_Escape"),
), ),
).Build() ).Build()
}), }),
@ -787,7 +803,7 @@ func startUI(){
// Handle files dropped into Picocrypt by user // Handle files dropped into Picocrypt by user
func onDrop(names []string){ func onDrop(names []string){
_status = s("Ready.") _status = "Ready."
recombine = false recombine = false
if tab==0{ if tab==0{
// Clear variables // Clear variables
@ -866,14 +882,14 @@ func onDrop(names []string){
fin.Read(tmp) fin.Read(tmp)
if string(tmp[:5])=="v1.13"{ if string(tmp[:5])=="v1.13"{
resetUI() resetUI()
_status = s("Please use Picocrypt v1.13 to decrypt this file.") _status = "Please use Picocrypt v1.13 to decrypt this file."
_status_color = color.RGBA{0xff,0x00,0x00,255} _status_color = color.RGBA{0xff,0x00,0x00,255}
fin.Close() fin.Close()
return return
} }
if valid,_:=regexp.Match(`^v\d\.\d{2}.{10}0?\d+`,tmp);!valid&&!isSplit{ if valid,_:=regexp.Match(`^v\d\.\d{2}.{10}0?\d+`,tmp);!valid&&!isSplit{
resetUI() resetUI()
_status = s("This doesn't seem to be a Picocrypt volume.") _status = "This doesn't seem to be a Picocrypt volume."
_status_color = color.RGBA{0xff,0x00,0x00,255} _status_color = color.RGBA{0xff,0x00,0x00,255}
fin.Close() fin.Close()
return return
@ -887,7 +903,7 @@ func onDrop(names []string){
tmp,_ = rsDecode(rs5,tmp) tmp,_ = rsDecode(rs5,tmp)
if string(tmp)=="v1.14"||string(tmp)=="v1.15"||string(tmp)=="v1.16"{ if string(tmp)=="v1.14"||string(tmp)=="v1.15"||string(tmp)=="v1.16"{
resetUI() resetUI()
_status = s("Please use Picocrypt v1.16 to decrypt this file.") _status = "Please use Picocrypt v1.16 to decrypt this file."
_status_color = color.RGBA{0xff,0x00,0x00,255} _status_color = color.RGBA{0xff,0x00,0x00,255}
fin.Close() fin.Close()
return return
@ -918,14 +934,14 @@ func onDrop(names []string){
fin.Read(flags) fin.Read(flags)
flags,err = rsDecode(rs5,flags) flags,err = rsDecode(rs5,flags)
if err!=nil{ if err!=nil{
_status = s("Input file is corrupt and cannot be decrypted.") _status = "Input file is corrupt and cannot be decrypted."
_status_color = color.RGBA{0xff,0x00,0x00,255} _status_color = color.RGBA{0xff,0x00,0x00,255}
return return
} }
if flags[2]==1{ if flags[2]==1{
keyfile = true keyfile = true
keyfileLabel = s("Select keyfile") keyfileLabel = "Select keyfile"
} }
fin.Close() fin.Close()
@ -1049,7 +1065,7 @@ func work(){
w.Close() w.Close()
file.Close() file.Close()
os.Remove(inputFile) os.Remove(inputFile)
_status = s("Operation cancelled by user.") _status = "Operation cancelled by user."
_status_color = color.RGBA{0xff,0xff,0xff,255} _status_color = color.RGBA{0xff,0xff,0xff,255}
return return
} }
@ -1130,7 +1146,7 @@ func work(){
// XChaCha20's max message size is 256 GiB // XChaCha20's max message size is 256 GiB
if total>256*1073741824{ if total>256*1073741824{
_status = s("Total size is larger than 256 GiB, XChaCha20's limit.") _status = "Total size is larger than 256 GiB, XChaCha20's limit."
_status_color = color.RGBA{0xff,0x00,0x00,255} _status_color = color.RGBA{0xff,0x00,0x00,255}
return return
} }
@ -1286,7 +1302,7 @@ func work(){
if keep{ if keep{
kept = true kept = true
}else{ }else{
_status = s("The header is corrupt and the input file cannot be decrypted.") _status = "The header is corrupt and the input file cannot be decrypted."
_status_color = color.RGBA{0xff,0x00,0x00,255} _status_color = color.RGBA{0xff,0x00,0x00,255}
fin.Close() fin.Close()
return return
@ -1331,7 +1347,7 @@ func work(){
} }
if !working{ if !working{
_status = s("Operation cancelled by user.") _status = "Operation cancelled by user."
_status_color = color.RGBA{0xff,0xff,0xff,255} _status_color = color.RGBA{0xff,0xff,0xff,255}
fin.Close() fin.Close()
fout.Close() fout.Close()
@ -1386,9 +1402,9 @@ func work(){
}else{ }else{
fin.Close() fin.Close()
if !keyCorrect{ if !keyCorrect{
_status = s("The provided password is incorrect.") _status = "The provided password is incorrect."
}else{ }else{
_status = s("The provided keyfile is incorrect.") _status = "The provided keyfile is incorrect."
} }
_status_color = color.RGBA{0xff,0x00,0x00,255} _status_color = color.RGBA{0xff,0x00,0x00,255}
key = nil key = nil
@ -1437,7 +1453,7 @@ func work(){
for{ for{
if !working{ if !working{
_status = s("Operation cancelled by user.") _status = "Operation cancelled by user."
_status_color = color.RGBA{0xff,0xff,0xff,255} _status_color = color.RGBA{0xff,0xff,0xff,255}
fin.Close() fin.Close()
fout.Close() fout.Close()
@ -1507,7 +1523,7 @@ func work(){
if keep{ if keep{
kept = true kept = true
}else{ }else{
_status = s("The input file is too corrupted to decrypt.") _status = "The input file is too corrupted to decrypt."
_status_color = color.RGBA{0xff,0x00,0x00,255} _status_color = color.RGBA{0xff,0x00,0x00,255}
fin.Close() fin.Close()
fout.Close() fout.Close()
@ -1529,7 +1545,7 @@ func work(){
if keep{ if keep{
kept = true kept = true
}else{ }else{
_status = s("The input file is too corrupted to decrypt.") _status = "The input file is too corrupted to decrypt."
_status_color = color.RGBA{0xff,0x00,0x00,255} _status_color = color.RGBA{0xff,0x00,0x00,255}
fin.Close() fin.Close()
fout.Close() fout.Close()
@ -1545,7 +1561,7 @@ func work(){
if keep{ if keep{
kept = true kept = true
}else{ }else{
_status = s("The input file is too corrupted to decrypt.") _status = "The input file is too corrupted to decrypt."
_status_color = color.RGBA{0xff,0x00,0x00,255} _status_color = color.RGBA{0xff,0x00,0x00,255}
fin.Close() fin.Close()
fout.Close() fout.Close()
@ -1645,7 +1661,7 @@ func work(){
if !working{ if !working{
fin.Close() fin.Close()
fout.Close() fout.Close()
_status = s("Operation cancelled by user.") _status = "Operation cancelled by user."
_status_color = color.RGBA{0xff,0xff,0xff,255} _status_color = color.RGBA{0xff,0xff,0xff,255}
// If user cancels, remove the unfinished files // If user cancels, remove the unfinished files
@ -1720,10 +1736,10 @@ func work(){
// If user chose to keep a corrupted/modified file, let them know // If user chose to keep a corrupted/modified file, let them know
if kept{ if kept{
_status = s("The input file is corrupted and/or modified. Please be careful.") _status = "The input file is corrupted and/or modified. Please be careful."
_status_color = color.RGBA{0xff,0xff,0x00,255} _status_color = color.RGBA{0xff,0xff,0x00,255}
}else{ }else{
_status = s("Completed.") _status = "Completed."
_status_color = color.RGBA{0x00,0xff,0x00,255} _status_color = color.RGBA{0x00,0xff,0x00,255}
} }
@ -1736,7 +1752,7 @@ func work(){
// This function is run if an issue occurs during decryption // This function is run if an issue occurs during decryption
func broken(){ func broken(){
_status = s("The input file is either corrupted or intentionally modified.") _status = "The input file is either corrupted or intentionally modified."
_status_color = color.RGBA{0xff,0x00,0x00,255} _status_color = color.RGBA{0xff,0x00,0x00,255}
if recombine{ if recombine{
os.Remove(inputFile) os.Remove(inputFile)
@ -2037,7 +2053,7 @@ func resetUI(){
outputWidth = 370 outputWidth = 370
password = "" password = ""
cPassword = "" cPassword = ""
keyfileLabel = s("Use a keyfile") keyfileLabel = "Keyfile"
keyfilePath = "" keyfilePath = ""
keyfile = false keyfile = false
metadata = "" metadata = ""
@ -2053,7 +2069,7 @@ func resetUI(){
paranoid = false paranoid = false
progress = 0 progress = 0
progressInfo = "" progressInfo = ""
_status = s("Ready.") _status = "Ready."
_status_color = color.RGBA{0xff,0xff,0xff,255} _status_color = color.RGBA{0xff,0xff,0xff,255}
giu.Update() giu.Update()
} }
@ -2178,6 +2194,11 @@ func main(){
if err==nil{ if err==nil{
if strings.HasPrefix(tmp,i.iso){ if strings.HasPrefix(tmp,i.iso){
selectedLocale = i.iso selectedLocale = i.iso
for j,k := range allLocales{
if k==i.iso{
languageSelected = int32(j)
}
}
} }
} }
} }
@ -2185,10 +2206,10 @@ func main(){
inputLabel = s("Drag and drop file(s) and folder(s) into this window.") inputLabel = s("Drag and drop file(s) and folder(s) into this window.")
orLabel = s("or") orLabel = s("or")
status = s("Ready.") status = s("Ready.")
_status = s("Ready.") _status = "Ready."
shredding = s("Ready.") shredding = s("Ready.")
passwordStateLabel = s("Show") passwordStateLabel = s("Show")
keyfileLabel = s("Keyfile") keyfileLabel = "Keyfile"
metadataPrompt = s("Metadata (optional):") metadataPrompt = s("Metadata (optional):")
// Create a temporary file to store sdelete64.exe // Create a temporary file to store sdelete64.exe
@ -2208,7 +2229,7 @@ func main(){
v.Body.Close() v.Body.Close()
if err==nil{ if err==nil{
if string(body[:5])!=version{ if string(body[:5])!=version{
_status = s("A newer version is available.") _status = "A newer version is available."
_status_color = color.RGBA{0,255,0,255} _status_color = color.RGBA{0,255,0,255}
} }
} }
@ -2229,7 +2250,7 @@ func main(){
window.SetDropCallback(onDrop) window.SetDropCallback(onDrop)
window.SetCloseCallback(func() bool{ window.SetCloseCallback(func() bool{
// Disable closing window if a Picocrypt is working to prevent temporary files // Disable closing window if a Picocrypt is working to prevent temporary files
if working||(shredding!=s("Ready.")&&shredding!=s("Completed.")){ if working{
return false return false
} }
return true return true
@ -2240,3 +2261,4 @@ func main(){
// Window closed, clean up // Window closed, clean up
os.Remove(sdelete64path) os.Remove(sdelete64path)
} }