mirror of
https://github.com/Xpl0itU/WiiUDownloader.git
synced 2025-05-09 13:52:02 -04:00
Gocritic changes
This commit is contained in:
parent
4bc0236cf8
commit
8f13b57ae8
7 changed files with 17 additions and 18 deletions
|
@ -25,7 +25,7 @@ func main() {
|
|||
return
|
||||
}
|
||||
|
||||
bundlePath := filepath.Join(filepath.Dir(filepath.Dir(execPath)))
|
||||
bundlePath := filepath.Dir(filepath.Dir(execPath))
|
||||
filePath := filepath.Join(bundlePath, "Resources", "lib", "share", "glib-schemas")
|
||||
if _, err := os.Stat(filePath); os.IsNotExist(err) {
|
||||
logger.Warning("glib-schemas not found")
|
||||
|
|
|
@ -583,7 +583,7 @@ func (mw *MainWindow) isTitleInQueue(title wiiudownloader.TitleEntry) bool {
|
|||
return false
|
||||
}
|
||||
|
||||
func (mw *MainWindow) addToQueue(tid string, name string) {
|
||||
func (mw *MainWindow) addToQueue(tid, name string) {
|
||||
titleID, err := strconv.ParseUint(tid, 16, 64)
|
||||
if err != nil {
|
||||
mw.logger.Fatal("Unable to parse title ID:", err)
|
||||
|
@ -743,7 +743,6 @@ func (mw *MainWindow) onDownloadQueueClicked(selectedPath string) error {
|
|||
defer close(queueStatusChan)
|
||||
errGroup := errgroup.Group{}
|
||||
|
||||
queueProcessingLoop:
|
||||
for _, title := range mw.titleQueue {
|
||||
errGroup.Go(func() error {
|
||||
tidStr := fmt.Sprintf("%016x", title.TitleID)
|
||||
|
@ -761,7 +760,7 @@ queueProcessingLoop:
|
|||
}
|
||||
|
||||
if !<-queueStatusChan {
|
||||
break queueProcessingLoop
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -7,17 +7,18 @@ func normalizeFilename(filename string) string {
|
|||
shouldAppend := true
|
||||
|
||||
for _, c := range filename {
|
||||
if c == '_' {
|
||||
switch {
|
||||
case c == '_':
|
||||
if shouldAppend {
|
||||
out.WriteRune('_')
|
||||
shouldAppend = false
|
||||
}
|
||||
} else if c == ' ' {
|
||||
case c == ' ':
|
||||
if shouldAppend {
|
||||
out.WriteRune(' ')
|
||||
shouldAppend = false
|
||||
}
|
||||
} else if (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || (c >= '0' && c <= '9') {
|
||||
case (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || (c >= '0' && c <= '9'):
|
||||
out.WriteRune(c)
|
||||
shouldAppend = true
|
||||
}
|
||||
|
|
|
@ -28,9 +28,12 @@ type ProgressReporter interface {
|
|||
Cancelled() bool
|
||||
}
|
||||
|
||||
func downloadFile(progressReporter ProgressReporter, client *grab.Client, downloadURL string, dstPath string, doRetries bool) error {
|
||||
func downloadFile(progressReporter ProgressReporter, client *grab.Client, downloadURL, dstPath string, doRetries bool) error {
|
||||
filePath := filepath.Base(dstPath)
|
||||
|
||||
t := time.NewTicker(500 * time.Millisecond)
|
||||
defer t.Stop()
|
||||
|
||||
for attempt := 1; attempt <= maxRetries; attempt++ {
|
||||
req, err := grab.NewRequest(dstPath, downloadURL)
|
||||
if err != nil {
|
||||
|
@ -41,9 +44,6 @@ func downloadFile(progressReporter ProgressReporter, client *grab.Client, downlo
|
|||
resp := client.Do(req)
|
||||
progressReporter.UpdateDownloadProgress(resp, filePath)
|
||||
|
||||
t := time.NewTicker(500 * time.Millisecond)
|
||||
defer t.Stop()
|
||||
|
||||
Loop:
|
||||
for {
|
||||
select {
|
||||
|
@ -69,7 +69,7 @@ func downloadFile(progressReporter ProgressReporter, client *grab.Client, downlo
|
|||
return nil
|
||||
}
|
||||
|
||||
func DownloadTitle(titleID string, outputDirectory string, doDecryption bool, progressReporter ProgressReporter, deleteEncryptedContents bool, logger *Logger) error {
|
||||
func DownloadTitle(titleID, outputDirectory string, doDecryption bool, progressReporter ProgressReporter, deleteEncryptedContents bool, logger *Logger) error {
|
||||
titleEntry := getTitleEntryFromTid(titleID)
|
||||
|
||||
progressReporter.SetGameTitle(titleEntry.Name)
|
||||
|
@ -179,7 +179,7 @@ func DownloadTitle(titleID string, outputDirectory string, doDecryption bool, pr
|
|||
if err := binary.Read(tmdDataReader, binary.BigEndian, &content.Size); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := checkContentHashes(outputDirectory, content, &cipherHashTree); err != nil {
|
||||
if err := checkContentHashes(outputDirectory, content, cipherHashTree); err != nil {
|
||||
if progressReporter.Cancelled() {
|
||||
break
|
||||
}
|
||||
|
|
5
hash.go
5
hash.go
|
@ -13,8 +13,7 @@ import (
|
|||
|
||||
var commonKey = []byte{0xD7, 0xB0, 0x04, 0x02, 0x65, 0x9B, 0xA2, 0xAB, 0xD2, 0xCB, 0x0D, 0xB2, 0x7F, 0xA2, 0xB6, 0x56}
|
||||
|
||||
func checkContentHashes(path string, content contentInfo, cipherHashTree *cipher.Block) error {
|
||||
cHashTree := *cipherHashTree
|
||||
func checkContentHashes(path string, content contentInfo, cipherHashTree cipher.Block) error {
|
||||
h3Data, err := os.ReadFile(filepath.Join(path, fmt.Sprintf("%s.h3", content.ID)))
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to read H3 hash tree file: %w", err)
|
||||
|
@ -42,7 +41,7 @@ func checkContentHashes(path string, content contentInfo, cipherHashTree *cipher
|
|||
iv := make([]byte, aes.BlockSize)
|
||||
for chunkNum := 0; chunkNum < chunkCount; chunkNum++ {
|
||||
encryptedFile.Read(buffer)
|
||||
cipher.NewCBCDecrypter(cHashTree, iv).CryptBlocks(decryptedContent, buffer)
|
||||
cipher.NewCBCDecrypter(cipherHashTree, iv).CryptBlocks(decryptedContent, buffer)
|
||||
|
||||
h0Hashes := decryptedContent[0:0x140]
|
||||
h1Hashes := decryptedContent[0x140:0x280]
|
||||
|
|
|
@ -17,7 +17,7 @@ var (
|
|||
keygen_pw = []byte{0x6d, 0x79, 0x70, 0x61, 0x73, 0x73}
|
||||
)
|
||||
|
||||
func encryptAES(data []byte, key []byte, iv []byte) ([]byte, error) {
|
||||
func encryptAES(data, key, iv []byte) ([]byte, error) {
|
||||
block, err := aes.NewCipher(key)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
|
|
@ -39,7 +39,7 @@ func NewLogger(logFilePath string) (*Logger, error) {
|
|||
}
|
||||
|
||||
// Open the log file for writing, truncating it if it exists
|
||||
logFile, err = os.OpenFile(logFilePath, os.O_CREATE|os.O_WRONLY|os.O_TRUNC, 0666)
|
||||
logFile, err = os.OpenFile(logFilePath, os.O_CREATE|os.O_WRONLY|os.O_TRUNC, 0o666)
|
||||
if err != nil {
|
||||
// If unable to open the log file, log the error to stdout
|
||||
log.New(os.Stdout, "", log.Ldate|log.Ltime).Printf("[Error] Unable to open log file: %v\n", err)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue