Looking for custom paths
Looking for custom paths
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.
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
Boxy II: http://www.ghoti.nl/boxyii.php
Elementals: http://www.ghoti.nl/Elementals.php
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
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
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
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
Boxy II: http://www.ghoti.nl/boxyii.php
Elementals: http://www.ghoti.nl/Elementals.php
-
- Posts: 171
- Joined: Mon Nov 14, 2005 1:32 am
- Location: Boston, Massachusetts
- Contact:
You mean something like this...
...Called something like this...
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!
Code: Select all
#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;
}
Code: Select all
pspDebugScreenInit();
listDirectory("ms0:/PSP/GAME/");
http://www.drvegetable.com/SonyPSP/DirList.zip
Hope this helps!
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
Boxy II: http://www.ghoti.nl/boxyii.php
Elementals: http://www.ghoti.nl/Elementals.php
hmm i don't get it to work:
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.
Code: Select all
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;
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
Boxy II: http://www.ghoti.nl/boxyii.php
Elementals: http://www.ghoti.nl/Elementals.php
-
- Posts: 171
- Joined: Mon Nov 14, 2005 1:32 am
- Location: Boston, Massachusetts
- Contact:
k here is the full code:
and here is the declaration and call code:
and last how i draw it onscreen
hope this helps
Code: Select all
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;
}
Code: Select all
char sTest[100];
if (pad.Buttons & PSP_CTRL_TRIANGLE){
if (iButtonTriangle == 0) {
GetNewTheme();
//sceGuTerm();
//sceKernelExitGame();
iButtonTriangle =1;
}
}
Code: Select all
pspDebugScreenSetXY(1, 2);
printf("sTest: %s", sTest);
My PSP games:
Boxy II: http://www.ghoti.nl/boxyii.php
Elementals: http://www.ghoti.nl/Elementals.php
Boxy II: http://www.ghoti.nl/boxyii.php
Elementals: http://www.ghoti.nl/Elementals.php
-
- Posts: 171
- Joined: Mon Nov 14, 2005 1:32 am
- Location: Boston, Massachusetts
- Contact:
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!)
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!)
Code: Select all
int iTest;
iTest =1;
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
Boxy II: http://www.ghoti.nl/boxyii.php
Elementals: http://www.ghoti.nl/Elementals.php