Exemplo n.º 1
0
CUString COpenFileDlg::GetSubPath( POSITION pos ) 
{

	if ( !m_bKeepDirLayout )
	{
		return _T( "" );
	}

	CUString strRet = GetNextPathName( pos );

	int nStartPos = strRet.Find( m_strDir );
	int nLength = strRet.ReverseFind( _T( '\\' ) ) + 1;

	if ( nStartPos >= 0 )
	{
		nStartPos += 1 + m_strDir.GetLength();
	}

	nLength -= nStartPos;

	if ( nLength < 0 )
	{
		nLength = 0;
	}

	strRet = strRet.Mid( nStartPos, nLength );

	return strRet;
}
Exemplo n.º 2
0
CUString COpenFileDlg::GetFileName( POSITION pos ) 
{
	CUString strRet = GetNextPathName( pos );

	int nPos = strRet.ReverseFind('\\');

	if ( nPos >= 0 )
	{
		strRet = strRet.Mid( nPos + 1 );
	}


	return strRet;
}
Exemplo n.º 3
0
	bool CUniString::TokenizeAsciiEscapedUnicode()
	{
		CUString tmp = GetStr();
		while( true ) {
			int idx = tmp.Find( "\\u" );
			if( idx < 0 )	{
				for( int i=0; i<tmp.GetLength(); i++ ) {
					char ch = tmp.GetAt(i);
					if( (int)ch >= 0 ) {
						char buf[4]; sprintf( buf, "%c", ch );
						unichar_list.PushBack( buf );
						enc_byte += 1;
					}
					else {
						return false;
					}
				}
				break;
			}
			else {
				for( int i=0; i<idx; i++ ) {
					char ch = tmp.GetAt(i);
					if( (int)ch >= 0 ) {
						char buf[4]; sprintf( buf, "%c", ch );
						unichar_list.PushBack( buf );
						enc_byte += 1;
					}
					else {
						return false;
					}
				}
				CUString uni = tmp.SubStr( idx, idx+6 );
				uni = EncodeUTF8( uni );
				unichar_list.PushBack( uni );
				enc_byte += uni.GetLength();
				tmp = tmp.Mid( idx+6 );
			}
		}

		return true;
	}
