Looking for custom paths

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

Moderators: cheriff, TyRaNiD

Post Reply
Ghoti
Posts: 288
Joined: Sat Dec 31, 2005 11:06 pm

Looking for custom paths

Post by Ghoti »

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.
HaQue
Posts: 91
Joined: Fri Nov 25, 2005 8:52 am
Location: Adelaide, Australia
Contact:

Post by HaQue »

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
Ghoti
Posts: 288
Joined: Sat Dec 31, 2005 11:06 pm

Post by Ghoti »

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
HaQue
Posts: 91
Joined: Fri Nov 25, 2005 8:52 am
Location: Adelaide, Australia
Contact:

Post by HaQue »

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 :)
Dr. Vegetable
Posts: 171
Joined: Mon Nov 14, 2005 1:32 am
Location: Boston, Massachusetts
Contact:

Post by Dr. Vegetable »

You mean something like this...

Code: Select all

#include <dirent.h>

int listDirectory&#40;char* szRoot&#41;
&#123;
	DIR* dirParent;
	struct dirent* dirEntry;
	int n = 0;

	if &#40;&#40;dirParent = opendir&#40;szRoot&#41;&#41; != NULL&#41;
	&#123;
		pspDebugScreenPrintf&#40;"Directory listing of %s\n", szRoot&#41;;
		while &#40;&#40;dirEntry = readdir&#40;dirParent&#41;&#41; != NULL&#41;
		&#123;
			pspDebugScreenPrintf&#40;"  %s\n", dirEntry->d_name&#41;;
			n++;
		&#125;

		pspDebugScreenPrintf&#40;"%d files found.\n", n&#41;;

		closedir&#40;dirParent&#41;;
	&#125;

	return n;
&#125;
...Called something like this...

Code: Select all

	pspDebugScreenInit&#40;&#41;;
	listDirectory&#40;"ms0&#58;/PSP/GAME/"&#41;;
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!
HaQue
Posts: 91
Joined: Fri Nov 25, 2005 8:52 am
Location: Adelaide, Australia
Contact:

Post by HaQue »

Thanks Dr V :) I almost had it complete, but yours is waaaaay more elegant! great work :)
Ghoti
Posts: 288
Joined: Sat Dec 31, 2005 11:06 pm

Post by Ghoti »

Aaah thanks that was exactly what i needed looks very nice thank you
Ghoti
Posts: 288
Joined: Sat Dec 31, 2005 11:06 pm

Post by Ghoti »

hmm i don't get it to work:

Code: Select all

	if &#40;&#40;dirParent = opendir&#40;"ms0&#58;/PSP/GAME/BOXY/Themes/"&#41;&#41; != NULL&#41; 
	&#123; 
		while &#40;&#40;dirEntry = readdir&#40;dirParent&#41;&#41; != NULL&#41; 
		&#123;	
			sprintf&#40;sTest, "%s/Block1.png",  dirEntry->d_name&#41;;
			
			iTest += 1;
		&#125;
		closedir&#40;dirParent&#41;; 
	&#125; 

	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.
Dr. Vegetable
Posts: 171
Joined: Mon Nov 14, 2005 1:32 am
Location: Boston, Massachusetts
Contact:

Post by Dr. Vegetable »

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.
Ghoti
Posts: 288
Joined: Sat Dec 31, 2005 11:06 pm

Post by Ghoti »

k here is the full code:

Code: Select all

int GetNewTheme&#40;void&#41;&#123;
	
	char buffer&#91;200&#93;;
	int randomize;
	randomize = &#40;rand&#40;&#41; % &#40;iTotalOfThemes-3+1&#41;&#41; + 3 ;

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

	return 0;

	

&#125;
and here is the declaration and call code:

Code: Select all


char sTest&#91;100&#93;;


if &#40;pad.Buttons & PSP_CTRL_TRIANGLE&#41;&#123;
				if &#40;iButtonTriangle == 0&#41; &#123;
				
				GetNewTheme&#40;&#41;;
				//sceGuTerm&#40;&#41;;
				//sceKernelExitGame&#40;&#41;;
				iButtonTriangle =1;
				&#125;
			&#125;
and last how i draw it onscreen

Code: Select all

pspDebugScreenSetXY&#40;1, 2&#41;;
	printf&#40;"sTest&#58; %s", sTest&#41;;
hope this helps
Dr. Vegetable
Posts: 171
Joined: Mon Nov 14, 2005 1:32 am
Location: Boston, Massachusetts
Contact:

Post by Dr. Vegetable »

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!)
Ghoti
Posts: 288
Joined: Sat Dec 31, 2005 11:06 pm

Post by Ghoti »

Code: Select all

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?
Post Reply