Refactored code

This commit is contained in:
TheFloW 2018-01-03 22:37:11 +01:00
parent ed667260ae
commit 6753b26b91
15 changed files with 68 additions and 52 deletions

View File

@ -525,8 +525,9 @@ int fileListGetArchiveEntries(FileList *list, const char *path, int sort) {
FileListEntry *entry = malloc(sizeof(FileListEntry));
if (entry) {
entry->name_length = strlen(DIR_UP);
entry->name = malloc(entry->name_length + 1);
strcpy(entry->name, DIR_UP);
entry->name_length = strlen(entry->name);
entry->is_folder = 1;
entry->type = FILE_TYPE_UNKNOWN;
fileListAddEntry(list, entry, sort);
@ -539,19 +540,22 @@ int fileListGetArchiveEntries(FileList *list, const char *path, int sort) {
while (curr) {
FileListEntry *entry = malloc(sizeof(FileListEntry));
if (entry) {
strcpy(entry->name, curr->name);
entry->is_folder = curr->is_folder;
if (entry->is_folder) {
entry->name_length = strlen(curr->name) + 1;
entry->name = malloc(entry->name_length + 1);
strcpy(entry->name, curr->name);
addEndSlash(entry->name);
entry->type = FILE_TYPE_UNKNOWN;
list->folders++;
} else {
entry->name_length = strlen(curr->name);
entry->name = malloc(entry->name_length + 1);
strcpy(entry->name, curr->name);
entry->type = getFileType(entry->name);
list->files++;
}
entry->name_length = strlen(entry->name);
entry->size = curr->size;
memcpy(&entry->ctime, (SceDateTime *)&curr->ctime, sizeof(SceDateTime));

View File

@ -72,10 +72,14 @@ static int getHexdecimal(const char *str) {
}
static int getBoolean(const char *str) {
if (strcasecmp(str, "false") == 0 || strcasecmp(str, "off") == 0 || strcasecmp(str, "no") == 0)
if (strcasecmp(str, "false") == 0 ||
strcasecmp(str, "off") == 0 ||
strcasecmp(str, "no") == 0)
return 0;
if (strcasecmp(str, "true") == 0 || strcasecmp(str, "on") == 0 || strcasecmp(str, "yes") == 0)
if (strcasecmp(str, "true") == 0 ||
strcasecmp(str, "on") == 0 ||
strcasecmp(str, "yes") == 0)
return 1;
return -1;
@ -131,7 +135,7 @@ static int readEntry(const char *line, ConfigEntry *entries, int n_entries) {
char name[MAX_CONFIG_NAME_LENGTH];
int len = p - line;
if (len > MAX_CONFIG_NAME_LENGTH - 1)
len = MAX_CONFIG_NAME_LENGTH-1;
len = MAX_CONFIG_NAME_LENGTH - 1;
strncpy(name, line, len);
name[len] = '\0';

View File

@ -145,7 +145,7 @@ static int decompressGzip(uint8_t *dst, int size_dst, uint8_t *src, int size_src
z.avail_out = size_dst;
z.next_out = dst;
if (inflateInit2(&z, 15+32) != Z_OK)
if (inflateInit2(&z, 15 + 32) != Z_OK)
return -1;
if (inflate(&z, Z_FINISH) != Z_STREAM_END) {

11
elf.c
View File

@ -151,9 +151,9 @@ int checkForUnsafeImports(void *buffer) {
char *uncompressBuffer(const Elf32_Ehdr *ehdr, const Elf32_Phdr *phdr, const segment_info *segment,
const char *buffer) {
if (ehdr->e_ident[EI_MAG0] != ELFMAG0 ||
ehdr->e_ident[EI_MAG1] != ELFMAG1 ||
ehdr->e_ident[EI_MAG2] != ELFMAG2 ||
ehdr->e_ident[EI_MAG3] != ELFMAG3) {
ehdr->e_ident[EI_MAG1] != ELFMAG1 ||
ehdr->e_ident[EI_MAG2] != ELFMAG2 ||
ehdr->e_ident[EI_MAG3] != ELFMAG3) {
return NULL;
}
@ -181,7 +181,7 @@ char *uncompressBuffer(const Elf32_Ehdr *ehdr, const Elf32_Phdr *phdr, const seg
continue;
}
uLongf buf_len = size;
int ret = uncompress((Bytef*)buf, &buf_len, (const Bytef*)buffer + offset, (segment + i)->length);
int ret = uncompress((Bytef *)buf, &buf_len, (const Bytef *)buffer + offset, (segment + i)->length);
if (ret != Z_OK) {
free(out);
return NULL;
@ -189,5 +189,4 @@ char *uncompressBuffer(const Elf32_Ehdr *ehdr, const Elf32_Phdr *phdr, const seg
buf += size;
}
return out;
}
}

23
file.c
View File

@ -333,7 +333,7 @@ int copyFile(const char *src_path, const char *dst_path, FileProcessParam *param
// The destination is a subfolder of the source folder
int len = strlen(src_path);
if (strncasecmp(src_path, dst_path, len) == 0 && (dst_path[len] == '/' || dst_path[len-1] == '/')) {
if (strncasecmp(src_path, dst_path, len) == 0 && (dst_path[len] == '/' || dst_path[len - 1] == '/')) {
return -2;
}
@ -421,7 +421,7 @@ int copyPath(const char *src_path, const char *dst_path, FileProcessParam *param
// The destination is a subfolder of the source folder
int len = strlen(src_path);
if (strncasecmp(src_path, dst_path, len) == 0 && (dst_path[len] == '/' || dst_path[len-1] == '/')) {
if (strncasecmp(src_path, dst_path, len) == 0 && (dst_path[len] == '/' || dst_path[len - 1] == '/')) {
return -2;
}
@ -504,7 +504,7 @@ int movePath(const char *src_path, const char *dst_path, int flags, FileProcessP
// The destination is a subfolder of the source folder
int len = strlen(src_path);
if (strncasecmp(src_path, dst_path, len) == 0 && (dst_path[len] == '/' || dst_path[len-1] == '/')) {
if (strncasecmp(src_path, dst_path, len) == 0 && (dst_path[len] == '/' || dst_path[len - 1] == '/')) {
return -2;
}
@ -671,6 +671,8 @@ FileListEntry *fileListCopyEntry(FileListEntry *src) {
return NULL;
memcpy(dst, src, sizeof(FileListEntry));
dst->name = malloc(src->name_length + 1);
strcpy(dst->name, src->name);
return dst;
}
@ -950,8 +952,9 @@ int fileListGetDeviceEntries(FileList *list) {
if (sceIoGetstat(devices[i], &stat) >= 0) {
FileListEntry *entry = malloc(sizeof(FileListEntry));
if (entry) {
entry->name_length = strlen(devices[i]);
entry->name = malloc(entry->name_length + 1);
strcpy(entry->name, devices[i]);
entry->name_length = strlen(entry->name);
entry->is_folder = 1;
entry->type = FILE_TYPE_UNKNOWN;
@ -995,8 +998,9 @@ int fileListGetDirectoryEntries(FileList *list, const char *path, int sort) {
FileListEntry *entry = malloc(sizeof(FileListEntry));
if (entry) {
entry->name_length = strlen(DIR_UP);
entry->name = malloc(entry->name_length + 1);
strcpy(entry->name, DIR_UP);
entry->name_length = strlen(entry->name);
entry->is_folder = 1;
entry->type = FILE_TYPE_UNKNOWN;
fileListAddEntry(list, entry, sort);
@ -1012,19 +1016,22 @@ int fileListGetDirectoryEntries(FileList *list, const char *path, int sort) {
if (res > 0) {
FileListEntry *entry = malloc(sizeof(FileListEntry));
if (entry) {
strcpy(entry->name, dir.d_name);
entry->is_folder = SCE_S_ISDIR(dir.d_stat.st_mode);
if (entry->is_folder) {
entry->name_length = strlen(dir.d_name) + 1;
entry->name = malloc(entry->name_length + 1);
strcpy(entry->name, dir.d_name);
addEndSlash(entry->name);
entry->type = FILE_TYPE_UNKNOWN;
list->folders++;
} else {
entry->name_length = strlen(dir.d_name);
entry->name = malloc(entry->name_length + 1);
strcpy(entry->name, dir.d_name);
entry->type = getFileType(entry->name);
list->files++;
}
entry->name_length = strlen(entry->name);
entry->size = dir.d_stat.st_size;
memcpy(&entry->ctime, (SceDateTime *)&dir.d_stat.st_ctime, sizeof(SceDateTime));

2
file.h
View File

@ -73,7 +73,7 @@ typedef struct {
typedef struct FileListEntry {
struct FileListEntry *next;
struct FileListEntry *previous;
char name[MAX_NAME_LENGTH];
char *name;
int name_length;
int is_folder;
int type;

View File

@ -620,7 +620,7 @@ int hash_thread(SceSize args_size, HashArguments *args) {
sceMsgDialogProgressBarSetValue(SCE_MSG_DIALOG_PROGRESSBAR_TARGET_BAR_DEFAULT, 0);
sceKernelDelayThread(DIALOG_WAIT); // Needed to see the percentage
uint64_t max = (uint64_t) (getFileSize(args->file_path)/(TRANSFER_SIZE));
uint64_t max = (uint64_t)(getFileSize(args->file_path) / TRANSFER_SIZE);
// SHA1 process
uint64_t value = 0;

View File

@ -22,7 +22,7 @@
INCLUDE_EXTERN_RESOURCE(english_us_txt);
static char *lang[] ={
static char *lang[] = {
"japanese",
"english_us",
"french",

4
main.c
View File

@ -364,7 +364,7 @@ void drawShellInfo(const char *path) {
// Battery
if (sceKernelGetModel() == SCE_KERNEL_MODEL_VITA) {
float battery_x = ALIGN_RIGHT(x, vita2d_texture_get_width(battery_image));
vita2d_draw_texture(battery_image, battery_x, SHELL_MARGIN_Y+3.0f);
vita2d_draw_texture(battery_image, battery_x, SHELL_MARGIN_Y + 3.0f);
vita2d_texture *battery_bar_image = battery_bar_green_image;
@ -376,7 +376,7 @@ void drawShellInfo(const char *path) {
float width = vita2d_texture_get_width(battery_bar_image);
vita2d_draw_texture_part(battery_bar_image, battery_x + 3.0f + (1.0f - percent) * width,
SHELL_MARGIN_Y + 5.0f, (1.0f - percent) * width, 0.0f, percent*width,
SHELL_MARGIN_Y + 5.0f, (1.0f - percent) * width, 0.0f, percent * width,
vita2d_texture_get_height(battery_bar_image));
if (scePowerIsBatteryCharging()) {

View File

@ -398,7 +398,8 @@ void setContextMenuMoreVisibilities() {
char check_path[MAX_PATH_LENGTH];
do {
if (strcasecmp(file_list.path, "ux0:app/") == 0 || strcasecmp(file_list.path, "ux0:patch/") == 0) {
if (strcasecmp(file_list.path, "ux0:app/") == 0 ||
strcasecmp(file_list.path, "ux0:patch/") == 0) {
menu_more_entries[MENU_MORE_ENTRY_INSTALL_FOLDER].visibility = CTX_INVISIBLE;
break;
}
@ -559,7 +560,7 @@ static int contextMenuMainEnterCallback(int sel, void *context) {
FileListEntry *file_entry = file_list.head->next; // Ignore '..'
int i;
for (i = 0; i < file_list.length-1; i++) {
for (i = 0; i < file_list.length - 1; i++) {
fileListAddEntry(&mark_list, fileListCopyEntry(file_entry), SORT_NONE);
// Next

18
photo.c
View File

@ -81,8 +81,8 @@ static int isHorizontal(float rad) {
static void photoMode(float *zoom, float width, float height, float rad, int mode) {
int horizontal = isHorizontal(rad);
float h = (horizontal ? height : width);
float w = (horizontal ? width : height);
float h = horizontal ? height : width;
float w = horizontal ? width : height;
switch (mode) {
case MODE_CUSTOM:
@ -90,9 +90,9 @@ static void photoMode(float *zoom, float width, float height, float rad, int mod
case MODE_PERFECT: // this is only used for showing image the first time
if (h > SCREEN_HEIGHT) { // first priority, fit height
*zoom = SCREEN_HEIGHT/h;
*zoom = SCREEN_HEIGHT / h;
} else if (w > SCREEN_WIDTH) { // second priority, fit screen
*zoom = SCREEN_WIDTH/w;
*zoom = SCREEN_WIDTH / w;
} else { // otherwise, original size
*zoom = 1.0f;
}
@ -104,11 +104,11 @@ static void photoMode(float *zoom, float width, float height, float rad, int mod
break;
case MODE_FIT_HEIGHT:
*zoom = SCREEN_HEIGHT/h;
*zoom = SCREEN_HEIGHT / h;
break;
case MODE_FIT_WIDTH:
*zoom = SCREEN_WIDTH/w;
*zoom = SCREEN_WIDTH / w;
break;
}
}
@ -216,7 +216,7 @@ int photoViewer(const char *file, int type, FileList *list, FileListEntry *entry
if ((*rel_pos + 1) < list->length) {
if ((*rel_pos + 1) < MAX_POSITION) {
(*rel_pos)++;
} else if ((*base_pos+*rel_pos + 1) < list->length) {
} else if ((*base_pos + *rel_pos + 1) < list->length) {
(*base_pos)++;
}
}
@ -298,7 +298,7 @@ int photoViewer(const char *file, int type, FileList *list, FileListEntry *entry
// Move
if (pad.lx < (ANALOG_CENTER - ANALOG_SENSITIVITY) || pad.lx > (ANALOG_CENTER + ANALOG_SENSITIVITY)) {
float d = ((pad.lx-ANALOG_CENTER) / MOVE_DIVISION) / zoom;
float d = ((pad.lx - ANALOG_CENTER) / MOVE_DIVISION) / zoom;
if (isHorizontal(rad)) {
x += cosf(rad) * d;
@ -308,7 +308,7 @@ int photoViewer(const char *file, int type, FileList *list, FileListEntry *entry
}
if (pad.ly < (ANALOG_CENTER - ANALOG_SENSITIVITY) || pad.ly > (ANALOG_CENTER + ANALOG_SENSITIVITY)) {
float d = ((pad.ly-ANALOG_CENTER) / MOVE_DIVISION) / zoom;
float d = ((pad.ly - ANALOG_CENTER) / MOVE_DIVISION) / zoom;
if (isHorizontal(rad)) {
y += cosf(rad) * d;

View File

@ -433,7 +433,7 @@ void drawPropertyDialog() {
if (width >= max_width) {
if (scroll_count < 60) {
scroll_x = x;
} else if (scroll_count < width+90) {
} else if (scroll_count < width + 90) {
scroll_x--;
} else if (scroll_count < width + 120) {
color = (color & 0x00FFFFFF) | ((((color >> 24) * (scroll_count - width - 90)) / 30) << 24); // fade-in in 0.5s

2
sfo.c
View File

@ -57,7 +57,7 @@ int getSfoString(void *buffer, const char *name, char *string, int length) {
if (strcmp(buffer + header->keyofs + entries[i].nameofs, name) == 0) {
memset(string, 0, length);
strncpy(string, buffer + header->valofs + entries[i].dataofs, length);
string[length-1] = '\0';
string[length - 1] = '\0';
return 0;
}
}

View File

@ -246,7 +246,7 @@ void loadTheme() {
// Font
snprintf(path, MAX_PATH_LENGTH - 1, "ux0:VitaShell/theme/%s/font.pgf", theme_name);
font = vita2d_load_custom_pgf(path);
font = vita2d_load_custom_pgf(path);
// Load theme
for (i = 0; i < N_THEME_IMAGES; i++) {

23
utils.c
View File

@ -164,27 +164,27 @@ void readPad() {
memset(&pad, 0, sizeof(SceCtrlData));
sceCtrlPeekBufferPositive(0, &pad, 1);
if (pad.ly < ANALOG_CENTER-ANALOG_THRESHOLD) {
if (pad.ly < ANALOG_CENTER - ANALOG_THRESHOLD) {
pad.buttons |= SCE_CTRL_LEFT_ANALOG_UP;
} else if (pad.ly > ANALOG_CENTER+ANALOG_THRESHOLD) {
} else if (pad.ly > ANALOG_CENTER + ANALOG_THRESHOLD) {
pad.buttons |= SCE_CTRL_LEFT_ANALOG_DOWN;
}
if (pad.lx < ANALOG_CENTER-ANALOG_THRESHOLD) {
if (pad.lx < ANALOG_CENTER - ANALOG_THRESHOLD) {
pad.buttons |= SCE_CTRL_LEFT_ANALOG_LEFT;
} else if (pad.lx > ANALOG_CENTER+ANALOG_THRESHOLD) {
} else if (pad.lx > ANALOG_CENTER + ANALOG_THRESHOLD) {
pad.buttons |= SCE_CTRL_LEFT_ANALOG_RIGHT;
}
if (pad.ry < ANALOG_CENTER-ANALOG_THRESHOLD) {
if (pad.ry < ANALOG_CENTER - ANALOG_THRESHOLD) {
pad.buttons |= SCE_CTRL_RIGHT_ANALOG_UP;
} else if (pad.ry > ANALOG_CENTER+ANALOG_THRESHOLD) {
} else if (pad.ry > ANALOG_CENTER + ANALOG_THRESHOLD) {
pad.buttons |= SCE_CTRL_RIGHT_ANALOG_DOWN;
}
if (pad.rx < ANALOG_CENTER-ANALOG_THRESHOLD) {
if (pad.rx < ANALOG_CENTER - ANALOG_THRESHOLD) {
pad.buttons |= SCE_CTRL_RIGHT_ANALOG_LEFT;
} else if (pad.rx > ANALOG_CENTER+ANALOG_THRESHOLD) {
} else if (pad.rx > ANALOG_CENTER + ANALOG_THRESHOLD) {
pad.buttons |= SCE_CTRL_RIGHT_ANALOG_RIGHT;
}
@ -251,7 +251,8 @@ int addEndSlash(char *path) {
int len = strlen(path);
if (len < MAX_PATH_LENGTH - 2) {
if (path[len - 1] != '/') {
strcat(path, "/");
path[len] = '/';
path[len + 1] = '\0';
return 1;
}
}
@ -311,7 +312,7 @@ void getTimeString(char string[16], int time_format, SceDateTime *time) {
switch(time_format) {
case SCE_SYSTEM_PARAM_TIME_FORMAT_12HR:
snprintf(string, 16, "%02d:%02d %s", (time_local.hour > 12) ? (time_local.hour-12) : ((time_local.hour == 0) ? 12 : time_local.hour), time_local.minute, time_local.hour >= 12 ? "PM" : "AM");
snprintf(string, 16, "%02d:%02d %s", (time_local.hour > 12) ? (time_local.hour - 12) : ((time_local.hour == 0) ? 12 : time_local.hour), time_local.minute, time_local.hour >= 12 ? "PM" : "AM");
break;
case SCE_SYSTEM_PARAM_TIME_FORMAT_24HR:
@ -328,7 +329,7 @@ int debugPrintf(const char *text, ...) {
vsnprintf(string, sizeof(string), text, list);
va_end(list);
SceUID fd = sceIoOpen("tm0:vitashell_log.txt", SCE_O_WRONLY | SCE_O_CREAT | SCE_O_APPEND, 0777);
SceUID fd = sceIoOpen("ux0:data/vitashell_log.txt", SCE_O_WRONLY | SCE_O_CREAT | SCE_O_APPEND, 0777);
if (fd >= 0) {
sceIoWrite(fd, string, strlen(string));
sceIoClose(fd);