Get folder on MS

Discuss the development of new homebrew software, tools and libraries.

Moderators: cheriff, TyRaNiD

Post Reply
erdi
Posts: 3
Joined: Mon Feb 04, 2008 11:06 am

Get folder on MS

Post by erdi »

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.
sakya
Posts: 190
Joined: Fri Apr 28, 2006 5:48 pm
Contact:

Re: Get folder on MS

Post by sakya »

Hi! :)

Have a look at pspiofilemgr.h and the functions sceIoDopen, sceIoDclose and sceIoDread.

Ciaooo
Sakya
jimparis
Posts: 1145
Joined: Fri Jun 10, 2005 4:21 am
Location: Boston

Post by jimparis »

Or just use standard opendir(), readdir(), closedir() functions, which take care of known problems with the sce functions.
pspZorba
Posts: 156
Joined: Sat Sep 22, 2007 11:45 am
Location: NY

Post by pspZorba »

Hi Hedi

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&#40;"Fichiers et repertoires", 0, 1, 1&#41;;

/* Define the main thread's attribute value &#40;optional&#41; */
PSP_MAIN_THREAD_ATTR&#40;THREAD_ATTR_USER | THREAD_ATTR_VFPU&#41;;
int sceInit&#40;void&#41;;  


int main&#40; void&#41; 
&#123;
	int ret;
	//System initilization
	sceInit&#40;&#41;;  //set exit callback 
	pspDebugScreenInit&#40;&#41;;  //init the screen in a special mode that allow us to print on it easily

	
	
	sceIoChdir&#40; "ms0&#58;/PSP/GAME/test"&#41;;  //set the cuurent dir, so we can use relative path
	
	sceIoMkdir&#40; "toto",0777&#41;; //create a directory named "toto"  in the current directory 
							  //&#40;we could have given the absolute path.
							  //777 is the standart permission for rwx for all
	

	//Prints the name of all files and directories &#40;including '.' and '..'
			//1&#41; open the directory
 	SceUID uid = sceIoDopen&#40;"ms0&#58;/PSP/GAME/test"&#41;; 
	struct SceIoDirent dirEnt;
	
	dirEnt.d_private=NULL; //if not done the at the first use of dirEnt in sceIoDread => crash
			//2&#41; for all the enties => at least toto and the eboot.pbp
	while&#40;sceIoDread&#40;uid, &dirEnt&#41;&#41;
	&#123;
		pspDebugScreenPrintf&#40;"Name&#58; %s \n",dirEnt.d_name&#41;;
	&#125;
		//we close the  directory
	sceIoDclose&#40;uid&#41;; 
	
		
	//rename a directory
	sceIoRename&#40; "toto" , "titi" &#41;;
	

	//delete a dir &#40; has to be empty!!&#41;
	sceIoRmdir&#40; "titi"&#41;;

	
	pspDebugScreenPrintf&#40;"------------------------\n"&#41;;
	//////////////////////// THE FILES
	//we create a file for test 
    uid = sceIoOpen&#40;"ms0&#58;/PSP/GAME/test/foo.txt", PSP_O_WRONLY | PSP_O_CREAT, 0777&#41;; //file creation 
    char *buffer=&#123;"pspZorba.com"&#125;;
    sceIoWrite&#40; uid, buffer, strlen&#40;buffer&#41;&#41;;
    sceIoClose&#40; uid&#41;;
    
	ScePspDateTime psp_time;
    SceIoStat d_stat;
    sceIoGetstat&#40; "ms0&#58;/PSP/GAME/test/foo.txt", &d_stat&#41;;//we load the file information

    pspDebugScreenPrintf&#40;"Name&#58; foo.txt  \n"&#41;;
	pspDebugScreenPrintf&#40;"size&#58; %lld bytes\n",d_stat.st_size&#41;; 
	
	//st_mode
	if&#40; FIO_S_IFLNK & d_stat.st_mode&#41; pspDebugScreenPuts&#40;"Link |"&#41;;
	if&#40; FIO_S_IFDIR & d_stat.st_mode&#41; pspDebugScreenPuts&#40;"Dir  |"&#41;;
	if&#40; FIO_S_IFREG & d_stat.st_mode&#41; pspDebugScreenPuts&#40;"File |"&#41;;
	
	char perm&#91;42&#93;;
	memset&#40;perm,'-',42&#41;; 

	if&#40; FIO_S_ISUID & d_stat.st_mode&#41; &#123; perm&#91;0&#93;='S';&#125;;
	if&#40; FIO_S_ISGID & d_stat.st_mode&#41; &#123; perm&#91;1&#93;='G';&#125;;
	if&#40; FIO_S_ISVTX & d_stat.st_mode&#41; &#123; perm&#91;2&#93;='V';&#125;;
	perm&#91;3&#93;=' ';
	if&#40; FIO_S_IRUSR  & d_stat.st_mode&#41; &#123; perm&#91;4&#93;='R';&#125;;
	if&#40; FIO_S_IWUSR  & d_stat.st_mode&#41; &#123; perm&#91;5&#93;='W';&#125;;
	if&#40; FIO_S_IXUSR  & d_stat.st_mode&#41; &#123; perm&#91;6&#93;='X';&#125;;
	perm&#91;7&#93;=' ';
	if&#40; FIO_S_IRGRP  & d_stat.st_mode&#41; &#123; perm&#91;8&#93;='R';&#125;;
	if&#40; FIO_S_IWGRP  & d_stat.st_mode&#41; &#123; perm&#91;9&#93;='W';&#125;;
	if&#40; FIO_S_IXGRP  & d_stat.st_mode&#41; &#123; perm&#91;10&#93;='X';&#125;;
	perm&#91;11&#93;=' ';
	if&#40; FIO_S_IROTH  & d_stat.st_mode&#41; &#123; perm&#91;12&#93;='R';&#125;;
	if&#40; FIO_S_IWOTH  & d_stat.st_mode&#41; &#123; perm&#91;13&#93;='W';&#125;;
	if&#40; FIO_S_IXOTH  & d_stat.st_mode&#41; &#123; perm&#91;14&#93;='X';&#125;;
	perm&#91;15&#93;=0;
	pspDebugScreenPrintf&#40;"mode %s|", perm&#41;;
	
	
	memset&#40;perm,'-',42&#41;; 
	if&#40; FIO_SO_IFLNK & d_stat.st_attr&#41; &#123; perm&#91;0&#93;='L';&#125;;
	if&#40; FIO_SO_IFDIR & d_stat.st_attr&#41; &#123; perm&#91;1&#93;='D';&#125;;
	if&#40; FIO_SO_IFREG & d_stat.st_attr&#41; &#123; perm&#91;2&#93;='F';&#125;;
	perm&#91;3&#93;=' ';
	if&#40; FIO_SO_IROTH & d_stat.st_attr&#41; &#123; perm&#91;4&#93;='R';&#125;;
	if&#40; FIO_SO_IWOTH & d_stat.st_attr&#41; &#123; perm&#91;5&#93;='W';&#125;;
	if&#40; FIO_SO_IXOTH & d_stat.st_attr&#41; &#123; perm&#91;6&#93;='X';&#125;;
	perm&#91;7&#93;=0;
	pspDebugScreenPrintf&#40;"attr %s\n", perm&#41;;
			
			
	psp_time = dirEnt.d_stat.st_ctime;
	pspDebugScreenPrintf&#40;"creation Time&#58; %d-%d-%d&#58;%d-%d-%d\n", psp_time.year, psp_time.month, psp_time.day, psp_time.hour , psp_time.minute , psp_time.second&#41;;

	psp_time = dirEnt.d_stat.st_atime;
	pspDebugScreenPrintf&#40;"Last access &#58; %d-%d-%d&#58;%d-%d-%d\n", psp_time.year, psp_time.month, psp_time.day, psp_time.hour , psp_time.minute , psp_time.second&#41;;

	psp_time = dirEnt.d_stat.st_mtime;
	pspDebugScreenPrintf&#40;"Last modification Time&#58; %d-%d-%d&#58;%d-%d-%d\n", psp_time.year, psp_time.month, psp_time.day, psp_time.hour , psp_time.minute , psp_time.second&#41;;

	ret = sceIoRemove&#40; "ms0&#58;/PSP/GAME/test/foo.txt"&#41;;//delete the file
	
	sceKernelSleepThread&#40;&#41;;
	
