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 ); } }
void CLanguage::SearchLanguageFiles( ) { CUString strSearchName; CFileFind fileFind; BOOL bFound = FALSE; // PVOID pTest = (PVOID)m_strLanguageDir; //CString str; //CString str1 =_T( "CSTRING1" ); //CString str2 =_T( "CSTRING2" ); //CUString str3( _W("CUSTRING" )); // str.Format( _W( "%s" ),str1 ); // str.Format( _W( "%s" ),(LPCWSTR)str3 ); // str.Format( _W( "%s\\lang\\*%s" ), // str1, // str3); // CUString* p1 = &str3; // CString* p2 = &str1; // build the filename search string strSearchName.Format( _W( "%s\\lang\\*%s" ), (LPCWSTR)m_strLanguageDir, (LPCWSTR)m_strLangFileExt ); CUStringConvert strCnv; bFound = fileFind.FindFile( strCnv.ToT( strSearchName ) ); while ( bFound ) { bFound = fileFind.FindNextFile(); CUString strFileName = fileFind.GetFileName(); CUString strLanguage = strFileName.Left( strFileName.GetLength() - m_strLangFileExt.GetLength() ); m_vLangFiles.push_back( strLanguage ); } sort( m_vLangFiles.begin(), m_vLangFiles.end() ); }
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; }
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; }
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; }
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(); }