Example #1
0
void CGenreEditDlg::OnOK() 
{
	int i;

	g_GenreTable.DeleteAll();
	g_GenreTable.AddDefaults();

	for ( i =0; i< m_nInsertPosition; i++ )
	{
		CUString strCDDBGenre;

		m_strGenre = CUString( m_List.GetItemText( i, 0 ) );
		strCDDBGenre = CUString( m_List.GetItemText( i, 1 ) );
		m_nID3V1ID = _ttoi( m_List.GetItemText( i, 2 ) );

		if ( m_nID3V1ID <= 0  ) m_nID3V1ID = 0;
		if ( m_nID3V1ID > 255 ) m_nID3V1ID = 255;

		g_GenreTable.AddEntry( m_nID3V1ID, CUString( m_strGenre ), strCDDBGenre, true );
	}

	g_GenreTable.Sort();
	g_GenreTable.Save( GENRE_TABLE_FILE_NAME );

	CDialog::OnOK();
}
Example #2
0
void CPlayerView::OnPlaylistSave() 
{
	static TCHAR BASED_CODE szFilter[] = _T( "M3U PlayList (*.m3u)|*.m3u|PLS Playlist (*.pls)|*.pls||" );

	CFileDialog dlg(	FALSE, _T( "m3u" ), _T( "playlist"),
						OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,
						szFilter );


	if ( IDOK == dlg.DoModal() )
	{
		unsigned int i = 0;
		CString strFileName = dlg.GetPathName();

		// delete old file
		FILE* pFile = CDexOpenFile( CUString( strFileName ), _W( "w" ) );
		fclose( pFile );

		// strip exentention
		strFileName = strFileName.Left( strFileName.GetLength() - 4 );

        CUString cuFileName( strFileName ); 
        PlayList playList( cuFileName );

        CString strExt( dlg.GetFileExt() );

		strExt.MakeLower();

		BOOL bIsPls =  strExt == _T( "pls" );


		for ( i = 0; i< m_vFileNames.size() ; i++ )
		{
			CString strEntry = m_vFileNames[ i ];
			if ( bIsPls )
			{
                playList.AddPLSEntry( CUString( strEntry ) );
			}
			else
			{
                playList.AddM3UEntry( CUString( strEntry ) );
			}
		}



	}
}
Example #3
0
void CGenericPropPage::UpdateControls()
{
	CString strTmp;
	g_config.SetLNormFactor( ( m_nLNormFactor<1 )?1:m_nLNormFactor );
	g_config.SetHNormFactor( ( m_nHNormFactor<1 )?1:m_nHNormFactor );
	g_config.SetNormTrack( m_bNormTrack );
	g_config.SetLowNormLevel( m_nLNormLevel );
	g_config.SetHighNormLevel( m_nUNormLevel );

	m_tmpDir.GetWindowText( strTmp );

	if ( !strTmp.IsEmpty() )
	{
		// Add trailing back space
		if ( strTmp[ strTmp.GetLength()-1 ] != _T( '\\' ) )
		{
			strTmp +=  _T( "\\" );
		}
	}

	g_config.SetTempDir( CUString( strTmp ) );
	g_config.SetAutoShutDown( m_bAutoShutDown );
	g_config.SetCDPlayDigital( m_bDigitalCDPlay );

}
Example #4
0
BOOL  CTextFile::ReadString( CUString& rString )
{
	BOOL bResult = FALSE;
	int nPos = 0;
	int nInputChar;

	rString = _T("");

	vector <CHAR> vChars;


	ASSERT( m_pFile );

	while ( EOF != ( nInputChar = fgetc( m_pFile ) ) )
	{
		bResult = TRUE;

		if ( CHAR_LF == (CHAR)nInputChar ||
			 CHAR_EOF == (CHAR)nInputChar )
		{
			break;
		}
//		if ( CHAR_CR != (char)nInputChar )
		{
			vChars.push_back( (CHAR)nInputChar );
		}
	}

	// terminate string
	vChars.push_back( _T( '\0' ) );

	rString = CUString( &vChars[0], CP_UTF8 );

	return bResult;
}
Example #5
0
void CEncoderDosXingDlg::GetControls(CEncoder* pEncoder)
{
	// Get data out of Controls
	UpdateData(TRUE);

	// Set items
	CString strTmp;

	m_cExtEncPath.GetWindowText( strTmp );

	pEncoder->SetUser1( CUString( strTmp ) );

	// Set bitrate selection
	pEncoder->SetBitrate(GetMinBitrate());

	pEncoder->SetOriginal( m_bOriginal );
	pEncoder->SetCopyRight( m_bCopyright );
	pEncoder->SetMode( m_bCbrOrVbr );
	
	pEncoder->SetUserN1(	( m_bDownmixToMono << 0 )	+
							( m_bFilterHighFreq << 1)	+
							( m_bSimpleStereo << 2 )	+
							( m_bEncChoose << 3 )
						);

	pEncoder->SetUserN2( m_nVbrScale );

}
Example #6
0
CComQIPtr<ILSVGPathSegList> GetPathSegList(CElementImpl* pElement)
{
	ATLASSERT(0);
	CComQIPtr<ILSVGPathSegList> seglist;
	CPathElement* pathElement;
#if 0

	if (!wcscmp(pElement->m_domElement->tagName, L"path"))
	{
		pathElement = (CPathElement*)pElement;

		SVGLib::ISVGAnimatedPathDataPtr pathData = pElement->m_domElement;
		seglist = pathData->normalizedPathSegList;
	}
	else
	{
		SVGLib::ISVGAnimationElementPtr animation = pElement->m_domElement;
		if (animation)
		{
			SVGLib::ISVGPathElementPtr path = animation->targetElement;
			pathElement = (CPathElement*)pElement->m_pDocument->m_pTree->FindDOMElement(path);

			_bstr_t attrname = (pElement->m_pDocument->m_activeKey == -2)? L"from": L"to";
			_bstr_t pathstr = animation->getAttribute(attrname);

			seglist.CreateInstance("SVG.SVGPathSegList");
			ParsePathData(path, seglist, CUString((BSTR)pathstr));
		}
	}
#endif

	return seglist;
}
Example #7
0
void CPlayerView::OnFileOpen() 
{
	POSITION	pos=NULL;

	CString strExt( _W( "M3U;PLS;" ) + GetInFileNameExt() );

	// create custom open file dialog
	COpenFileDlg fileDlg( g_config.GetPlayDir(), CUString( strExt ), IDI_FILE_ICON);

	fileDlg.ShowDelOrigCtrl( FALSE );
	fileDlg.ShowNormalizeCtrl( FALSE );
	fileDlg.ShowRiffWavCtrl( FALSE );
	fileDlg.ShowKeepDirLayoutCtrl( FALSE );

	// check if OK button has been pressed
    if ( IDOK == fileDlg.DoModal() ) 
    {
		// Save to the config file
		g_config.SetPlayDir(fileDlg.GetDir());
		g_config.Save();

		pos = fileDlg.GetStartPosition();


		// Obtain the number of files
		while ( NULL != pos )
		{
			AddToPlayList( CString( fileDlg.GetNextPathName(pos) ) );
		}	
    }
}
Example #8
0
void COpenFileDlg::OnOK() 
{

	UpdateData( TRUE );

	m_strSelectedFiles = NULL;
	m_nSelectedFiles = 0;

	int index = m_ctrlRequestedFiles.GetNextItem( -1, LVNI_SELECTED );

	while ( index >= 0 )
	{
		m_nSelectedFiles++;
		index = m_ctrlRequestedFiles.GetNextItem( index, LVNI_SELECTED );
	}

	m_strSelectedFiles=new CUString[ m_nSelectedFiles ];

	index = m_ctrlRequestedFiles.GetNextItem( -1, LVNI_SELECTED );
	m_nSelectedFiles = 0;

	while ( index >= 0 )
	{
		m_strSelectedFiles[ m_nSelectedFiles++ ] = CUString( m_ctrlRequestedFiles.GetItemText( index, FILE_OPEN_PATH ) + _T( "\\" ) + m_ctrlRequestedFiles.GetItemText( index, FILE_OPEN_NAME ) );
		index=m_ctrlRequestedFiles.GetNextItem( index, LVNI_SELECTED );
	}

	g_config.SetFileOpenRecursive( m_bRecursiveDir );
	g_config.SetKeepDirLayout( m_bKeepDirLayout );

	CDialog::OnOK();
}
Example #9
0
void TestOutputPlug( HWND hWnd )
{
	WINAMPPLUGINPROP	tmpProp;
    WIN32_FIND_DATA		sFF;
    HANDLE				hFind = NULL;
	CUString			strPluginDir( g_config.GetAppPath() + _W( "\\Plugins\\out_*.dll" ) );

	LTRACE2( _T( "Scanning for plugins using mask %s" ) , strPluginDir );

    CUStringConvert strCnv;

	hFind = FindFirstFile( strCnv.ToT( strPluginDir ), &sFF);

	g_strWinampExt = _T("");

	// setup the Output module Window Handle
	g_OutModule.hMainWindow = hWnd;

	// setup the Output Module Instance Handle
	g_OutModule.hDllInstance = NULL;

	while ( NULL != hFind &&
			hFind != INVALID_HANDLE_VALUE )
	{

		if ( ! ( sFF.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY ) ) 
		{
            CUStringConvert strCnv;
            CUString strFullName( g_config.GetAppPath() + _W( "\\Plugins\\" ) + CUString( sFF.cFileName ) );


			LTRACE2( _T( "Getting plugin %s" ), strCnv.ToT( strFullName ));

			tmpProp.hDll = NULL;
		
			tmpProp.hDll = CDexLoadLibrary( strFullName );
			if ( tmpProp.hDll )
			{


				WINAMPGETOUTMODULE pGetMod = (WINAMPGETOUTMODULE)
					GetProcAddress(	tmpProp.hDll,
									"winampGetOutModule" );

				// call "winampGetInModule" DLL function
				Out_Module* pOutModule = pGetMod();
			}

			// scan for next file
            if ( NULL != hFind && !FindNextFile( hFind, &sFF) ) 
			{
                FindClose( hFind );
                hFind = NULL;
            }

		}
	}
}
Example #10
0
CUString GetWinampPluginInfo( int i )
{
	CUString strRet( _W("") );

	if ( i< (int)gs_vWinAmpProps.size() )
	{
		strRet = CUString( gs_vWinAmpProps[i].pModule->description, CP_UTF8);
	}
	return strRet;
}
Example #11
0
void CEncoderDosDlg::GetControls(CEncoder* pEncoder)
{
	// Get data out of Controls
	UpdateData(TRUE);

	// Set items
	CString strTmp;
	m_cExtEncPath.GetWindowText( strTmp );
	pEncoder->SetUser1( CUString( strTmp ) );
	pEncoder->SetUser2( CUString( m_strExtEncOpts ));
	pEncoder->SetOnTheFlyEncoding( m_bEncDuringRead );
	pEncoder->SetChunkSupport( m_bEncDuringRead );
	pEncoder->SetUserN1( m_bHideDosBox );
	pEncoder->SetExtention( CUString( m_strExtention ) );

	((CEncoderDos*)pEncoder)->SetAddStdinWavHeader( m_bSendWavHeader );

	// Get bitrate selection
	pEncoder->SetBitrate(GetMinBitrate());
}
Example #12
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 #13
0
void COpenFileDlg::OnChangeEditDir() 
{
	if (m_bInit)
	{
        CString strTmp;
		m_EditDir.GetWindowText( strTmp );
        m_strDir = CUString( strTmp );
		FillFileList();

		// Update controls
		UpdateData(FALSE);
	}
}
Example #14
0
CUString	CLanguage::GetString( const DWORD nID ) const
{
    CUString strRet;

    DWORD	dwIndex;

    for ( dwIndex = 0; dwIndex < m_vStrings.size(); dwIndex++ )
    {
        if ( m_vStrings[ dwIndex ].nID == nID )
        {
            strRet = m_vStrings[ dwIndex ].strValue;
            break;
        }
    }
    if ( strRet.IsEmpty() )
    {
        CString strResource;
        strResource.LoadString( nID );
        strRet = CUString( strResource );
#ifdef _DEBUG
        ReportMissingID( nID, strRet, 0 );
#endif
    }
    else
    {
#ifdef _DEBUG
        CString strResource;
        strResource.LoadString( nID );

        if ( 0 != strRet.Compare( CUString( strResource ) ) )
        {
            ReportChangedID( nID, CUString( strResource ), strRet, 0 );
        }
#endif
    }


    return strRet;
}
Example #15
0
void CCueSheet::OnBnClickedButton1()
{
	CreateSheet();

    CUStringConvert strCnv;
    CUStringConvert strCnv1;

    CDInfo& cdInfo = m_pDoc->GetCDInfo();
    CUString cueSheetName;
    DWORD cdID = cdInfo.GetDiscID();

    cueSheetName.Format( _W( "%s%08X.cue" ), 
        (LPCWSTR)g_config.GetMP3OutputDir(),
        cdID );

    CUString strFilter = g_language.GetString( IDS_CUESHEETFILESELECTION );

    CFileDialog cueFileDlg(
        FALSE,
        _T( ".cue" ),
        strCnv.ToT( cueSheetName ),
        OFN_OVERWRITEPROMPT,
        strCnv1.ToT( strFilter ) );

    if ( IDOK == cueFileDlg.DoModal() )
    {
        CUString strFileName = CUString( cueFileDlg.GetPathName() );
        FILE* pFile = CDexOpenFile( strFileName, _W( "w" ) );

        if ( pFile )
        {
#ifdef UNICODE
            BYTE btBOM[] = { 0xEF, 0xBB, 0xBF };
            fwrite( &btBOM, sizeof( btBOM ), 1, pFile );
#endif
            LPCSTR lpszUtf = strCnv.ToUTF8( m_strCueSheet );
            fwrite( lpszUtf, 
                    strlen( lpszUtf ), 
                    1, 
                    pFile );
            fclose( pFile );
        }

    }
}
Example #16
0
// "GotoURL" function by Stuart Patterson
// As seen in the August, 1997 Windows Developer's Journal.
HINSTANCE CHyperLink::GotoURL(LPCTSTR url, int showcmd)
{
    TCHAR key[ 4096 ];	

	HINSTANCE result=0;

	memset( &key, 0, sizeof( key ) );
    // First try ShellExecute()
//    HINSTANCE result = ShellExecute(NULL, _T("open"), url, NULL,NULL, showcmd);

    // If it failed, get the .htm regkey and lookup the program
    if ((UINT)result <= HINSTANCE_ERROR) {		
		
        if (GetRegKey(HKEY_CLASSES_ROOT, _T(".htm"), key) == ERROR_SUCCESS)
		{
            lstrcat(key, _T("\\shell\\open\\command"));

            if (GetRegKey(HKEY_CLASSES_ROOT, key, key ) == ERROR_SUCCESS)
			{
                TCHAR *pos;
                pos = _tcsstr(key, _T("\"%1\""));
                if (pos == NULL) {                     // No quotes found
                    pos = _tcsstr( key, _T("%1"));       // Check for %1, without quotes
                    if (pos == NULL)                   // No parameter at all...
                        pos = key+lstrlen(key)-1;
                    else
                        *pos = '\0';                   // Remove the parameter
                }
                else
                    *pos = '\0';                       // Remove the parameter

                lstrcat(pos, _T(" "));
                lstrcat(pos, url);
                
                CUStringConvert strCnv;
                
                result = (HINSTANCE) WinExec( strCnv.ToACP( CUString(  key )), showcmd );
            }
        }
	}
	  
    return result;
}
Example #17
0
void COpenFileDlg::AddRecursiveFiles( const CUString& strDir,int nItem )
{
	CFileFind	fileFind;
	CUString		pathAndFileType = strDir + CUString( _W( "\\*.*" ));
	BOOL		bStop=FALSE;

    CUStringConvert strCnv;

	// Iterate through the items in the listbox and populate the listconrol.
	if (fileFind.FindFile( strCnv.ToT( pathAndFileType ) ) )
	{
		do
		{
			bStop=(fileFind.FindNextFile()==0);
			CUString strFileName = CUString( fileFind.GetFileName() );
			CUString strFileRoot = CUString( fileFind.GetRoot() );
			CUString strFileType;

			if (	TRUE == fileFind.IsDirectory() && 
					FALSE == fileFind.IsDots() &&
					TRUE == m_bRecursiveDir )
			{
				AddRecursiveFiles( strDir + CUString( _W( "\\" ) ) + strFileName, nItem );
			}

			if (fileFind.IsDirectory()==FALSE && fileFind.IsDots()==FALSE)
			{
				int nPos=strFileName.ReverseFind( _T( '.' ) );
				

				if (nPos>0)
				{
					CUString strExt;
					strExt = strFileName.Right(strFileName.GetLength()-nPos-1);

					strFileType = strExt;

					strExt.MakeUpper();

					if ( CompareExt( strExt ) == TRUE )
					{
						CUString strFileSize;
						CUString strFileDate;
						CTime	fileTime;

						// Get the data/time stamp of this file
						fileFind.GetLastWriteTime( fileTime );

						// Format date time string
						strFileDate.Format( _W( "%4d/%02d/%02d %02d:%02d" ), fileTime.GetYear(), fileTime.GetMonth(), fileTime.GetDay(), fileTime.GetHour(), fileTime.GetMinute() );

						strFileSize.Format( _W( "%10.2f" ), fileFind.GetLength() / ( 1024.0 * 1024.0 ) );

                        CUStringConvert strCnv;

						m_ctrlRequestedFiles.InsertItem( nItem, strCnv.ToT( strFileName ));

						m_ctrlRequestedFiles.SetItemText( nItem, FILE_OPEN_TYPE, strCnv.ToT( strFileType ) );

						m_ctrlRequestedFiles.SetItemText( nItem, FILE_OPEN_DATE ,strCnv.ToT( strFileDate ) );

						m_ctrlRequestedFiles.SetItemText( nItem, FILE_OPEN_PATH, strCnv.ToT( strFileRoot ) );

						m_ctrlRequestedFiles.SetItemText( nItem, FILE_OPEN_SIZE, strCnv.ToT( strFileSize ) );

						m_ctrlRequestedFiles.SetItemData( nItem, (DWORD)fileTime.GetTime() );

						nItem++;
					}
				}
			}
		} while (bStop!=TRUE);
	}	


	m_bSortAscending=TRUE;
}
Example #18
0
CDEX_ERR CEncoderLameDll::OpenStream(CUString strOutFileName,DWORD dwSampleRate,WORD nChannels)
{
	CDEX_ERR bReturn = CDEX_OK;

	CUString strLang;
    CUStringConvert strCnv;

	ENTRY_TRACE( _T( "CEncoderLameDll::OpenStream( %s, %ld, %d" ),
				strCnv.ToT( strOutFileName + _W( "." ) + GetExtension() ),
				dwSampleRate,
				nChannels );


	DWORD dwInSampleRate = dwSampleRate;

	m_strStreamFileName = strOutFileName;

	// clear all config settings
	memset( &m_beConfig, 0, sizeof(m_beConfig) );

	// set the number of input channels
	m_nInputChannels = nChannels;

	// Divide sample rate by two for MPEG2
	if ( ( GetVersion() >=1 ) && ( dwInSampleRate >= 32000 ) )
	{
		m_dResampleRatio = 2.0;
		dwSampleRate = dwInSampleRate / 2;
	}

	// mask mode, just to be sure (due to an old hack)
	m_nMode &= 0x0F;

	// Do we have to downmix/upmix ?
	if ( BE_MP3_MODE_MONO == m_nMode )
	{
		if ( 2 == nChannels )
		{
			m_bDownMixToMono = TRUE;
		}
		else
		{
			m_bDownMixToMono = FALSE;
		}
	}
	else 
	{
		if ( 1 == nChannels )
		{
			m_bUpMixToStereo = TRUE;
		}
		else
			m_bUpMixToStereo=FALSE;
	}

	int	nCRC		= m_bCRC;
	int nVBR		= (nCRC>>12)&0x0F;
	int nVbrMethod	= (nCRC>>16)&0x0F;

	m_beConfig.dwConfig						= BE_CONFIG_LAME;
	m_beConfig.format.LHV1.dwStructVersion	= 1;
	m_beConfig.format.LHV1.dwStructSize		= sizeof(m_beConfig);
	m_beConfig.format.LHV1.dwSampleRate		= dwSampleRate;
	m_beConfig.format.LHV1.dwReSampleRate	= m_nOutSampleRate;
	m_beConfig.format.LHV1.nMode			= m_nMode; 
	m_beConfig.format.LHV1.dwBitrate		= m_nBitrate;
	m_beConfig.format.LHV1.dwMaxBitrate		= m_nMaxBitrate;
	m_beConfig.format.LHV1.dwMpegVersion	= (dwSampleRate>=32000)?MPEG1:MPEG2;
	m_beConfig.format.LHV1.dwPsyModel		= 0;
	m_beConfig.format.LHV1.dwEmphasis		= 0;
	m_beConfig.format.LHV1.bCRC				= nCRC&0x01;;
	m_beConfig.format.LHV1.bCopyright		= m_bCopyRight;
	m_beConfig.format.LHV1.bPrivate			= m_bPrivate;
	m_beConfig.format.LHV1.bOriginal		= m_bOriginal;

	// allways write the VBR header, even for CBR file
	m_beConfig.format.LHV1.bWriteVBRHeader	= TRUE;

	if ( nVbrMethod > 0 )
	{
		m_beConfig.format.LHV1.bEnableVBR		= TRUE;
		m_beConfig.format.LHV1.nVbrMethod		= (VBRMETHOD)(nVbrMethod-1) ;

		// is this the ABR method ?
		if ( ( VBR_METHOD_ABR + 1 ) == nVbrMethod )
		{
			// get the average bit rate
			m_beConfig.format.LHV1.dwVbrAbr_bps= LOWORD( GetUserN1() )*1000;
			m_beConfig.format.LHV1.nVBRQuality = 0 ;
		}
		else
		{
			// no ABR selected
			m_beConfig.format.LHV1.dwVbrAbr_bps = 0;
			m_beConfig.format.LHV1.nVBRQuality = nVBR ;
		}
	}

	// Get Quality from third nibble
	m_beConfig.format.LHV1.nPreset=( (nCRC >> 8 ) & 0x0F );

	m_fpOut= CID3Tag::SaveInitialV2Tag( strOutFileName + _W( "." ) + GetExtension(), GetId3V2PadSize() );
    //m_fpOut = CDexOpenFile( strOutFileName + _W( "." ) + GetExtension(), _W( "wb+" ) );

	if ( NULL == m_fpOut )
	{
		CUString strErr;

		strLang = g_language.GetString( IDS_ENCODER_ERROR_COULDNOTOPENFILE );

		strErr.Format( strLang, (LPCWSTR)CUString( strOutFileName + _W( "." ) + GetExtension() ) );

        CDexMessageBox( strErr );

		bReturn  = CDEX_FILEOPEN_ERROR;
	}


	if ( CDEX_OK == bReturn )
	{
		int nReturn = m_InitStream(	&m_beConfig,
									&m_dwInBufferSize,
									&m_dwOutBufferSize,
									&m_hbeStream );

		switch ( nReturn )
		{
			case CDEX_OK:
				// do nothing
			break;
			case -1:
				strLang = g_language.GetString( IDS_ENCODER_ERROR_SAMPLERATEBITRATEMISMATCH );
				CDexMessageBox( strLang );
				bReturn = CDEX_ERROR;
			break;
			case -2:
				strLang = g_language.GetString( IDS_ENCODER_ERROR_INVALIDINPUTSTREAM );
				CDexMessageBox( strLang );
				bReturn = CDEX_ERROR;
			break;
			default:
				strLang = g_language.GetString( IDS_ENCODER_ERROR_INVALIDINPUTSTREAM );
				CDexMessageBox( strLang );
				bReturn = CDEX_ERROR;
			break;

		}
	}

	if ( CDEX_OK == bReturn )
	{

		if ( ( GetVersion() >= 1 ) && ( dwInSampleRate >= 32000 ) )
		{
			// Add multiplcation factor for resampling
			m_dwInBufferSize *= 2;
		}

		if ( m_bDownMixToMono )
		{
			m_dwInBufferSize *= 2;
		}


		// Allocate Output Buffer size
		m_pbOutputStream = new BYTE[ m_dwOutBufferSize ];

		// Only expect halve the number of samples
		// in case we have to upsample
		if ( m_bUpMixToStereo )
		{
			// Allocate upsample Buffer size
			m_psInputStream = new SHORT[ m_dwInBufferSize ];

			m_dwInBufferSize /= 2;

		}
	}

	if ( CDEX_OK == bReturn ) 
	{
		// Initialize the input stream
		bReturn = InitInputStream();
	}


	EXIT_TRACE( _T( "CEncoderLameDll::OpenStream, return value %d" ), bReturn );

	return bReturn;
}
Example #19
0
UINT CPlayerView::PlayThreadFunc(PVOID pParams)
{
	BYTE*			pStream		 = NULL;
	CDEX_ERR		bErr		 = CDEX_OK;
	CPlayerView*	pDlg		 = NULL;
	int				nCurrentFile = -1;
	CString			strFileName;

	ENTRY_TRACE( _T( "CPlayerView::PlayFunc" ) );

	nCurrentFile	= 0;

	pDlg=(CPlayerView*)pParams;

	pDlg->m_bAbortThread	= FALSE;
	pDlg->m_nTotalTime = 0;
	pDlg->m_nCurrentTime = 0;

	nCurrentFile = 	pDlg->m_PlayList.GetCurSel( );

	if ( pDlg->GetPlayRandom() )
	{
		srand( (unsigned)time( NULL ) );
		nCurrentFile = rand() % pDlg->m_vFileNames.size();
	}

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

	while(	( nCurrentFile >= 0 ) &&
			( nCurrentFile < (int)pDlg->m_vFileNames.size() ) && 
			( FALSE == pDlg->m_bAbortThread ) )
	{
		DWORD	dwStreamIndex=0;

		strFileName = pDlg->m_vFileNames[ nCurrentFile ];

#ifdef _DEBUG
//		strFileName = "http://urn.nottingham.ac.uk/urnlive.pls";
//		strFileName = "http://reclib.su.nottingham.ac.uk:8080";
#endif

		pDlg->m_PlayList.SetCurSel( nCurrentFile );

		LTRACE( _T( "Playing track %s (file %d)" ), strFileName, nCurrentFile );

		pDlg->SetThreadCommand( THREAD_PLAY_NEXT_TRACK );

		// Delete the old stream if it does exist
		if ( pDlg->m_pInStream )
		{
			delete pDlg->m_pInStream; pDlg->m_pInStream = NULL;
		}


		// create proper input stream
		pDlg->m_pInStream = ICreateStream( CUString( strFileName ) ); 

		pDlg->m_dwSeekOffset = 0;

		// Open the MPEG stream
		if (pDlg->m_pInStream->OpenStream( CUString( strFileName ) ) )
		{
			DWORD	dwInBufferSize = pDlg->m_pInStream->GetBufferSize();
			int		nMPEGBytes=0;

			// Create a play stream object
			pDlg->m_pPlayStream=new PlayWavStream;

			pDlg->m_pPlayStream->CopyStreamInfo( *pDlg->m_pInStream );

			// Initialize play stream object
			if ( FALSE == pDlg->m_pPlayStream->OpenStream( _W( "" ) ) )
			{
				pDlg->m_bAbortThread = TRUE;
			}

			// Allocate stream input buffer
			auto_ptr<BYTE> pStream( new BYTE[ dwInBufferSize  + STREAMBUFFERSIZE ] );
	
			pDlg->m_bAbortCurrent = FALSE;

			// Set status
			pDlg->m_nStatus = PLAYING;

			while ( ( !pDlg->m_bAbortThread ) && 
					( FALSE == pDlg->m_bAbortCurrent ) )
			{

				if ( PLAYING != pDlg->m_nStatus )
				{
					WaitForSingleObject( pDlg->m_ePaused, INFINITE );
					dwStreamIndex = 0;
					pDlg->m_pInStream->Seek( pDlg->m_dwSeekOffset, SEEK_TIME );

				}

				if ( pDlg->m_bAbortThread )
				{
					break;
				}

				if ( (nMPEGBytes = pDlg->m_pInStream->Read( (BYTE*)( pStream.get() ) + dwStreamIndex,dwInBufferSize ) ) >0 )
				{
					// increase current stream index position
					dwStreamIndex += nMPEGBytes ;

					// play the stuff when there is STREAMBUFFERSIZE samples are present
					while ( ( dwStreamIndex >= STREAMBUFFERSIZE ) && 
							( FALSE == pDlg->m_bAbortThread )  &&
							( FALSE == pDlg->m_bAbortCurrent ) )
					{
						if ( PLAYING != pDlg->m_nStatus )
						{
							break;
						}

						pDlg->m_pPlayStream->Write( pStream.get(), STREAMBUFFERSIZE );
						dwStreamIndex-= STREAMBUFFERSIZE;
						memmove( pStream.get() , (BYTE*)pStream.get() + STREAMBUFFERSIZE, dwStreamIndex );
					}

					pDlg->m_dwBitRate=pDlg->m_pInStream->GetBitRate();
					pDlg->m_nTotalTime=pDlg->m_pInStream->GetTotalTime();
				}
				else
				{
					while ( dwStreamIndex )
					{
						DWORD dwBytes = min( STREAMBUFFERSIZE, dwStreamIndex );

						if ( pDlg->m_bAbortThread )
						{
							break;
						}

						if ( dwBytes < STREAMBUFFERSIZE )
						{
							memset( (BYTE*)pStream.get() + dwBytes, 0, STREAMBUFFERSIZE - dwBytes );
						}

						pDlg->m_pPlayStream->Write( pStream.get(), STREAMBUFFERSIZE );

						dwStreamIndex-= dwBytes;

						if ( dwStreamIndex )
						{
							memmove( pStream.get() , (BYTE*)pStream.get() + dwBytes, dwStreamIndex );
						}
					}

					pDlg->m_bAbortCurrent = TRUE;
				}
			}
		}
		else
		{
			pDlg->MessageBox( _T( "Problem opening the file" ) );
		}

		// Close the mpeg stream
		if (pDlg->m_pInStream)
		{
			pDlg->m_pInStream->CloseStream();

			// Don't delete it, since we want to able to get 
			// the file details
		}

		// Close the play stream
		if (pDlg->m_pPlayStream)
		{
			LTRACE( _T( "Closing the output stream !!!!" ) );
			pDlg->m_pPlayStream->CloseStream();
		}


		delete pDlg->m_pPlayStream; pDlg->m_pPlayStream = NULL;

		switch ( pDlg->GetThreadCommand() )
		{
			case THREAD_PLAY_NEXT_TRACK:
				if ( pDlg->GetPlayRandom() )
				{
					int nNewFile = nCurrentFile;

					// randomize until we got a different track
					while ( pDlg->m_vFileNames.size() > 1 &&
							nCurrentFile == nNewFile )
					{
						srand( (unsigned)time( NULL ) );
						nNewFile = rand() % pDlg->m_vFileNames.size();
					}
					nCurrentFile = nNewFile;
				}
				else
				{
					nCurrentFile++;
				}
			break;
			case THREAD_PLAY_PREV_TRACK:
				if ( nCurrentFile > 0 )
				{
					nCurrentFile--;
				}
			break;
			case THREAD_PLAY_FINISH:
				pDlg->m_bAbortThread = TRUE;
			break;
			case THREAD_PLAY_TRACK:
				nCurrentFile = 	pDlg->m_PlayList.GetCurSel( );
			break;
		}
	}

	pDlg->m_nStatus = IDLE;

	pDlg->m_pThread = NULL;

	pDlg->m_eThreadFinished.SetEvent();

	EXIT_TRACE( _T( "CPlayerView::PlayThreadFunc" ) );

	return 0;
}
Example #20
0
UINT CMP3ToWavDlg::ConvertFunc(PVOID pParams)
{
	CUString		strLang;
	int			nPeakValue	= 0;
	DWORD		dwIndex		= 0;
	CDEX_ERR	bErr		= CDEX_OK;
	PBYTE		pStream		= NULL;
 	DWORD       dwTotalTime = 0;

	ENTRY_TRACE( _T( "ConvertFunc" ) );

	CMP3ToWavDlg* pDlg = (CMP3ToWavDlg*)pParams;

	pDlg->m_wCurrentTrack = 0;
	pDlg->m_bAbortThread = FALSE;


	CUString strOutDir(g_config.GetCnvOutputDir());

	while(	pDlg->m_wCurrentTrack < pDlg->m_nTotalFiles && 
			!pDlg->m_bAbortThread )
	{
		BOOL bNoToAll = FALSE;

		nPeakValue	= 0;

		POSITION nFileListPos = pDlg->m_Pos;

		pDlg->m_strMP3FileName = pDlg->m_pFileDlg->GetNextPathName( pDlg->m_Pos );
		pDlg->m_strWavFileName = pDlg->m_pFileDlg->GetFileName( nFileListPos );

		CUString strSubPath = pDlg->m_pFileDlg->GetSubPath( nFileListPos );

		int nPos = pDlg->m_strWavFileName.ReverseFind('.');

		if (nPos > 0 )
		{
			pDlg->m_strWavFileName= pDlg->m_strWavFileName.Left( nPos );
		}

		strOutDir = g_config.GetCnvOutputDir() + strSubPath;

		// Prepend output directory
		pDlg->m_strWavFileName= strOutDir + CUString( pDlg->m_strWavFileName );

		// Create Ouput directory
		if ( CDEX_OK != DoesDirExist( strOutDir, FALSE )  )
		{
			LTRACE( _T( "ConvertFunc::Error creating output dir %s" ), strOutDir );

			strLang = g_language.GetString( IDS_CANNOT_CREATE_OUTDIR );
			CDexMessageBox( strLang + strOutDir );
			bErr = CDEX_ERROR;
		}

		// Clear error flag
		bErr = CDEX_OK;

		LTRACE( _T( "Converting track %d" ), pDlg->m_wCurrentTrack );

		// Reset estimate timer
		//pDlg->m_TimeTrack.ReInit();

		pDlg->m_nPercentCompleted=0;

		// create proper input stream
		pDlg->m_pInStream = ICreateStream( CUString( pDlg->m_strMP3FileName ) );

		if ( FALSE == CheckNoFileOverwrite(	pDlg,
										CUString( pDlg->m_strWavFileName ) + _W( ".wav" ), 
										TRUE,
										pDlg->m_bYesToAll,
										bNoToAll ) )
		{
			// Open the input stream if available
			if (	pDlg->m_pInStream && 
					pDlg->m_pInStream->OpenStream( CUString( pDlg->m_strMP3FileName ) ) )
			{
				DWORD	dwBufferSize = pDlg->m_pInStream->GetBufferSize();

				// Reset estimate timer
 				dwTotalTime = pDlg->m_pInStream->GetTotalTime();
 				pDlg->m_TimeTrack.ReInit( dwTotalTime );

				// Create a play stream object
				OSndStreamWAV wavStream;

				wavStream.CopyStreamInfo( *pDlg->m_pInStream );

				// Initialize output WAV stream object
				wavStream.OpenStream( CUString( pDlg->m_strWavFileName ) );

				// Allocate stream input buffer
				pStream = new BYTE[ dwBufferSize ];

				int nMPEGBytes = 0;

				double dSampleRatio = 1.0;

				BOOL bFinished = FALSE;

				while( ( FALSE == bFinished ) && !pDlg->m_bAbortThread )
				{
					nMPEGBytes = pDlg->m_pInStream->Read( pStream, dwBufferSize );
	
					if ( nMPEGBytes > 0 )
					{

						for ( dwIndex=0; dwIndex< (DWORD)nMPEGBytes / 2; dwIndex++ )
						{
							if ( abs( ((SHORT*)pStream)[dwIndex]) > nPeakValue )
								nPeakValue=abs( ((SHORT*)pStream )[ dwIndex ] );
						}

						if ( nMPEGBytes > 0 )
						{
							wavStream.Write( pStream, nMPEGBytes );
						}

						int nTotalTime = pDlg->m_pInStream->GetTotalTime();
						int nCurrentTime = pDlg->m_pInStream->GetCurrentTime();

						if ( nTotalTime )
						{
							pDlg->m_nPercentCompleted = nCurrentTime * 100 / nTotalTime;
						}
						else
						{
							pDlg->m_nPercentCompleted = 0;
						}
					}
					else
					{
						bFinished = TRUE;
					}

				}

				delete [] pStream; pStream= NULL;

				// Close input stream
				pDlg->m_pInStream->CloseStream();

				// Close the WAV stream
				wavStream.CloseStream();

				// close the Input stream

				// Check if we have to normalize the file
				if (	pDlg->m_pFileDlg->m_bNormalize && 
						FALSE == pDlg->m_bAbortThread )
				{
					double dNormFactor=1.0;

					// Reset estimate timer
					pDlg->m_TimeTrack.ReInit(dwTotalTime);

					// Set percentage completed to zero
					pDlg->m_nPercentCompleted=0;

					// Determine normalization factor
					dNormFactor=((nPeakValue-1.0)/327.68);

					// DO we have to normalize this file
					if (dNormFactor<(double)g_config.GetLowNormLevel() || dNormFactor>(double)g_config.GetHighNormLevel())
					{
						if (dNormFactor<(double)g_config.GetLowNormLevel())
						{
							// Normalize to for desired level
							dNormFactor=(double)g_config.GetLNormFactor()/dNormFactor;
						}
						else
						{
							// Normalize to for desired level
							dNormFactor=(double)g_config.GetHNormFactor()/dNormFactor;
						}

						// Little fine tuning to avoid overflows due to round off errors
						dNormFactor*=0.9999;

						LTRACE( _T( "CMP3ToWavDlg::Normalizing Track/File %s with factor %f" ), pDlg->m_strWavFileName, dNormFactor );

						CWAV myWav;

						// Step 1: Open the input WAV file
						if ( myWav.StartNormalizeAudioFile( CUString( pDlg->m_strWavFileName ) )!=0)
						{
							// Step 2: Loop through data and normalize chunk
							while ( myWav.NormalizeAudioFileChunk( dNormFactor, pDlg->m_nPercentCompleted ) == FALSE && 
									!pDlg->m_bAbortThread )
							{
								::Sleep(0);
							}
					
							// Step 3: Close the input WAV file, and replace original
							myWav.CloseNormalizeAudioFile( CUString( pDlg->m_strWavFileName ) , pDlg->m_bAbortThread, TRUE );
						}
					}
				}

				// Check if thread has been aborted, if so, remove original file
				if ( TRUE == pDlg->m_bAbortThread )
				{
					LTRACE( _T( "Deleting file ( due to abort ) %s.wav" ), pDlg->m_strWavFileName );
					DeleteFile( pDlg->m_strWavFileName + _T( ".wav" ) );
				}

				// Check if we have to delete the file
				if ( pDlg->m_pFileDlg->m_bDeleteOriginal && ( FALSE == pDlg->m_bAbortThread )  )
				{
					LTRACE( _T( "Deleting file ( user request ) %s" ), pDlg->m_strMP3FileName );
					DeleteFile( pDlg->m_strMP3FileName );
				}
			}
		}
		else
		{
			if ( TRUE == bNoToAll )
			{
				pDlg->m_bAbortThread = TRUE;
			}
		}

		// delete input stream object
		delete pDlg->m_pInStream;pDlg->m_pInStream=NULL;

		// Jump to the next track
		pDlg->m_wCurrentTrack++;
	}

	pDlg->m_eThreadFinished.SetEvent();

	// OK close the stuff
	pDlg->PostMessage( WM_COMMAND, IDCANCEL,0);

	EXIT_TRACE( _T( "RipFunc" ) );
	return 0;
}
Example #21
0
void InitWinAmpPlugins( HWND hWnd )
{
	WINAMPPLUGINPROP	tmpProp;
    WIN32_FIND_DATA		sFF;
    HANDLE				hFind = NULL;
	CUString			strPluginDir( g_config.GetAppPath() + _W( "\\Plugins\\in_*.dll" ) );

	LTRACE2( _T( "Scanning for plugins using mask %s"), strPluginDir );

    CUStringConvert strCnv;

	hFind = FindFirstFile( strCnv.ToT( strPluginDir ), &sFF);

	g_strWinampExt = _W("");

	// setup the Output module Window Handle
	g_OutModule.hMainWindow = hWnd;

	// setup the Output Module Instance Handle
	g_OutModule.hDllInstance = NULL;

	while ( NULL != hFind &&
			hFind != INVALID_HANDLE_VALUE )
	{

		if ( ! ( sFF.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY ) ) 
		{

            CUStringConvert strCnv;
            CUString strFullName( g_config.GetAppPath() + _W( "\\Plugins\\" ) + CUString( sFF.cFileName ) );

            LTRACE2( _T( "Getting plugin %s" ), strFullName );

			tmpProp.hDll = NULL;
		
			tmpProp.hDll = CDexLoadLibrary( strFullName );

			if ( tmpProp.hDll )
			{


				WINAMPGETINMODULE2 pGetMod = (WINAMPGETINMODULE2)
					GetProcAddress(	tmpProp.hDll,
									"winampGetInModule2" );

				// call "winampGetInModule2" DLL function
				tmpProp.pModule = pGetMod();

				// set the file name
				tmpProp.strFileName = sFF.cFileName;

				// setup window handler
				tmpProp.pModule->hMainWindow = hWnd;
				tmpProp.pModule->hDllInstance = tmpProp.hDll;

				tmpProp.pModule->Init(  );
				tmpProp.strExt = CUString( tmpProp.pModule->FileExtensions, CP_UTF8 );
				
				
				if ( 0 != tmpProp.pModule->UsesOutputPlug )
				{
					if ( !g_strWinampExt.IsEmpty() )
						g_strWinampExt += _W( ";" );

					g_strWinampExt+= tmpProp.strExt;

					LTRACE2( _T( "Adding plugin %s to list" ), sFF.cFileName );

					gs_vWinAmpProps.push_back( tmpProp );
				}
				else
				{
					tmpProp.pModule->Quit(  );
					LTRACE2( _T( "Plugin (%s) NOT added, since it does not use the output plugin" ), sFF.cFileName );
				}
			}

			// scan for next file
            if ( NULL != hFind && !FindNextFile( hFind, &sFF) ) 
			{
                FindClose( hFind );
                hFind = NULL;
            }

		}
	}
}
Example #22
0
CDEX_ERR CEncoderFaacDll::OpenStream(CUString strOutFileName,DWORD dwSampleRate,WORD nChannels)
{
	CDEX_ERR	bReturn		= CDEX_OK;
	bool		bStereo		= true;
	CUString		strLang;

    CUStringConvert strCnv;

	ENTRY_TRACE( _T( "CEncoderFaacDll::OpenStream( %s, %d %d" ),
                strCnv.ToT( strOutFileName + _W( "." ) + GetExtension() ),
				dwSampleRate,
				nChannels );


	// setup number of input channels
	m_nInputChannels = nChannels;

	// setup number of output channels
	if ( ( m_nMode & 0xFFFF ) == BE_MP3_MODE_MONO )
	{
		bStereo = false;
	}

	// mixer setup
	if ( ( false == bStereo ) && ( 2 == nChannels ) )
	{
		m_bDownMixToMono  = TRUE;
	}
	else
	{
		m_bDownMixToMono = FALSE;
	}

	if (  ( true == bStereo ) && ( 1 == nChannels ) )
	{
		m_bUpMixToStereo = TRUE;
	}
	else
	{
		m_bUpMixToStereo = FALSE;
	}

		
	// try to get a handle
	m_handle = faacEncOpen( dwSampleRate,
							(bStereo == true )? 2 : 1,
							&m_dwInBufferSize,
							&m_dwOutBufferSize );


	if ( NULL == m_handle )
	{
		CUString strMsg;

		strLang = g_language.GetString( IDS_LOADLIBRARY_FAILED );

		strMsg.Format(	strLang , (LPCWSTR)CUString( ( g_config.GetAppPath() + _W( "\\" ) + m_strEncoderPath ) ) );

		CDexMessageBox( strMsg );
		
		LTRACE( _T( "CEncoderFaacDll::OpenStream Failed to get handle" ) );

		bReturn = CDEX_ERROR;
	}

	if ( CDEX_OK == bReturn )
	{
		// get current config
		m_pConfig = faacEncGetCurrentConfiguration( m_handle );

		// set settings
		if ( GetUserN1() & 0x08 )
		{
			m_pConfig->mpegVersion = FAAC_MPEG4;
		}
		else
		{
			m_pConfig->mpegVersion = FAAC_MPEG2;
		}

		m_pConfig->bitRate = m_nBitrate * 1000;

		m_pConfig->allowMidside = ( GetUserN1() & 0x02 ) ? TRUE : FALSE;

		m_pConfig->useLfe = ( GetUserN1() & 0x04 ) ? TRUE : FALSE;; /* ? */
		m_pConfig->useTns = ( GetUserN1() & 0x01 ) ? TRUE : FALSE;
		m_pConfig->inputFormat = FAAC_INPUT_16BIT;
		m_pConfig->aacObjectType = ( GetUserN2() & 0x07 );
		m_pConfig->shortctl = SHORTCTL_NORMAL;

		switch ( ( GetUserN1() >> 8 ) & 0x0F )
		{
			case 0: m_pConfig->bandWidth = 16000; break;
			case 1: m_pConfig->bandWidth = 18000; break;
			case 2: m_pConfig->bandWidth = 19500; break;
			default: m_pConfig->bandWidth = 19500; break;
		}

		// set new config
		if ( FALSE == faacEncSetConfiguration( m_handle, m_pConfig ) )
		{
			CUString strMsg;

			strLang = g_language.GetString( IDS_LOADLIBRARY_FAILED );

			strMsg.Format(	strLang , (LPCWSTR)CUString( g_config.GetAppPath() + _W( "\\" ) + m_strEncoderPath ) );

			CDexMessageBox( strMsg );
			
			LTRACE( _T( "CEncoderFaacDll::OpenStream Failed to set config" ) );

			bReturn = CDEX_ERROR;
		}

	}
Example #23
0
void CMainFrame::OnLanguageSelection( UINT nID ) 
{
    CDocTemplate*	pTemplate = NULL;
    POSITION		pos;
    CDocument*		pDocument = NULL;

	int nLanguageSelection = nID - ID_LANGUAGE_START;


	if ( 0 == nLanguageSelection )
	{
		WORD nLanguage;

		CHyperLink myLink;

		CUString strVersions;
		// FIXME
		strVersions.Format( _W("cdexversion=1.70&beta=8&cdexdir=%s" ), (LPCWSTR)g_config.GetAppPath() );

		for ( nLanguage=0; nLanguage < g_language.GetNumLanguageStrings(); nLanguage++)
		{
			CUString strLangName( g_language.GetLanguageString( nLanguage ) );
			CUString strLangVersion;
			strLangVersion.Format( _W("%s=%s"), (LPCWSTR)strLangName, (LPCWSTR)g_language.GetRevisionLevel( strLangName ) );
			strVersions += _W( "&" ) + strLangVersion;
		}

//		myLink.GotoURL( _T("www.cdex.n3.net/lang/langcheck.php?") + strVersions , SW_SHOW );
		myLink.GotoURL( _T("cdexos.sourceforge.net/lang/cdex_v1.70"), SW_SHOW );
	}
	else
	{
//		nLanguageSelection--;

		// Switch to selected language
		CString strMenu;

		m_pPopupMenu->GetMenuString( nLanguageSelection, strMenu, MF_BYPOSITION );

		g_language.SetLanguage( CUString( strMenu ) );

		// get document template
		pos = AfxGetApp()->GetFirstDocTemplatePosition();

		pTemplate = AfxGetApp()->GetNextDocTemplate( pos );

		POSITION docpos = pTemplate->GetFirstDocPosition( );

		// Loop through documents in this template
		while ( docpos )
		{
			VERIFY( pDocument = pTemplate->GetNextDoc(docpos) );

			// update all view attached to this document
			pDocument->UpdateAllViews( NULL,WM_CDEX_INITIAL_UPDATE, NULL );
		}

		g_config.SetLanguage( g_language.GetLanguage() );
		g_config.Save();

		SetLanguageMenu( );
	}
}
Example #24
0
bool CMainFrame::SetLanguageMenu()
{
	CMenu* pParentMenu = GetMenu();
	CMenu* pMenu = GetMenu()->GetSubMenu( m_nLangOptionMenuPos );
    
    CUStringConvert strCnv;

	ASSERT( pMenu );

	if ( NULL == m_pPopupMenu )
	{
		m_pPopupMenu = new CMenu;

		m_pPopupMenu->CreatePopupMenu();

		CUString strAdd( g_language.GetString( IDS_CHECKFORADDITIONAL_LANGUAGE_FILES ) );

        CUStringConvert strCnv;

		// Add Check for Updates
        m_pPopupMenu->AppendMenu( MF_STRING | MF_ENABLED, ID_LANGUAGE_START, strCnv.ToT( strAdd ) );

		// Add language menu items
		for ( DWORD idx = 0; idx < g_language.GetNumLanguageStrings() ; idx++ )
		{

			CUString strAdd( g_language.GetLanguageString( idx ) );
			m_pPopupMenu->AppendMenu( MF_STRING | MF_ENABLED, ID_LANGUAGE_START + idx + 1, strCnv.ToT( strAdd ) );
		}
	}

	CString strCurrent;
	pMenu->GetMenuString( m_nLangLangMenuPos, strCurrent, MF_BYPOSITION );

	// Add language menu items
	for ( DWORD idx = 0; idx < m_pPopupMenu->GetMenuItemCount(); idx++ )
	{
		CString strMenu;

		if ( 0 == idx )
		{
			m_pPopupMenu->ModifyMenu(	idx, 
										MF_BYPOSITION | MF_STRING,
										ID_LANGUAGE_START,
										strCnv.ToT( g_language.GetString( IDS_CHECKFORADDITIONAL_LANGUAGE_FILES ) ));

		}

		// get menu string
		m_pPopupMenu->GetMenuString( idx, strMenu, MF_BYPOSITION );

		// check if this is the selected language
		if ( 0 == g_language.GetLanguage().CompareNoCase( CUString( strMenu ) ) )
		{
			m_pPopupMenu->CheckMenuItem( idx, MF_BYPOSITION | MF_CHECKED  );
		}
		else
		{
			m_pPopupMenu->CheckMenuItem( idx, MF_BYPOSITION | MF_UNCHECKED  );
		}
	}

	// remove exisiting menu item
	pMenu->RemoveMenu( m_nLangLangMenuPos, MF_BYPOSITION );

	// insert new popup menu
	pMenu->InsertMenu(	m_nLangLangMenuPos,
						MF_BYPOSITION | MF_POPUP, 
						(UINT)m_pPopupMenu->m_hMenu, 
						strCurrent );


	// peform translation
	g_language.TranslateMenu( GetMenu(), m_nMenuID );

	// refresh frame windows
	ActivateFrame( SW_HIDE );
	ActivateFrame( SW_SHOW );

	return true;
}
Example #25
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 #26
0
BOOL CLanguage::TranslateMenu( CMenu* pMenu, const int nMenuID, BOOL bTopLevel )
{
    CMenu*			pChildMenu = NULL;
    static CUString	strMissing;
    BOOL			bReturn = TRUE;
    static int		nPopUpIdx = 0;

    if ( bTopLevel )
    {
        nPopUpIdx = MAKELPARAM( 0, nMenuID );
        strMissing = _T( "" );
    }

    DWORD i = pMenu->GetMenuItemCount();
    for( i = 0; i < pMenu->GetMenuItemCount(); i++ )
    {
        pChildMenu = pMenu->GetSubMenu( i );

        int nItemID = pMenu->GetMenuItemID( i );

        if ( MENU_SEPARARTOR != nItemID )
        {
            CUString strLang;

            if ( bTopLevel )
            {
                strLang = GetMainMenuItem( nMenuID, i );
            }
            else
            {
                if ( MENU_POPUP != nItemID )
                {
                    strLang = GetSubMenuItem( nItemID );
                }
                else
                {
                    strLang = GetSubMenuItem( nPopUpIdx );
                    nPopUpIdx++;
                }
            }

            if ( MENU_POPUP != nItemID )
            {
                CUStringConvert strCnv;

                if ( !strLang.IsEmpty() )
                {
                    pMenu->ModifyMenu( nItemID, MF_STRING, nItemID, strCnv.ToT( strLang ) );
                }
                else
                {
                    CString strTmp;
                    pMenu->GetMenuString( nItemID, strTmp, MF_BYCOMMAND );
                    ReportMissingID( nItemID, CUString( strTmp ), 1 );
                }
            }
            else
            {
                int nPosition = UINT( pChildMenu->m_hMenu );

                if ( !strLang.IsEmpty() )
                {
                    int nPosition = UINT( pChildMenu->m_hMenu );

                    CUStringConvert strCnv;

                    pMenu->ModifyMenu(	UINT( pChildMenu->m_hMenu ),
                                        MF_STRING | MF_POPUP,
                                        UINT( pChildMenu->m_hMenu ),
                                        strCnv.ToT( strLang ) );
                }
                else
                {

                    if ( bTopLevel )
                    {
                        CString strTmp;
                        pMenu->GetMenuString( i, strTmp, MF_BYPOSITION );
                        strMissing += _W( "#" ) + CUString( strTmp );
                    }
                    else
                    {
                        CString strTmp;
                        pMenu->GetMenuString( 0, strTmp, MF_BYPOSITION );
                        ReportMissingID( nItemID, CUString( strTmp ), 1 );
                    }
                }

                TranslateMenu( pMenu->GetSubMenu(i), -1, FALSE );
            }
        }
    }

    if ( bTopLevel )
    {
        if ( !strMissing.IsEmpty() )
        {
            ReportMissingID( nMenuID, strMissing + _W( "#" ), 1 );
        }
    }

    return bReturn;
}
Example #27
0
#include "StdAfx.h"
#include "TextFile.h"
#include "Util.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

#define CHAR_EOF 26
#define CHAR_LF  10
#define CHAR_CR  13

const CUString CTextFile::m_strCRLF( CUString( (CHAR)CHAR_CR ) + CUString( (CHAR)CHAR_LF ) );
const CUString CTextFile::m_strLF( CUString( (CHAR)CHAR_LF ) );

IMPLEMENT_DYNAMIC( CTextFile, CObject)


// Always open the file as a binary file, the class will be
// transparent regarding unix/dos test files

CTextFile::CTextFile( )
		:CObject( ),
		m_pFile( NULL ),
		m_bWriteAsDosFile( false )

{
}
Example #28
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 #29
0
STDMETHODIMP CWebSite::LoadDocument(BSTR pathName, BOOL *success)
{
	ATLASSERT(m_pRootDir == NULL);

//
	CComQIPtr<IDOMDocument> document;
	document.CoCreateInstance(CLSID_DOMDocument);

	VARIANT_BOOL bsuccess;
	document->load(pathName, &bsuccess);
	if (bsuccess)
	{
		char dir[_MAX_PATH];
		char path[_MAX_PATH];
		char filename[_MAX_PATH];
		char ext[_MAX_PATH];
		_splitpath(_bstr_t(pathName), dir, path, filename, ext);

		TCHAR mdbfullpathname[260];
		_makepath(mdbfullpathname, dir, path, "site_data", "mdb");

		TCHAR rootpath[_MAX_PATH];
		_makepath(rootpath, dir, path, "root", NULL);

		m_rootPath = rootpath;

		// Open website database data
		if (m_siteDataConnection == NULL)
		{
			try
			{
				swprintf(m_connstr, L"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=%S", mdbfullpathname);

				m_siteDataConnection.CreateInstance(__uuidof(ADODB::Connection));
				m_siteDataConnection->Open(m_connstr, "", "", ADODB::adConnectUnspecified);
			}
			catch (_com_error &e)
			{
				DbError(e);
			}
		}

		GetHomepageFileIdFromDB();	// ReadSettings

		m_pRootDir = new CSiteDir;
		m_pRootDir->m_pWebSite = this;
		m_pRootDir->m_pathName = CUString((BSTR)m_rootPath);

		m_pRootDir->BuildFromDatabase();
		m_pRootDir->ScanFiles(TRUE, FALSE);

	//	m_pRootDir->UpdateOutLinks();

		CComQIPtr<IWebSite> site = this;

		m_hChangeThread = CreateThread(NULL, 0, ChangeNotifyThread, site.p, 0, &m_dwChangeThreadID);

	// TODO Fire UI Update event

		ShowViews();
	}

	return S_OK;
}
Example #30
0
void CPlayerView::AddToPlayList( const CString& strFileName ) 
{
	CString strExt( strFileName );
	CString strDir( strFileName );
	CString strCurrentDir;

	int nPos;

	nPos = strExt.ReverseFind( '.' );

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


	nPos = strDir.ReverseFind( _T( '\\' ) );

	if ( nPos > 0 ) 
	{
		strDir = strDir.Left( nPos );
	}
	

	char lpszCurDir[ MAX_PATH + 1 ] = {'\0',};
	
	// Get current directory
	_getcwd( lpszCurDir, sizeof( lpszCurDir ) );

	if ( 0 == strExt.CompareNoCase( _T( "M3U" ) ) )
	{
		// go to the directory
		if ( 0 == _tchdir( strDir ) )
		{
			// open the playlist
			FILE* pFile = CDexOpenFile( CUString( strFileName ), _W( "rt" ) );

			if ( NULL != pFile )
			{
				char lpszLine[ 8192 ] = {'\0',};

				// read the lines in the playlist file
				while ( NULL != fgets( lpszLine, sizeof( lpszLine ), pFile ) )
				{
					if ( '\n' == lpszLine[ strlen( lpszLine ) -1 ] )
					{
						lpszLine[ strlen( lpszLine ) -1 ] = '\0';
					}

					// skip extended info
					if ( '#' != lpszLine[0] )
					{
						CString strEntry( lpszLine );

						int nPos = 0;

						if ( strDir.Find( _T( ":\\" ) ) < 0 ) 
						{
							if ( 0 == ( nPos = strEntry.Find( _T( ".\\" ) ) ) )
							{
								strEntry = strDir + strEntry.Mid( 1 );
							}
							else
							{
								strEntry = strDir + _T( "\\" ) + strEntry;
							}
						}

						AddStringToPlayList( strEntry );
					}
				}

				// close the playlist file
				fclose( pFile );
			}
		}

	}
	else if ( 0 == strExt.CompareNoCase( _T( "PLS" ) ) )
	{
		CIni	plsIni;
		int		nNumEntries = 0;
		CString	strEntry;
		CString	strNumber;
		int		i = 0;
		

		// go to the directory
		if ( 0 == _tchdir( strDir ) )
		{

			plsIni.SetIniFileName( CUString( strFileName ) );

			nNumEntries = plsIni.GetValue(	_T( "playlist" ),
											_T( "NumberOfEntries" ), 
											nNumEntries );

			for ( i = 1; i <= nNumEntries; i++ )
			{
				strNumber.Format( _T( "File%d"), i );

				strEntry = plsIni.GetValue( CUString( _W( "playlist" ) ),
											CUString( strNumber ),
											_W( "" ) );


				if ( !strEntry.IsEmpty() )
				{

					int nPos = 0;

					if ( strDir.Find( _T( ":\\" ) ) < 0 ) 
					{
						if ( 0 == ( nPos = strEntry.Find( _T( ".\\" ) ) ) )
						{
							strEntry = strDir + strEntry.Mid( 1 );
						}
						else
						{
							strEntry = strDir + _T( "\\" ) + strEntry;
						}
					}
					AddStringToPlayList( strEntry );
				}
			}
		}
	}
	else
	{
		AddStringToPlayList( strFileName );
	}

	// switch back to the current directory
	chdir( lpszCurDir );

}