Skip to content

Commit

Permalink
Add ability to specify a directory to extract files to
Browse files Browse the repository at this point in the history
  • Loading branch information
VitaSmith committed Dec 15, 2020
1 parent 6c74090 commit d986668
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
13 changes: 10 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,15 @@ directory as the NUS content, and can be compiled for Linux or macOS.
### Usage

```
cdecrypt <NUS file or directory>
cdecrypt <NUS file or directory> [<target directory or existing file>]
```

The content is extracted into the same directory where the NUS files reside.
On Windows, you can also drag and drop a directory/file directly onto `cdecrypt.exe`.
If only one parameter is specified, the content is extracted into the same
directory where the NUS files reside. If an existing file is provided as the
second parameter, it is ignored (to preserve compatibility with the previous
versions of CDecrypt). If the second parameter is not an existing file, then
it is used as the target directory to extract files in, with any intermediate
directories created if needed.

Note that on Windows, you can drag and drop a directory/file directly onto
`cdecrypt.exe`.
5 changes: 4 additions & 1 deletion cdecrypt.c
Original file line number Diff line number Diff line change
Expand Up @@ -497,6 +497,9 @@ int main_utf8(int argc, char** argv)

printf("FST entries: %u\n", entries);

char* dst_dir = ((argc <= 2) || is_file(argv[2])) ? argv[1] : argv[2];
printf("Extracting to directory: '%s'\n", dst_dir);
create_path(dst_dir);
char path[PATH_MAX] = { 0 };
uint32_t entry[16];
uint32_t l_entry[16];
Expand All @@ -519,7 +522,7 @@ int main_utf8(int argc, char** argv)
} else {
uint32_t offset;
memset(path, 0, sizeof(path));
strcpy(path, argv[1]);
strcpy(path, dst_dir);

size_t short_path = strlen(path) + 1;
for (uint32_t j = 0; j < level; j++) {
Expand Down
2 changes: 1 addition & 1 deletion util.c
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ bool is_directory(const char* path)

char* change_extension(const char* path, const char* extension)
{
static char new_path[256];
static char new_path[PATH_MAX];
strncpy(new_path, basename((char*)path), sizeof(new_path) - 1);
for (size_t i = 0; i < sizeof(new_path); i++) {
if (new_path[i] == '.')
Expand Down

0 comments on commit d986668

Please sign in to comment.