Skip to content

Commit

Permalink
update 1.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
aimerneige committed Jan 19, 2022
1 parent b112c47 commit 9a3c408
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 5 deletions.
2 changes: 1 addition & 1 deletion TODO.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
- [x] *.cy file check
- [ ] read file in cache
- [ ] Chinese language support
- [ ] decrypt folder
- [x] decrypt directly
4 changes: 4 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## 1.2.0

Support decrypt directory.

## 1.1.1

DO NOT USE ELSE
Expand Down
8 changes: 4 additions & 4 deletions cmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ func Execute() {
app := &cli.App{
Name: "ddlcpad",
Usage: "Doki Doki Literature Club Plus Asset Decrypter",
UsageText: "ddlcpad file",
Version: "1.1.1",
UsageText: "ddlcpad file/directory",
Version: "1.2.0",
Action: func(c *cli.Context) error {

// if wrong args, exit
Expand All @@ -46,8 +46,8 @@ func Execute() {
// check if a directory
if utils.CheckFileIsDir(fileIn) {
logs.InfoLog(fmt.Sprintf("Directory \"%s\" detect, try to decrypt all file in it.", fileIn))
// todo decrypt whole folder
logs.ErrorLog("(pr welcome) Wait for next version :(")
core.DecryptDirectly(fileIn)
logs.DecryptDirectlySuccessfulMsg()
return nil
}

Expand Down
54 changes: 54 additions & 0 deletions core/decrypt.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,60 @@ func Decrypt(in, out string) bool {
return true
}

// DecryptDirectly Decrypt all data in directory and create new file.
func DecryptDirectly(dirPath string) {
logs.InfoLog(fmt.Sprintf("Start read files in directory \"%s\".", dirPath))

successful := 0
failed := 0
skiped := 0

// read files in directory
files, err := ioutil.ReadDir(dirPath)
if err != nil {
// todo err handle
panic(err)
}

for _, file := range files {
// if file is a directory, skip.
if file.IsDir() {
logs.InfoLog(fmt.Sprintf("Directory \"%s\" found, skip.", file.Name()))
skiped++
continue
}

// file name
in := dirPath + "/" + file.Name()
out := fmt.Sprintf("%s.out", in)

// if a *.cy.out file exists, skip.
if utils.CheckFileExist(out) {
logs.InfoLog(fmt.Sprintf("File \"%s\" already exist, skip.", out))
skiped++
continue
}

// try to decrypt file
if Decrypt(in, out) {
logs.InfoLog(fmt.Sprintf("File \"%s\" decrypt successful!", in))
successful++
} else {
logs.ErrorLog(fmt.Sprintf("File \"%s\" decrypt failed!", in))
failed++
}
}

total := successful + failed + skiped

// print result
logs.InfoLog("Decrypt finished.")
logs.InfoLog(fmt.Sprintf("Successful: %d", successful))
logs.InfoLog(fmt.Sprintf("Failed: %d", failed))
logs.InfoLog(fmt.Sprintf("Skipped: %d", skiped))
logs.InfoLog(fmt.Sprintf("Total: %d", total))
}

// xorByte XOR all bytes input with decrypt key
func xorByte(str []byte) (ret []byte) {
for i := 0; i < len(str); i++ {
Expand Down
13 changes: 13 additions & 0 deletions logs/logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,19 @@ func DecryptSuccessfulMsg() {
fmt.Print("\033[32m***********************************************************\033[0m\n")
}

// DecryptDirectlySuccessfulMsg Print help message when decrypt directly success.
func DecryptDirectlySuccessfulMsg() {
fmt.Print("\033[32m*****************************************************\033[0m\n")
fmt.Print("\033[32m* Decrypted Successful! *\033[0m\n")
fmt.Print("\033[32m* Decryption has been completed. *\033[0m\n")
fmt.Print("\033[32m* There may be something wrong, all error has been *\033[0m\n")
fmt.Print("\033[32m* skiped, you can check the log for more detail. *\033[0m\n")
fmt.Print("\033[32m* Now you can use AssetStudio to get all the assert *\033[0m\n")
fmt.Print("\033[32m* files. Here to download AssertStudio: *\033[0m\n")
fmt.Print("\033[32m* <https://github.com/Perfare/AssetStudio> *\033[0m\n")
fmt.Print("\033[32m*****************************************************\033[0m\n")
}

// DecryptFailMsg Print help message when decrypt fail.
func DecryptFailMsg() {
fmt.Print("\033[31m***********************************************************\033[0m\n")
Expand Down

0 comments on commit 9a3c408

Please sign in to comment.