Exemplo n.º 1
0
/**
* @brief Refer OrigName and create a NewName
* @param OrigName ucs2 filename for reference ex. "Test1.txt"
* @param NewName Output ucs2 filename "Test1
* @param u4MaxSize NewName size in bytes
*/
U32 btmtk_goep_gen_temp_filename(U32 count,const U8 *OrigName, U8 *NewName, U32 u4MaxSize){
    U8 d1, d2, d3;
    U8 buffer[16];
        
    if( 0 == count ){
        ext_ucs2ncpy((S8 *)NewName, (const S8 *)OrigName, u4MaxSize);
        return ext_ucs2strlen((const S8*) NewName );
    }
    
    /// find the "." in Origname and append it with number
    /// ex. Test1.txt ot Test1(dup-xxx).txt

    count = count % 1000; // only support 3 digital
    d1 =  (U8)(count/100);
    d2 =  (U8)( (count - (d1 * 100) )/10);
    d3 =  (U8)(count - (d1 * 100) - ( d2 * 10));
    if( d3 != (count%10) ){
        //ERROR!
        d1 = d2 = d3 = 0;
    }
    buffer[0] = '0';
    buffer[1] = buffer[3] = buffer[5] = buffer[7] = buffer[8]= buffer[9]= 0;
    buffer[2] = '0' + d1;
    buffer[4] = '0' + d2;
    buffer[6] = '0' + d3;  
    ext_ucs2ncpy((S8 *)NewName, "D u p ( ", u4MaxSize);
    ext_ucs2ncat((S8 *)NewName, (const S8 *)buffer, u4MaxSize);
    ext_ucs2ncat((S8 *)NewName, (const S8 *)") ", u4MaxSize);    
    ext_ucs2ncat((S8 *)NewName, (const S8 *)OrigName, u4MaxSize);
    return ext_ucs2strlen((const S8*)NewName);
}
Exemplo n.º 2
0
/*
 * OPP Server receives a file
 */
U16 * bt_goep_make_tmpfile_prefix(U16 *name, U16 size, U16 *old_name, U16 num)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    static U16 prefix[10];
    U16 l1, l2;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    //TODO ascii to unicode
    sprintf( (S8 *)prefix, (const S8 *)"Dup(%d)", num);

    l1 = ext_ucs2strlen((const S8*)prefix);
    l2 = ext_ucs2strlen((const S8*)old_name);

    size = size -1;

    if (l1 + l2 > size)
    {
        return NULL;
    }

    ext_ucs2ncpy((S8 *)name, (S8 *)prefix, OPPS_TMP_BUFF_SIZE);
    ext_ucs2ncat((S8 *)name, (S8 *)old_name, OPPS_TMP_BUFF_SIZE);

    return name;
}
Exemplo n.º 3
0
/*****************************************************************************
 * FUNCTION
 *  bt_goep_make_folderpath
 * DESCRIPTION
 *  This function is to make full path of receive file
 * PARAMETERS
 * path     [OUT]
 * drive    [IN]
 * folder   [IN]
 * file     [IN]
 * RETURNS
 *  S32
 *****************************************************************************/
