Added silent flag to mkpsxixo
This commit is contained in:
parent
aad614833a
commit
6b14cee120
600
tools/mkpsxiso.c
600
tools/mkpsxiso.c
|
@ -1,250 +1,350 @@
|
||||||
/*
|
/*
|
||||||
* mkpsxiso
|
* mkpsxiso
|
||||||
*
|
*
|
||||||
* Converts an ISO to a .bin/.cue of a Playstation disk
|
* Converts an ISO to a .bin/.cue of a Playstation disk
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
char iso2raw_sec[16];
|
#ifndef bool
|
||||||
char iso2raw_sub[8];
|
typedef enum t_bool
|
||||||
char iso2raw_buf[2048];
|
{
|
||||||
char iso2raw_edc[4];
|
false = 0,
|
||||||
char iso2raw_ecc[276];
|
true = 1
|
||||||
|
}bool;
|
||||||
void Iso2Raw_init()
|
|
||||||
{
|
#endif // bool
|
||||||
int x;
|
|
||||||
|
char iso2raw_sec[16];
|
||||||
for(x = 0; x < 16; x++)
|
char iso2raw_sub[8];
|
||||||
iso2raw_sec[x] = 0xFF;
|
char iso2raw_buf[2048];
|
||||||
|
char iso2raw_edc[4];
|
||||||
iso2raw_sec[0] = 0;
|
char iso2raw_ecc[276];
|
||||||
iso2raw_sec[11] = 0;
|
bool silent_flag;
|
||||||
iso2raw_sec[12] = 0;
|
|
||||||
iso2raw_sec[13] = 2;
|
void Iso2Raw_init()
|
||||||
iso2raw_sec[14] = 0;
|
{
|
||||||
iso2raw_sec[15] = 2;
|
int x;
|
||||||
|
|
||||||
for(x = 0; x < 8; x++)
|
for (x = 0; x < 16; x++)
|
||||||
iso2raw_sub[x] = 0;
|
iso2raw_sec[x] = 0xFF;
|
||||||
|
|
||||||
for(x = 0; x < 4; x++)
|
iso2raw_sec[0] = 0;
|
||||||
iso2raw_edc[x] = 1;
|
iso2raw_sec[11] = 0;
|
||||||
|
iso2raw_sec[12] = 0;
|
||||||
for(x = 0; x < 276; x++)
|
iso2raw_sec[13] = 2;
|
||||||
iso2raw_ecc[x] = 2;
|
iso2raw_sec[14] = 0;
|
||||||
}
|
iso2raw_sec[15] = 2;
|
||||||
|
|
||||||
int Iso2Raw_licenseFile(char *licFile, char *binFile) {
|
for (x = 0; x < 8; x++)
|
||||||
FILE *lic, *bin;
|
iso2raw_sub[x] = 0;
|
||||||
char buffer[37632];
|
|
||||||
int sz;
|
for (x = 0; x < 4; x++)
|
||||||
int ret;
|
iso2raw_edc[x] = 1;
|
||||||
|
|
||||||
lic = fopen(licFile, "rb"); //lic = new RandomAccessFile(licFile, "r");
|
for (x = 0; x < 276; x++)
|
||||||
|
iso2raw_ecc[x] = 2;
|
||||||
if(lic == NULL)
|
}
|
||||||
{
|
|
||||||
printf("Error! Could not open license file!\n");
|
int Iso2Raw_licenseFile(char *licFile, char *binFile) {
|
||||||
ret = 0;
|
FILE *lic, *bin;
|
||||||
goto Iso2Raw_licenseFile_end;
|
char buffer[37632];
|
||||||
}
|
int sz;
|
||||||
|
int ret;
|
||||||
bin = fopen(binFile, "rb+"); //bin = new RandomAccessFile(binFile, "rw");
|
|
||||||
|
lic = fopen(licFile, "rb"); //lic = new RandomAccessFile(licFile, "r");
|
||||||
if(bin == NULL)
|
|
||||||
{
|
if (lic == NULL)
|
||||||
printf("Error! Could not open BIN file!\n");
|
{
|
||||||
fclose(lic);
|
printf("Error! Could not open license file!\n");
|
||||||
ret = 0;
|
ret = 0;
|
||||||
goto Iso2Raw_licenseFile_end;
|
goto Iso2Raw_licenseFile_end;
|
||||||
}
|
}
|
||||||
|
|
||||||
fseek(lic, 0, SEEK_END);
|
bin = fopen(binFile, "rb+"); //bin = new RandomAccessFile(binFile, "rw");
|
||||||
sz = ftell(lic);
|
|
||||||
fseek(lic, 0, SEEK_SET);
|
if (bin == NULL)
|
||||||
|
{
|
||||||
|
printf("Error! Could not open BIN file!\n");
|
||||||
if (sz != 37632)
|
fclose(lic);
|
||||||
{
|
ret = 0;
|
||||||
printf("Error! License file size mismatch. Image not licensed!\n");
|
goto Iso2Raw_licenseFile_end;
|
||||||
fclose(lic);
|
}
|
||||||
fclose(bin);
|
|
||||||
ret = 0;
|
fseek(lic, 0, SEEK_END);
|
||||||
goto Iso2Raw_licenseFile_end;
|
sz = ftell(lic);
|
||||||
}
|
fseek(lic, 0, SEEK_SET);
|
||||||
|
|
||||||
fseek(bin, 0, SEEK_END);
|
|
||||||
sz = ftell(bin);
|
if (sz != 37632)
|
||||||
fseek(bin, 0, SEEK_SET);
|
{
|
||||||
|
printf("Error! License file size mismatch. Image not licensed!\n");
|
||||||
if ((sz % 2352) != 0)
|
fclose(lic);
|
||||||
{
|
fclose(bin);
|
||||||
printf("Error! RAW image file size is not a multiple of 2352. Image not licensed!\n");
|
ret = 0;
|
||||||
fclose(lic);
|
goto Iso2Raw_licenseFile_end;
|
||||||
fclose(bin);
|
}
|
||||||
ret = 0;
|
|
||||||
goto Iso2Raw_licenseFile_end;
|
fseek(bin, 0, SEEK_END);
|
||||||
}
|
sz = ftell(bin);
|
||||||
|
fseek(bin, 0, SEEK_SET);
|
||||||
fread(buffer, sizeof(char), 37632, lic);
|
|
||||||
fwrite(buffer, sizeof(char), 37632, bin);
|
if ((sz % 2352) != 0)
|
||||||
|
{
|
||||||
fclose(lic);
|
printf("Error! RAW image file size is not a multiple of 2352. Image not licensed!\n");
|
||||||
fclose(bin);
|
fclose(lic);
|
||||||
ret = 1;
|
fclose(bin);
|
||||||
|
ret = 0;
|
||||||
Iso2Raw_licenseFile_end:
|
goto Iso2Raw_licenseFile_end;
|
||||||
if(ret == 0)
|
}
|
||||||
printf("Error licensing file! You must NOT burn the RAW image!\n");
|
|
||||||
|
fread(buffer, sizeof(char), 37632, lic);
|
||||||
return ret;
|
fwrite(buffer, sizeof(char), 37632, bin);
|
||||||
}
|
|
||||||
|
fclose(lic);
|
||||||
void Iso2Raw_generateCue(char *binFileName)
|
fclose(bin);
|
||||||
{
|
ret = 1;
|
||||||
int x, y;
|
|
||||||
char binBaseName[256];
|
Iso2Raw_licenseFile_end:
|
||||||
char cueFileName[256];
|
if (ret == 0)
|
||||||
FILE *cue_file;
|
printf("Error licensing file! You must NOT burn the RAW image!\n");
|
||||||
|
|
||||||
for(x = (strlen(binFileName) - 1); x >= 0; x--)
|
return ret;
|
||||||
{
|
}
|
||||||
if(binFileName[x] == '/' || binFileName[x] == '\\' || binFileName[x] == ':')
|
|
||||||
break;
|
void Iso2Raw_generateCue(char *binFileName)
|
||||||
}
|
{
|
||||||
|
int x, y;
|
||||||
x++;
|
char binBaseName[256];
|
||||||
y = 0;
|
char cueFileName[256];
|
||||||
|
FILE *cue_file;
|
||||||
for(; x < strlen(binFileName); x++)
|
|
||||||
binBaseName[y++] = binFileName[x];
|
for (x = (strlen(binFileName) - 1); x >= 0; x--)
|
||||||
|
{
|
||||||
binBaseName[y] = 0;
|
if (binFileName[x] == '/' || binFileName[x] == '\\' || binFileName[x] == ':')
|
||||||
|
break;
|
||||||
y = 0;
|
}
|
||||||
|
|
||||||
for(x = 0; x < strlen(binFileName); x++)
|
x++;
|
||||||
{
|
y = 0;
|
||||||
if(binFileName[x] == '.')
|
|
||||||
break;
|
for (; x < strlen(binFileName); x++)
|
||||||
else
|
binBaseName[y++] = binFileName[x];
|
||||||
cueFileName[y++] = binFileName[x];
|
|
||||||
}
|
binBaseName[y] = 0;
|
||||||
|
|
||||||
cueFileName[y] = 0;
|
y = 0;
|
||||||
|
|
||||||
strcat(cueFileName, ".cue");
|
for (x = 0; x < strlen(binFileName); x++)
|
||||||
|
{
|
||||||
cue_file = fopen(cueFileName, "wb");
|
if (binFileName[x] == '.')
|
||||||
|
break;
|
||||||
fprintf(cue_file, "FILE \"%s\" BINARY\n", binBaseName);
|
else
|
||||||
fprintf(cue_file, "TRACK 01 MODE2/2352\n");
|
cueFileName[y++] = binFileName[x];
|
||||||
fprintf(cue_file, " INDEX 01 00:00:00\n");
|
}
|
||||||
|
|
||||||
fclose(cue_file);
|
cueFileName[y] = 0;
|
||||||
}
|
|
||||||
|
strcat(cueFileName, ".cue");
|
||||||
int Iso2Raw_convert(char *isofile, char *rawfile, char *licfile)
|
|
||||||
{
|
cue_file = fopen(cueFileName, "wb");
|
||||||
FILE *infile, *outfile;
|
|
||||||
int c;
|
fprintf(cue_file, "FILE \"%s\" BINARY\n", binBaseName);
|
||||||
int thesec = 0;
|
fprintf(cue_file, "TRACK 01 MODE2/2352\n");
|
||||||
int filesize, totalsectors, sector;
|
fprintf(cue_file, " INDEX 01 00:00:00\n");
|
||||||
|
|
||||||
infile = fopen(isofile, "rb");
|
fclose(cue_file);
|
||||||
|
}
|
||||||
if(infile == NULL)
|
|
||||||
{
|
int Iso2Raw_convert(char *isofile, char *rawfile, char *licfile)
|
||||||
printf("An error has occured while trying to open file %s\n", isofile);
|
{
|
||||||
return 0;
|
FILE *infile, *outfile;
|
||||||
}
|
int c;
|
||||||
|
int thesec = 0;
|
||||||
fseek(infile, 0, SEEK_END);
|
int filesize, totalsectors, sector;
|
||||||
filesize = ftell(infile);
|
|
||||||
fseek(infile, 0, SEEK_SET);
|
infile = fopen(isofile, "rb");
|
||||||
|
|
||||||
if ((filesize % 2048) != 0)
|
if (infile == NULL)
|
||||||
{
|
{
|
||||||
printf("Error! ISO file size is not a multiple of 2048. Operation aborted!\n");
|
printf("An error has occured while trying to open file %s\n", isofile);
|
||||||
fclose(infile);
|
return 0;
|
||||||
return 0;
|
}
|
||||||
}
|
|
||||||
|
fseek(infile, 0, SEEK_END);
|
||||||
outfile = fopen(rawfile, "wb+");
|
filesize = ftell(infile);
|
||||||
fseek(outfile, 0, SEEK_SET);
|
fseek(infile, 0, SEEK_SET);
|
||||||
|
|
||||||
if(outfile == NULL)
|
if ((filesize % 2048) != 0)
|
||||||
{
|
{
|
||||||
printf("An error has occured while trying to create file %s\n", rawfile);
|
printf("Error! ISO file size is not a multiple of 2048. Operation aborted!\n");
|
||||||
fclose(infile);
|
fclose(infile);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
sector = 1;
|
outfile = fopen(rawfile, "wb+");
|
||||||
totalsectors = filesize / 2048;
|
fseek(outfile, 0, SEEK_SET);
|
||||||
for(;;)
|
|
||||||
{
|
if (outfile == NULL)
|
||||||
c = fread(iso2raw_buf, sizeof(char), 2048, infile);
|
{
|
||||||
if(c!=2048)break;
|
printf("An error has occured while trying to create file %s\n", rawfile);
|
||||||
|
fclose(infile);
|
||||||
fwrite(iso2raw_sec, sizeof(char), 16, outfile);
|
return 0;
|
||||||
fwrite(iso2raw_sub, sizeof(char), 8, outfile);
|
}
|
||||||
fwrite(iso2raw_buf, sizeof(char), 2048, outfile);
|
|
||||||
fwrite(iso2raw_edc, sizeof(char), 4, outfile);
|
sector = 1;
|
||||||
fwrite(iso2raw_ecc, sizeof(char), 276, outfile);
|
totalsectors = filesize / 2048;
|
||||||
|
for (;;)
|
||||||
thesec++;
|
{
|
||||||
|
c = fread(iso2raw_buf, sizeof(char), 2048, infile);
|
||||||
if (thesec > 74)
|
if (c!=2048)break;
|
||||||
{
|
|
||||||
thesec = 0;
|
fwrite(iso2raw_sec, sizeof(char), 16, outfile);
|
||||||
iso2raw_sec[13]++;
|
fwrite(iso2raw_sub, sizeof(char), 8, outfile);
|
||||||
}
|
fwrite(iso2raw_buf, sizeof(char), 2048, outfile);
|
||||||
|
fwrite(iso2raw_edc, sizeof(char), 4, outfile);
|
||||||
iso2raw_sec[14] = ((thesec/10)<<4)|(thesec - ((thesec/10)*10));
|
fwrite(iso2raw_ecc, sizeof(char), 276, outfile);
|
||||||
|
|
||||||
printf("\r%d%% completed...", sector * 100 / totalsectors);
|
thesec++;
|
||||||
sector++;
|
|
||||||
}
|
if (thesec > 74)
|
||||||
|
{
|
||||||
printf("\r100%% completed! \n");
|
thesec = 0;
|
||||||
|
iso2raw_sec[13]++;
|
||||||
fclose(infile);
|
}
|
||||||
fclose(outfile);
|
|
||||||
|
iso2raw_sec[14] = ((thesec/10)<<4)|(thesec - ((thesec/10)*10));
|
||||||
Iso2Raw_generateCue(rawfile);
|
|
||||||
|
if (silent_flag == false)
|
||||||
if(!Iso2Raw_licenseFile(licfile, rawfile))
|
{
|
||||||
return 0;
|
printf("\r%d%% completed...", sector * 100 / totalsectors);
|
||||||
|
}
|
||||||
return 1;
|
|
||||||
}
|
sector++;
|
||||||
|
}
|
||||||
int main(int argc, char *argv[])
|
|
||||||
{
|
if (silent_flag == false)
|
||||||
puts("mkpsxiso (C Edition) v0.1b - Converts a standard ISO image to .bin/.cue (PSX)");
|
{
|
||||||
puts("This software is based on Bruno Freitas' mkpsxiso in Java - bootsector@ig.com.br");
|
printf("\r100%% completed! \n");
|
||||||
puts("That version is in turn based on Conyers' mkpsxiso - http://www.conyers.demon.co.uk");
|
}
|
||||||
puts("Author: Giuseppe Gatta (aka nextvolume) - 01/07/2009 - tails92@gmail.com\n");
|
|
||||||
|
fclose(infile);
|
||||||
if(argc != 4)
|
fclose(outfile);
|
||||||
{
|
|
||||||
printf("Usage: mkpsxiso <iso file> <bin file> <PSX license file>\n");
|
Iso2Raw_generateCue(rawfile);
|
||||||
return 1;
|
|
||||||
}
|
if (!Iso2Raw_licenseFile(licfile, rawfile))
|
||||||
|
return 0;
|
||||||
Iso2Raw_init();
|
|
||||||
|
return 1;
|
||||||
if (!Iso2Raw_convert(argv[1], argv[2], argv[3]))
|
}
|
||||||
{
|
|
||||||
puts("ISO file conversion failed.");
|
int AddMusicTracksToCue(int track_n, char * bin_file, int bin_name_length, char * track)
|
||||||
return 1;
|
{
|
||||||
}
|
char * track_tokens = strtok(track,"=");
|
||||||
|
char * aux_tokens;
|
||||||
puts("ISO file conversion terminated successfully!!");
|
char * file_name;
|
||||||
|
FILE * out_file;
|
||||||
return 0;
|
FILE * track_file;
|
||||||
}
|
|
||||||
|
if (strncmp(track_tokens,"--track",strlen("--track") ) != 0)
|
||||||
|
{
|
||||||
|
printf("Incorrect %s parameter!\n",track_tokens);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
track_tokens = strtok(NULL,"=");
|
||||||
|
|
||||||
|
bin_file[bin_name_length - 3] = 'c';
|
||||||
|
bin_file[bin_name_length - 2] = 'u';
|
||||||
|
bin_file[bin_name_length - 1] = 'e';
|
||||||
|
|
||||||
|
out_file = fopen(bin_file,"a+");
|
||||||
|
|
||||||
|
if (out_file == NULL)
|
||||||
|
{
|
||||||
|
printf("Error opening %s .\n",bin_file);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
track_file = fopen(track_tokens,"r");
|
||||||
|
|
||||||
|
if (track_file == NULL)
|
||||||
|
{
|
||||||
|
printf("Could not open track %s!\n",track_tokens);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
fclose(track_file);
|
||||||
|
|
||||||
|
aux_tokens = strtok(track_tokens,"\\/");
|
||||||
|
|
||||||
|
while(aux_tokens != NULL)
|
||||||
|
{
|
||||||
|
file_name = aux_tokens;
|
||||||
|
aux_tokens = strtok(NULL,"\\/");
|
||||||
|
}
|
||||||
|
|
||||||
|
fprintf(out_file, "FILE \"%s\" BINARY\n", file_name);
|
||||||
|
fprintf(out_file, "TRACK %.02d AUDIO\n",track_n);
|
||||||
|
fprintf(out_file, "\tINDEX 00 00:00:00\n");
|
||||||
|
fprintf(out_file, "\tINDEX 01 00:02:00\n");
|
||||||
|
|
||||||
|
printf("Track %s added.\n",file_name);
|
||||||
|
|
||||||
|
fclose(out_file);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void showHelp(void)
|
||||||
|
{
|
||||||
|
puts("mkpsxiso (C Edition) v0.1b - Converts a standard ISO image to .bin/.cue (PSX)");
|
||||||
|
puts("Usage: mkpsxiso <iso file> <bin file> <PSX license file> [-s] [--track=path1] ... [--track=pathn]\n");
|
||||||
|
puts("This software is based on Bruno Freitas' mkpsxiso in Java - bootsector@ig.com.br");
|
||||||
|
puts("That version is in turn based on Conyers' mkpsxiso - http://www.conyers.demon.co.uk");
|
||||||
|
puts("Author: Giuseppe Gatta (aka nextvolume) - 01/07/2009 - tails92@gmail.com\n");
|
||||||
|
puts("Music track modifications by Xavier Del Campo (aka Xavi92) - 14/10/2016 - xavi.dcr@gmail.com\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(int argc, char *argv[])
|
||||||
|
{
|
||||||
|
int track_n = 2;
|
||||||
|
int i = 4;
|
||||||
|
|
||||||
|
if (argc < 4)
|
||||||
|
{
|
||||||
|
showHelp();
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
else if (argc > 4)
|
||||||
|
{
|
||||||
|
if (strcmp(argv[i], "-s") == 0)
|
||||||
|
{
|
||||||
|
silent_flag = true;
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Iso2Raw_init();
|
||||||
|
|
||||||
|
if (!Iso2Raw_convert(argv[1], argv[2], argv[3]))
|
||||||
|
{
|
||||||
|
puts("ISO file conversion failed.");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (; i < argc; i++)
|
||||||
|
{
|
||||||
|
if (AddMusicTracksToCue(track_n, argv[2], strlen(argv[2]), argv[i]) != 0)
|
||||||
|
{
|
||||||
|
// Errors are already reported by AddMusicTracksToCue().
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
track_n++;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue