📄 jvm_file.c
字号:
}
return NULL;
}
/*****************************************************************************
* FUNCTION
* jvm_file_findnext
* DESCRIPTION
*
* PARAMETERS
* void
* RETURNS
*
*****************************************************************************/
char *jvm_file_findnext(void)
{
/*----------------------------------------------------------------*/
/* Local Variables */
/*----------------------------------------------------------------*/
FS_DOSDirEntry info;
int file_count = work_info_ptr->virtual_file_info.virtual_file_count;
/*----------------------------------------------------------------*/
/* Code Body */
/*----------------------------------------------------------------*/
if (!find_file_from_vitual_file)
{
if (FS_FindNext(KVM_FindFilehandle, &info, WCHARFilename, 2 * MAX_WCHAR_FILENAME_LEN) == FS_NO_ERROR)
{
kal_dchar2char(WCHARFilename, CHARFilename);
return CHARFilename;
}
else
{
find_file_from_vitual_file = KAL_TRUE;
if (KVM_FindFilehandle > 0)
{
FS_FindClose(KVM_FindFilehandle);
}
}
}
if (find_file_is_java_dir)
{
if (find_file_vitual_file_id < (kal_uint32) file_count)
{
return (char*)work_info_ptr->virtual_file_info.virtual_file_name[find_file_vitual_file_id++];
}
else
{
return NULL;
}
}
else
{
while (find_file_vitual_file_id < (kal_uint32) file_count)
{
if (strncmp
(findString, work_info_ptr->virtual_file_info.virtual_file_name[find_file_vitual_file_id],
strlen(findString)) == 0)
{
return (char*)work_info_ptr->virtual_file_info.virtual_file_name[find_file_vitual_file_id++];
}
else
{
find_file_vitual_file_id++;
}
}
}
return NULL;
}
/*****************************************************************************
* FUNCTION
* jvm_file_isexist
* DESCRIPTION
*
* PARAMETERS
* filename [?]
* RETURNS
*
*****************************************************************************/
int jvm_file_isexist(char *filename)
{
/*----------------------------------------------------------------*/
/* Local Variables */
/*----------------------------------------------------------------*/
/*----------------------------------------------------------------*/
/* Code Body */
/*----------------------------------------------------------------*/
/* system files are files except .db, .jar files */
if (is_system_file((char*)filename))
{
kal_wsprintf(WCHARFilename, "%s\\%s", work_sys_dir_path, filename);
}
else
{
kal_wsprintf(WCHARFilename, "%s\\%s", work_dir_path, filename);
}
if (FS_GetAttributes(WCHARFilename) < 0)
{
int i, file_count = work_info_ptr->virtual_file_info.virtual_file_count;
/* if didn't find that, try virtual files */
for (i = 0; i < file_count; i++)
{
if (strcmp(filename, work_info_ptr->virtual_file_info.virtual_file_name[i]) == 0)
{
return 1;
}
}
return 0;
}
else
{
return 1;
}
}
/*****************************************************************************
* FUNCTION
* jvm_file_device_ind_handler
* DESCRIPTION
*
* PARAMETERS
* ilm_ptr [?]
* RETURNS
* void
*****************************************************************************/
void jvm_file_device_ind_handler(ilm_struct *ilm_ptr)
{
/*----------------------------------------------------------------*/
/* Local Variables */
/*----------------------------------------------------------------*/
/*----------------------------------------------------------------*/
/* Code Body */
/*----------------------------------------------------------------*/
switch (ilm_ptr->msg_id)
{
case MSG_ID_FMT_MMI_CARD_PLUG_IN_IND:
/*
* if the Java task has been paused, we don't have to handle the message.
* * The disk info will be retrieved again on resume.
*/
if (!jvm_vm_is_paused() && jvm_is_busy())
{
int i;
for (i = 0; i < 25; i++)
{
if ((disk_info[i].drive_type == FS_DRIVE_V_REMOVABLE) && (disk_info[i].serial == 1))
{
disk_info[i].is_mounted = KAL_TRUE;
disk_changed = KAL_TRUE;
}
}
}
/* If JVM is waiting for message to wakeup, send the message */
if (g_jvm_keypad_need_notify)
{
ilm_struct *send_ilm;
g_jvm_keypad_need_notify = KAL_FALSE;
send_ilm = (ilm_struct*) allocate_ilm(MOD_MMI);
send_ilm->local_para_ptr = NULL;
send_ilm->peer_buff_ptr = NULL;
send_ilm->msg_id = MSG_ID_JAVA_KEYPAD_NOTIFY_IND;
SEND_ILM(MOD_MMI, MOD_J2ME, MMI_J2ME_SAP, send_ilm);
}
/*
* pause VM for a while, let FMT task can complete drive checking.
* * XXX, the mechanism should apply to other VM solution, too.
*/
g_jvm_card_plugin_event = 5;
break;
case MSG_ID_FMT_MMI_CARD_PLUG_OUT_IND:
/*
* if the Java task has been paused, we don't have to handle the message.
* * The disk info will be retrieved again on resume.
*/
if (!jvm_vm_is_paused() && jvm_is_busy())
{
int i;
for (i = 0; i < 25; i++)
{
if ((disk_info[i].drive_type == FS_DRIVE_V_REMOVABLE) && (disk_info[i].serial == 1))
{
disk_info[i].is_mounted = KAL_FALSE;
disk_changed = KAL_TRUE;
}
}
}
/* If JVM is waiting for message to wakeup, send the message */
if (g_jvm_keypad_need_notify)
{
ilm_struct *send_ilm;
g_jvm_keypad_need_notify = KAL_FALSE;
send_ilm = (ilm_struct*) allocate_ilm(MOD_MMI);
send_ilm->local_para_ptr = NULL;
send_ilm->peer_buff_ptr = NULL;
send_ilm->msg_id = MSG_ID_JAVA_KEYPAD_NOTIFY_IND;
SEND_ILM(MOD_MMI, MOD_J2ME, MMI_J2ME_SAP, send_ilm);
}
default:
break;
}
}
/*****************************************************************************
* FUNCTION
* _jvm_file_is_disk_avialable
* DESCRIPTION
*
* PARAMETERS
* drive [IN]
* RETURNS
*
*****************************************************************************/
kal_bool _jvm_file_is_disk_avialable(char drive)
{
/*----------------------------------------------------------------*/
/* Local Variables */
/*----------------------------------------------------------------*/
FS_HANDLE temp_handle;
/*----------------------------------------------------------------*/
/* Code Body */
/*----------------------------------------------------------------*/
disk_access_name[0] = drive + 'A';
temp_handle = FS_Open(disk_access_name, FS_OPEN_DIR | FS_READ_ONLY);
if (temp_handle >= 0)
{
FS_Close(temp_handle);
return KAL_TRUE;
}
return KAL_FALSE;
}
/*****************************************************************************
* FUNCTION
* jvm_file_update_diskinfo
* DESCRIPTION
*
* PARAMETERS
* void
* RETURNS
* void
*****************************************************************************/
void jvm_file_update_diskinfo(void)
{
/*----------------------------------------------------------------*/
/* Local Variables */
/*----------------------------------------------------------------*/
int i;
int temp_id = FS_GetDrive(FS_DRIVE_V_NORMAL, 1, FS_NO_ALT_DRIVE);
/*----------------------------------------------------------------*/
/* Code Body */
/*----------------------------------------------------------------*/
/* drive_type 0 means invalid type. */
for (i = 0; i < 25; i++)
{
disk_info[i].drive_type = 0;
}
if (FS_GetDevStatus((unsigned int)temp_id, FS_EXPORT_STATE_ENUM) == FS_DEVICE_EXPORTED_ERROR)
{
temp_id = -1; /* this disk drive is used by USB and should not be manipulated by Java */
}
temp_id -= 'A';
if (temp_id >= 0 && temp_id <= 25)
{
disk_info[temp_id].drive_type = FS_DRIVE_V_NORMAL;
disk_info[temp_id].serial = 1;
if (_jvm_file_is_disk_avialable((char)temp_id))
{
disk_info[temp_id].is_mounted = KAL_TRUE;
}
else
{
disk_info[temp_id].is_mounted = KAL_FALSE;
}
}
temp_id = FS_GetDrive(FS_DRIVE_V_NORMAL, 2, FS_NO_ALT_DRIVE);
if (FS_GetDevStatus((unsigned int)temp_id, FS_EXPORT_STATE_ENUM) == FS_DEVICE_EXPORTED_ERROR)
{
temp_id = -1; /* this disk drive is used by USB and should not be manipulated by Java */
}
temp_id -= 'A';
if (temp_id >= 0 && temp_id <= 25)
{
disk_info[temp_id].drive_type = FS_DRIVE_V_NORMAL;
disk_info[temp_id].serial = 2;
if (_jvm_file_is_disk_avialable((char)temp_id))
{
disk_info[temp_id].is_mounted = KAL_TRUE;
}
else
{
disk_info[temp_id].is_mounted = KAL_FALSE;
}
}
temp_id = FS_GetDrive(FS_DRIVE_V_REMOVABLE, 1, FS_NO_ALT_DRIVE);
if (FS_GetDevStatus((unsigned int)temp_id, FS_EXPORT_STATE_ENUM) == FS_DEVICE_EXPORTED_ERROR)
{
temp_id = -1; /* this disk drive is used by USB and should not be manipulated by Java */
}
temp_id -= 'A';
if (temp_id >= 0 && temp_id <= 25)
{
disk_info[temp_id].drive_type = FS_DRIVE_V_REMOVABLE;
disk_info[temp_id].serial = 1;
if (_jvm_file_is_disk_avialable((char)temp_id))
{
disk_info[temp_id].is_mounted = KAL_TRUE;
}
else
{
disk_info[temp_id].is_mounted = KAL_FALSE;
}
}
}
/*****************************************************************************
* FUNCTION
* check_and_create_hidden_folder
* DESCRIPTION
*
* PARAMETERS
* folder [?]
* RETURNS
*
*****************************************************************************/
kal_int32 check_and_create_hidden_folder(kal_wchar *folder)
{
/*----------------------------------------------------------------*/
/* Local Variables */
/*----------------------------------------------------------------*/
kal_int32 attribute = FS_GetAttributes(folder);
kal_int32 return_code = FS_NO_ERROR;
/*----------------------------------------------------------------*/
/* Code Body */
/*----------------------------------------------------------------*/
if (attribute > 0)
{
/* this directory maybe exists */
if ((attribute & FS_ATTR_DIR) == FS_ATTR_DIR)
{
/* add hidden attribute */
if ((attribute & FS_ATTR_HIDDEN) != FS_ATTR_HIDDEN)
{
FS_SetAttributes(folder, (BYTE) (attribute | FS_ATTR_HIDDEN));
}
return return_code;
}
else
{ /* This is a file. The file should not be there */
FS_Delete(folder);
}
}
/* this directory doesn't exist. Create the directory */
return_code = FS_CreateDir(folder);
if (return_code != FS_NO_ERROR)
{
return return_code;
}
FS_SetAttributes(folder, (BYTE) (attribute | FS_ATTR_HIDDEN));
return return_code;
}
/* Dennis Shih */
extern j2me_custom_resource_info_struct g_jvm_resource_info;
/*****************************************************************************
* FUNCTION
* getAliasDrive
* DESCRIPTION
* Get the alias drive from j2me_custom_resource_info_struct by index.
* PARAMETERS
* idx [IN] The index of the alias drive in the structure.
* RETURNS
* The alias drive name.
*****************************************************************************/
kal_char *getAliasDrive(int idx)
{
/*----------------------------------------------------------------*/
/* Local Variables */
/*----------------------------------------------------------------*/
kal_char *aliasname = NULL;
/*----------------------------------------------------------------*/
/* Code Body */
/*----------------------------------------------------------------*/
aliasname = g_jvm_resource_info.alias_drive[idx];
return aliasname;
}
/* Dennis Shih */
/*****************************************************************************
* FUNCTION
* getAliasDriveType
* DESCRIPTION
* Get the alias drive type from j2me_custom_resource_info_struct by index.
* PARAMETERS
* idx [IN] The index of the alias drive in the structure.
* RETURNS
* The alias drive type.
*****************************************************************************/
kal_int32 getAliasDriveType(int idx)
{
/*----------------------------------------------------------------*/
/* Local Variables */
/*----------------------------------------------------------------*/
/*----------------------------------------------------------------*/
/* Code Body */
/*----------------------------------------------------------------*/
if (idx < 0)
return -1;
return g_jvm_resource_info.alias_drive_type[idx];
}
/* Dennis Shih */
/*****************************************************************************
* FUNCTION
* getRealDrive
* DESCRIPTION
* Get the real drive name by FS_GetDrive().
* PARAMETERS
* type [IN] The type of the drive.
* RETURNS
* The real drive name.
*****************************************************************************/
kal_int32 getRealDrive(int type)
{
/*----------------------------------------------------------------*/
/* Local Variables */
/*----------------------------------------------------------------*/
int realdrive = 0;
/*----------------------------------------------------------------*/
/* Code Body */
/*----------------------------------------------------------------*/
if (type == FS_DRIVE_V_NORMAL)
{
realdrive = FS_GetDrive(FS_DRIVE_V_NORMAL, 1, FS_NO_ALT_DRIVE);
}
else
{
realdrive = FS_GetDrive(FS_DRIVE_V_REMOVABLE, 1, FS_NO_ALT_DRIVE);
}
realdrive -= 'A';
return realdrive;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -