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 

Looking for custom paths

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



Joined: 31 Dec 2005
Posts: 288

PostPosted: Mon Jan 30, 2006 6:58 am    Post subject: Looking for custom paths Reply with quote

Hi folks,

I have this theme thing build in but now i use the directories 1 to 20 with in those dirs the themes. What i want is to get the total number of directories inside my theme directory and then cycle through them to randomly get one and use that theme.

i know how to randomize i use that for a other function aswell. i know how to open the theme that works now in the 1 to 20 directory system what i don't know is how to get all the dirs in a dir and cycle through them what kind of function do i need?

i looked in the sample from the sdk and it looks like they use SceIoDirent but i am not sure how to use it.
_________________
My PSP games:

Boxy II: http://www.ghoti.nl/boxyii.php
Elementals: http://www.ghoti.nl/Elementals.php
Back to top
View user's profile Send private message
HaQue



Joined: 25 Nov 2005
Posts: 91
Location: Adelaide, Australia

PostPosted: Mon Jan 30, 2006 7:49 pm    Post subject: Reply with quote

Hi,

I think you want to just add dir's to your "/theme/" dir and have your program automatically detect how many themes, then grab a random one and run it.

I have some ideas by doing a search for "directory" in the samples dir of the SDK, but no time to investigate them right now. I don't want to give you false info!

for the time being though, you could just create an .ini file and add the folder names to it, and use similar code to whats in "C:\cygwin\usr\local\pspdev\psp\sdk\samples\kernel\fileio\main.c"

or loop through 1 - x and use that number as a variable to the the folder names (as they are numbers), until the current number is not found.

Happy Coding!

HaQue
_________________
www.smartwave-wireless.com
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Ghoti



Joined: 31 Dec 2005
Posts: 288

PostPosted: Mon Jan 30, 2006 8:38 pm    Post subject: Reply with quote

the last thing you say is how i do it now. But i hoped that there was a way so that people could just make custom directory names in the theme map. But you were correct about what i want.

i'll look into the ini thingy though thanks
_________________
My PSP games:

Boxy II: http://www.ghoti.nl/boxyii.php
Elementals: http://www.ghoti.nl/Elementals.php
Back to top
View user's profile Send private message
HaQue



Joined: 25 Nov 2005
Posts: 91
Location: Adelaide, Australia

PostPosted: Mon Jan 30, 2006 10:38 pm    Post subject: Reply with quote

Hi,
Just taking a look at the sample code now and I think it is quite easy to do exactly what you want.

I'll post back the results after I have it working. I can use the code myself too :)
_________________
www.smartwave-wireless.com
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Dr. Vegetable



Joined: 14 Nov 2005
Posts: 171
Location: Boston, Massachusetts

PostPosted: Tue Jan 31, 2006 1:52 pm    Post subject: Reply with quote

You mean something like this...

Code:

#include <dirent.h>

int listDirectory(char* szRoot)
{
   DIR* dirParent;
   struct dirent* dirEntry;
   int n = 0;

   if ((dirParent = opendir(szRoot)) != NULL)
   {
      pspDebugScreenPrintf("Directory listing of %s\n", szRoot);
      while ((dirEntry = readdir(dirParent)) != NULL)
      {
         pspDebugScreenPrintf("  %s\n", dirEntry->d_name);
         n++;
      }

      pspDebugScreenPrintf("%d files found.\n", n);

      closedir(dirParent);
   }

   return n;
}


...Called something like this...

Code:

   pspDebugScreenInit();
   listDirectory("ms0:/PSP/GAME/");


You can download the complete code for a simple PSP directory listing sample program at the following link:

http://www.drvegetable.com/SonyPSP/DirList.zip

Hope this helps!
Back to top
View user's profile Send private message Visit poster's website AIM Address Yahoo Messenger
HaQue



Joined: 25 Nov 2005
Posts: 91
Location: Adelaide, Australia

PostPosted: Tue Jan 31, 2006 2:46 pm    Post subject: Reply with quote

Thanks Dr V :) I almost had it complete, but yours is waaaaay more elegant! great work :)
_________________
www.smartwave-wireless.com
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Ghoti



Joined: 31 Dec 2005
Posts: 288

PostPosted: Tue Jan 31, 2006 10:18 pm    Post subject: Reply with quote

Aaah thanks that was exactly what i needed looks very nice thank you
_________________
My PSP games:

Boxy II: http://www.ghoti.nl/boxyii.php
Elementals: http://www.ghoti.nl/Elementals.php
Back to top
View user's profile Send private message
Ghoti



Joined: 31 Dec 2005
Posts: 288

