Add SFO Reader

This commit is contained in:
theorywrong 2016-09-01 13:51:27 +02:00
parent 2893fb8768
commit ae077a6515
6 changed files with 147 additions and 1 deletions

View File

@ -1,6 +1,6 @@
TITLE_ID = VITASHELL
TARGET = VitaShell
OBJS = main.o init.o io_process.o package_installer.o archive.o photo.o file.o text.o hex.o \
OBJS = main.o init.o io_process.o package_installer.o archive.o photo.o file.o text.o hex.o sfo.o \
uncommon_dialog.o message_dialog.o ime_dialog.o config.o theme.o language.o utils.o sha1.o \
audioplayer.o minizip/unzip.o minizip/ioapi.o

1
file.c
View File

@ -362,6 +362,7 @@ static ExtensionType extension_types[] = {
{ ".MP3", FILE_TYPE_MP3 },
{ ".VPK", FILE_TYPE_VPK },
{ ".ZIP", FILE_TYPE_ZIP },
{ ".SFO", FILE_TYPE_SFO },
};
int getFileType(char *file) {

1
file.h
View File

@ -37,6 +37,7 @@ enum FileTypes {
FILE_TYPE_MP3,
FILE_TYPE_VPK,
FILE_TYPE_ZIP,
FILE_TYPE_SFO,
};
enum SortFlags {

5
main.c
View File

@ -48,6 +48,7 @@
#include "language.h"
#include "utils.h"
#include "audioplayer.h"
#include "sfo.h"
int _newlib_heap_size_user = 64 * 1024 * 1024;
@ -279,6 +280,10 @@ int handleFile(char *file, FileListEntry *entry) {
case FILE_TYPE_ZIP:
res = archiveOpen(file);
break;
case FILE_TYPE_SFO:
res = SFOReader(file);
break;
default:
errorDialog(type);

112
sfo.c Normal file
View File

@ -0,0 +1,112 @@
#include "main.h"
#include "archive.h"
#include "file.h"
#include "text.h"
#include "hex.h"
#include "message_dialog.h"
#include "theme.h"
#include "language.h"
#include "utils.h"
#include "sfo.h"
int SFOReader(char* file)
{
uint8_t *buffer = malloc(BIG_BUFFER_SIZE);
if (!buffer)
return -1;
int size = 0;
if (isInArchive()) {
size = ReadArchiveFile(file, buffer, BIG_BUFFER_SIZE);
} else {
size = ReadFile(file, buffer, BIG_BUFFER_SIZE);
}
if (size <= 0) {
free(buffer);
return size;
}
sfo_header_t *sfo_header = (sfo_header_t*)buffer;
if (sfo_header->magic != 0x46535000)
{
return -1;
}
int scroll_allow = sfo_header->indexTableEntries - MAX_ENTRIES;
if (scroll_allow < 0) { scroll_allow = 0; }
int line_show = sfo_header->indexTableEntries;
if (line_show > MAX_ENTRIES) { line_show = MAX_ENTRIES; }
int current_pos = 0;
while (1)
{
readPad();
if (pressed_buttons & SCE_CTRL_CANCEL)
{
break;
}
if (hold_buttons & SCE_CTRL_UP || hold2_buttons & SCE_CTRL_LEFT_ANALOG_UP)
{
if (current_pos != 0)
{
current_pos--;
}
}
else if (hold_buttons & SCE_CTRL_DOWN || hold2_buttons & SCE_CTRL_LEFT_ANALOG_DOWN)
{
if (current_pos != scroll_allow)
{
current_pos++;
}
}
// Start drawing
startDrawing();
// Draw shell info
drawShellInfo(file);
sfo_index_t *sfo_index;
int i;
// Draw scroll bar
if (scroll_allow > 0) {
drawScrollBar(current_pos, sfo_header->indexTableEntries);
}
pgf_draw_textf(SHELL_MARGIN_X + 750, START_Y, GENERAL_COLOR, FONT_SIZE, "%d", scroll_allow);
pgf_draw_textf(SHELL_MARGIN_X + 750, START_Y + FONT_Y_SPACE, GENERAL_COLOR, FONT_SIZE, "%d", line_show);
// Faire le systéme pour baisé l'écran
for (i = 0; i < line_show; i++)
{
sfo_index = (sfo_index_t*)(buffer + sizeof(sfo_header_t) + (sizeof(sfo_index_t) * (i + current_pos)));
char* key = (char*)buffer + sfo_header->keyTableOffset + sfo_index->keyOffset;
pgf_draw_textf(SHELL_MARGIN_X, START_Y + (FONT_Y_SPACE * i), GENERAL_COLOR, FONT_SIZE, "%s", key);
if (sfo_index->param_fmt == 1028)
{
unsigned int* value = (unsigned int*)buffer + sfo_header->dataTableOffset + sfo_index->dataOffset;
pgf_draw_textf(SHELL_MARGIN_X + 450, START_Y + (FONT_Y_SPACE * i), GENERAL_COLOR, FONT_SIZE, "%d", *value);
}
else
{
char* value = (char*)buffer + sfo_header->dataTableOffset + sfo_index->dataOffset;
pgf_draw_textf(SHELL_MARGIN_X + 450, START_Y + (FONT_Y_SPACE * i), GENERAL_COLOR, FONT_SIZE, "%s", value);
}
}
// End drawing
endDrawing();
}
free(buffer);
return 0;
}

27
sfo.h Normal file
View File

@ -0,0 +1,27 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdint.h>
#include <psp2/io/stat.h>
#include <psp2/io/fcntl.h>
#include <psp2/kernel/processmgr.h>
// Struct from : http://www.vitadevwiki.com/index.php?title=System_File_Object_(SFO)_(PSF)
typedef struct{
int magic; //PSF
int version; //1.1
int keyTableOffset;
int dataTableOffset;
int indexTableEntries;
} sfo_header_t;
typedef struct{
uint16_t keyOffset; //offset of keytable + keyOffset
uint16_t param_fmt; //enum (see below)
uint32_t paramLen;
uint32_t paramMaxLen;
uint32_t dataOffset; //offset of datatable + dataOffset
} sfo_index_t;
int SFOReader(char* file);