Skip to content

Commit 418322e

Browse files
committed
Added a progress bar for a better UX.
1 parent 8c425f5 commit 418322e

File tree

5 files changed

+69
-4
lines changed

5 files changed

+69
-4
lines changed

LICENSE-THIRD-PARTY.md

+23
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,26 @@ ILSpy is distributed under the MIT License. There is only one first-party compon
1212

1313
ILSpy uses other open-source libraries to make its magic happen, and we want to thank the people working
1414
on those components! For the respective licenses and copyright information please see third-party notices.
15+
16+
# github.com/schollz/progressbar
17+
MIT License
18+
19+
Copyright (c) 2017 Zack
20+
21+
Permission is hereby granted, free of charge, to any person obtaining a copy
22+
of this software and associated documentation files (the "Software"), to deal
23+
in the Software without restriction, including without limitation the rights
24+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
25+
copies of the Software, and to permit persons to whom the Software is
26+
furnished to do so, subject to the following conditions:
27+
28+
The above copyright notice and this permission notice shall be included in all
29+
copies or substantial portions of the Software.
30+
31+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
32+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
33+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
34+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
35+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
36+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
37+
SOFTWARE.

README.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ arguments and an explanation of their effects:
4343
-allow-duplicates
4444
Decompile file even if its hash has already been encountered
4545
-d string
46-
The directory to search for DLLs
46+
The directory to search for .NET files
4747
-e string
4848
Comma separated list of file extensions to search for (default ".dll")
4949
-ilspy string
@@ -57,6 +57,7 @@ arguments and an explanation of their effects:
5757
-r Scan recursively
5858
-respect-file-case
5959
Respect filenames' case when matching their extensions
60+
-v Display log messages rather than a progress bar
6061
```
6162

6263
## Building from source

cmd/finley/main.go

+30-3
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ import (
1616
"strings"
1717
"sync"
1818
"time"
19+
20+
"github.com/schollz/progressbar/v2"
1921
)
2022

2123
var (
@@ -32,6 +34,7 @@ func main() {
3234
numDecompilers := flag.Int("num-workers", runtime.NumCPU(), "Number of .NET decompiler instances to run concurrently")
3335
allowDuplicateFiles := flag.Bool("allow-duplicates", false, "Decompile file even if its hash has already been encountered")
3436
ilspycmdPath := flag.String("ilspy", "ilspycmd", "The 'ilspycmd' binary to use")
37+
verbose := flag.Bool("v", false, "Display log messages rather than a progress bar")
3538

3639
flag.Parse()
3740

@@ -70,6 +73,8 @@ func main() {
7073

7174
fileHashesToDecompiledPaths := make(map[string]string)
7275

76+
onJobComplete := make(chan struct{})
77+
7378
err = filepath.Walk(*targetDirPath,
7479
func(filePath string, info os.FileInfo, err error) error {
7580
// Gotta check the error provided by the last call.
@@ -136,6 +141,10 @@ func main() {
136141
}
137142

138143
d.queue(func() error {
144+
defer func() {
145+
onJobComplete <- struct{}{}
146+
}()
147+
139148
err := decompileNETFile(decompileNETInfo{
140149
ilspycmdPath: *ilspycmdPath,
141150
filePath: filePath,
@@ -149,7 +158,9 @@ func main() {
149158
ioutil.WriteFile(filepath.Join(finalOutputDirPath, "decompile-failure.log"),
150159
[]byte(err.Error()),
151160
0600)
152-
log.Printf("[warn] %s", err.Error())
161+
if *verbose {
162+
log.Printf("[warn] %s", err.Error())
163+
}
153164
return nil
154165
}
155166
return fmt.Errorf("failed to decompile '%s' - %s", filePath, err.Error())
@@ -163,18 +174,34 @@ func main() {
163174
filePath, fileSha256str)
164175
}
165176

166-
log.Printf("decompiled '%s' to '%s'", filePath, finalOutputDirPath)
177+
if *verbose {
178+
log.Printf("decompiled '%s' to '%s'", filePath, finalOutputDirPath)
179+
}
167180

168181
return nil
169182
})
170183

171184
return nil
172185
})
173186
if err != nil {
174-
log.Println(err)
187+
log.Fatalln(err.Error())
175188
}
176189

190+
var bar *progressbar.ProgressBar
191+
if !*verbose {
192+
bar = progressbar.NewOptions(len(fileHashesToDecompiledPaths),
193+
progressbar.OptionShowCount())
194+
}
195+
go func() {
196+
for range onJobComplete {
197+
if bar != nil {
198+
bar.Add(1)
199+
}
200+
}
201+
}()
202+
177203
err = d.wait()
204+
close(onJobComplete)
178205
if err != nil {
179206
log.Fatalln(err.Error())
180207
}

go.mod

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
module github.com/stephen-fox/finley
22

33
go 1.13
4+
5+
require github.com/schollz/progressbar/v2 v2.15.0

go.sum

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
2+
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
3+
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
4+
github.com/mitchellh/colorstring v0.0.0-20190213212951-d06e56a500db h1:62I3jR2EmQ4l5rM/4FEfDWcRD+abF5XlKShorW5LRoQ=
5+
github.com/mitchellh/colorstring v0.0.0-20190213212951-d06e56a500db/go.mod h1:l0dey0ia/Uv7NcFFVbCLtqEBQbrT4OCwCSKTEv6enCw=
6+
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
7+
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
8+
github.com/schollz/progressbar/v2 v2.15.0 h1:dVzHQ8fHRmtPjD3K10jT3Qgn/+H+92jhPrhmxIJfDz8=
9+
github.com/schollz/progressbar/v2 v2.15.0/go.mod h1:UdPq3prGkfQ7MOzZKlDRpYKcFqEMczbD7YmbPgpzKMI=
10+
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
11+
github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q=
12+
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=

0 commit comments

Comments
 (0)