PostPosted: Wed Feb 01, 2006 1:00 am    Post subject: Reply with quote

hmm i don't get it to work:

Code:
   if ((dirParent = opendir("ms0:/PSP/GAME/BOXY/Themes/")) != NULL)
   {
      while ((dirEntry = readdir(dirParent)) != NULL)
      {   
         sprintf(sTest, "%s/Block1.png",  dirEntry->d_name);
         
         iTest += 1;
      }
      closedir(dirParent);
   }

   return 0;


i have this sTest which is a char[100] and i draw it on screen but it never holds any string what am i doing wrong? it should have "1/Block1.png" but it is just blanc any ideas?

by the way the iTest get + 1 every time so the function is used but the string is not saved.
_________________
My PSP games:

Boxy II: http://www.ghoti.nl/boxyii.php
Elementals: http://www.ghoti.nl/Elementals.php
Back to top
View user's profile Send private message
Dr. Vegetable



Joined: 14 Nov 2005
Posts: 171
Location: Boston, Massachusetts

PostPosted: Wed Feb 01, 2006 2:31 am    Post subject: Reply with quote

Ghoti wrote:
i have this sTest which is a char[100] and i draw it on screen but it never holds any string what am i doing wrong? it should have "1/Block1.png" but it is just blanc any ideas?

You would have to post more of your code for anyone to be able to answer this question for you.
Back to top
View user's profile Send private message Visit poster's website AIM Address Yahoo Messenger
Ghoti



Joined: 31 Dec 2005
Posts: 288

PostPosted: Wed Feb 01, 2006 4:10 am    Post subject: Reply with quote

k here is the full code:
Code:

int GetNewTheme(void){
   
   char buffer[200];
   int randomize;
   randomize = (rand() % (iTotalOfThemes-3+1)) + 3 ;

   
   DIR* dirParent;
   struct dirent* dirEntry;
   
   
   // this code has to be in the next if statement.
   sprintf(buffer, "ms0:/PSP/GAME/Boxy/Themes/2/background.png");
   GameBackground = loadImage(buffer);
   
   
   
   if ((dirParent = opendir("ms0:/PSP/GAME/BOXY/Themes/")) != NULL)
   {
      while ((dirEntry = readdir(dirParent)) != NULL)
      {   
         if (iTest == 3) {
            sprintf(sTest, "%s/Block1.png",  dirEntry->d_name);
         }
         iTest += 1;
      }
      closedir(dirParent);
   }

   return 0;

   

}


and here is the declaration and call code:

Code:


char sTest[100];


if (pad.Buttons & PSP_CTRL_TRIANGLE){
            if (iButtonTriangle == 0) {
            
            GetNewTheme();
            //sceGuTerm();
            //sceKernelExitGame();
            iButtonTriangle =1;
            }
         }
and last how i draw it onscreen

Code:
pspDebugScreenSetXY(1, 2);
   printf("sTest: %s", sTest);


hope this helps
_________________
My PSP games:

Boxy II: http://www.ghoti.nl/boxyii.php
Elementals: http://www.ghoti.nl/Elementals.php
Back to top
View user's profile Send private message
Dr. Vegetable



Joined: 14 Nov 2005
Posts: 171
Location: Boston, Massachusetts

PostPosted: Wed Feb 01, 2006 5:29 am    Post subject: Reply with quote

You still don't show your declaration and initialization of iTest, but it looks like you are using this to skip past the "." and ".." directory entries? Then you should be initializing iTest = 1, since you check its value before you increment the value.

What output do you get from your program? Do you see the text "sTest:" with nothing after it? How many subdirectories do you have in the "Theme" folder? (Hint: Add more and try again!)
Back to top
View user's profile Send private message Visit poster's website AIM Address Yahoo Messenger
Ghoti



Joined: 31 Dec 2005
Posts: 288

PostPosted: Wed Feb 01, 2006 5:57 am    Post subject: Reply with quote

Code:
int iTest;
iTest =1;


that's how i initialize it.

I have 4 directories in my themes map and i also draw iTest and that number increases after i call the GetNewTheme() function. So i know that it goes through all the directories.

Yes you are correct i saw that when i had 2 directories that it gave 4 directories back so i assumed that it had "." and ".." sorry i forget to put that in.

and your assumption is correct i do get the string "iTest: " without the value it should give.

i have also tried losing the iTest integer fro getting the third directory so it saves the string for each directory, in my assumption it should hold the last directory after the function but that also results in a empty value.

any ideas?
_________________
My PSP games:

Boxy II: http://www.ghoti.nl/boxyii.php
Elementals: http://www.ghoti.nl/Elementals.php
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