return 0;
&#125;
 
 
 


/* Exit callback */
int exit_callback&#40;int arg1, int arg2, void *common&#41;
&#123;
        sceKernelExitGame&#40;&#41;;
        return &#40;int&#41;0;
&#125;

/* Callback thread */
int CallbackThread&#40;SceSize args, void *argp&#41;
&#123;
        int cbid;

        cbid = sceKernelCreateCallback&#40;"Exit Callback", exit_callback, NULL&#41;;
        sceKernelRegisterExitCallback&#40;cbid&#41;;

        sceKernelSleepThreadCB&#40;&#41;;

        return 0;
&#125;

int sceInit&#40;void&#41;
&#123;
       int thid = 0;

        thid = sceKernelCreateThread&#40;"update_thread", CallbackThread, 0x11, 0xFA0, 0, 0&#41;;
        if&#40;thid >= 0&#41;
        &#123;
                sceKernelStartThread&#40;thid, 0, 0&#41;;
        &#125;

        return thid;
&#125;




and the makefile:

Code: Select all

#########################################################
#
#           &#40;@&#41; pspZorba &#58; example 6
#
#########################################################


#########################################################
#
#           definition des variables 
#
#########################################################

# Set Here the path where you want to copy your EBOOUT
MOUNT_POINT = F&#58;/PSP/GAME/test

