mirror of
https://github.com/RaySollium99/picodrive.git
synced 2025-09-05 07:17:45 -04:00
bin_to_cso_mp3 improved
git-svn-id: file:///home/notaz/opt/svn/PicoDrive@539 be3aeb3a-fb24-0410-a615-afba39da0efa
This commit is contained in:
parent
052c0f86cb
commit
f8a6410104
2 changed files with 66 additions and 11 deletions
|
@ -2,12 +2,14 @@
|
|||
* bin_to_cso_mp3
|
||||
* originally written by Exophase as "bin_to_iso_ogg"
|
||||
* updated for cso/mp3 by notaz
|
||||
* v2
|
||||
*/
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/stat.h>
|
||||
#include <string.h>
|
||||
#include <ctype.h>
|
||||
|
||||
#ifndef MAX_PATH
|
||||
#define MAX_PATH 1024
|
||||
|
@ -100,12 +102,28 @@ static void myexit(int code)
|
|||
|
||||
char *skip_whitespace(char *str)
|
||||
{
|
||||
while(*str == ' ')
|
||||
while (isspace(*str))
|
||||
str++;
|
||||
|
||||
return str;
|
||||
}
|
||||
|
||||
char *skip_whitespace_rev(char *str)
|
||||
{
|
||||
while (isspace(*str))
|
||||
str--;
|
||||
|
||||
return str;
|
||||
}
|
||||
|
||||
char *skip_nonspace_rev(char *str)
|
||||
{
|
||||
while (!isspace(*str))
|
||||
str--;
|
||||
|
||||
return str;
|
||||
}
|
||||
|
||||
s32 load_bin_cue(char *cue_file_name)
|
||||
{
|
||||
FILE *cue_file = fopen(cue_file_name, "rb");
|
||||
|
@ -116,6 +134,7 @@ s32 load_bin_cue(char *cue_file_name)
|
|||
{
|
||||
char line_buffer[256];
|
||||
char *line_buffer_ptr;
|
||||
char *tmp;
|
||||
|
||||
char bin_file_name[MAX_PATH];
|
||||
char *separator_pos;
|
||||
|
@ -129,11 +148,31 @@ s32 load_bin_cue(char *cue_file_name)
|
|||
u32 i;
|
||||
|
||||
// First, get filename. Only support binary right now.
|
||||
fgets(line_buffer, 255, cue_file);
|
||||
|
||||
strcpy(bin_file_name, strchr(line_buffer, '"') + 1);
|
||||
|
||||
*(strrchr(bin_file_name, '"')) = 0;
|
||||
tmp = fgets(line_buffer, 255, cue_file);
|
||||
if (tmp == NULL) goto invalid;
|
||||
separator_pos = line_buffer + strlen(line_buffer) - 1;
|
||||
separator_pos = skip_whitespace_rev(separator_pos);
|
||||
if (separator_pos <= line_buffer) goto invalid;
|
||||
separator_pos = skip_nonspace_rev(separator_pos);
|
||||
if (separator_pos <= line_buffer) goto invalid;
|
||||
separator_pos = skip_whitespace_rev(separator_pos);
|
||||
if (separator_pos <= line_buffer) goto invalid;
|
||||
// see if what's there is a quote.
|
||||
if(*separator_pos == '"')
|
||||
{
|
||||
separator_pos[0] = 0;
|
||||
separator_pos = strrchr(line_buffer, '"');
|
||||
if (separator_pos == NULL) goto invalid;
|
||||
strcpy(bin_file_name, separator_pos + 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Otherwise go to the next space.
|
||||
separator_pos[1] = 0;
|
||||
separator_pos = strrchr(line_buffer, ' ');
|
||||
if (separator_pos == NULL) goto invalid;
|
||||
strcpy(bin_file_name, separator_pos + 1);
|
||||
}
|
||||
|
||||
// Might have to change directory first.
|
||||
separator_pos = strrchr(cue_file_name, DIR_SEPARATOR_CHAR);
|
||||
|
@ -153,8 +192,6 @@ s32 load_bin_cue(char *cue_file_name)
|
|||
cd_bin.bin_file = fopen(bin_file_name, "rb");
|
||||
#endif
|
||||
|
||||
printf("loaded bin file %s (%p)\n", bin_file_name, cd_bin.bin_file);
|
||||
|
||||
*separator_pos = DIR_SEPARATOR_CHAR;
|
||||
chdir(current_dir);
|
||||
}
|
||||
|
@ -167,6 +204,16 @@ s32 load_bin_cue(char *cue_file_name)
|
|||
#endif
|
||||
}
|
||||
|
||||
if (cd_bin.bin_file == NULL)
|
||||
{
|
||||
printf("can't open bin file: \"%s\"\n", bin_file_name);
|
||||
return -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("found bin file: %s\n", bin_file_name);
|
||||
}
|
||||
|
||||
for(i = 0; i < 100; i++)
|
||||
{
|
||||
cd_bin.logical_tracks[i] = NULL;
|
||||
|
@ -338,6 +385,9 @@ s32 load_bin_cue(char *cue_file_name)
|
|||
return 0;
|
||||
}
|
||||
|
||||
return -1;
|
||||
invalid:
|
||||
printf("error: invalid/unsupported .cue file\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -600,9 +650,9 @@ s32 convert_bin_cue(char *output_name_base)
|
|||
#ifdef _WIN32
|
||||
static void update_path(void)
|
||||
{
|
||||
char buff1[MAX_PATH], buff2[MAX_PATH];
|
||||
char buff1[MAX_PATH*4], *buff2;
|
||||
char *path;
|
||||
int i;
|
||||
int size, i;
|
||||
|
||||
path = getenv("PATH");
|
||||
GetModuleFileNameA(NULL, buff1, sizeof(buff1));
|
||||
|
@ -610,8 +660,13 @@ static void update_path(void)
|
|||
if (buff1[i] == '\\') break;
|
||||
buff1[i] = 0;
|
||||
|
||||
snprintf(buff2, sizeof(buff2), "%s;%s", path, buff1);
|
||||
size = strlen(path) + strlen(buff1) + 3;
|
||||
buff2 = malloc(size);
|
||||
if (buff2 == NULL) return;
|
||||
|
||||
snprintf(buff2, size, "%s;%s", path, buff1);
|
||||
SetEnvironmentVariableA("PATH", buff2);
|
||||
free(buff2);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
|
Binary file not shown.
Loading…
Add table
Add a link
Reference in a new issue