Exemplo n.º 4
0
CUString	CLanguage::GetMainMenuItem( const DWORD nID, const DWORD nItem )
{
    CUString strRet;

    strRet = GetSubMenuItem( nID );

    DWORD	dwIndex = 0;
    int		nStart  = 0;
    int		nStop   = strRet.GetLength();

    for ( dwIndex = 0; dwIndex < nItem; dwIndex++ )
    {
        nStart = strRet.Find( '#', nStart + 1 );

        if ( -1 == nStart )
        {
            break;
        }
    }

    if ( -1 != nStart )
    {
        nStop = strRet.Find( '#', nStart + 1 );

        if ( -1 == nStop )
        {
            nStop = strRet.GetLength();
        }
    }

    if ( nStop - nStart > 2 )
    {
        strRet = strRet.Mid( nStart + 1, nStop - nStart - 1 );
    }

    return strRet;
}
Exemplo n.º 5
0
BOOL CLanguage::InitDialogStrings( CDialog* pDialog, long lSection )
{
    short nCtrlID;
    CUString sText;
    CWnd* pWndCtrl;
    DWORD	nIndex = 0;
    CUStringConvert strCnv;

    CUString strLang = GetDialogString( MAKELPARAM( 0, lSection ) );

    if( !strLang.IsEmpty() )
    {
        pDialog->SetWindowText( strCnv.ToT( strLang ) );
    }
    else
    {
        CString strMissing;
        pDialog->GetWindowText( strMissing );
        ReportMissingID( MAKELPARAM( 0, lSection ), CUString( strMissing ), 2 );
    }

    // test if the dialog has child windows
    if( pWndCtrl = pDialog->GetWindow( GW_CHILD | GW_HWNDFIRST ) )
    {
        // lool through all controls (windows) and replace text
        do
        {
            nCtrlID = pWndCtrl->GetDlgCtrlID();


            if (	!pWndCtrl->IsKindOf( RUNTIME_CLASS( CEdit ) ) &&
                    !pWndCtrl->IsKindOf( RUNTIME_CLASS( CListCtrl ) ) &&
                    !pWndCtrl->IsKindOf( RUNTIME_CLASS( CSpinButtonCtrl) )
               )
            {

                if( nCtrlID > 0 )
                {
                    // check if the Id is in the range of common strings
                    if( (nCtrlID >= COMMON_IDMIN) && (nCtrlID <= COMMON_IDMAX) )
                    {
                        strLang = GetString( nCtrlID );
                    }
                    else
                    {
                        strLang = GetDialogString( MAKELPARAM( nCtrlID, lSection ) );
                    }

                    if( !strLang.IsEmpty() )
                    {

                        if ( pWndCtrl->IsKindOf( RUNTIME_CLASS( CComboBox ) ) )
                        {
                            CUString strAdd;
                            int		nPos = -1;

                            // remove old strings
                            ((CComboBox*)pWndCtrl)->ResetContent();

                            while ( ( nPos = strLang.Find( '\n' ) ) >= 0 )
                            {
                                ((CComboBox*)pWndCtrl)->AddString( strCnv.ToT( strLang.Left( nPos ) ) );
                                strLang = strLang.Mid( nPos + 1 );
                                nPos++;
                            }

                            if ( strLang.GetLength() > nPos )
                            {
                                ((CComboBox*)pWndCtrl)->AddString( strCnv.ToT( strLang.Mid( nPos ) ) );
                            }
                        }
                        else
                        {
                            pDialog->SetDlgItemText( nCtrlID, strCnv.ToT( strLang ) );
                        }
                    }
                    else
                    {
                        CString strMissing;

                        if ( pWndCtrl->IsKindOf( RUNTIME_CLASS( CComboBox ) ) )
                        {
                            int nIndex = 0;
                            int	nItems = ((CComboBox*)pWndCtrl)->GetCount();

                            for ( nIndex =0; nIndex < nItems; nIndex++ )
                            {
                                CString strTmp;

                                ((CComboBox*)pWndCtrl)->GetLBText( nIndex, strTmp );
                                strMissing += strTmp;

                                if ( nIndex < nItems - 1 )
                                {
                                    strMissing += _T( "\n" );
                                }
                            }
                        }
                        else
                        {
                            pDialog->GetDlgItemText( nCtrlID, strMissing );
                        }
                        if ( !strMissing.IsEmpty() )
                        {
                            ReportMissingID( MAKELPARAM( nCtrlID, lSection ), CUString( strMissing ), 2 );
                        }
                    }
                }
            }

            pWndCtrl = pWndCtrl->GetWindow( GW_HWNDNEXT );

        } while( (pWndCtrl != NULL) && (pWndCtrl != pDialog->GetWindow( GW_CHILD | GW_HWNDFIRST )) );
    }

    return TRUE;
}
Exemplo n.º 6
0
void CLanguage::ParseLanguageFile( const CUString& strFileName )
{
    BOOL bResult		= TRUE;
    DWORD dwRevision	= 0;
    FILE* pFile			= NULL;

    CUString strFullFileName = m_strLanguageDir + _W("\\lang\\") + strFileName + m_strLangFileExt;
    CUStringConvert strCnv;

    pFile = CDexOpenFile( strFullFileName, _W( "r" ) );

    if ( NULL != pFile )
    {
        CHAR lpszRead[ 1024 ];
        int nStart = 0;
        int nStop  = 0;

        CUString strRead;

        memset( lpszRead, 0, sizeof( lpszRead ) );

        while ( fgets( lpszRead, sizeof( lpszRead ), pFile  ) )
        {
            bool         bHasNumber = false;
            bool         bIsMenu    = false;
            bool         bIsDialog  = false;
            bool	     bHasString = false;
            DWORD        nIndex = 0;
            CLangElement newElement;

            strRead = _T( "" );

            for ( nIndex = 0; nIndex< strlen( lpszRead ); nIndex++ )
            {
                if (	( lpszRead[ nIndex ] != 0x0A ) &&
                        ( lpszRead[ nIndex ] != 0x0D ) )
                {
                    strRead +=  (TCHAR)lpszRead[ nIndex ];
                }
            }

            TranslateTab( strRead );

            nStart = strRead.Find( _T( '#' ) );

            if ( nStart >= 0 )
            {
                if ( ( nStart + 1 ) == strRead.Find( _T( 'M' ) ) )
                {
                    nStart++;
                    bIsMenu = TRUE;
                }
                else if ( ( nStart + 1 ) == strRead.Find( _T( 'D' ) ) )
                {
                    nStart++;
                    bIsDialog = TRUE;
                }


                nStop = strRead.Find( _T( '#' ), nStart + 1 );

                if ( nStop > 2 )
                {
                    CUString strID ( strRead.Mid( nStart + 1, nStop - nStart -1 ) );
                    swscanf( strID, _W( "%x" ), &newElement.nID );
                    bHasNumber = true;
                }

            }
            else
            {
                if ( strRead.Find( CODEPAGETAG ) == 0 )
                {
                    m_dwCodePageID = _wtoi( strRead.Mid( CODEPAGETAG.GetLength() ) );
                }
                else if ( strRead.Find( LANGTAG ) == 0 )
                {
                    m_dwLangID = _wtoi( strRead.Mid( LANGTAG.GetLength() ) );
                }
                else if ( strRead.Find( SUBLANGTAG ) == 0 )
                {
                    m_dwSubLangID = _wtoi( strRead.Mid( SUBLANGTAG.GetLength() ) );
                }
                else if ( strRead.Find( REVISIONTAG ) == 0 )
                {
                    int nPos;
                    nPos = strRead.Find( _W( ",v " ) );
                    if ( nPos >= 0 )
                    {
                        float fVersion = 1.0f;
                        swscanf( strRead.Mid( nPos+3,4 ), _W( "%f" ), &fVersion );
                        dwRevision =   (DWORD)( 100 * ( fVersion + 0.005 ) );
                    }

                }
            }

            nStart = strRead.Find( '"' );

            if ( nStart >= 0 )
            {
                nStop = strRead.Find( '"', nStart + 1 );

                if ( nStop > 2 )
                {
                    lpszRead[ 0 ] = '\0';

                    for ( nIndex = nStart + 1; nIndex < (DWORD)nStop; nIndex++)
                    {
                        lpszRead[ nIndex - nStart - 1] = (CHAR)strRead.GetAt( nIndex );
                        lpszRead[ nIndex - nStart ] = '\0';
                    }

                    newElement.strValue = CUString( lpszRead, m_dwCodePageID );
                    bHasString = true;
                }
            }

            if ( bHasString && bHasNumber )
            {
                if ( bIsMenu )
                {
                    m_vMenus.push_back( newElement );
                }
                else if ( bIsDialog )
                {
                    m_vDialogs.push_back( newElement );
                }
                else
                {
                    m_vStrings.push_back( newElement );
                }
            }
            memset( lpszRead, 0, sizeof( lpszRead ) );
        }

        fclose( pFile );
    }


#ifdef UNICODE
    TCHAR* pTest = _wsetlocale( LC_ALL, GetString( 99 ) );
#else
    TCHAR* pTest = setlocale( LC_ALL, strCnv.ToT( GetString( 99 ) ) );

#endif
    SetThreadLocale( MAKELCID( m_dwLangID, m_dwSubLangID ) );
    setlocale( LC_NUMERIC, "English" );
}
Exemplo n.º 7
0
bool CDecoder::LoadFoundation( CUOption* option )
{
	if( option == NULL )	return false;
	this->option = option;

	// check options
	CUString key="foundation";
	CUString foundation_dn;
	if( option->GetValue( key, foundation_dn ) == false ) { fprintf( stderr, "Required option is not defined: foundation\n" ); return false; }
	this->foundation_dn = foundation_dn;

	char fn[1024];
	sprintf( fn ,"%s/pair.utf8", foundation_dn.GetStr() );

	CUTextFile file( fn, "r" );
	if( file.CheckOpen() == false )	return false;

	CUString content;
	file.LoadToStr( content );
	CUStringListRO content_list( content, "\n" );
	if( content_list.GetSize() < 4 )	{ fprintf( stderr, "Error: Invalid pair.utf\n" ); return false; }

	src_org = content_list.GetAt(0);
	tgt_org = content_list.GetAt(1);
	src_tok = content_list.GetAt(2);
	tgt_tok = content_list.GetAt(3);

	// load trans tree
	CUStringListRO src_tok_list( src_tok, " " );
	trans_tree.Set( src_tok_list );
	for( int i=4; i<content_list.GetSize(); i++ ) {
		CUString str = content_list.GetAt(i);
		if( str.Find( "S-P\t") == 0 ) {
			CUStringListRO tmp_list( str.Mid(4), ":" );
			if( trans_tree.ApplyParse( tmp_list ) == false ) {
				fprintf( stderr, "Error: Invalid parse rule: %s\n", str.GetStr() );
				return false;
			}
			else {
				//trans_tree.Print( stderr );
			}
		}
	}

	// apply trans rule 
	for( int i=4; i<content_list.GetSize(); i++ ) {
		CUString str = content_list.GetAt(i);
		if( str.Find( "TR\t") == 0 ) {
			CUStringListRO tmp_list( str.Mid(3), "\t" );
			if( trans_tree.ApplyTransRule( tmp_list ) == false ) {
				fprintf( stderr, "Error: Invalid parse rule: %s\n", str.GetStr() );
				return false;
			}
			else {
				//trans_tree.Print( stderr );
			}
		}
	}

	// apply trans rule 
	for( int i=4; i<content_list.GetSize(); i++ ) {
		CUString str = content_list.GetAt(i);
		if( str.Find( "TL\t") == 0 ) {
			CUStringListRO tmp_list( str.Mid(3), "\t" );
			if( trans_tree.ApplyTransLexical( tmp_list ) == false ) {
				fprintf( stderr, "Error: Invalid parse lexical: %s\n", str.GetStr() );
				return false;
			}
			else {
				//trans_tree.Print( stderr );
			}
		}
	}

	trans_tree.OrderByTrans();
	trans_tree.Print( stderr );
	CUString trans_str = trans_tree.GetTransStr();

	CUStringListRO tmp1( tgt_tok, " " );
	fprintf( stderr, "TGT: " );
	for( int i=0; i<tmp1.GetSize(); i++ ) {
		CUString tmp = tmp1.GetAt(i);
		fprintf( stderr, " %s", tmp.Left( tmp.ReverseFind('/') ).GetStr() );
	}
	fprintf( stderr, "\n" );

	CUStringListRO tmp2( trans_str, " " );
	fprintf( stderr, "OUT: " );
	for( int i=0; i<tmp2.GetSize(); i++ ) {
		CUString tmp = tmp2.GetAt(i);
		fprintf( stderr, " %s", tmp.Left( tmp.ReverseFind('/') ).GetStr() );
	}
	fprintf( stderr, "\n" );


	return true;
}
Exemplo n.º 8
0
CUString FormatTrackNameString( CUString strFormat, ENUM_FILENAME_CONVERTS nType ) 
{
	int i;

	switch ( nType )
	{
		case FILENAME_CONVERT_NONE:
			// do noting
		break;
		case FILENAME_CONVERT_LOWER:
			strFormat.MakeLower();
		break;

		case FILENAME_CONVERT_UPPER:
			strFormat.MakeUpper();
		break;

		case FILENAME_CONVERT_FC_UPPER:
			strFormat.MakeLower();
			if ( strFormat.GetLength() > 0 )
			{
				CUString strTmp( strFormat.Left( 1 ) );
				strTmp.MakeUpper();
				strFormat.SetAt( 0, strTmp.GetAt( 0 ) );
			}
		break;
		case FILENAME_CONVERT_FCEW_UPPER:
			strFormat.MakeLower();

			for ( i=0; i < strFormat.GetLength()-1; i++ )
			{
				if ( i == 0 )
				{
					CUString strTmp( strFormat.Mid( 0, 1 ) );
					strTmp.MakeUpper();
					strFormat.SetAt( 0, strTmp.GetAt( 0 ) );
				} else
				{
					if (  ( 0 == _istalnum( strFormat.GetAt( i ) )  ) &&
						  ( _T( '\'' ) != strFormat.GetAt( i ) ) )
					{
						CUString strTmp( strFormat.Mid( i+1, 1 ) );
						strTmp.MakeUpper();
						strFormat.SetAt( i+1, strTmp.GetAt( 0 ) );
					}
				}
			}
		break;
		case FILENAME_CONVERT_SWAP_ARTIST_TRACK:
			i = strFormat.Find( _W( " / " ) );

			if ( i > 0 )
			{
				CUString str1;
				CUString str2;

				str1 = strFormat.Left( i );
				str2 = strFormat.Mid( i + 3 );

				strFormat = str2 + _W( " / " ) + str1;
			}
		break;
		default:
			ASSERT( FALSE );
	}

	return strFormat;
}
Exemplo n.º 9
0
void BuildFileName(	CUString strFormat,
					CUString strArray[NUMFILENAME_IDS],
					CUString& strName,CUString& strDir)
{

	CUString strTmp( strFormat );
	int		nPos = 0;
	int		i;

	for ( i=0; i<NUMFILENAME_IDS; i++ )
	{
		strArray[i] = FixFileNameString( strArray[i] );
	}

	// loop through all the tokens
	while ( (( nPos = strTmp.Find( _T( '%' ),nPos ) ) >=0 ) && ( nPos + 1 < strTmp.GetLength() ) )
	{
		ENUM_FILENAME_CONVERTS	convertType = FILENAME_CONVERT_NONE;
		int						nPercentID = 0;
		int						nSkipChars = 2;

		WCHAR chEval = strTmp.GetAt( nPos + 1 );

		if ( _W( 'l' ) == chEval )
		{
			convertType = FILENAME_CONVERT_LOWER;
			chEval = strTmp.GetAt( nPos + 2 );
			nSkipChars++;
		}
		if ( _W( 'u' ) == chEval )
		{
			convertType = FILENAME_CONVERT_UPPER;
			chEval = strTmp.GetAt( nPos + 2 );
			nSkipChars++;
		}
		if ( _W( 'c' ) == chEval )
		{
			convertType = FILENAME_CONVERT_FCEW_UPPER;
			chEval = strTmp.GetAt( nPos + 2 );
			nSkipChars++;
		}
		if ( _W( 'f' ) == chEval )
		{
			convertType = FILENAME_CONVERT_FC_UPPER;
			chEval = strTmp.GetAt( nPos + 2 );
			nSkipChars++;
		}

		// Get %ID number
		switch ( chEval )
		{
			case '1': nPercentID =  0; break;
			case '2': nPercentID =  1; break;
			case '3': nPercentID =  2; break;
			case '4': nPercentID =  3; break;
			case '5': nPercentID =  4; break;
			case '6': nPercentID =  5; break;
			case '7': nPercentID =  6; break;
			case '8': nPercentID =  7; break;
			case 'Y': nPercentID =  8; break;
			case 'G': nPercentID =  9; break;
			case 'A': nPercentID = 10; break;

			default:
				nPercentID = -1;
				nPos++;
			break;
		}

	
		if ( nPercentID >= 0 && nPercentID < NUMFILENAME_IDS )
		{
			CUString strLeft( strTmp.Left( nPos ) );
			CUString strMid( strArray[ nPercentID ] );
			CUString strRight( strTmp.Right( strTmp.GetLength() - nPos - nSkipChars ) );

			// do filename mangling
			strMid = FormatTrackNameString( strMid, convertType );

			strTmp = strLeft + strMid + strRight;

		}
		else
		{
			// Delete token
//			strTmp = strTmp.Left( nPos ) + strTmp.Right( strTmp.GetLength() - nPos - 1 );
		}
	}

	// Split result in a directory and file name portion
	// Search for last backslash
	nPos = strTmp.ReverseFind( _T( '\\' ) );

	if ( nPos >= 2 )
	{
		// OK, we've found the backsplash, do the split
		strDir = strTmp.Left( nPos + 1 );
		strName = strTmp.Right( strTmp.GetLength() - nPos - 1 );
	}
	else
	{
		// Only a filename, just assign the string to the filename and clear the directory
		strDir = _T( "" );
		strName = strTmp;
	}

	strDir.TrimLeft();
	strDir.TrimRight();

	// remove spaces before the directory separator and double backslashes
	INT	nIndex = 0;
	while ( nIndex < strDir.GetLength() )
	{
		if ( _T( '\\' ) == strDir[ nIndex ] )
		{
			if ( nIndex > 0 )
			{
				if ( ( _T( '\\' ) == strDir[ nIndex - 1 ] ) || 
					 ( _T( ' ' ) == strDir[ nIndex - 1 ] ))
				{
					strDir = strDir.Left( nIndex ) + strDir.Mid( nIndex + 1 );
					nIndex = 0;
					continue;
				}
			}
		}
		if ( _T( ' ' ) == strDir[ nIndex ] )
		{
			if ( nIndex > 0 )
			{
				if ( ( _T( '\\' ) == strDir[ nIndex - 1 ] ) )
				{
					strDir = strDir.Left( nIndex ) + strDir.Mid( nIndex + 1 );
					nIndex = 0;
					continue;
				}
			}
		}

		nIndex++;

	}

	strDir.TrimLeft();
	strDir.TrimRight();

	strName.TrimLeft();
	strName.TrimRight();

}