mirror of
https://github.com/RaySollium99/picodrive.git
synced 2025-09-05 15:27:46 -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
|
* bin_to_cso_mp3
|
||||||
* originally written by Exophase as "bin_to_iso_ogg"
|
* originally written by Exophase as "bin_to_iso_ogg"
|
||||||
* updated for cso/mp3 by notaz
|
* updated for cso/mp3 by notaz
|
||||||
|
* v2
|
||||||
*/
|
*/
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include <ctype.h>
|
||||||
|
|
||||||
#ifndef MAX_PATH
|
#ifndef MAX_PATH
|
||||||
#define MAX_PATH 1024
|
#define MAX_PATH 1024
|
||||||
|
@ -100,12 +102,28 @@ static void myexit(int code)
|
||||||
|
|
||||||
char *skip_whitespace(char *str)
|
char *skip_whitespace(char *str)
|
||||||
{
|
{
|
||||||
while(*str == ' ')
|
while (isspace(*str))
|
||||||
str++;
|
str++;
|
||||||
|
|
||||||
return 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)
|
s32 load_bin_cue(char *cue_file_name)
|
||||||
{
|
{
|
||||||
FILE *cue_file = fopen(cue_file_name, "rb");
|
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[256];
|
||||||
char *line_buffer_ptr;
|
char *line_buffer_ptr;
|
||||||
|
char *tmp;
|
||||||
|
|
||||||
char bin_file_name[MAX_PATH];
|
char bin_file_name[MAX_PATH];
|
||||||
char *separator_pos;
|
char *separator_pos;
|
||||||
|
@ -129,11 +148,31 @@ s32 load_bin_cue(char *cue_file_name)
|
||||||
u32 i;
|
u32 i;
|
||||||
|
|
||||||
// First, get filename. Only support binary right now.
|
// First, get filename. Only support binary right now.
|
||||||
fgets(line_buffer, 255, cue_file);
|
tmp = fgets(line_buffer, 255, cue_file);
|
||||||
|
if (tmp == NULL) goto invalid;
|
||||||
strcpy(bin_file_name, strchr(line_buffer, '"') + 1);
|
separator_pos = line_buffer + strlen(line_buffer) - 1;
|
||||||
|
separator_pos = skip_whitespace_rev(separator_pos);
|
||||||
*(strrchr(bin_file_name, '"')) = 0;
|
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.
|
// Might have to change directory first.
|
||||||
separator_pos = strrchr(cue_file_name, DIR_SEPARATOR_CHAR);
|
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");
|
cd_bin.bin_file = fopen(bin_file_name, "rb");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
printf("loaded bin file %s (%p)\n", bin_file_name, cd_bin.bin_file);
|
|
||||||
|
|
||||||
*separator_pos = DIR_SEPARATOR_CHAR;
|
*separator_pos = DIR_SEPARATOR_CHAR;
|
||||||
chdir(current_dir);
|
chdir(current_dir);
|
||||||
}
|
}
|
||||||
|
@ -167,6 +204,16 @@ s32 load_bin_cue(char *cue_file_name)
|
||||||
#endif
|
#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++)
|
for(i = 0; i < 100; i++)
|
||||||
{
|
{
|
||||||
cd_bin.logical_tracks[i] = NULL;
|
cd_bin.logical_tracks[i] = NULL;
|
||||||
|
@ -338,6 +385,9 @@ s32 load_bin_cue(char *cue_file_name)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return -1;
|
||||||
|
invalid:
|
||||||
|
printf("error: invalid/unsupported .cue file\n");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -600,9 +650,9 @@ s32 convert_bin_cue(char *output_name_base)
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
static void update_path(void)
|
static void update_path(void)
|
||||||
{
|
{
|
||||||
char buff1[MAX_PATH], buff2[MAX_PATH];
|
char buff1[MAX_PATH*4], *buff2;
|
||||||
char *path;
|
char *path;
|
||||||
int i;
|
int size, i;
|
||||||
|
|
||||||
path = getenv("PATH");
|
path = getenv("PATH");
|
||||||
GetModuleFileNameA(NULL, buff1, sizeof(buff1));
|
GetModuleFileNameA(NULL, buff1, sizeof(buff1));
|
||||||
|
@ -610,8 +660,13 @@ static void update_path(void)
|
||||||
if (buff1[i] == '\\') break;
|
if (buff1[i] == '\\') break;
|
||||||
buff1[i] = 0;
|
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);
|
SetEnvironmentVariableA("PATH", buff2);
|
||||||
|
free(buff2);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
Binary file not shown.
Loading…
Add table
Add a link
Reference in a new issue