# name displayed by the XMB
PSP_EBOOT_TITLE = pspZorba-ex8

# fisrt icon displayed &#40;*.PNG&#41;  by the XMB
PSP_EBOOT_ICON = NULL

# animation &#40;*.PMF&#41; displayed by the XMB
PSP_EBOOT_ICON1 = NULL

# it's a picture &#40;*.PNG&#41;displayed after some seconds rather  with transparency to allow us to see the first icon and the anim.
PSP_EBOOT_UNKPNG = NULL

# background image &#40;*.PNG&#41; displayed 
PSP_EBOOT_PIC1 = NULL

# music &#40;*.AT3&#41; 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$&#40;PSPSDK&#41;/include
LIBDIR = -L. -L/usr/local/pspdev/lib -L$&#40;PSPSDK&#41;/lib
LIBS =  -lstdc++ -lpspctrl -lpspdebug -lpspge -lpspdisplay -lc -lpspuser -lpspnet_inet

OBJECTS = main.o 

#########################################################
#all&#58; $&#40;OBJECTS&#41; a.elf a_strip.elf PARAM.SFO EBOOT.PBP
all&#58; EBOOT.PBP

EBOOT.PBP&#58; PARAM.SFO a_strip.elf 
	pack-pbp $@ PARAM.SFO $&#40;PSP_EBOOT_ICON&#41; $&#40;PSP_EBOOT_ICON1&#41; $&#40;PSP_EBOOT_UNKPNG&#41; $&#40;PSP_EBOOT_PIC1&#41; $&#40;PSP_EBOOT_SND0&#41; a_strip.elf NULL
	cp eboot.pbp $&#40;MOUNT_POINT&#41;

PARAM.SFO&#58; a_strip.elf
	mksfo $&#40;PSP_EBOOT_TITLE&#41; $@

a_strip.elf&#58;    a.elf
	psp-strip $< -o $@

a.elf&#58; $&#40;OBJECTS&#41; Makefile
	psp-gcc $&#40;CXXFLAGS&#41; $&#40;LIBDIR&#41; $&#40;OBJECTS&#41; $&#40;LIBS&#41; -o $@
	psp-fixup-imports  $@

main.o&#58; main.cpp 
	psp-g++ $&#40;INCDIR&#41;  $&#40;CXXFLAGS&#41; -c -o $@ $<


	
clean&#58;
	rm -f $&#40;OBJECTS&#41; a.elf a_strip.elf PARAM.SFO EBOOT.PBP



--pspZorba--
NO to K1.5 !
erdi
Posts: 3
Joined: Mon Feb 04, 2008 11:06 am

Post by erdi »

Thanks all for the help, tomorrow I will try to put this on my code =)
J.F.
Posts: 2906
Joined: Sun Feb 22, 2004 11:41 am

Post by J.F. »

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.

Code: Select all

	// get launch directory name for our home
	strncpy&#40;psp_home,argv&#91;0&#93;,sizeof&#40;psp_home&#41;-1&#41;;
	psp_home&#91;sizeof&#40;psp_home&#41;-1&#93; = 0;
	char *str_ptr=strrchr&#40;psp_home,'/'&#41;;
	if &#40;str_ptr&#41;&#123;
		str_ptr++;
		*str_ptr = 0;
	&#125;
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.
erdi
Posts: 3
Joined: Mon Feb 04, 2008 11:06 am

Post by erdi »

I worked! Thanks again!

@J.F.

Thanks, I will use it.
TyRaNiD
Posts: 907
Joined: Sun Jan 18, 2004 12:23 am

Post by TyRaNiD »

And the SDK will do the path stuff for you, you don't need to call sceIoChdir at all as the initialization of the c library should have already done so :)
moonlight
Posts: 567
Joined: Wed Oct 26, 2005 7:46 pm

Post by moonlight »

TyRaNiD wrote:And the SDK will do the path stuff for you, you don't need to call sceIoChdir at all as the initialization of the c library should have already done so :)
unless you want to small down your application size and use the pspsdk libc instead of newlib :p
Post Reply