forums.ps2dev.org Forum Index forums.ps2dev.org
Homebrew PS2, PSP & PS3 Development Discussions
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Get folder on MS

 
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Development
View previous topic :: View next topic  
Author Message
erdi



Joined: 04 Feb 2008
Posts: 3

PostPosted: Sat Feb 09, 2008 5:03 am    Post subject: Get folder on MS Reply with quote

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.
Back to top
View user's profile Send private message
sakya



Joined: 28 Apr 2006
Posts: 190

PostPosted: Sat Feb 09, 2008 5:41 am    Post subject: Re: Get folder on MS Reply with quote

Hi! :)

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

Ciaooo
Sakya
Back to top
View user's profile Send private message Visit poster's website
jimparis



Joined: 10 Jun 2005
Posts: 1179
Location: Boston

PostPosted: Sat Feb 09, 2008 6:44 am    Post subject: Reply with quote

Or just use standard opendir(), readdir(), closedir() functions, which take care of known problems with the sce functions.
Back to top
View user's profile Send private message
pspZorba



Joined: 22 Sep 2007
Posts: 156
Location: NY

PostPosted: Sat Feb 09, 2008 7:38 am    Post subject: Reply with quote

Hi Hedi

A short sample:

Code:

#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:

#########################################################
#
#           (@) 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 !
Back to top
View user's profile Send private message
erdi



Joined: 04 Feb 2008
Posts: 3

PostPosted: Sat Feb 09, 2008 12:46 pm    Post subject: Reply with quote

Thanks all for the help, tomorrow I will try to put this on my code =)
Back to top
View user's profile Send private message
J.F.



Joined: 22 Feb 2004
Posts: 2906

PostPosted: Sun Feb 10, 2008 6:37 am    Post subject: Reply with quote

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:
   // 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;
   }


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.
Back to top
View user's profile Send private message AIM Address
erdi



Joined: 04 Feb 2008
Posts: 3

PostPosted: Sun Feb 10, 2008 10:45 am    Post subject: Reply with quote

I worked! Thanks again!

@J.F.

Thanks, I will use it.
Back to top
View user's profile Send private message
TyRaNiD



Joined: 18 Jan 2004
Posts: 918

PostPosted: Sun Feb 10, 2008 10:06 pm    Post subject: Reply with quote

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 :)
Back to top
View user's profile Send private message
moonlight



Joined: 26 Oct 2005
Posts: 567

PostPosted: Sun Feb 10, 2008 10:15 pm    Post subject: Reply with quote

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
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Development All times are GMT + 10 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group