I am trying to find a way of getting the paths of each folder inside another folder, I couldn't find anything on the web.
I need that to see the homebrews so I can launch them from my app.
Thanks.
Get folder on MS
Re: Get folder on MS
Hi! :)
Have a look at pspiofilemgr.h and the functions sceIoDopen, sceIoDclose and sceIoDread.
Ciaooo
Sakya
Have a look at pspiofilemgr.h and the functions sceIoDopen, sceIoDclose and sceIoDread.
Ciaooo
Sakya
Hi Hedi
A short sample:
and the makefile:
A short sample:
Code: Select all
#include <pspkernel.h>
#include <pspdebug.h>
#include <pspctrl.h>
#include <pspiofilemgr_stat.h>
#include <string>
/* Define the module info section */
PSP_MODULE_INFO("Fichiers et repertoires", 0, 1, 1);
/* Define the main thread's attribute value (optional) */
PSP_MAIN_THREAD_ATTR(THREAD_ATTR_USER | THREAD_ATTR_VFPU);
int sceInit(void);
int main( void)
{
int ret;
//System initilization
sceInit(); //set exit callback
pspDebugScreenInit(); //init the screen in a special mode that allow us to print on it easily
sceIoChdir( "ms0:/PSP/GAME/test"); //set the cuurent dir, so we can use relative path
sceIoMkdir( "toto",0777); //create a directory named "toto" in the current directory
//(we could have given the absolute path.
//777 is the standart permission for rwx for all
//Prints the name of all files and directories (including '.' and '..'
//1) open the directory
SceUID uid = sceIoDopen("ms0:/PSP/GAME/test");
struct SceIoDirent dirEnt;
dirEnt.d_private=NULL; //if not done the at the first use of dirEnt in sceIoDread => crash
//2) for all the enties => at least toto and the eboot.pbp
while(sceIoDread(uid, &dirEnt))
{
pspDebugScreenPrintf("Name: %s \n",dirEnt.d_name);
}
//we close the directory
sceIoDclose(uid);
//rename a directory
sceIoRename( "toto" , "titi" );
//delete a dir ( has to be empty!!)
sceIoRmdir( "titi");
pspDebugScreenPrintf("------------------------\n");
//////////////////////// THE FILES
//we create a file for test
uid = sceIoOpen("ms0:/PSP/GAME/test/foo.txt", PSP_O_WRONLY | PSP_O_CREAT, 0777); //file creation
char *buffer={"pspZorba.com"};
sceIoWrite( uid, buffer, strlen(buffer));
sceIoClose( uid);
ScePspDateTime psp_time;
SceIoStat d_stat;
sceIoGetstat( "ms0:/PSP/GAME/test/foo.txt", &d_stat);//we load the file information
pspDebugScreenPrintf("Name: foo.txt \n");
pspDebugScreenPrintf("size: %lld bytes\n",d_stat.st_size);
//st_mode
if( FIO_S_IFLNK & d_stat.st_mode) pspDebugScreenPuts("Link |");
if( FIO_S_IFDIR & d_stat.st_mode) pspDebugScreenPuts("Dir |");
if( FIO_S_IFREG & d_stat.st_mode) pspDebugScreenPuts("File |");
char perm[42];
memset(perm,'-',42);
if( FIO_S_ISUID & d_stat.st_mode) { perm[0]='S';};
if( FIO_S_ISGID & d_stat.st_mode) { perm[1]='G';};
if( FIO_S_ISVTX & d_stat.st_mode) { perm[2]='V';};
perm[3]=' ';
if( FIO_S_IRUSR & d_stat.st_mode) { perm[4]='R';};
if( FIO_S_IWUSR & d_stat.st_mode) { perm[5]='W';};
if( FIO_S_IXUSR & d_stat.st_mode) { perm[6]='X';};
perm[7]=' ';
if( FIO_S_IRGRP & d_stat.st_mode) { perm[8]='R';};
if( FIO_S_IWGRP & d_stat.st_mode) { perm[9]='W';};
if( FIO_S_IXGRP & d_stat.st_mode) { perm[10]='X';};
perm[11]=' ';
if( FIO_S_IROTH & d_stat.st_mode) { perm[12]='R';};
if( FIO_S_IWOTH & d_stat.st_mode) { perm[13]='W';};
if( FIO_S_IXOTH & d_stat.st_mode) { perm[14]='X';};
perm[15]=0;
pspDebugScreenPrintf("mode %s|", perm);
memset(perm,'-',42);
if( FIO_SO_IFLNK & d_stat.st_attr) { perm[0]='L';};
if( FIO_SO_IFDIR & d_stat.st_attr) { perm[1]='D';};
if( FIO_SO_IFREG & d_stat.st_attr) { perm[2]='F';};
perm[3]=' ';
if( FIO_SO_IROTH & d_stat.st_attr) { perm[4]='R';};
if( FIO_SO_IWOTH & d_stat.st_attr) { perm[5]='W';};
if( FIO_SO_IXOTH & d_stat.st_attr) { perm[6]='X';};
perm[7]=0;
pspDebugScreenPrintf("attr %s\n", perm);
psp_time = dirEnt.d_stat.st_ctime;
pspDebugScreenPrintf("creation Time: %d-%d-%d:%d-%d-%d\n", psp_time.year, psp_time.month, psp_time.day, psp_time.hour , psp_time.minute , psp_time.second);
psp_time = dirEnt.d_stat.st_atime;
pspDebugScreenPrintf("Last access : %d-%d-%d:%d-%d-%d\n", psp_time.year, psp_time.month, psp_time.day, psp_time.hour , psp_time.minute , psp_time.second);
psp_time = dirEnt.d_stat.st_mtime;
pspDebugScreenPrintf("Last modification Time: %d-%d-%d:%d-%d-%d\n", psp_time.year, psp_time.month, psp_time.day, psp_time.hour , psp_time.minute , psp_time.second);
ret = sceIoRemove( "ms0:/PSP/GAME/test/foo.txt");//delete the file
sceKernelSleepThread();
return 0;
}
/* Exit callback */
int exit_callback(int arg1, int arg2, void *common)
{
sceKernelExitGame();
return (int)0;
}
/* Callback thread */
int CallbackThread(SceSize args, void *argp)
{
int cbid;
cbid = sceKernelCreateCallback("Exit Callback", exit_callback, NULL);
sceKernelRegisterExitCallback(cbid);
sceKernelSleepThreadCB();
return 0;
}
int sceInit(void)
{
int thid = 0;
thid = sceKernelCreateThread("update_thread", CallbackThread, 0x11, 0xFA0, 0, 0);
if(thid >= 0)
{
sceKernelStartThread(thid, 0, 0);
}
return thid;
}
and the makefile:
Code: Select all
#########################################################
#
# (@) pspZorba : example 6
#
#########################################################
#########################################################
#
# definition des variables
#
#########################################################
# Set Here the path where you want to copy your EBOOUT
MOUNT_POINT = F:/PSP/GAME/test
# name displayed by the XMB
PSP_EBOOT_TITLE = pspZorba-ex8
# fisrt icon displayed (*.PNG) by the XMB
PSP_EBOOT_ICON = NULL
# animation (*.PMF) displayed by the XMB
PSP_EBOOT_ICON1 = NULL
# it's a picture (*.PNG)displayed after some seconds rather with transparency to allow us to see the first icon and the anim.
PSP_EBOOT_UNKPNG = NULL
# background image (*.PNG) displayed
PSP_EBOOT_PIC1 = NULL
# music (*.AT3) rather a loop but not mandatory
PSP_EBOOT_SND0 = NULL
CXXFLAGS = -g -G0 -Wall -O3 -D_PSP_FW_VERSION=150 -fno-rtti -fno-exceptions
INCDIR = -I. -I$(PSPSDK)/include
LIBDIR = -L. -L/usr/local/pspdev/lib -L$(PSPSDK)/lib
LIBS = -lstdc++ -lpspctrl -lpspdebug -lpspge -lpspdisplay -lc -lpspuser -lpspnet_inet
OBJECTS = main.o
#########################################################
#all: $(OBJECTS) a.elf a_strip.elf PARAM.SFO EBOOT.PBP
all: EBOOT.PBP
EBOOT.PBP: PARAM.SFO a_strip.elf
pack-pbp $@ PARAM.SFO $(PSP_EBOOT_ICON) $(PSP_EBOOT_ICON1) $(PSP_EBOOT_UNKPNG) $(PSP_EBOOT_PIC1) $(PSP_EBOOT_SND0) a_strip.elf NULL
cp eboot.pbp $(MOUNT_POINT)
PARAM.SFO: a_strip.elf
mksfo $(PSP_EBOOT_TITLE) $@
a_strip.elf: a.elf
psp-strip $< -o $@
a.elf: $(OBJECTS) Makefile
psp-gcc $(CXXFLAGS) $(LIBDIR) $(OBJECTS) $(LIBS) -o $@
psp-fixup-imports $@
main.o: main.cpp
psp-g++ $(INCDIR) $(CXXFLAGS) -c -o $@ $<
clean:
rm -f $(OBJECTS) a.elf a_strip.elf PARAM.SFO EBOOT.PBP
--pspZorba--
NO to K1.5 !
NO to K1.5 !
Try not to use hardcoded paths. Assuming your path is GAME can get you in trouble is the person puts it in GAME380, for example. Instead, get the path dynamically. Here's some common code for getting the path.
That code takes the first argument (which should be a full path and filename for the currently running app) and terminates the string after the rightmost '/' to give the path to the app. Note that it operates on a COPY of the argument.
Code: Select all
// get launch directory name for our home
strncpy(psp_home,argv[0],sizeof(psp_home)-1);
psp_home[sizeof(psp_home)-1] = 0;
char *str_ptr=strrchr(psp_home,'/');
if (str_ptr){
str_ptr++;
*str_ptr = 0;
}