Skip to content

Commit

Permalink
Allow entering paths surrounded by quotation marks
Browse files Browse the repository at this point in the history
- or spaces
  • Loading branch information
Morilli committed Jul 31, 2022
1 parent f991c27 commit a335aec
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 6 deletions.
10 changes: 4 additions & 6 deletions gui.c
Original file line number Diff line number Diff line change
Expand Up @@ -241,19 +241,17 @@ LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
case WM_COMMAND:
if (lParam && HIWORD(wParam) == BN_CLICKED) {
if ((HWND) lParam == GoButton) {
char binPath[GetWindowTextLength(BinTextBox)+1];
char audioPath[GetWindowTextLength(AudioTextBox)+1];
char eventsPath[GetWindowTextLength(EventsTextBox)+1];
GetWindowText(BinTextBox, binPath, sizeof(binPath));
GetWindowText(AudioTextBox, audioPath, sizeof(audioPath));
GetWindowText(EventsTextBox, eventsPath, sizeof(eventsPath));
char* binPath = GetPathFromTextBox(BinTextBox);
char* audioPath = GetPathFromTextBox(AudioTextBox);
char* eventsPath = GetPathFromTextBox(EventsTextBox);
bool onlyAudioGiven = *audioPath && !*binPath && !*eventsPath;
char** bnk_extract_args = onlyAudioGiven ? (char*[]) {"", "-a", audioPath, NULL} : (char*[]) {"", "-b", binPath, "-a", audioPath, "-e", eventsPath, NULL};
int duped_stderr = dup(STDERR_FILENO);
// redirect stderr to a temporary file, in order to be able to read it back and display later
FILE* temp_file = tmpfile();
dup2(fileno(temp_file), STDERR_FILENO);
WemInformation* wemInformation = bnk_extract(onlyAudioGiven ? 3 : 7, bnk_extract_args);
free(binPath); free(audioPath); free(eventsPath);
if (wemInformation) {
wemInformation->grouped_wems->wemData = (AudioData*) wemInformation->sortedWemDataList;
InsertStringToTreeview(wemInformation->grouped_wems, TVI_ROOT);
Expand Down
17 changes: 17 additions & 0 deletions utility.c
Original file line number Diff line number Diff line change
Expand Up @@ -422,3 +422,20 @@ uint8_t* WavFromOgg(ReadableBinaryData* oggData)

return rawPcmDataFromOgg;
}

char* GetPathFromTextBox(HWND textBox)
{
int text_length = GetWindowTextLength(textBox);
char* path = malloc(text_length + 1);
GetWindowText(textBox, path, text_length + 1);
char* path_start = path;
char* path_end = path + text_length;
while(*path_start == ' ' || *path_start == '"') path_start++;
while (*path_end == ' ' || *path_end == '"' || *path_end == '\0') {
*path_end = '\0';
path_end--;
}
memmove(path, path_start, path_end - path_start + 2);

return path;
}
2 changes: 2 additions & 0 deletions utility.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,6 @@ void* FillProgressBar(void* _args);

uint8_t* WavFromOgg(ReadableBinaryData* oggData);

char* GetPathFromTextBox(HWND textBox);

#endif

0 comments on commit a335aec

Please sign in to comment.