mirror of
https://github.com/wiiu-env/homebrew_on_menu_plugin.git
synced 2024-11-29 05:24:24 +01:00
Improve logging
This commit is contained in:
parent
cf955172f8
commit
87ee4aa3ca
@ -12,77 +12,77 @@ fileReadInformation gFileReadInformation[FILE_READ_INFO_SIZE] __attribute__((sec
|
|||||||
int readFile(int slot, uint8_t *buffer, uint32_t size) {
|
int readFile(int slot, uint8_t *buffer, uint32_t size) {
|
||||||
fileReadInformation *info = &gFileReadInformation[slot];
|
fileReadInformation *info = &gFileReadInformation[slot];
|
||||||
if (!info->compressed) {
|
if (!info->compressed) {
|
||||||
//DEBUG_FUNCTION_LINE("non compressed\n");
|
//DEBUG_FUNCTION_LINE("non compressed");
|
||||||
return read(info->fd, buffer, size);
|
return read(info->fd, buffer, size);
|
||||||
} else {
|
} else {
|
||||||
int startValue = info->strm.total_out;
|
int startValue = info->strm.total_out;
|
||||||
uint32_t newSize = 0;
|
uint32_t newSize = 0;
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
//DEBUG_FUNCTION_LINE("We want to read %d\n", size);
|
//DEBUG_FUNCTION_LINE("We want to read %d", size);
|
||||||
//DEBUG_FUNCTION_LINE("startValue %d \n",startValue);
|
//DEBUG_FUNCTION_LINE("startValue %d ",startValue);
|
||||||
do {
|
do {
|
||||||
int CHUNK = 0x1000;
|
int CHUNK = 0x1000;
|
||||||
uint32_t nextOut = CHUNK;
|
uint32_t nextOut = CHUNK;
|
||||||
if (nextOut > size) {
|
if (nextOut > size) {
|
||||||
nextOut = size;
|
nextOut = size;
|
||||||
}
|
}
|
||||||
//DEBUG_FUNCTION_LINE("nextOut = %d\n",nextOut);
|
//DEBUG_FUNCTION_LINE("nextOut = %d",nextOut);
|
||||||
if (info->strm.avail_in == 0) {
|
if (info->strm.avail_in == 0) {
|
||||||
//DEBUG_FUNCTION_LINE("Reading %d from compressed stream\n",CHUNK);
|
//DEBUG_FUNCTION_LINE("Reading %d from compressed stream",CHUNK);
|
||||||
info->strm.avail_in = read(info->fd, info->in, CHUNK);
|
info->strm.avail_in = read(info->fd, info->in, CHUNK);
|
||||||
if (info->strm.avail_in == 0) {
|
if (info->strm.avail_in == 0) {
|
||||||
DEBUG_FUNCTION_LINE("strm.avail_in is 0\n");
|
DEBUG_FUNCTION_LINE("strm.avail_in is 0");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
info->strm.next_in = info->in;
|
info->strm.next_in = info->in;
|
||||||
}
|
}
|
||||||
//DEBUG_FUNCTION_LINE("info->strm.avail_in = %d\n",info->strm.avail_in);
|
//DEBUG_FUNCTION_LINE("info->strm.avail_in = %d",info->strm.avail_in);
|
||||||
//DEBUG_FUNCTION_LINE("info->strm.next_in = %d\n",info->strm.next_in);
|
//DEBUG_FUNCTION_LINE("info->strm.next_in = %d",info->strm.next_in);
|
||||||
|
|
||||||
/* run inflate() on input until output buffer not full */
|
/* run inflate() on input until output buffer not full */
|
||||||
do {
|
do {
|
||||||
//DEBUG_FUNCTION_LINE("newSize %d, size %d, info->strm.avail_out %d\n", newSize, size, info->strm.avail_out);
|
//DEBUG_FUNCTION_LINE("newSize %d, size %d, info->strm.avail_out %d", newSize, size, info->strm.avail_out);
|
||||||
|
|
||||||
if (nextOut > size - newSize) {
|
if (nextOut > size - newSize) {
|
||||||
nextOut = size - newSize;
|
nextOut = size - newSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
info->strm.avail_out = nextOut;
|
info->strm.avail_out = nextOut;
|
||||||
//DEBUG_FUNCTION_LINE("info->strm.avail_out = %d\n",info->strm.avail_out);
|
//DEBUG_FUNCTION_LINE("info->strm.avail_out = %d",info->strm.avail_out);
|
||||||
info->strm.next_out = (buffer + newSize);
|
info->strm.next_out = (buffer + newSize);
|
||||||
//DEBUG_FUNCTION_LINE("info->strm.next_out = %08X\n",info->strm.next_out);
|
//DEBUG_FUNCTION_LINE("info->strm.next_out = %08X",info->strm.next_out);
|
||||||
ret = inflate(&info->strm, Z_NO_FLUSH);
|
ret = inflate(&info->strm, Z_NO_FLUSH);
|
||||||
//DEBUG_FUNCTION_LINE("ret = %d\n",ret);
|
//DEBUG_FUNCTION_LINE("ret = %d",ret);
|
||||||
if (ret == Z_STREAM_ERROR) {
|
if (ret == Z_STREAM_ERROR) {
|
||||||
DEBUG_FUNCTION_LINE("Z_STREAM_ERROR\n");
|
DEBUG_FUNCTION_LINE("Z_STREAM_ERROR");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (ret) {
|
switch (ret) {
|
||||||
case Z_NEED_DICT:
|
case Z_NEED_DICT:
|
||||||
DEBUG_FUNCTION_LINE("Z_NEED_DICT\n");
|
DEBUG_FUNCTION_LINE("Z_NEED_DICT");
|
||||||
ret = Z_DATA_ERROR; /* and fall through */
|
ret = Z_DATA_ERROR; /* and fall through */
|
||||||
case Z_DATA_ERROR:
|
case Z_DATA_ERROR:
|
||||||
case Z_MEM_ERROR:
|
case Z_MEM_ERROR:
|
||||||
DEBUG_FUNCTION_LINE("Z_MEM_ERROR or Z_DATA_ERROR\n");
|
DEBUG_FUNCTION_LINE("Z_MEM_ERROR or Z_DATA_ERROR");
|
||||||
(void) inflateEnd(&info->strm);
|
(void) inflateEnd(&info->strm);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
//int canBeWritten = CHUNK - info->strm.avail_out;
|
//int canBeWritten = CHUNK - info->strm.avail_out;
|
||||||
//DEBUG_FUNCTION_LINE("canBeWritten = %d\n",canBeWritten);
|
//DEBUG_FUNCTION_LINE("canBeWritten = %d",canBeWritten);
|
||||||
|
|
||||||
newSize = info->strm.total_out - startValue;
|
newSize = info->strm.total_out - startValue;
|
||||||
if (newSize == size) {
|
if (newSize == size) {
|
||||||
//DEBUG_FUNCTION_LINE("newSize was as wanted %d\n", newSize);
|
//DEBUG_FUNCTION_LINE("newSize was as wanted %d", newSize);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
nextOut = CHUNK;
|
nextOut = CHUNK;
|
||||||
if (newSize + nextOut >= (size)) {
|
if (newSize + nextOut >= (size)) {
|
||||||
nextOut = (size) - newSize;
|
nextOut = (size) - newSize;
|
||||||
}
|
}
|
||||||
//DEBUG_FUNCTION_LINE("newSize = %d\n",newSize);
|
//DEBUG_FUNCTION_LINE("newSize = %d",newSize);
|
||||||
//DEBUG_FUNCTION_LINE("nextOut = %d\n",nextOut);
|
//DEBUG_FUNCTION_LINE("nextOut = %d",nextOut);
|
||||||
} while (info->strm.avail_out == 0 && newSize < (size));
|
} while (info->strm.avail_out == 0 && newSize < (size));
|
||||||
|
|
||||||
/* done when inflate() says it's done */
|
/* done when inflate() says it's done */
|
||||||
@ -142,7 +142,7 @@ bool initCompressedFileReadInformation(fileReadInformation *info) {
|
|||||||
info->strm.next_in = Z_NULL;
|
info->strm.next_in = Z_NULL;
|
||||||
int ret = inflateInit2(&info->strm, MAX_WBITS | 16); //gzip
|
int ret = inflateInit2(&info->strm, MAX_WBITS | 16); //gzip
|
||||||
if (ret != Z_OK) {
|
if (ret != Z_OK) {
|
||||||
DEBUG_FUNCTION_LINE("ret != Z_OK\n");
|
DEBUG_FUNCTION_LINE("ret != Z_OK");
|
||||||
info->cInitDone = false;
|
info->cInitDone = false;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -154,7 +154,7 @@ bool initCompressedFileReadInformation(fileReadInformation *info) {
|
|||||||
int32_t loadFileIntoBuffer(uint32_t lowerTitleID, const char *filepath, char *buffer, int sizeToRead) {
|
int32_t loadFileIntoBuffer(uint32_t lowerTitleID, const char *filepath, char *buffer, int sizeToRead) {
|
||||||
int32_t id = getIDByLowerTitleID(lowerTitleID);
|
int32_t id = getIDByLowerTitleID(lowerTitleID);
|
||||||
if (id < 0) {
|
if (id < 0) {
|
||||||
DEBUG_FUNCTION_LINE("Failed to get id by titleid\n");
|
DEBUG_FUNCTION_LINE("Failed to get id by titleid");
|
||||||
return -3;
|
return -3;
|
||||||
}
|
}
|
||||||
if (!mountRomfs(id)) {
|
if (!mountRomfs(id)) {
|
||||||
@ -168,15 +168,15 @@ int32_t loadFileIntoBuffer(uint32_t lowerTitleID, const char *filepath, char *bu
|
|||||||
int32_t fd = (handle & 0x00000FFF);
|
int32_t fd = (handle & 0x00000FFF);
|
||||||
int32_t romid = (handle & 0x00FFF000) >> 12;
|
int32_t romid = (handle & 0x00FFF000) >> 12;
|
||||||
|
|
||||||
DEBUG_FUNCTION_LINE("READ %d from %d rom: %d\n", sizeToRead, fd, romid);
|
DEBUG_FUNCTION_LINE("READ %d from %d rom: %d", sizeToRead, fd, romid);
|
||||||
|
|
||||||
int readSize = readFile(fd, (uint8_t *) buffer, (sizeToRead));
|
int readSize = readFile(fd, (uint8_t *) buffer, (sizeToRead));
|
||||||
|
|
||||||
DEBUG_FUNCTION_LINE("Close %d %d\n", fd, romid);
|
DEBUG_FUNCTION_LINE("Close %d %d", fd, romid);
|
||||||
DeInitFile(fd);
|
DeInitFile(fd);
|
||||||
if (gFileInfos[romid].openedFiles--) {
|
if (gFileInfos[romid].openedFiles--) {
|
||||||
if (gFileInfos[romid].openedFiles <= 0) {
|
if (gFileInfos[romid].openedFiles <= 0) {
|
||||||
DEBUG_FUNCTION_LINE("unmount romfs no more handles\n");
|
DEBUG_FUNCTION_LINE("unmount romfs no more handles");
|
||||||
unmountRomfs(romid);
|
unmountRomfs(romid);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -221,10 +221,10 @@ int32_t FSOpenFile_for_ID(uint32_t id, const char *filepath, int *handle) {
|
|||||||
|
|
||||||
int fd = open(buffer, 0);
|
int fd = open(buffer, 0);
|
||||||
if (fd >= 0) {
|
if (fd >= 0) {
|
||||||
DEBUG_FUNCTION_LINE("Opened %s from %s \n", buffer, romName);
|
DEBUG_FUNCTION_LINE("Opened %s from %s ", buffer, romName);
|
||||||
int slot = fileReadInformation_getSlot();
|
int slot = fileReadInformation_getSlot();
|
||||||
if (slot < 0) {
|
if (slot < 0) {
|
||||||
DEBUG_FUNCTION_LINE("Failed to get a slot\n");
|
DEBUG_FUNCTION_LINE("Failed to get a slot");
|
||||||
return -5;
|
return -5;
|
||||||
}
|
}
|
||||||
fileReadInformation *info = &gFileReadInformation[slot];
|
fileReadInformation *info = &gFileReadInformation[slot];
|
||||||
@ -232,7 +232,7 @@ int32_t FSOpenFile_for_ID(uint32_t id, const char *filepath, int *handle) {
|
|||||||
if (!nonCompressed) {
|
if (!nonCompressed) {
|
||||||
info->compressed = true;
|
info->compressed = true;
|
||||||
initCompressedFileReadInformation(info);
|
initCompressedFileReadInformation(info);
|
||||||
DEBUG_FUNCTION_LINE("Init compressed, got slot %d\n", slot);
|
DEBUG_FUNCTION_LINE("Init compressed, got slot %d", slot);
|
||||||
} else {
|
} else {
|
||||||
info->cInitDone = true;
|
info->cInitDone = true;
|
||||||
}
|
}
|
||||||
|
@ -22,9 +22,9 @@ void unmountRomfs(uint32_t id) {
|
|||||||
if (gFileInfos[id].romfsMounted) {
|
if (gFileInfos[id].romfsMounted) {
|
||||||
char romName[10];
|
char romName[10];
|
||||||
snprintf(romName, 10, "%08X", id);
|
snprintf(romName, 10, "%08X", id);
|
||||||
DEBUG_FUNCTION_LINE("Unmounting %s\n", romName);
|
DEBUG_FUNCTION_LINE("Unmounting %s", romName);
|
||||||
int res = romfsUnmount(romName);
|
int res = romfsUnmount(romName);
|
||||||
DEBUG_FUNCTION_LINE("res: %d\n", res);
|
DEBUG_FUNCTION_LINE("res: %d", res);
|
||||||
gFileInfos[id].romfsMounted = false;
|
gFileInfos[id].romfsMounted = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -37,7 +37,7 @@ void unmountAllRomfs() {
|
|||||||
|
|
||||||
bool mountRomfs(uint32_t id) {
|
bool mountRomfs(uint32_t id) {
|
||||||
if (id >= FILE_INFO_SIZE) {
|
if (id >= FILE_INFO_SIZE) {
|
||||||
DEBUG_FUNCTION_LINE("HANDLE WAS TOO BIG %d\n", id);
|
DEBUG_FUNCTION_LINE("HANDLE WAS TOO BIG %d", id);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (!gFileInfos[id].romfsMounted) {
|
if (!gFileInfos[id].romfsMounted) {
|
||||||
@ -45,13 +45,13 @@ bool mountRomfs(uint32_t id) {
|
|||||||
snprintf(buffer, 256, "fs:/vol/external01/%s", gFileInfos[id].path);
|
snprintf(buffer, 256, "fs:/vol/external01/%s", gFileInfos[id].path);
|
||||||
char romName[10];
|
char romName[10];
|
||||||
snprintf(romName, 10, "%08X", id);
|
snprintf(romName, 10, "%08X", id);
|
||||||
DEBUG_FUNCTION_LINE("Mount %s as %s\n", buffer, romName);
|
DEBUG_FUNCTION_LINE("Mount %s as %s", buffer, romName);
|
||||||
if (romfsMount(romName, buffer) == 0) {
|
if (romfsMount(romName, buffer) == 0) {
|
||||||
DEBUG_FUNCTION_LINE("Mounted successfully \n");
|
DEBUG_FUNCTION_LINE("Mounted successfully ");
|
||||||
gFileInfos[id].romfsMounted = true;
|
gFileInfos[id].romfsMounted = true;
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
DEBUG_FUNCTION_LINE("Mounting failed\n");
|
DEBUG_FUNCTION_LINE("Mounting failed");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user