Skip to content

Commit

Permalink
restore previous output directories
Browse files Browse the repository at this point in the history
  • Loading branch information
lico-n committed Dec 10, 2021
1 parent 5762c66 commit 4025572
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"github.com/lico-n/unneko"
"os"
"path/filepath"
"strings"
"sync"
)

Expand All @@ -17,7 +18,7 @@ func main() {
args := flag.Args()

if len(args) == 0 {
fmt.Fprintln(os.Stderr, "unneko v1.14.0 by Lico#6969")
fmt.Fprintln(os.Stderr, "unneko v1.15.0 by Lico#6969")
fmt.Fprintln(os.Stderr, "Usage: unneko <flags> input-file")
flag.PrintDefaults()
os.Exit(-1)
Expand Down Expand Up @@ -57,17 +58,18 @@ func performExtraction(inputFilePath string, outputDir string) error {
wg := &sync.WaitGroup{}
wg.Add(numOfSaveWorker)
for i := 0; i < numOfSaveWorker; i++ {
go startFileSavingWorker(wg, outputDir, extractedChan)
go startFileSavingWorker(wg, inputFilePath, outputDir, extractedChan)
}

wg.Wait()
return nil
}

func startFileSavingWorker(wg *sync.WaitGroup, outputPath string, ch <-chan *unneko.ExtractedFile) {
func startFileSavingWorker(wg *sync.WaitGroup, inputFile string, outputPath string, ch <-chan *unneko.ExtractedFile) {
defer wg.Done()
for file := range ch {
outputFilePath := filepath.Join(outputPath, file.Path())

outputFilePath := filepath.Join(outputPath, getFileNameWithoutExt(inputFile), file.Path())

outputDir := filepath.Dir(outputFilePath)
if err := os.MkdirAll(outputDir, os.ModePerm); err != nil {
Expand All @@ -81,3 +83,9 @@ func startFileSavingWorker(wg *sync.WaitGroup, outputPath string, ch <-chan *unn
}
}
}

func getFileNameWithoutExt(inputFile string) string {
baseFile := filepath.Base(inputFile)
splitted := strings.Split(baseFile, ".")
return splitted[0]
}

0 comments on commit 4025572

Please sign in to comment.