From 418322ead5d7ca1eef26ba85da10ea9254da15f7 Mon Sep 17 00:00:00 2001 From: Stephen Fox Date: Sat, 21 Mar 2020 20:53:07 -0400 Subject: [PATCH] Added a progress bar for a better UX. --- LICENSE-THIRD-PARTY.md | 23 +++++++++++++++++++++++ README.md | 3 ++- cmd/finley/main.go | 33 ++++++++++++++++++++++++++++++--- go.mod | 2 ++ go.sum | 12 ++++++++++++ 5 files changed, 69 insertions(+), 4 deletions(-) create mode 100644 go.sum diff --git a/LICENSE-THIRD-PARTY.md b/LICENSE-THIRD-PARTY.md index 0632f83..d52e39f 100644 --- a/LICENSE-THIRD-PARTY.md +++ b/LICENSE-THIRD-PARTY.md @@ -12,3 +12,26 @@ ILSpy is distributed under the MIT License. There is only one first-party compon ILSpy uses other open-source libraries to make its magic happen, and we want to thank the people working on those components! For the respective licenses and copyright information please see third-party notices. + +# github.com/schollz/progressbar +MIT License + +Copyright (c) 2017 Zack + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/README.md b/README.md index 0fa06dc..85cbdcb 100644 --- a/README.md +++ b/README.md @@ -43,7 +43,7 @@ arguments and an explanation of their effects: -allow-duplicates Decompile file even if its hash has already been encountered -d string - The directory to search for DLLs + The directory to search for .NET files -e string Comma separated list of file extensions to search for (default ".dll") -ilspy string @@ -57,6 +57,7 @@ arguments and an explanation of their effects: -r Scan recursively -respect-file-case Respect filenames' case when matching their extensions + -v Display log messages rather than a progress bar ``` ## Building from source diff --git a/cmd/finley/main.go b/cmd/finley/main.go index a15193b..dff69dd 100644 --- a/cmd/finley/main.go +++ b/cmd/finley/main.go @@ -16,6 +16,8 @@ import ( "strings" "sync" "time" + + "github.com/schollz/progressbar/v2" ) var ( @@ -32,6 +34,7 @@ func main() { numDecompilers := flag.Int("num-workers", runtime.NumCPU(), "Number of .NET decompiler instances to run concurrently") allowDuplicateFiles := flag.Bool("allow-duplicates", false, "Decompile file even if its hash has already been encountered") ilspycmdPath := flag.String("ilspy", "ilspycmd", "The 'ilspycmd' binary to use") + verbose := flag.Bool("v", false, "Display log messages rather than a progress bar") flag.Parse() @@ -70,6 +73,8 @@ func main() { fileHashesToDecompiledPaths := make(map[string]string) + onJobComplete := make(chan struct{}) + err = filepath.Walk(*targetDirPath, func(filePath string, info os.FileInfo, err error) error { // Gotta check the error provided by the last call. @@ -136,6 +141,10 @@ func main() { } d.queue(func() error { + defer func() { + onJobComplete <- struct{}{} + }() + err := decompileNETFile(decompileNETInfo{ ilspycmdPath: *ilspycmdPath, filePath: filePath, @@ -149,7 +158,9 @@ func main() { ioutil.WriteFile(filepath.Join(finalOutputDirPath, "decompile-failure.log"), []byte(err.Error()), 0600) - log.Printf("[warn] %s", err.Error()) + if *verbose { + log.Printf("[warn] %s", err.Error()) + } return nil } return fmt.Errorf("failed to decompile '%s' - %s", filePath, err.Error()) @@ -163,7 +174,9 @@ func main() { filePath, fileSha256str) } - log.Printf("decompiled '%s' to '%s'", filePath, finalOutputDirPath) + if *verbose { + log.Printf("decompiled '%s' to '%s'", filePath, finalOutputDirPath) + } return nil }) @@ -171,10 +184,24 @@ func main() { return nil }) if err != nil { - log.Println(err) + log.Fatalln(err.Error()) } + var bar *progressbar.ProgressBar + if !*verbose { + bar = progressbar.NewOptions(len(fileHashesToDecompiledPaths), + progressbar.OptionShowCount()) + } + go func() { + for range onJobComplete { + if bar != nil { + bar.Add(1) + } + } + }() + err = d.wait() + close(onJobComplete) if err != nil { log.Fatalln(err.Error()) } diff --git a/go.mod b/go.mod index 2dc44ff..b5ed32a 100644 --- a/go.mod +++ b/go.mod @@ -1,3 +1,5 @@ module github.com/stephen-fox/finley go 1.13 + +require github.com/schollz/progressbar/v2 v2.15.0 diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..fad2e10 --- /dev/null +++ b/go.sum @@ -0,0 +1,12 @@ +github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= +github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/mitchellh/colorstring v0.0.0-20190213212951-d06e56a500db h1:62I3jR2EmQ4l5rM/4FEfDWcRD+abF5XlKShorW5LRoQ= +github.com/mitchellh/colorstring v0.0.0-20190213212951-d06e56a500db/go.mod h1:l0dey0ia/Uv7NcFFVbCLtqEBQbrT4OCwCSKTEv6enCw= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/schollz/progressbar/v2 v2.15.0 h1:dVzHQ8fHRmtPjD3K10jT3Qgn/+H+92jhPrhmxIJfDz8= +github.com/schollz/progressbar/v2 v2.15.0/go.mod h1:UdPq3prGkfQ7MOzZKlDRpYKcFqEMczbD7YmbPgpzKMI= +github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q= +github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=