Example #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;
}
Example #2
0
void CLanguage::EncodeTab( CUString& strModify ) const
{
    int nPos;

    while ( ( nPos = strModify.Find( _W( "\t" ) ) ) >= 0 )
    {
        strModify = strModify.Left( nPos ) + _W( "\\t" ) + strModify.Right( strModify.GetLength() - nPos -1 );
    }
    while ( ( nPos = strModify.Find( _W( "\n" ) ) ) >= 0 )
    {
        strModify = strModify.Left( nPos ) + _W( "\\n" ) + strModify.Right( strModify.GetLength() - nPos -1 );
    }
    while ( ( nPos = strModify.Find( _W( "\r" ) ) ) >= 0 )
    {
        strModify = strModify.Left( nPos ) + _W( "\\r" ) + strModify.Right( strModify.GetLength() - nPos -1 );
    }
}
Example #3
0
void CLanguage::ReportChangedID( int nID, const CUString& strResource, const CUString& strEnglish, int nType ) const
{
    if ( g_nReportMissing )
    {
        BOOL		bAdd = TRUE;
        CUString    strWrite;
        CUString    strTmp;
        CString		strRead;
        CStdioFile	cFile;
        CUStringConvert strCnv;

        switch ( nType )
        {
        case 0:
            strWrite.Format( _W( "#%04X# \"%s\"" ), nID, (LPCWSTR)strEnglish );
            strTmp.Format( _W( "#    # \"%s\"" ), (LPCWSTR)strResource );
            strWrite += _W( "\n" ) + strTmp;
            break;
        case 1:
            strWrite.Format( _W( "#M%04X# \"%s\"" ), nID, (LPCWSTR)strEnglish );
            strTmp.Format( _W( "#M    # \"%s\"" ), (LPCWSTR)strResource );
            strWrite += _W( "\n" ) + strTmp;
            break;
        case 2:
            strWrite.Format( _W( "#D%08X# \"%s\"" ), nID, (LPCWSTR)strEnglish );
            strTmp.Format( _W( "#D        # \"%s\"" ), (LPCWSTR)strResource );
            strWrite += _W( "\n" ) + strTmp;
            break;
        }

        EncodeTab( strWrite );

        if ( cFile.Open(	_T( "c:\\temp\\missing.txt" ),
                            CFile::modeReadWrite | CFile::modeNoTruncate | CFile::modeCreate ) )
        {
            while ( cFile.ReadString( strRead ) )
            {
                if ( strWrite.Find( CUString( strRead ) ) >=0 )
                {
                    bAdd = FALSE;
                    break;
                }
            }
        }

        if ( bAdd )
        {
            cFile.WriteString( strCnv.ToT( strWrite + _W( "\n" ) ) );
        }

        cFile.Close();
    }
}
Example #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;
}
Example #5
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;
	}
Example #6
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;
}
Example #7
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" );
}
Example #8
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;
}
Example #9
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;
}