Skip to content
This repository has been archived by the owner on May 7, 2023. It is now read-only.

Commit

Permalink
Updated to v2.21
Browse files Browse the repository at this point in the history
- Reduced newlib usage to the minimum
- All settings are now saved in savedata0:
  • Loading branch information
GrapheneCt authored May 4, 2020
1 parent f1a844c commit b593d0b
Show file tree
Hide file tree
Showing 10 changed files with 85 additions and 91 deletions.
3 changes: 1 addition & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ include("${DOLCESDK}/share/dolce.cmake" REQUIRED)

set(VITA_APP_NAME "Eleven Music Player")
set(VITA_TITLEID "ELEVENMPV")
set(VITA_VERSION "02.20")
set(VITA_VERSION "02.21")

set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O3 -Wall -Werror")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
Expand Down Expand Up @@ -66,7 +66,6 @@ add_executable(${PROJECT_NAME}
source/dirbrowse.c
source/fs.c
source/main.c
source/status_bar.c
source/textures.c
source/touch.c
source/utils.c
Expand Down
44 changes: 23 additions & 21 deletions source/config.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include <psp2/kernel/clib.h>
#include <psp2/io/fcntl.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>

Expand All @@ -12,6 +12,8 @@
config_t config;
static int config_version_holder = 0;

extern void* mspace;

const char *config_file =
"config_ver = %d\n"
"metadata_flac = %d\n"
Expand All @@ -24,23 +26,23 @@ const char *config_file =
int Config_Save(config_t config) {
int ret = 0;

char *buf = malloc(128);
int len = snprintf(buf, 128, config_file, CONFIG_VERSION, config.meta_flac, config.meta_mp3, config.meta_opus, config.sort,
char *buf = sceClibMspaceMalloc(mspace, 128);
int len = sceClibSnprintf(buf, 128, config_file, CONFIG_VERSION, config.meta_flac, config.meta_mp3, config.meta_opus, config.sort,
config.alc_mode, config.device);

if (R_FAILED(ret = FS_WriteFile("ux0:data/ElevenMPV/config.cfg", buf, len))) {
free(buf);
if (R_FAILED(ret = FS_WriteFile("savedata0:config.cfg", buf, len))) {
sceClibMspaceFree(mspace, buf);
return ret;
}

free(buf);
sceClibMspaceFree(mspace, buf);
return 0;
}

int Config_Load(void) {
int ret = 0;

if (!FS_FileExists("ux0:data/ElevenMPV/config.cfg")) {
if (!FS_FileExists("savedata0:config.cfg")) {
// set these to the following by default:
config.meta_flac = SCE_FALSE;
config.meta_mp3 = SCE_TRUE;
Expand All @@ -52,22 +54,22 @@ int Config_Load(void) {
}

SceOff size = 0;
FS_GetFileSize("ux0:data/ElevenMPV/config.cfg", &size);
char *buf = malloc(size + 1);
FS_GetFileSize("savedata0:config.cfg", &size);
char *buf = sceClibMspaceMalloc(mspace, size + 1);

if (R_FAILED(ret = FS_ReadFile("ux0:data/ElevenMPV/config.cfg", buf, size))) {
free(buf);
if (R_FAILED(ret = FS_ReadFile("savedata0:config.cfg", buf, size))) {
sceClibMspaceFree(mspace, buf);
return ret;
}

buf[size] = '\0';
sscanf(buf, config_file, &config_version_holder, &config.meta_flac, &config.meta_mp3, &config.meta_opus, &config.sort,
&config.alc_mode, &config.device);
free(buf);
sceClibMspaceFree(mspace, buf);

// Delete config file if config file is updated. This will rarely happen.
if (config_version_holder < CONFIG_VERSION) {
sceIoRemove("ux0:data/ElevenMPV/config.cfg");
sceIoRemove("savedata0:config.cfg");
config.meta_flac = SCE_FALSE;
config.meta_mp3 = SCE_TRUE;
config.meta_opus = SCE_TRUE;
Expand All @@ -88,20 +90,20 @@ int Config_GetLastDirectory(void) {
"uma0:/"
};

if (!FS_FileExists("ux0:data/ElevenMPV/lastdir.txt")) {
snprintf(root_path, 8, "ux0:/");
FS_WriteFile("ux0:data/ElevenMPV/lastdir.txt", root_path, strlen(root_path) + 1);
if (!FS_FileExists("savedata0:lastdir.txt")) {
sceClibSnprintf(root_path, 8, "ux0:/");
FS_WriteFile("savedata0:lastdir.txt", root_path, strlen(root_path) + 1);
strcpy(cwd, root_path); // Set Start Path to "sdmc:/" if lastDir.txt hasn't been created.
}
else {
strcpy(root_path, root_paths[config.device]);
SceOff size = 0;

FS_GetFileSize("ux0:data/ElevenMPV/lastdir.txt", &size);
char *buf = malloc(size + 1);
FS_GetFileSize("savedata0:lastdir.txt", &size);
char *buf = sceClibMspaceMalloc(mspace, size + 1);

if (R_FAILED(ret = FS_ReadFile("ux0:data/ElevenMPV/lastdir.txt", buf, size))) {
free(buf);
if (R_FAILED(ret = FS_ReadFile("savedata0:lastdir.txt", buf, size))) {
sceClibMspaceFree(mspace, buf);
return ret;
}

Expand All @@ -114,7 +116,7 @@ int Config_GetLastDirectory(void) {
else
strcpy(cwd, root_path);

free(buf);
sceClibMspaceFree(mspace, buf);
}

return 0;
Expand Down
45 changes: 24 additions & 21 deletions source/dirbrowse.c
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#include <psp2/kernel/clib.h>
#include <psp2/io/dirent.h>
#include <psp2/io/fcntl.h>
#include <psp2/io/stat.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>

#include "common.h"
Expand All @@ -15,19 +15,22 @@

File *files = NULL;

extern void* mspace;
void* sceClibMspaceCalloc(void* space, size_t num, size_t size);

static void Dirbrowse_RecursiveFree(File *node) {
if (node == NULL) // End of list
return;

Dirbrowse_RecursiveFree(node->next); // Nest further
free(node); // Free memory
sceClibMspaceFree(mspace, node); // Free memory
}

static void Dirbrowse_SaveLastDirectory(void) {
char *buf = malloc(256);
int len = snprintf(buf, 256, "%s\n", cwd);
FS_WriteFile("ux0:data/elevenmpv/lastdir.txt", buf, len);
free(buf);
char *buf = sceClibMspaceMalloc(mspace, 256);
int len = sceClibSnprintf(buf, 256, "%s\n", cwd);
FS_WriteFile("savedata0:lastdir.txt", buf, len);
sceClibMspaceFree(mspace, buf);
}

static int cmpstringp(const void *p1, const void *p2) {
Expand Down Expand Up @@ -62,7 +65,7 @@ int Dirbrowse_PopulateFiles(SceBool refresh) {

if (R_SUCCEEDED(dir = sceIoDopen(cwd))) {
int entryCount = 0;
SceIoDirent *entries = (SceIoDirent *)calloc(MAX_FILES, sizeof(SceIoDirent));
SceIoDirent *entries = (SceIoDirent *)sceClibMspaceCalloc(mspace, MAX_FILES, sizeof(SceIoDirent));

while (sceIoDread(dir, &entries[entryCount]) > 0)
entryCount++;
Expand All @@ -72,17 +75,17 @@ int Dirbrowse_PopulateFiles(SceBool refresh) {

for (int i = -1; i < entryCount; i++) {
// Allocate Memory
File *item = (File *)malloc(sizeof(File));
memset(item, 0, sizeof(File));
File *item = (File *)sceClibMspaceMalloc(mspace, sizeof(File));
sceClibMemset(item, 0, sizeof(File));

if ((strcmp(cwd, root_path)) && (i == -1) && (!parent_dir_set)) {
if ((sceClibStrcmp(cwd, root_path)) && (i == -1) && (!parent_dir_set)) {
strcpy(item->name, "..");
item->is_dir = SCE_TRUE;
parent_dir_set = SCE_TRUE;
file_count++;
}
else {
if ((i == -1) && (!(strcmp(cwd, root_path))))
if ((i == -1) && (!(sceClibStrcmp(cwd, root_path))))
continue;

item->is_dir = SCE_S_ISDIR(entries[i].d_stat.st_mode);
Expand All @@ -108,7 +111,7 @@ int Dirbrowse_PopulateFiles(SceBool refresh) {
}
}

free(entries);
sceClibMspaceFree(mspace, entries);
}
else
return dir;
Expand All @@ -126,7 +129,7 @@ int Dirbrowse_PopulateFiles(SceBool refresh) {
void Dirbrowse_DisplayFiles(void) {
vita2d_font_draw_text(font, 102, 40 + ((72 - vita2d_font_text_height(font, 25, cwd)) / 2) + 20, RGBA8(255, 255, 255, 255), 25, cwd);

if (!(!strcmp(cwd, root_path)))
if (!(!sceClibStrcmp(cwd, root_path)))
vita2d_draw_texture(icon_back, 25, 54);

int i = 0, printed = 0;
Expand All @@ -142,14 +145,14 @@ void Dirbrowse_DisplayFiles(void) {

if (file->is_dir)
vita2d_draw_texture(icon_dir, 15, 117 + (72 * printed));
else if ((!strncasecmp(file->ext, "flac", 4)) || (!strncasecmp(file->ext, "it", 4)) || (!strncasecmp(file->ext, "mod", 4))
|| (!strncasecmp(file->ext, "mp3", 4)) || (!strncasecmp(file->ext, "ogg", 4)) || (!strncasecmp(file->ext, "opus", 4))
|| (!strncasecmp(file->ext, "s3m", 4))|| (!strncasecmp(file->ext, "wav", 4)) || (!strncasecmp(file->ext, "xm", 4)))
else if ((!sceClibStrncasecmp(file->ext, "flac", 4)) || (!sceClibStrncasecmp(file->ext, "it", 4)) || (!sceClibStrncasecmp(file->ext, "mod", 4))
|| (!sceClibStrncasecmp(file->ext, "mp3", 4)) || (!sceClibStrncasecmp(file->ext, "ogg", 4)) || (!sceClibStrncasecmp(file->ext, "opus", 4))
|| (!sceClibStrncasecmp(file->ext, "s3m", 4))|| (!sceClibStrncasecmp(file->ext, "wav", 4)) || (!sceClibStrncasecmp(file->ext, "xm", 4)))
vita2d_draw_texture(icon_audio, 15, 117 + (72 * printed));
else
vita2d_draw_texture(icon_file, 15, 117 + (72 * printed));

if (strncmp(file->name, "..", 2) == 0)
if (sceClibStrncmp(file->name, "..", 2) == 0)
vita2d_font_draw_text(font, 102, 120 + (72 / 2) + (72 * printed), RGBA8(51, 51, 51, 255), 25, "Parent folder");
else
vita2d_font_draw_text(font, 102, 120 + (72 / 2) + (72 * printed), RGBA8(51, 51, 51, 255), 25, file->name);
Expand Down Expand Up @@ -188,9 +191,9 @@ void Dirbrowse_OpenFile(void) {
Dirbrowse_PopulateFiles(SCE_TRUE);
}
}
else if ((!strncasecmp(file->ext, "flac", 4)) || (!strncasecmp(file->ext, "it", 4)) || (!strncasecmp(file->ext, "mod", 4))
|| (!strncasecmp(file->ext, "mp3", 4)) || (!strncasecmp(file->ext, "ogg", 4)) || (!strncasecmp(file->ext, "opus", 4))
|| (!strncasecmp(file->ext, "s3m", 4))|| (!strncasecmp(file->ext, "wav", 4)) || (!strncasecmp(file->ext, "xm", 4)))
else if ((!sceClibStrncasecmp(file->ext, "flac", 4)) || (!sceClibStrncasecmp(file->ext, "it", 4)) || (!sceClibStrncasecmp(file->ext, "mod", 4))
|| (!sceClibStrncasecmp(file->ext, "mp3", 4)) || (!sceClibStrncasecmp(file->ext, "ogg", 4)) || (!sceClibStrncasecmp(file->ext, "opus", 4))
|| (!sceClibStrncasecmp(file->ext, "s3m", 4))|| (!sceClibStrncasecmp(file->ext, "wav", 4)) || (!sceClibStrncasecmp(file->ext, "xm", 4)))
Menu_PlayAudio(path);
}

Expand All @@ -202,7 +205,7 @@ int Dirbrowse_Navigate(SceBool parent) {
return -1;

// Special case ".."
if ((parent) || (!strncmp(file->name, "..", 2))) {
if ((parent) || (!sceClibStrncmp(file->name, "..", 2))) {
char *slash = NULL;

// Find last '/' in working directory
Expand Down
4 changes: 2 additions & 2 deletions source/fs.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include <psp2/kernel/clib.h>
#include <psp2/io/dirent.h>
#include <psp2/io/fcntl.h>
#include <psp2/io/stat.h>
#include <string.h>

#include "common.h"
#include "fs.h"
Expand Down Expand Up @@ -29,7 +29,7 @@ SceBool FS_DirExists(const char *path) {
}

const char *FS_GetFileExt(const char *filename) {
const char *dot = strrchr(filename, '.');
const char *dot = sceClibStrrchr(filename, '.');

if (!dot || dot == filename)
return "";
Expand Down
5 changes: 2 additions & 3 deletions source/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@

#define CLIB_HEAP_SIZE 1 * 1024 * 1024

int _newlib_heap_size_user = 1 * 1024 * 1024;
int _newlib_heap_size_user = 128 * 1024;
void* mspace;

int sceAppMgrAcquireBgmPortForMusicPlayer(void);

int main(int argc, char *argv[]) {

void* clibm_base;
void* mspace;
SceUID clib_heap = sceKernelAllocMemBlock("ClibHeap", SCE_KERNEL_MEMBLOCK_TYPE_USER_RW_UNCACHE, CLIB_HEAP_SIZE, NULL);
sceKernelGetMemBlockBase(clib_heap, &clibm_base);
mspace = sceClibMspaceCreate(clibm_base, CLIB_HEAP_SIZE);
Expand All @@ -36,7 +36,6 @@ int main(int argc, char *argv[]) {
font = vita2d_load_font_file("app0:Roboto-Regular.ttf");
Textures_Load();

sceIoMkdir("ux0:data/ElevenMPV", 0777);
Config_Load();
Config_GetLastDirectory();

Expand Down
Loading

0 comments on commit b593d0b

Please sign in to comment.