U16 * bt_goep_make_folderpath(U16 *path, U8 drive, U16 *folder, U16 *file)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    U16 l1 = 0, l2 = 0;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    BT_OPP_ASSERT(path);

    path[l1] = L'\0';

    if (drive)
    {
        sprintf( (S8*) path, (const S8 *) "%c:\\", drive);
        l1 = ext_ucs2strlen((const S8*)path);
        path[l1] = L'\0';
    }

    if (folder)
    {
        //TODO check path length
        ext_ucs2ncat((S8 *)path, (S8 *)folder, OPPS_TMP_BUFF_SIZE);

        l2 = ext_ucs2strlen((const S8*)folder);
        l1 += l2;
        if (folder[l2-1] != L'\\' && file)
        {
            path[l1] = L'\\';
            l1++;
        }

        path[l1] = L'\0';
    }

    if (file)
    {
        ext_ucs2ncat((S8 *)path, (S8 *)file, OPPS_TMP_BUFF_SIZE);
    }

    return path;
}
Exemplo n.º 4
0
/**
* @brief Compose Folder and Filename to Filepath
* @param Folder ucs2 folder path ex. L"\\est"
* @param Filename ucs2 filename ex. L"Text1.txt"
* @param Filepath Output filepath ex. L"\\est\\Text1.txt"
* @param u4MaxSize the size of FilePath in bytes
* 
*/
U32 btmtk_goep_compose_filepath(const U8 *Folder1, const U8 *Folder2, U8 *FilePath, U32 u4MaxSize){
    S32 index;
    ext_ucs2ncpy((S8 *)FilePath, (const S8 *)Folder1, u4MaxSize);

    index = ext_ucs2strlen((const S8*) FilePath );
    if( index > 0){
        index--;
        if( (FilePath[index*2] == '\\' ||FilePath[index*2] == '/' ) && FilePath[index*2+1] == 0   ){
            FilePath[index*2] = FilePath[index*2+1] = 0;
        }else if( (Folder1[index*2] == '\\' ||Folder1[index*2] == '/' ) && Folder1[index*2+1] == 0 ) {
            FilePath[index*2] = FilePath[index*2+1] = 0;
        }
    }
    
    ext_ucs2ncat( (S8 *)FilePath, (const S8*) "/", u4MaxSize); // FS_FOLDER_DELIMITOR
    
    index = ext_ucs2strlen((const S8*) Folder2 );
    if( index > 0){
        if( (Folder2[0] == '\\' || Folder2[0] == '/') && Folder2[1] == 0 ){
            Folder2 +=2;
        }else if(  (Folder2[1] == '\\'  || Folder2[1] == '/' )&& Folder2[0] == 0 ){
            Folder2 +=2;
        }else{
        }

        ext_ucs2ncat((S8 *)FilePath, (const S8 *)Folder2, u4MaxSize);
    }

    index = ext_ucs2strlen((const S8*) FilePath );
    if( index >= 0){
        index--;
        if( (FilePath[index*2] == '\\' ||FilePath[index*2] == '/' ) && FilePath[index*2+1] == 0   ){
            FilePath[index*2] = FilePath[index*2+1] = 0;
        }else if( (FilePath[index*2] == '\\' ||FilePath[index*2] == '/' ) && FilePath[index*2+1] == 0 ) {
            FilePath[index*2] = FilePath[index*2+1] = 0;
        }
    }

    return ext_ucs2strlen((const S8*)FilePath);
}
Exemplo n.º 5
0
/**
* @brief This function is to truncate object name if exceeds max buffer size
* PARAMETERS
* new_name    [OUT]
* old_name    [IN]
* max_len     [IN]
**/
void bt_goep_truncate_ntoh_filename(U16 *dst_name, const U16 *src_netname, U16 max_dst_len)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    U32 src_name_len;
    U16 *p_ext, *p1;
    U32 ext_len;
    U16 copy_len;
    S8 l_wave[8];
    if( 0 == max_dst_len ){
        GOEP_ASSERT(0);
    }
    
    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/

    src_name_len = ext_ucs2strlen((const S8*)src_netname);

    // max_dst_len /= ENCODING_LENGTH;
    max_dst_len /= 2; //TODO unicode is 2 byte
     
    if (src_name_len < max_dst_len)
    {
        /* need not truncate */
        ext_ucs2ncpy((S8 *)dst_name, (S8 *) src_netname, max_dst_len);

        p1 = dst_name;
        for(; *p1; p1++)
        {
            *p1 = bt_goep_ntohs(*p1);
        }
        *p1 = (U16)'\0';

    }
    else
    {
        /* need truncate */
        GOEP_MEMSET( (U8*) dst_name, 0, max_dst_len * 2 ); //* ENCODING_LENGTH);
        
        /* find filename ext */
        p_ext = (U16 *)ext_ucs2rchr((const S8 *)(S8 *)src_netname, (U16)(L'.'));
        
        if(p_ext)
        {
            ext_len = ext_ucs2strlen((const S8*)p_ext);
        }
        else
        {
            ext_len = 0;
        }
        
        /* 1 char for '~'; 1 char for \0 */
        copy_len = (U16) (max_dst_len - ext_len - 1 - 1 );
        ext_ucs2ncpy((S8 *) l_wave, (const S8*) L"-", 8);
        p1 = (U16 *)l_wave;
        for(; *p1; p1++)
        {
            *p1 = bt_goep_ntohs(*p1);
        }
        
        
        ext_ucs2ncpy((S8 *)dst_name, (const S8 *)src_netname, copy_len);
        ext_ucs2ncat((S8 *)dst_name, (const S8 *)l_wave, max_dst_len);
        if (p_ext)
        {
            ext_ucs2ncat((S8 *)dst_name, (const S8 *)p_ext, max_dst_len);
        }
        
        p1 = dst_name;
        for(; *p1; p1++)
        {
            *p1 = bt_goep_ntohs(*p1);
        }
        *p1 = (U16)'\0';
        
    }
    
}
Exemplo n.º 6
0
/*
* @param ucFilename ucs2 filename
* @u4MaxLen bytes
*/
BT_BOOL btmtk_goep_get_private_filepath(U8 type, const U8 *ucFilename, U8 *ucOutFilepath, U32 u4MaxLen) {
    BT_BOOL l_bret = FALSE;

#if defined(BTMTK_ON_WISESDK)
    //SDK
    U8 tempPath[512];
    U8 l_u2RootPath[512];

    btmtk_os_memset( l_u2RootPath, 0, sizeof(l_u2RootPath));
    ext_chset_utf8_to_ucs2_string( l_u2RootPath, sizeof(l_u2RootPath)-2, g_bt_dir_buf);
    if( FALSE == btmtk_goep_is_folder_exist( (const U16*) l_u2RootPath) ) {
        GOEP_Report("[GOEP] btmtk_goep_get_private_filepath no root folder");
        return FALSE;
    }

    /// <sdk root path>\\xxx\\@btmtk\\ folder
    ext_ucs2ncpy( (S8*)tempPath, l_u2RootPath, sizeof(tempPath)/2);
    ext_ucs2ncat( (S8*)tempPath, (const S8*)L"\\Component\\MBT\\HWAdapt\\MTK\\LIB\\@btmtk", sizeof(tempPath)/2);
    if( 0 != ext_ucs2strlen((const S8*)tempPath) && FALSE == btmtk_goep_is_folder_exist((const U16*)tempPath) ) {
        btmtk_goep_create_folder((const U16*)tempPath);
    }

    switch(type) {
    case 0:  /// <sdk root path>\\xxx\\@btmtk\\ .
        ext_ucs2ncat( (S8*)tempPath, (const S8*)L"\\", sizeof(tempPath)/2);
        ext_ucs2ncat( (S8*)tempPath, ucFilename, sizeof(tempPath)/2);
        ext_ucs2ncpy((S8 *) ucOutFilepath, tempPath, u4MaxLen );
        if( ext_ucs2strlen((const S8*)ucOutFilepath) == ext_ucs2strlen((const S8*)tempPath) ) {
            l_bret = TRUE;
        }

        break;
    case 1:  /// <sdk root path>\\xxx\\@btmtk\\profile
        ext_ucs2ncpy( (S8*)tempPath, l_u2RootPath, sizeof(tempPath)/2);
        ext_ucs2ncat( (S8*)tempPath, (const S8*)L"\\Component\\MBT\\HWAdapt\\MTK\\LIB\\@btmtk\\profile", sizeof(tempPath)/2);
        if( FALSE == btmtk_goep_is_folder_exist((const U16*)tempPath) ) {
            btmtk_goep_create_folder((const U16*)tempPath);
        }
        ext_ucs2ncat( (S8*)tempPath, (const S8*)L"\\", sizeof(tempPath)/2);
        ext_ucs2ncat( (S8*)tempPath, ucFilename, sizeof(tempPath)/2);
        ext_ucs2ncpy((S8 *) ucOutFilepath, tempPath, u4MaxLen );
        if( ext_ucs2strlen((const S8*)ucOutFilepath) == ext_ucs2strlen((const S8*)tempPath) ) {
            l_bret = TRUE;
        }

        break;
    case 2:  /// <sdk root path>\\xxx\\@btmtk\\data
        ext_ucs2ncpy( (S8*)tempPath, l_u2RootPath, sizeof(tempPath)/2);
        ext_ucs2ncat( (S8*)tempPath, (const S8*)L"\\Component\\MBT\\HWAdapt\\MTK\\LIB\\@btmtk\\data", sizeof(tempPath)/2);
        if( FALSE == btmtk_goep_is_folder_exist((const U16*)tempPath) ) {
            btmtk_goep_create_folder((const U16*)tempPath);
        }
        ext_ucs2ncat( (S8*)tempPath, (const S8*)L"\\", sizeof(tempPath)/2);
        ext_ucs2ncat( (S8*)tempPath, ucFilename, sizeof(tempPath)/2);
        ext_ucs2ncpy((S8 *) ucOutFilepath, tempPath, u4MaxLen );
        if( ext_ucs2strlen((const S8*)ucOutFilepath) == ext_ucs2strlen((const S8*)tempPath) ) {
            l_bret = TRUE;
        }
        break;
    default:
        GOEP_Report("[OBEX][Err] btmtk_goep_get_private_filepath fail param:%d");
        break;
    }

#else
    // Target
    U8 tempPath[512];

    switch(type) {
    case 0: /// Z:\\@btmtk
        ext_ucs2ncpy( (S8 *) tempPath, (const S8*)L"Z:\\@btmtk", sizeof( tempPath ) );
        break;
    case 1: /// C:\\@btmtk\\profiles
        ext_ucs2ncpy( (S8 *) tempPath, (const S8*)L"C:\\@btmtk\\profiles", sizeof( tempPath ) );
        break;
    case 2: /// C:\\@btmtk\\data
        ext_ucs2ncpy( (S8 *) tempPath, (const S8*)L"C:\\@btmtk\\data", sizeof( tempPath ) );
        break;
    default:
        break;
    }

    if( 0 != ext_ucs2strlen((const S8*)tempPath) ) {
        if (FALSE == btmtk_goep_is_folder_exist( (const U16*) tempPath) ) {
            btmtk_goep_create_folder((const U16*)tempPath);
        }
        ext_ucs2ncat( (S8*)tempPath, (const S8*)L"\\", sizeof(tempPath)/2);
        ext_ucs2ncat( (S8*)tempPath, (const S8*)ucFilename, sizeof(tempPath)/2);

        ext_ucs2ncpy( (S8 *)ucOutFilepath, (const S8*)tempPath, u4MaxLen);
        if( ext_ucs2strlen((const S8*)ucOutFilepath) == ext_ucs2strlen((const S8*)tempPath) ) {
            l_bret = TRUE;
        }
    }

#endif
    return l_bret;
}
Exemplo n.º 7
0
S32 btmtk_goep_fs_findfirst(U8 *ucFolderPath, bt_ftp_find_struct **findstruct, bt_ftp_obj_info_struct *ftp_file_info) {
#ifdef BTMTK_GOEP_USE_WIN32_FS
    char sdir[256];
    char filter[64];
    U32 test_arrtibe;
    struct _wfinddata_t c_file;
    long hFile;
    bt_ftp_find_struct *pfind;

    GOEP_MEMSET((U8 *)ftp_file_info, 0, sizeof(bt_ftp_obj_info_struct) );

    ext_ucs2_str_n_to_asc_str(sdir, ucFolderPath, sizeof(sdir));

    // keep the previous folder path
    g_oldcwd[0] = 0;
    if ( NULL == _wgetcwd( (U16 *)g_oldcwd, sizeof(g_oldcwd)/2 ) ) {
        /// cannot keep the current folder
        GOEP_Report("[FS][ERR] fail to get cwd bufsize:(%d) err:%d!", sizeof(g_oldcwd)/2, GetLastError());
        return EXT_FS_ERR;
    }

    printf( "[fs] getcwd is '%s'\n", g_oldcwd);
    printf( "[fs] fs findfirst '%s' \n", sdir );
    _wchdir( (U16 *) ucFolderPath );


    ext_strncpy (filter, "*.*", 64);
    hFile = _wfindfirst(L"*.*", &c_file);

    if( -1 == hFile ) {
        return EXT_FS_ERR;
    } else {
        //plong = (long * )malloc(sizeof(long));
        pfind = (bt_ftp_find_struct *) malloc( sizeof(bt_ftp_find_struct) );
        *findstruct = pfind;

        if( *findstruct == NULL ) {
            return EXT_FS_ERR;
        }
        ((bt_ftp_find_struct *)*findstruct)->hFile = hFile;

        ext_ucs2ncpy( (S8 *) ftp_file_info->file_name, (const S8 *) c_file.name, sizeof(ftp_file_info->file_name)/2);
        update_win32_file_time(ftp_file_info);
        test_arrtibe = (_A_SUBDIR & c_file.attrib);
        if( _A_SUBDIR == test_arrtibe) {
            ftp_file_info->isFile = FALSE;
        } else {
            ftp_file_info->isFile = TRUE;
        }
        return EXT_FS_OK;
    }
#endif

#ifdef BTMTK_ON_WISE
    U8 *filter;
    S32 hFile;
    S32 len;
    bt_ftp_find_struct *pfind;
    FS_DOSDirEntry dir_entry;
    U8 filename[ BTMTK_EP_MAX_FILENAME_LEN ]; /// output

    //ext_ucs2ncpy (filter, (const U8 *)L"\\*.*", sizeof(filter)/2);
    len = ext_ucs2strlen((const S8*)ucFolderPath)*2 + 10;
    filter = (U8 *) get_ctrl_buffer( len ); // plus L"\\*.*"
    if( NULL == filter ) {
        return EXT_FS_ERR;
    }
    btmtk_os_memset( filter, 0, len);
    ext_ucs2ncpy( (U8 *) filter,  (const U8 *) ucFolderPath , len-2);
    ext_ucs2ncat( (U8 *) filter, (const U8 *) L"\\*.*", len-2);

    ext_ucs2ncpy((S8 *)filename, (const U8 *)L"", (sizeof(filename)/2)-1);

    hFile = (S32) FS_FindFirst(
                (const WCHAR*)filter,
                0,
                0,
                &dir_entry,
                (U16*) filename,
                sizeof(filename) );
    if( NULL == filter ) {
        free_ctrl_buffer(filter);
        filter = NULL;
    }
    if ( hFile >= 0) {
        GOEP_MEMSET((U8 *)ftp_file_info, 0, sizeof(bt_ftp_obj_info_struct) );
        pfind = (bt_ftp_find_struct *) get_ctrl_buffer( sizeof(bt_ftp_find_struct) );
        *findstruct = pfind;
        if( *findstruct == NULL ) {
            FS_FindClose( (FS_HANDLE) hFile );
            return EXT_FS_ERR;
        }
        ((bt_ftp_find_struct *)*findstruct)->hFile = hFile;

        static_convert_DirEntry_to_file_info( &dir_entry, ftp_file_info , filename);

        return EXT_FS_OK;
    } else {
        return EXT_FS_ERR;
    }

#endif

#ifdef BTMTK_ON_LINUX

    int ret;
    int err_num;

    bt_ext_log("[GOEP_FS] btmtk_goep_fs_findfirst(): Linux Version.");

    ext_chset_ucs2_to_utf8_string((U8 *) g_folder_path, sizeof(g_folder_path)-1, ucFolderPath);
    // strncpy(g_folder_path, ucFolderPath, sizeof(g_folder_path));
    bt_ext_log("[GOEP_FS] g_folder_path: %s", g_folder_path);

    g_opened_dir = opendir( g_folder_path);
    if (g_opened_dir == NULL) {
        err_num = errno;
        bt_ext_err("[FS_ERR] opendir() failed. %s", (char*) strerror(err_num));
        return EXT_FS_ERR;
    }

    return static_linux_fill_file_info(ftp_file_info);

#endif

    return EXT_FS_ERR;
}