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 

Strange problem with japanese filenames and user mode app!

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



Joined: 30 Sep 2006
Posts: 65

PostPosted: Thu Mar 20, 2008 3:34 am    Post subject: Strange problem with japanese filenames and user mode app! Reply with quote

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:


/*
*/

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

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

extern "C" {
#include "fat.h"
}

PSP_MODULE_INFO("FAT_TEST", 0x0, 0, 1);
PSP_MAIN_THREAD_NAME("Fat Test");

#define printf pspDebugScreenPrintf

#define MS_ROOT      "ms0:/"

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




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



Joined: 18 Mar 2007
Posts: 38

PostPosted: Thu Mar 20, 2008 4:16 am    Post subject: Reply with quote

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



Joined: 30 Sep 2006
Posts: 65

PostPosted: Thu Mar 20, 2008 10:43 am    Post subject: Reply with quote

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



Joined: 18 Mar 2007
Posts: 38

PostPosted: Thu Mar 20, 2008 2:43 pm    Post subject: Reply with quote

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