📄 plx_fs.c
字号:
#endif
Attr = 0x00;
AttrMask = 0x00;
#ifdef PLX_FILE_UNICODE
ret = FS_FindFirst( (WCHAR*)filename, Attr, AttrMask, &FileInfo, FileName, 127);
#else
ret = FS_FindFirst(NamePattern, Attr, AttrMask, &FileInfo, FileName, 127);
#endif
if ( ret < 0 ) {
free ( pfind );
return NULL;
}
pfind->findhandle = ret;
if ( FileInfo.Attributes & FS_ATTR_DIR )
pfind->find.filetype = PLXFT_DIR;
else
pfind->find.filetype = PLXFT_FILE;
pfind->find.filesize = FileInfo.FileSize;
#ifdef PLX_FILE_ASCII
UnicodeToAnsii( (S8 *)pfind->find.filename, (S8 *)FileName );
#elif defined PLX_FILE_UTF8
Plx_UnicodeToUTF8( pfind->find.filename, (char*)FileName);
#elif defined PLX_FILE_UNICODE
UCS2Strcpy( (S8 *)pfind->find.filename, FileName );
#endif
return (PLXFINDHANDLE)pfind;
}
int plx_FindNextFile (PLXFINDHANDLE findHandle)
{
find_handle *pfind = (find_handle *)findHandle;
FS_DOSDirEntry FileInfo;
WCHAR FileName[128];
int ret, filehandle;
filehandle = pfind->findhandle;
ret = FS_FindNext(filehandle, &FileInfo, FileName, 127);
if ( ret != FS_NO_ERROR )
return 0;
if ( FileInfo.Attributes & FS_ATTR_DIR )
pfind->find.filetype = PLXFT_DIR;
else
pfind->find.filetype = PLXFT_FILE;
pfind->find.filesize = FileInfo.FileSize;
#ifdef PLX_FILE_ASCII
UnicodeToAnsii( (S8 *)pfind->find.filename, (S8 *)FileName );
#elif defined PLX_FILE_UTF8
Plx_UnicodeToUTF8( pfind->find.filename, (char*)FileName);
#elif defined PLX_FILE_UNICODE
UCS2Strcpy( (S8 *)pfind->find.filename, (const S8 *)FileName );
#endif
return 1;
}
void plx_FindClose(PLXFINDHANDLE hFindFile)
{
find_handle *pfind = (find_handle *)hFindFile;
FS_FindClose( pfind->findhandle );
free ( pfind );
return ;
}
/*********************************************************************\
* Function
* Purpose
* Params
* Return
* Remarks
**********************************************************************/
#define FS_SAVE_SPACE 16*1024
unsigned long plx_GetAvailableSize(const char *drive)
{
WCHAR DriveName[12];
FS_DiskInfo DiskInfo;
unsigned int freesize;
int clustersize;
char drv[5];
S32 fs_ret;
PlxTrace(drive);
plx_strncpy(drv, drive, 4);
drv[4] = '\0';
// drv = *drive;
if ( drv[0] >= 'a' && drv[0] <= 'z' )
drv[0] = drv[0] - 'a' + 'A';
AnsiiToUnicodeString((S8 *)DriveName, (S8 *)drv);
fs_ret = FS_GetDiskInfo(DriveName, &DiskInfo, FS_DI_BASIC_INFO|FS_DI_FREE_SPACE);
if (fs_ret < 0)
{
return 0;
}
#if 0
PlxTrace("*** Get available size - FS_GetClusterSize = %d", clustersize);
PlxTrace("*** Get available size - DiskInfo.BadClusters = %d", DiskInfo.BadClusters);
PlxTrace("*** Get available size - DiskInfo.BytesPerSector = %d", DiskInfo.BytesPerSector);
PlxTrace("*** Get available size - DiskInfo.FreeClusters = %d", DiskInfo.FreeClusters);
PlxTrace("*** Get available size - DiskInfo.SectorsPerCluster = %d", DiskInfo.SectorsPerCluster);
PlxTrace("*** Get available size - DiskInfo.TotalClusters = %d", DiskInfo.TotalClusters);
#endif
freesize = DiskInfo.FreeClusters*DiskInfo.SectorsPerCluster*DiskInfo.BytesPerSector;
PlxTrace("*** Get available size = %d", freesize);
if (freesize < FS_SAVE_SPACE)
return 0;
else
return (freesize-FS_SAVE_SPACE);
}
/*********************************************************************\
* Function
* Purpose
* Params
* Return
* Remarks
**********************************************************************/
/*
#define FILE_ATTRIBUTE_ARCHIVE 0x00000020
#define FILE_ATTRIBUTE_HIDDEN 0x00000002
#define FILE_ATTRIBUTE_NORMAL 0x00000080
#define FILE_ATTRIBUTE_OFFLINE 0x00001000
#define FILE_ATTRIBUTE_READONLY 0x00000001
#define FILE_ATTRIBUTE_SYSTEM 0x00000004
#define FILE_ATTRIBUTE_TEMPORARY 0x00000100
#define FILE_ATTRIBUTE_DIRECTORY 0x00000010
#define FILE_ATTRIBUTE_ENCRYPTED 0x00000040
#define FILE_ATTRIBUTE_SPARSE_FILE 0x00000200
#define FILE_ATTRIBUTE_REPARSE_POINT 0x00000400
#define FILE_ATTRIBUTE_COMPRESSED 0x00000800
#define FILE_ATTRIBUTE_NOT_CONTENT_INDEXED 0x00002000
#define FS_ATTR_ARCHIVE 0x20
#define FS_ATTR_HIDDEN 0x02
#define FS_ATTR_READ_ONLY 0x01
#define FS_ATTR_SYSTEM 0x04
#define FS_ATTR_VOLUME 0x08
#define FS_ATTR_DIR 0x10
#define FS_LONGNAME_ATTR 0x0F
*/
BOOL plx_SetFileAttributes( const char * filename, DWORD dwFileAttributes)
{
WCHAR wFileName[256];
int ret;
BYTE attr = 0;
if( filename == NULL || *filename == 0 )
return 0;
#ifdef PLX_FILE_ASCII
AnsiiToUnicodeString((S8 *)wFileName, (S8 *)filename );
#elif defined PLX_FILE_UTF8
Plx_UTF8ToUnicode( (char*)wFileName, filename);
#else
UCS2Strcpy((S8 * )wFileName, (const S8 * )filename );
#endif
attr = 0;
if ( dwFileAttributes & FILE_ATTRIBUTE_READONLY )
attr |= FS_ATTR_READ_ONLY;
if ( dwFileAttributes & FILE_ATTRIBUTE_HIDDEN )
attr |= FS_ATTR_HIDDEN;
if ( dwFileAttributes & FILE_ATTRIBUTE_SYSTEM )
attr |= FS_ATTR_SYSTEM;
#ifdef MMI_ON_HARDWARE_p // if FS_ATTR_DIR is set, occured error on simulator
if ( dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY )
attr |= FS_ATTR_DIR;
#endif
if ( dwFileAttributes & FILE_ATTRIBUTE_ARCHIVE )
attr |= FS_ATTR_ARCHIVE;
ret = FS_SetAttributes( wFileName, attr );
if ( ret != FS_NO_ERROR )
return 0;
return 1;
}
DWORD plx_GetFileAttributes( const char * filename )
{
WCHAR wFileName[256];
int attr;
DWORD dwAttr = 0;
if( filename == NULL || *filename == 0 )
return 0;
#ifdef PLX_FILE_ASCII
AnsiiToUnicodeString((S8 *)wFileName, (S8 *)filename );
#elif defined PLX_FILE_UTF8
Plx_UTF8ToUnicode( (char*)wFileName, filename);
#else
UCS2Strcpy((S8 * )wFileName, (const S8 * )filename );
#endif
attr = FS_GetAttributes( wFileName );
if ( attr < 0 )
return (DWORD)-1;
if ( (unsigned)attr & FS_ATTR_ARCHIVE )
dwAttr |= FILE_ATTRIBUTE_ARCHIVE;
if ( (unsigned)attr & FS_ATTR_HIDDEN )
dwAttr |= FILE_ATTRIBUTE_HIDDEN;
if ( (unsigned)attr & FS_ATTR_READ_ONLY )
dwAttr |= FILE_ATTRIBUTE_READONLY;
if ( (unsigned)attr & FS_ATTR_SYSTEM )
dwAttr |= FILE_ATTRIBUTE_SYSTEM;
if ( (unsigned)attr & FS_ATTR_DIR )
dwAttr |= FILE_ATTRIBUTE_DIRECTORY;
return (DWORD)dwAttr;
}
/*********************************************************************
* Function
* Purpose
* Params
* Return
* Remarks
**********************************************************************/
#ifdef PLX_FILE_UTF8
static int Plx_UTF8ToUnicode( char *strdest, const char *strsrc)
{
unsigned char code0, code1, code2, uh, ul;
unsigned char *psrc = (unsigned char *)strsrc;
// two bytes not alignment
if ( (unsigned long)strdest & 0x00000001 ) {
unsigned char *pdest = (unsigned char *)strdest;
while ( *psrc != 0 ) {
// 0800 - FFFF 1110xxxx 10xxxxxx 10xxxxxx
if ( (*psrc & 0xE0 ) == 0xE0 ) {
code2 = *psrc++;
code1 = *psrc++;
code0 = *psrc++;
ul = (code0 & 0x3F) + ((code1 & 0x03 ) << 6 );
uh = ((code1 & 0x3C ) >> 2 ) + ((code2 & 0x0f) << 4);
*pdest++ = ul;
*pdest++ = uh;
}else if ( (*psrc & 0xC0 ) == 0xC0 ) {
// 0080 - 07FF 110xxxxx 10xxxxxx
code1 = *psrc++;
code0 = *psrc++;
ul = (code0 & 0x3F) + ((code1 & 0x03 ) << 6 );
uh = (code1 & 0x1C ) >> 2;
*pdest++ = ul;
*pdest++ = uh;
}else if ( *psrc < 128 ) {
*pdest++ = *psrc ++;
*pdest++ = (unsigned char)0;
}
}
*pdest = (unsigned char)0;
*(pdest+1) = (unsigned char)0;
return ((unsigned long)pdest - (unsigned long)strdest);
}
else {
unsigned short *pdest = (unsigned short *)strdest;
while ( *psrc != 0 ) {
// 0800 - FFFF 1110xxxx 10xxxxxx 10xxxxxx
if ( (*psrc & 0xE0 ) == 0xE0 ) {
code2 = *psrc++;
code1 = *psrc++;
code0 = *psrc++;
ul = (code0 & 0x3F) + ((code1 & 0x03 ) << 6 );
uh = ((code1 & 0x3C ) >> 2 ) + ((code2 & 0x0f) << 4);
*pdest++ = (unsigned short)ul + (((unsigned short)uh) << 8 ) ;
}else if ( (*psrc & 0xC0 ) == 0xC0 ) {
// 0080 - 07FF 110xxxxx 10xxxxxx
code1 = *psrc++;
code0 = *psrc++;
ul = (code0 & 0x3F) + ((code1 & 0x03 ) << 6 );
uh = (code1 & 0x1C ) >> 2 ;
*pdest++ = (unsigned short)ul + (((unsigned short)uh) << 8 ) ;
}else if ( *psrc < 128 ) {
*pdest++ = (unsigned short)*psrc++;
}
}
*pdest = 0;
return ((unsigned long)pdest - (unsigned long)strdest);
}
return 0;
}
static int Plx_UnicodeToUTF8( char *strdest, const char *strsrc)
{
unsigned short code0, code1, code2;
unsigned short unicode;
unsigned char *pdest = (unsigned char *)strdest;
// two bytes not alignment
if ( (unsigned long)strsrc & 0x00000001 ) {
unsigned char *psrc= (unsigned char *)strsrc;
unicode = *psrc++;
unicode += *psrc++ << 8;
while ( unicode != 0 ) {
if ( unicode <= 0x007F ) {
*pdest ++ = (unsigned char )unicode;
}
else if ( unicode <= 0x07FF ) {
// 0080 - 07FF 110xxxxx 10xxxxxx
code1 = (( unicode & 0x07c0 ) >> 6 ) | 0x00c0;
code0 = (unicode & 0x003f) | 0x0080;
*pdest++ = (unsigned char)code1;
*pdest++ = (unsigned char)code0;
} else {
// 0800 - FFFF 1110xxxx 10xxxxxx 10xxxxxx
code2 = (( unicode & 0xf000) >> 12 ) | 0x00e0;
code1 = (( unicode & 0x0fc0 ) >> 6 ) | 0x0080;
code0 = (unicode & 0x003f) | 0x0080;
*pdest++ = (unsigned char)code2;
*pdest++ = (unsigned char)code1;
*pdest++ = (unsigned char)code0;
}
unicode = *psrc++;
unicode += *psrc++ << 8;
}
}
else { // two bytes alignment
unsigned short *psrc= (unsigned short *)strsrc;
unicode = *psrc++;
while ( unicode != 0 ) {
if ( unicode <= 0x007F ) {
*pdest ++ = (unsigned char )unicode;
}
else if ( unicode <= 0x07FF ) {
// 0080 - 07FF 110xxxxx 10xxxxxx
code1 = (( unicode & 0x07c0 ) >> 6 ) | 0x00c0;
code0 = (unicode & 0x003f) | 0x0080;
*pdest++ = (unsigned char)code1;
*pdest++ = (unsigned char)code0;
} else {
// 0800 - FFFF 1110xxxx 10xxxxxx 10xxxxxx
code2 = (( unicode & 0xf000) >> 12 ) | 0x00e0;
code1 = (( unicode & 0x0fc0 ) >> 6 ) | 0x0080;
code0 = (unicode & 0x003f) | 0x0080;
*pdest++ = (unsigned char)code2;
*pdest++ = (unsigned char)code1;
*pdest++ = (unsigned char)code0;
}
unicode = *psrc++;
}
}
*pdest = 0;
return ((unsigned long)pdest - (unsigned long)strdest);
}
#endif
/*********************************************************************
* Function
* Purpose
* Params
* Return
* Remarks
**********************************************************************/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -