diff --git a/samples/Makefile b/samples/Makefile index 22fbb39b990..6d3776ad60d 100644 --- a/samples/Makefile +++ b/samples/Makefile @@ -23,6 +23,7 @@ release-samples: $(MKDIR) -p $(SHARE_TARGET) cp -f Makefile_sample $(SAMPLES_TARGET)/Makefile cp -f Makefile.pref_sample $(SAMPLES_TARGET)/Makefile.pref + cp -f Makefile.ioprp_sample $(SAMPLES_TARGET)/Makefile.ioprp cp -f Makefile.eeglobal_sample $(SAMPLES_TARGET)/Makefile.eeglobal cp -f Makefile.eeglobal_cpp_sample $(SAMPLES_TARGET)/Makefile.eeglobal_cpp cp -f Makefile.iopglobal_sample $(SAMPLES_TARGET)/Makefile.iopglobal diff --git a/samples/Makefile.eeglobal_sample b/samples/Makefile.eeglobal_sample index 05babd11031..7ebd40dbe49 100644 --- a/samples/Makefile.eeglobal_sample +++ b/samples/Makefile.eeglobal_sample @@ -92,12 +92,3 @@ $(EE_ERL): $(EE_OBJS) $(EE_LIB): $(EE_OBJS) $(DIR_GUARD) $(EE_AR) cru $(EE_LIB) $(EE_OBJS) - -$(IOPRP_BIN): $(IOPRP_CONTENTS) -ifeq (_$(IOPRP_CONTENTS)_,__) - $(error Cannot generate IOPRP if 'IOPRP_CONTENTS' variable is empty) -else - $(DIR_GUARD) - romimg -c $@ $< -endif - diff --git a/samples/Makefile.ioprp_sample b/samples/Makefile.ioprp_sample new file mode 100644 index 00000000000..0084dea6902 --- /dev/null +++ b/samples/Makefile.ioprp_sample @@ -0,0 +1,15 @@ +# _____ ___ ____ ___ ____ +# ____| | ____| | | |____| +# | ___| |____ ___| ____| | \ PS2DEV Open Source Project. +#----------------------------------------------------------------------- +# Copyright ps2dev - http://www.ps2dev.org +# Licenced under Academic Free License version 2.0 +# Review ps2sdk README & LICENSE files for further details. + +$(IOPRP_BIN): $(IOPRP_CONTENTS) +ifeq (_$(IOPRP_CONTENTS)_,__) + $(error Cannot generate IOPRP if 'IOPRP_CONTENTS' variable is empty) +else + $(DIR_GUARD) + romimg -C $@ $< +endif diff --git a/tools/romimg/src/main.c b/tools/romimg/src/main.c index d60e6086178..ef724899d6a 100644 --- a/tools/romimg/src/main.c +++ b/tools/romimg/src/main.c @@ -7,6 +7,7 @@ #include #include #include +#include #include "romimg.h" @@ -34,13 +35,15 @@ static void DisplayROMImgDetails(const ROMIMG *ROMImg) static void DisplaySyntaxHelp(void) { - printf(REDBOLD"Syntax error"DEFCOL". Syntax:\n" - "ROMIMG -c \n\tCreate ROM image\n" + printf("Syntax:\n" + "ROMIMG -c \n\tCreate ROM image *\n" "ROMIMG -l \n\tList files in ROM image\n" - "ROMIMG -a \n\tAdd file(s) to ROM image\n" + "ROMIMG -a \n\tAdd file(s) to ROM image *\n" "ROMIMG -d \n\tDelete file(s) from ROM image\n" "ROMIMG -x \n\tExtract all files from ROM image\n" - "ROMIMG -x \n\tExtract file from ROM image\n"); + "ROMIMG -x \n\tExtract file from ROM image\n" + "\n note*: write the switch in uppercase to perform filename transformation (eg: 'ioman.irx' > 'IOMAN')\n" + ); } static void DisplayAddDeleteOperationResult(int result, const char *InvolvedFile) @@ -80,31 +83,30 @@ int main(int argc, char **argv) if (argc < 2) { DisplaySyntaxHelp(); - DPRINTF("ERROR: LESS THAN TWO ARGS PROVIDED\n"); return EINVAL; } - if (argc >= 4 && strcmp(argv[1], "-c") == 0) { + if (argc >= 4 && strcasecmp(argv[1], "-c") == 0) { if ((result = CreateBlankROMImg(argv[2], &ROMImg)) == 0) { for (FilesAffected = 0, i = 0; i < argc - 3; i++) { printf("Adding file '%s'", argv[3 + i]); - if ((result = AddFile(&ROMImg, argv[3 + i])) == 0) + if ((result = AddFile(&ROMImg, argv[3 + i], isupper(argv[1][1]))) == 0) FilesAffected++; printf(result == 0 ? GRNBOLD" done!"DEFCOL"\n" : REDBOLD" failed!"DEFCOL"\n"); } if (FilesAffected > 0) { - printf("Writing image..."); + printf("Writing image... "); printf("%s", (result = WriteROMImg(argv[2], &ROMImg)) == 0 ? GRNBOLD"done!"DEFCOL"\n" : REDBOLD"failed!"DEFCOL"\n"); } UnloadROMImg(&ROMImg); } else - ERROR("(Internal fault) Can't create blank image file: %d. Please report.\n", result); - } else if (argc >= 4 && strcmp(argv[1], "-a") == 0) { + ERROR("(Internal fault) Can't create blank image file: %d (%s). Please report.\n", result, strerror(result)); + } else if (argc >= 4 && strcasecmp(argv[1], "-a") == 0) { if ((result = LoadROMImg(&ROMImg, argv[2])) == 0) { for (i = 0, FilesAffected = 0; i < argc - 3; i++) { printf("Adding file '%s'", argv[3 + i]); - if ((result = AddFile(&ROMImg, argv[3 + i])) == 0) + if ((result = AddFile(&ROMImg, argv[3 + i], isupper(argv[1][1]))) == 0) FilesAffected++; DisplayAddDeleteOperationResult(result, argv[3 + i]); } diff --git a/tools/romimg/src/platform.c b/tools/romimg/src/platform.c index 965c38f680f..14e4a6c6c16 100644 --- a/tools/romimg/src/platform.c +++ b/tools/romimg/src/platform.c @@ -4,6 +4,7 @@ #include #include +#include #include "dprintf.h" #if defined(_WIN32) || defined(WIN32) #include @@ -114,3 +115,12 @@ int GetCurrentWorkingDirectory(char *buffer, unsigned int BufferSize) return EIO; #endif } + +void upperbuff(char *temp) +{ + char *s = temp; + while (*s) { + *s = toupper((unsigned char) *s); + s++; + } +} diff --git a/tools/romimg/src/platform.h b/tools/romimg/src/platform.h index f277fb5ba16..9d9a5970767 100644 --- a/tools/romimg/src/platform.h +++ b/tools/romimg/src/platform.h @@ -6,6 +6,7 @@ int GetLocalhostName(char *buffer, unsigned int BufferSize); unsigned int GetSystemDate(void); unsigned int GetFileCreationDate(const char *path); int GetCurrentWorkingDirectory(char *buffer, unsigned int BufferSize); +void upperbuff(char *temp); #if defined(_WIN32) || defined(WIN32) #define PATHSEP '\\' @@ -13,4 +14,4 @@ int GetCurrentWorkingDirectory(char *buffer, unsigned int BufferSize); #define PATHSEP '/' #endif -#endif /* __PLATFORM_H__ */ \ No newline at end of file +#endif /* __PLATFORM_H__ */ diff --git a/tools/romimg/src/romimg.c b/tools/romimg/src/romimg.c index 1bed3a35be1..90eda8b2099 100644 --- a/tools/romimg/src/romimg.c +++ b/tools/romimg/src/romimg.c @@ -6,11 +6,15 @@ #include #include #include +#include +#include #include "platform.h" #include "romimg.h" #include "SonyRX.h" +#define IMAGE_COMMENT_BASESIZE 31 + struct ROMImgStat { void *image; @@ -139,12 +143,7 @@ static int GetExtInfoStat(const struct ROMImgStat *ImageStat, struct RomDirFileF int CreateBlankROMImg(const char *filename, ROMIMG *ROMImg) { unsigned int CommentLength; - char LocalhostName[32], cwd[128]; -#if defined(_WIN32) || defined(WIN32) - char UserName[32] = ""; -#else - char* UserName; -#endif + char LocalhostName[32] = {0}, cwd[PATH_MAX] = {0}, UserName[32] = {0}; struct FileEntry *ResetFile; struct ExtInfoFieldEntry *ExtInfoEntry; @@ -154,14 +153,15 @@ int CreateBlankROMImg(const char *filename, ROMIMG *ROMImg) #if defined(_WIN32) || defined(WIN32) GetUsername(UserName, sizeof(UserName)); #else - UserName = getenv("USER"); + getlogin_r(UserName, sizeof(UserName)); #endif GetLocalhostName(LocalhostName, sizeof(LocalhostName)); GetCurrentWorkingDirectory(cwd, sizeof(cwd)); /* Comment format: YYYYMMDD-XXXYYY,conffile,,@/ */ - CommentLength = 31 + strlen(filename) + strlen(UserName) + strlen(LocalhostName) + strlen(cwd); - ROMImg->comment = (char *)malloc(CommentLength); - sprintf(ROMImg->comment, "%08x,conffile,%s,%s@%s/%s", ROMImg->date, filename, (UserName[0] =='\0')?"":UserName, LocalhostName, cwd); + CommentLength = IMAGE_COMMENT_BASESIZE + strlen(filename) + sizeof(LocalhostName) + sizeof(UserName) + sizeof(cwd); + ROMImg->comment = (char *)malloc( CommentLength+1); + if (!ROMImg->comment) return ENOMEM; + snprintf(ROMImg->comment, CommentLength, "%08x,conffile,%s,%s@%s/%s", ROMImg->date, filename, UserName, LocalhostName, cwd); // Create a blank RESET file. ROMImg->NumFiles = 1; @@ -452,8 +452,9 @@ static int AddExtInfoStat(struct FileEntry *file, unsigned char type, void *data return result; } -int AddFile(ROMIMG *ROMImg, const char *path) +int AddFile(ROMIMG *ROMImg, const char *path, int upperconv) { + char tbuf[9] = "\0"; // we dont need a large buf, this is for filling in the filename on ROMFS FILE *InputFile; int result; unsigned int FileDateStamp; @@ -461,6 +462,16 @@ int AddFile(ROMIMG *ROMImg, const char *path) if ((InputFile = fopen(path, "rb")) != NULL) { const char* fname = strrchr(path, PATHSEP); if (fname == NULL) fname = path; else fname++; + if (upperconv) { + strncpy(tbuf, fname, sizeof(tbuf)); + tbuf[sizeof(tbuf) - 1] = '\0'; + if (tbuf[0] != '\0') { + upperbuff(tbuf); + fname = tbuf; + char* T = strrchr(fname, '.'); + if (T != NULL) *T = '\0'; //null terminate extension + } + } int size; fseek(InputFile, 0, SEEK_END); size = ftell(InputFile); @@ -476,7 +487,7 @@ int AddFile(ROMIMG *ROMImg, const char *path) file = &ROMImg->files[ROMImg->NumFiles - 1]; memset(&ROMImg->files[ROMImg->NumFiles - 1], 0, sizeof(struct FileEntry)); - strncpy(file->RomDir.name, fname, sizeof(file->RomDir.name) - 1); + strncpy(file->RomDir.name, fname, sizeof(file->RomDir.name)); file->RomDir.name[sizeof(file->RomDir.name) - 1] = '\0'; file->RomDir.ExtInfoEntrySize = 0; diff --git a/tools/romimg/src/romimg.h b/tools/romimg/src/romimg.h index ad6f872e7c6..ecbabb3ec8f 100644 --- a/tools/romimg/src/romimg.h +++ b/tools/romimg/src/romimg.h @@ -68,9 +68,9 @@ int CreateBlankROMImg(const char *filename, ROMIMG *ROMImg); int WriteROMImg(const char *file, const ROMIMG *ROMImg); int LoadROMImg(ROMIMG *ROMImg, const char *path); void UnloadROMImg(ROMIMG *ROMImg); -int AddFile(ROMIMG *ROMImg, const char *path); +int AddFile(ROMIMG *ROMImg, const char *path, int upperconv); int DeleteFile(ROMIMG *ROMImg, const char *filename); int ExtractFile(const ROMIMG *ROMImg, const char *filename, const char *FileToExtract); int IsFileExists(const ROMIMG *ROMImg, const char *filename); -#endif /* __ROMING_H__ */ \ No newline at end of file +#endif /* __ROMING_H__ */