Skip to content

Commit

Permalink
added '-l' for a limit on file size
Browse files Browse the repository at this point in the history
added some error handling for files we don't want to check
  • Loading branch information
rtfmkiesel committed May 10, 2023
1 parent 4e4b3ac commit 482949c
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 24 deletions.
17 changes: 9 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,17 @@ A client for [LOLDrivers](https://github.com/magicsword-io/LOLDrivers) (Living O
LOLDrivers-client.exe -m [MODE] [OPTIONS]
Modes:
online Download the newest driver set (default)
local Use a local drivers.json file (requires '-f')
internal Use the built-in driver set (can be outdated)
online Download the newest driver set (default)
local Use a local drivers.json file (requires '-f')
internal Use the built-in driver set (can be outdated, fallback)
Options:
-d Directory to scan for drivers (default: Windows Default)
-f File path to 'drivers.json' for mode 'local'
-t Number of threads to spawn (default: 20)
-v Print verbose messages (default: false)
-h Shows this text
-d Directory to scan for drivers (default: Windows Default)
-l Size limit for files to scan in MB (default: 10)
-f File path to 'drivers.json' for mode 'local'
-t Number of threads to spawn (default: 20)
-v Print verbose messages (default: false)
-h Shows this text
```
**Warning:** This project is not affiliated with the [LOLDrivers](https://github.com/magicsword-io/LOLDrivers) repository. JSON structure changes in the LOLDrivers API may break this client. Since this clients gets compiled with a working data set, it will fall back to the internal data set, if the parsing of the online data or the local file was not successful.

Expand Down
23 changes: 13 additions & 10 deletions cli/loldrivers-client/loldrivers-client.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,13 @@ func main() {
// Setup & parse command line arguments
var flagMode string
var flagDir string
var flagFileLimit int64
var flagLocalFile string
var flagThreads int
var flagVerbose bool
flag.StringVar(&flagMode, "m", "online", "")
flag.StringVar(&flagDir, "d", "", "")
flag.Int64Var(&flagFileLimit, "l", 10, "")
flag.StringVar(&flagLocalFile, "f", "", "")
flag.IntVar(&flagThreads, "t", 20, "")
flag.BoolVar(&flagVerbose, "v", false, "")
Expand All @@ -34,16 +36,17 @@ func main() {
LOLDrivers-client.exe -m [MODE] [OPTIONS]
Modes:
online Download the newest driver set (default)
local Use a local drivers.json file (requires '-f')
internal Use the built-in driver set (can be outdated)
online Download the newest driver set (default)
local Use a local drivers.json file (requires '-f')
internal Use the built-in driver set (can be outdated, fallback)
Options:
-d Directory to scan for drivers (default: Windows Default)
-f File path to 'drivers.json' for mode 'local'
-t Number of threads to spawn (default: 20)
-v Print verbose messages (default: false)
-h Shows this text
-d Directory to scan for drivers (default: Windows Default)
-l Size limit for files to scan in MB (default: 10)
-f File path to 'drivers.json' for mode 'local'
-t Number of threads to spawn (default: 20)
-v Print verbose messages (default: false)
-h Shows this text
`)
}
flag.Parse()
Expand Down Expand Up @@ -181,7 +184,7 @@ Options:

for _, path := range filesystem.DriverPaths {
// Get all files
files, err := filesystem.FilesInFolder(path)
files, err := filesystem.FilesInFolder(path, flagFileLimit)
if err != nil {
logger.CatchCrit(err)
}
Expand All @@ -194,7 +197,7 @@ Options:
} else {
// Scan the user specified folder for drivers
// Get all files
files, err := filesystem.FilesInFolder(flagDir)
files, err := filesystem.FilesInFolder(flagDir, flagFileLimit)
if err != nil {
logger.CatchCrit(err)
}
Expand Down
35 changes: 29 additions & 6 deletions pkg/filesystem/filesystem.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,22 +47,45 @@ func FileRead(filepath string) (contentBytes []byte, err error) {
return contentBytes, nil
}

// FilesInFolder() will return a []string of files in a folder (recursively)
func FilesInFolder(path string) (files []string, err error) {
// FilesInFolder() will return a []string of filepaths from a given folder (recursively)
//
// sizeLimit in MB (ex: 5)
func FilesInFolder(path string, sizeLimit int64) (files []string, err error) {
logger.Verbose(fmt.Sprintf("[*] Searching for files in %s", path))

// Walk over every file in a given folder
err = filepath.Walk(path, func(path string, info os.FileInfo, err error) error {
if err != nil {
// Ignore a file if we get "Access is denied" error
if os.IsPermission(err) {
return nil
}

// Ignore a file if we get "The system cannot find the file specified" error
if os.IsNotExist(err) {
return nil
}

return err
}

// Only append if it's not a directory
if !info.IsDir() {
// Append to slice
files = append(files, path)
// Skip directories and non regular files
if info.IsDir() || !info.Mode().IsRegular() {
return nil
}

// Skip files that can't be read
if info.Mode().Perm()&0400 == 0 {
return nil
}

// Skip files larger than the specified size limit
if info.Size() > sizeLimit*1024*1024 {
return nil
}

// Append to slice
files = append(files, path)
return nil
})

Expand Down

0 comments on commit 482949c

Please sign in to comment.