Skip to content

Commit

Permalink
added -silent flag
Browse files Browse the repository at this point in the history
  • Loading branch information
rifsxd committed Mar 9, 2024
1 parent 4dca18b commit 8b714e4
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 18 deletions.
4 changes: 2 additions & 2 deletions common/meta/info.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package meta
// Info variables
const Dev = "RifsxD"
const Name = "DVPL_LZ4 CLI TOOL"
const Version = "1.2.4"
const Version = "1.2.5"
const Repo = "https://github.com/rifsxd/dvpl_lz4"
const Web = "https://rxd-mods.xyz"
const Commit = "07/03/2024"
const Commit = "09/03/2024"
const Info = "A CLI/GUI Tool Coded In GoLang To Convert WoTB ( Dava ) SmartDLC DVPL File Based On LZ4 High Compression."
32 changes: 25 additions & 7 deletions common/utils/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ type Config struct {
Path string // New field to specify the directory path.
Ignore string
IgnoreExt bool
Silent bool // New field to specify silent mode.
}

// DVPLFooter represents the DVPL file footer data.
Expand Down Expand Up @@ -56,12 +57,14 @@ func PrintElapsedTime(elapsedTime time.Duration) {
}
}

// ParseCommandLineArgs parses the command-line arguments and returns the configuration.
func ParseCommandLineArgs() (*Config, error) {
config := &Config{}
flag.StringVar(&config.Mode, "mode", "", "Mode can be 'compress' / 'decompress' / 'help' (for an extended help guide).")
flag.BoolVar(&config.KeepOriginals, "keep-originals", false, "Keep original files after compression/decompression.")
flag.StringVar(&config.Path, "path", "", "directory/files path to process. Default is the current directory.")
flag.StringVar(&config.Ignore, "ignore", "", "Comma-separated list of file extensions to ignore during compression.")
flag.BoolVar(&config.Silent, "silent", false, "Run in silent mode (suppresses log prints from process).")

flag.Parse()

Expand Down Expand Up @@ -132,6 +135,7 @@ func PrintHelpMessage() {
`)
}

// ProcessFiles process files in the directory or file specified in the config.
func ProcessFiles(directoryOrFile string, config *Config) (successCount, failureCount, ignoredCount int, err error) {
// Initialize counters
successCount = 0
Expand Down Expand Up @@ -202,7 +206,9 @@ func ProcessFiles(directoryOrFile string, config *Config) (successCount, failure
return 0, 0, 0, err
}

fmt.Printf("%sFile%s %s has been successfully %s into %s%s%s\n", colors.GreenColor, colors.ResetColor, filePath, getAction(config.Mode), colors.GreenColor, newName, colors.ResetColor)
if !config.Silent {
fmt.Printf("%sFile%s %s has been successfully %s into %s%s%s\n", colors.GreenColor, colors.ResetColor, filePath, getAction(config.Mode), colors.GreenColor, newName, colors.ResetColor)
}

if !config.KeepOriginals {
err := os.Remove(filePath)
Expand All @@ -213,7 +219,9 @@ func ProcessFiles(directoryOrFile string, config *Config) (successCount, failure

successCount++
} else {
fmt.Printf("%sIgnoring%s file %s\n", colors.YellowColor, colors.ResetColor, directoryOrFile)
if !config.Silent {
fmt.Printf("%sIgnoring%s file %s\n", colors.YellowColor, colors.ResetColor, directoryOrFile)
}
ignoredCount++
}
}
Expand Down Expand Up @@ -248,7 +256,9 @@ func VerifyDVPLFiles(directoryOrFile string, config *Config) (successCount, fail
for _, dirItem := range dirList {
succ, fail, ignored, err := VerifyDVPLFiles(filepath.Join(directoryOrFile, dirItem.Name()), config)
if err != nil {
fmt.Printf("Error processing directory %s: %v\n", dirItem.Name(), err)
if !config.Silent {
fmt.Printf("Error processing directory %s: %v\n", dirItem.Name(), err)
}
}
successCount += succ
failureCount += fail
Expand All @@ -257,25 +267,33 @@ func VerifyDVPLFiles(directoryOrFile string, config *Config) (successCount, fail
} else {
// Ignore non-.dvpl files during verification
if !strings.HasSuffix(directoryOrFile, dvplExtension) {
fmt.Printf("%sIgnoring%s file %s\n", colors.YellowColor, colors.ResetColor, directoryOrFile)
if !config.Silent {
fmt.Printf("%sIgnoring%s file %s\n", colors.YellowColor, colors.ResetColor, directoryOrFile)
}
ignoredCount++
return successCount, failureCount, ignoredCount, nil
}

filePath := directoryOrFile
fileData, err := os.ReadFile(filePath)
if err != nil {
fmt.Printf("%sError%s reading file %s: %v\n", colors.RedColor, colors.ResetColor, directoryOrFile, err)
if !config.Silent {
fmt.Printf("%sError%s reading file %s: %v\n", colors.RedColor, colors.ResetColor, directoryOrFile, err)
}
return 0, 0, 0, err
}

_, err = dvpl.DecompressDVPL(fileData)
if err != nil {
fmt.Printf("%sFile%s %s %sfailed to verify due to %v%s\n", colors.RedColor, colors.ResetColor, directoryOrFile, colors.RedColor, err, colors.ResetColor)
if !config.Silent {
fmt.Printf("%sFile%s %s %sfailed to verify due to %v%s\n", colors.RedColor, colors.ResetColor, directoryOrFile, colors.RedColor, err, colors.ResetColor)
}
return 0, 1, 0, nil // Return failure count as 1 for this file
}

fmt.Printf("%sFile%s %s has been successfully %s\n", colors.GreenColor, colors.ResetColor, filePath, getAction(config.Mode))
if !config.Silent {
fmt.Printf("%sFile%s %s has been successfully %s\n", colors.GreenColor, colors.ResetColor, filePath, getAction(config.Mode))
}

successCount++
}
Expand Down
36 changes: 27 additions & 9 deletions dvpl_lz4_lite/dvpl_lz4_lite.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ const (
// Info variables
const Dev = "RifsxD"
const Name = "DVPL_LZ4 CLI TOOL"
const Version = "1.2.4-lite"
const Version = "1.2.5-lite"
const Repo = "https://github.com/rifsxd/dvpl_lz4"
const Web = "https://rxd-mods.xyz"
const Commit = "08/03/2024"
const Commit = "09/03/2024"
const Info = "A CLI Tool Coded In GoLang To Convert WoTB ( Dava ) SmartDLC DVPL File Based On LZ4 High Compression."

// Constants related to DVPL format
Expand Down Expand Up @@ -185,7 +185,9 @@ func VerifyDVPLFiles(directoryOrFile string, config *Config) (successCount, fail
for _, dirItem := range dirList {
succ, fail, ignored, err := VerifyDVPLFiles(filepath.Join(directoryOrFile, dirItem.Name()), config)
if err != nil {
fmt.Printf("Error processing directory %s: %v\n", dirItem.Name(), err)
if !config.Silent {
fmt.Printf("Error processing directory %s: %v\n", dirItem.Name(), err)
}
}
successCount += succ
failureCount += fail
Expand All @@ -194,25 +196,33 @@ func VerifyDVPLFiles(directoryOrFile string, config *Config) (successCount, fail
} else {
// Ignore non-.dvpl files during verification
if !strings.HasSuffix(directoryOrFile, dvplExtension) {
fmt.Printf("%sIgnoring%s file %s\n", YellowColor, ResetColor, directoryOrFile)
if !config.Silent {
fmt.Printf("%sIgnoring%s file %s\n", YellowColor, ResetColor, directoryOrFile)
}
ignoredCount++
return successCount, failureCount, ignoredCount, nil
}

filePath := directoryOrFile
fileData, err := os.ReadFile(filePath)
if err != nil {
fmt.Printf("%sError%s reading file %s: %v\n", RedColor, ResetColor, directoryOrFile, err)
if !config.Silent {
fmt.Printf("%sError%s reading file %s: %v\n", RedColor, ResetColor, directoryOrFile, err)
}
return 0, 0, 0, err
}

_, err = DecompressDVPL(fileData)
if err != nil {
fmt.Printf("%sFile%s %s %sfailed to verify due to %v%s\n", RedColor, ResetColor, directoryOrFile, RedColor, err, ResetColor)
if !config.Silent {
fmt.Printf("%sFile%s %s %sfailed to verify due to %v%s\n", RedColor, ResetColor, directoryOrFile, RedColor, err, ResetColor)
}
return 0, 1, 0, nil // Return failure count as 1 for this file
}

fmt.Printf("%sFile%s %s has been successfully %s\n", GreenColor, ResetColor, filePath, getAction(config.Mode))
if !config.Silent {
fmt.Printf("%sFile%s %s has been successfully %s\n", GreenColor, ResetColor, filePath, getAction(config.Mode))
}

successCount++
}
Expand All @@ -227,6 +237,7 @@ type Config struct {
Path string // New field to specify the directory path.
Ignore string
IgnoreExt bool
Silent bool // New field to specify silent mode.
}

func PrintElapsedTime(elapsedTime time.Duration) {
Expand All @@ -249,12 +260,14 @@ func PrintElapsedTime(elapsedTime time.Duration) {
}
}

// ParseCommandLineArgs parses the command-line arguments and returns the configuration.
func ParseCommandLineArgs() (*Config, error) {
config := &Config{}
flag.StringVar(&config.Mode, "mode", "", "Mode can be 'compress' / 'decompress' / 'help' (for an extended help guide).")
flag.BoolVar(&config.KeepOriginals, "keep-originals", false, "Keep original files after compression/decompression.")
flag.StringVar(&config.Path, "path", "", "directory/files path to process. Default is the current directory.")
flag.StringVar(&config.Ignore, "ignore", "", "Comma-separated list of file extensions to ignore during compression.")
flag.BoolVar(&config.Silent, "silent", false, "Run in silent mode (suppresses log prints from process).")

flag.Parse()

Expand Down Expand Up @@ -322,6 +335,7 @@ func getAction(mode string) string {
return GreenColor + "decompressed" + ResetColor
}

// ProcessFiles process files in the directory or file specified in the config.
func ProcessFiles(directoryOrFile string, config *Config) (successCount, failureCount, ignoredCount int, err error) {
// Initialize counters
successCount = 0
Expand Down Expand Up @@ -392,7 +406,9 @@ func ProcessFiles(directoryOrFile string, config *Config) (successCount, failure
return 0, 0, 0, err
}

fmt.Printf("%sFile%s %s has been successfully %s into %s%s%s\n", GreenColor, ResetColor, filePath, getAction(config.Mode), GreenColor, newName, ResetColor)
if !config.Silent {
fmt.Printf("%sFile%s %s has been successfully %s into %s%s%s\n", GreenColor, ResetColor, filePath, getAction(config.Mode), GreenColor, newName, ResetColor)
}

if !config.KeepOriginals {
err := os.Remove(filePath)
Expand All @@ -403,7 +419,9 @@ func ProcessFiles(directoryOrFile string, config *Config) (successCount, failure

successCount++
} else {
fmt.Printf("%sIgnoring%s file %s\n", YellowColor, ResetColor, directoryOrFile)
if !config.Silent {
fmt.Printf("%sIgnoring%s file %s\n", YellowColor, ResetColor, directoryOrFile)
}
ignoredCount++
}
}
Expand Down

0 comments on commit 8b714e4

Please sign in to comment.