Skip to content

Commit

Permalink
Added a progress bar for a better UX.
Browse files Browse the repository at this point in the history
  • Loading branch information
stephen-fox committed Mar 22, 2020
1 parent 8c425f5 commit 418322e
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 4 deletions.
23 changes: 23 additions & 0 deletions LICENSE-THIRD-PARTY.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
33 changes: 30 additions & 3 deletions cmd/finley/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ import (
"strings"
"sync"
"time"

"github.com/schollz/progressbar/v2"
)

var (
Expand All @@ -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()

Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -136,6 +141,10 @@ func main() {
}

d.queue(func() error {
defer func() {
onJobComplete <- struct{}{}
}()

err := decompileNETFile(decompileNETInfo{
ilspycmdPath: *ilspycmdPath,
filePath: filePath,
Expand All @@ -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())
Expand All @@ -163,18 +174,34 @@ func main() {
filePath, fileSha256str)
}

log.Printf("decompiled '%s' to '%s'", filePath, finalOutputDirPath)
if *verbose {
log.Printf("decompiled '%s' to '%s'", filePath, finalOutputDirPath)
}

return nil
})

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())
}
Expand Down
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
module github.com/stephen-fox/finley

go 1.13

require github.com/schollz/progressbar/v2 v2.15.0
12 changes: 12 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -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=

0 comments on commit 418322e

Please sign in to comment.