Improve code

This commit is contained in:
Xpl0itU 2023-08-26 16:19:21 +02:00
parent 4176b1b168
commit 954d92e932
4 changed files with 14 additions and 19 deletions

View file

@ -89,11 +89,10 @@ func (mw *MainWindow) updateTitles(titles []wiiudownloader.TitleEntry) {
continue
}
iter := store.Append()
err = store.Set(iter,
if err := store.Set(iter,
[]int{IN_QUEUE_COLUMN, KIND_COLUMN, TITLE_ID_COLUMN, REGION_COLUMN, NAME_COLUMN},
[]interface{}{mw.isTitleInQueue(entry), wiiudownloader.GetFormattedKind(entry.TitleID), fmt.Sprintf("%016x", entry.TitleID), wiiudownloader.GetFormattedRegion(entry.Region), entry.Name},
)
if err != nil {
); err != nil {
mw.logger.Fatal("Unable to set values:", err)
}
}
@ -215,8 +214,7 @@ func (mw *MainWindow) ShowAll() {
mw.progressWindow.Window.ShowAll()
go func() {
err := mw.onDecryptContentsMenuItemClicked(selectedPath)
if err != nil {
if err := mw.onDecryptContentsMenuItemClicked(selectedPath); err != nil {
glib.IdleAdd(func() {
mw.showError(err)
})
@ -363,8 +361,7 @@ func (mw *MainWindow) ShowAll() {
mw.progressWindow.Window.ShowAll()
go func() {
err := mw.onDownloadQueueClicked(selectedPath)
if err != nil {
if err := mw.onDownloadQueueClicked(selectedPath); err != nil {
glib.IdleAdd(func() {
mw.showError(err)
})
@ -461,11 +458,10 @@ func (mw *MainWindow) filterTitles(filterText string) {
continue
}
iter := storeRef.Append()
err = storeRef.Set(iter,
if err := storeRef.Set(iter,
[]int{IN_QUEUE_COLUMN, KIND_COLUMN, TITLE_ID_COLUMN, REGION_COLUMN, NAME_COLUMN},
[]interface{}{mw.isTitleInQueue(entry), wiiudownloader.GetFormattedKind(entry.TitleID), fmt.Sprintf("%016x", entry.TitleID), wiiudownloader.GetFormattedRegion(entry.Region), entry.Name},
)
if err != nil {
); err != nil {
mw.logger.Fatal("Unable to set values:", err)
}
}

View file

@ -14,7 +14,7 @@ extern void callProgressCallback(int progress);
*/
import "C"
import (
"fmt"
"errors"
"time"
"unsafe"
@ -74,7 +74,7 @@ func runDecryption(path string, deleteEncryptedContents bool) error {
C.set_progress_callback(C.ProgressCallback(C.callProgressCallback))
if int(C.cdecrypt_main(2, (**C.char)(unsafe.Pointer(&argv[0])))) != 0 {
return fmt.Errorf("decryption failed")
return errors.New("decryption failed")
}
if deleteEncryptedContents {

View file

@ -4,6 +4,7 @@ import (
"crypto/aes"
"crypto/cipher"
"crypto/sha1"
"errors"
"fmt"
"os"
"path/filepath"
@ -26,7 +27,7 @@ func checkContentHashes(path string, content contentInfo, cipherHashTree *cipher
h3Hash := sha1.Sum(h3Data)
if !reflect.DeepEqual(h3Hash[:8], content.Hash[:8]) {
return fmt.Errorf("h3 Hash mismatch")
return errors.New("h3 Hash mismatch")
}
chunkCount := int(content.Size / 0x10000)
@ -56,13 +57,13 @@ func checkContentHashes(path string, content contentInfo, cipherHashTree *cipher
h2HashesHash := sha1.Sum(h2Hashes)
if !reflect.DeepEqual(h0HashesHash[:], h1Hash) {
return fmt.Errorf("h0 Hashes Hash mismatch")
return errors.New("h0 Hashes Hash mismatch")
}
if !reflect.DeepEqual(h1HashesHash[:], h2Hash) {
return fmt.Errorf("h1 Hashes Hash mismatch")
return errors.New("h1 Hashes Hash mismatch")
}
if !reflect.DeepEqual(h2HashesHash[:], h3Hash) {
return fmt.Errorf("h2 Hashes Hash mismatch")
return errors.New("h2 Hashes Hash mismatch")
}
encryptedFile.Seek(0xFC00, 1)
h0HashNum++

View file

@ -11,7 +11,7 @@ func isThisDecryptedFile(path string) bool {
}
func doDeleteEncryptedContents(path string) error {
err := filepath.Walk(path, func(filePath string, info os.FileInfo, err error) error {
return filepath.Walk(path, func(filePath string, info os.FileInfo, err error) error {
if err != nil {
return err
}
@ -22,6 +22,4 @@ func doDeleteEncryptedContents(path string) error {
}
return nil
})
return err
}