Strange problem with japanese filenames and user mode app!

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

Moderators: cheriff, TyRaNiD

Post Reply
theHobbit
Posts: 65
Joined: Sat Sep 30, 2006 5:26 am

Strange problem with japanese filenames and user mode app!

Post by theHobbit »

Hi there, i'm trying to add japanese support to my app and i'm using the fat.h and fat.c code from cooleyes ppa to read the long and short names of files and directories.

Ok i have this simple test to read all the files and directories from the memory stick root and check if the file or directory can be opened.

this is the main.cpp code:

Code: Select all


/*
*/

#include <pspkernel.h>
#include <pspdebug.h>
#include <pspsdk.h>

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

extern "C" &#123;
#include "fat.h"
&#125;

PSP_MODULE_INFO&#40;"FAT_TEST", 0x0, 0, 1&#41;;
PSP_MAIN_THREAD_NAME&#40;"Fat Test"&#41;;

#define printf pspDebugScreenPrintf

#define MS_ROOT		"ms0&#58;/"

int main&#40; int argc, char *argv&#91;&#93; &#41; 
&#123;
	p_fat_info fat_info;
	char path&#91;256&#93;;
	char shortpath&#91;256&#93;;
	char file&#91;256&#93;;
		
	pspDebugScreenInit&#40;&#41;;
	
	fat_init&#40;&#41;;
	strcpy&#40;path,   MS_ROOT&#41;;
	strcpy&#40;shortpath, MS_ROOT&#41;;
	u32 count = fat_readdir&#40;path, shortpath, &fat_info&#41;;
	
	if&#40; count != INVALID &#41; &#123;
		printf&#40; "Dir opened &#40;%s&#41;\n", shortpath&#41;;
		printf&#40; "%d Entries\n", count&#41;;
		for&#40;int i = 0; i < count; i++&#41; &#123;
			printf&#40; "%d - %s\n", i, fat_info&#91;i&#93;.filename&#41;;
			sprintf&#40;file, "%s%s", MS_ROOT, fat_info&#91;i&#93;.filename&#41;;
			
			if&#40; fat_info&#91;i&#93;.attr & FAT_FILEATTR_DIRECTORY &#41; &#123;
				p_fat_info f_info;
				char shortdir&#91;256&#93;, dir&#91;256&#93;;
				u32 c = -1;
				sprintf&#40;shortdir, "%s%s", shortpath, fat_info&#91;i&#93;.filename&#41;;
				sprintf&#40;dir, "%s%s", path, fat_info&#91;i&#93;.longname&#41;;
				if&#40; &#40;c = fat_readdir&#40;dir, shortdir,  &f_info&#41;&#41; != INVALID &#41; &#123;
					printf&#40; "Dir opened &#40;%s&#41;\n", shortdir&#41;;
					printf&#40; "Found %d entries\n", c&#41;;
				&#125;
				else &#123;
					printf&#40; "Could not open dir &#40;%s - %d&#41;\n", shortdir, c&#41;;
				&#125;
			&#125;
			else &#123;
			
				FILE *f = fopen&#40;file, "rb"&#41;;
				if&#40; f == NULL &#41; &#123;
					printf&#40; "Could not open file &#40;%s&#41;\n", file&#41;;
				&#125;
				else &#123;
					printf&#40; "File opened &#40;%s&#41;\n", file&#41;;
					fclose&#40;f&#41;;
				&#125;
			&#125;
		&#125;
	&#125;
	else &#123;
		printf&#40;  "Could not open dir &#40;%s&#41;\n", shortpath&#41;;
	&#125;
	
	
	printf&#40; "Done\n"&#41;;
exit_app&#58;
	sceKernelDelayThread&#40; 2 * 1000000 &#41;;
	sceKernelExitGame&#40; &#41;;
	return 0;
&#125;


Inside the ms root i have several files and dirs, some with english names and
others with japanese names. Now if i compile the app like a kernel one with the PSP_MODULE_INFO("FAT_TEST", 0x1000, 0, 1); all the japanese names get read properly and I can open the files, but if i compile it like a user mode app with PSP_MODULE_INFO("FAT_TEST", 0x0, 0, 1); the japanese names get read wrong (something like ___.mp3) and cannot be opened.

I have tried some apps like the ereader and it works fine for the 1.5 kernel version but for the 3.xx kernel version it cannot play the japanese names mp3s, and the latest build of cooleyes ppa for 3.xx kernel can't enter directories with japanese names either.

I'm using the 3.90 m33 firmware and a psp fat for testing. Does it have anything to do with the firmware version?

Does anyone know how to solve this? Thanks in advance!!
Archaemic
Posts: 38
Joined: Sun Mar 18, 2007 7:23 am

Post by Archaemic »

I've been encountering the same problem, but was unaware that a kernel mode module could read properly...

Anyway, all non-ascii characters get read as -2.
theHobbit
Posts: 65
Joined: Sat Sep 30, 2006 5:26 am

Post by theHobbit »

now i think i have found a solution, if you change the charset (to shift jis for example) in the psp system settings the japanese names are read properly now, but i dont know if something can be done to the fat.c code to handle this with any charset in the system settings.
Archaemic
Posts: 38
Joined: Sun Mar 18, 2007 7:23 am

Post by Archaemic »

Ahh, I see, all the characters are read in depending on the current codepage that the system settings are set to.

Is there any way to circumvent this or have it use a certain codepage for the duration of the program?
Post Reply