⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 app.cpp

📁 这是一个mp3的源代码
💻 CPP
📖 第 1 页 / 共 2 页
字号:
		{
			ERRORSTR( "tx file failed, %s\n", cRio.GetErrorStr() );
			fclose( fpFile );
			DELETEARRAY pszBuf;
			return FALSE;
		}
	}

	// cleanup
	fclose( fpFile );
	DELETEARRAY pszBuf;
	return TRUE;
}

///////////////////////////////////////////////////////////////////////////////
// change playlist order
static BOOL ChangePlaylistOrder( CRio& cRio, char* pszPlaylistOrder )
{
	UINT auiPosNew[ CRIO_MAX_DIRENTRY ];

	UINT uiPosNew = 0;
	char* pszEntry;
	do
	{
		pszEntry = strtok( uiPosNew ? NULL : pszPlaylistOrder, " " );
		if ( pszEntry )
			auiPosNew[ uiPosNew++ ] = atoi( pszEntry ) - 1;
	} while( pszEntry && (uiPosNew < CRIO_MAX_DIRENTRY) );

	if ( !cRio.SetFileOrder(auiPosNew, uiPosNew) )
	{
		ERRORSTR( "change in playlist order failed, %s\n", cRio.GetErrorStr() );
		return FALSE;
	}

	return TRUE;
}

///////////////////////////////////////////////////////////////////////////////
// display help
static void Help( void )
{
	INFOSTR( "\nRio utility v%d.%02d - The Snowblind Alliance (c) 1999\n", CRIO_ID_VERSION/100, CRIO_ID_VERSION%100 );
	INFOSTR( "----------------------------------------------------\n" );
	INFOSTR( "command line switches available :-\n" );
	INFOSTR( "	-d  display directory\n" );
	INFOSTR( "	-iy initialize with check for bad blocks\n" );
	INFOSTR( "	-in initialize without check for bad blocks\n" );
	INFOSTR( "	-x  perform operations on external flash ram\n" );
	INFOSTR( "	-u  specify file(s) to upload\n" );
	INFOSTR( "	-g  specify file to download\n" );
	INFOSTR( "	-f  specify text based playlist file which contains files to be upload\n" );
	INFOSTR( "	-z  specify file to delete\n" );
	INFOSTR( "	-za delete all files\n" );
	INFOSTR( "	-o  specify new playlist order in quotes\n" );
	INFOSTR( "	-p  specify parallel port base IO address, default=0x%x\n", PORT_BASE_DEFAULT );
	INFOSTR( "	-v  enable verbose mode\n" );
	INFOSTR( "	-di specify initialization delay (default is %ld)\n", CRIO_TIME_IODELAY_INIT );
	INFOSTR( "	-dt specify tx delay (default is %ld)\n", CRIO_TIME_IODELAY_TX );
	INFOSTR( "	-dr specify rx delay (default is %ld)\n", CRIO_TIME_IODELAY_RX );
	INFOSTR( "\nexamples...\n" );
	INFOSTR( "	; display directory using parallel port at 0x278\n" );
	INFOSTR( "		rio -p 0x278 -d\n" );
	INFOSTR( "	; initialize (with bad block check) and upload files\n" );
	INFOSTR( "		rio -iy -u *.mp3\n" );
	INFOSTR( "	; delete existing files and upload playlist onto external flash ram\n" );
	INFOSTR( "		rio -za -f playlist.txt -x\n" );
	INFOSTR( "	; initialize, upload files in playlist and then display directory\n" );
	INFOSTR( "		rio -d -in -f playlist.txt\n" );
	INFOSTR( "	; download file then delete it and finally display directory\n" );
	INFOSTR( "		rio -d -g mp3Files/song.mp3 -z song.mp3\n" );
	INFOSTR( "	; reverse playlist order and display directory, also change rx iodelay\n" );
	INFOSTR( "		rio -o \"5 4 3 2 1\" -d -dr %ld\n", CRIO_TIME_IODELAY_RX*2 );
}

///////////////////////////////////////////////////////////////////////////////
int main( int iCountArg, char* paszArg[] )
{
	// default settings
	BOOL bDisplayDir = FALSE;
	BOOL bInit = FALSE;
	BOOL bInitMarkBadBlock = FALSE;
	BOOL bUseExternalFlash = FALSE;
	BOOL bDeleteAll = FALSE;
	BOOL bVerbose = FALSE;
	CRio* pRio = NULL;
	char* pszFileDelete = NULL;
	char* pszFileDownload = NULL;
	char* pszFilePlaylist = NULL;
	char* pszFilePlaylistTemp = NULL;
	char* pszPlaylistOrder = NULL;
	long lTimeIODelayInit = -1;
	long lTimeIODelayTx = -1;
	long lTimeIODelayRx = -1;
	int iPortBase = PORT_BASE_DEFAULT;
	int iPosDumpDirectory = 0;
	int iSizeDumpDirectory = 0;

	// process command line args
	if ( iCountArg < 2 )
	{
		Help();
		CLEANUP_RETURN( FALSE );
	}
	for( int iA=1; iA<iCountArg; ++iA )
	{
		// check for display directory request
		if ( !strcmp(paszArg[iA], "-d") )
			bDisplayDir = TRUE;
		// check for init with mark bad block request
		else if ( !strcmp(paszArg[iA], "-iy") )
		{
			bInit = TRUE;
			bInitMarkBadBlock = TRUE;
		}
		// check for init without mark bad block request
		else if ( !strcmp(paszArg[iA], "-in") )
			bInit = TRUE;
		// check for delete all file request
		else if ( !strcmp(paszArg[iA], "-za") )
			bDeleteAll = TRUE;
		// check for request to use external flash memory
		else if ( !strcmp(paszArg[iA], "-x") )
			bUseExternalFlash = TRUE;
		// check for verbose mode request
		else if ( !strcmp(paszArg[iA], "-v") )
			bVerbose = TRUE;
		// check for dump directory request
		else if ( !strcmp(paszArg[iA], "-h") )
		{
			if ( (iA+2) < iCountArg )
			{
				++iA;
				iPosDumpDirectory = atoi( paszArg[iA] );
				++iA;
				iSizeDumpDirectory = atoi( paszArg[iA] );
			}
		}
		// check for delete file request
		else if ( !strcmp(paszArg[iA], "-z") )
		{
			if ( (iA+1) < iCountArg )
			{
				++iA;
				pszFileDelete = paszArg[iA];
			}
		}
		// check for upload file request
		else if ( !strcmp(paszArg[iA], "-u") )
		{
			if ( (iA+1) < iCountArg )
			{
				++iA;

				// append all command line upload requests to temp playlist
				if ( !pszFilePlaylistTemp )
					pszFilePlaylistTemp = tmpnam( NULL );

				if ( pszFilePlaylistTemp )
				{
					FILE* fpFile = fopen( pszFilePlaylistTemp, "a" );
					if ( !fpFile )
					{
						ERRORSTR( "unable to open '%s' for amend\n", pszFilePlaylistTemp );
						CLEANUP_RETURN( FALSE );
					}
					while( iA < iCountArg )
					{
						fprintf( fpFile, "%s\n", paszArg[iA] );
						if ( (iA+1) < iCountArg )
						{
							if ( paszArg[iA+1][0] == '-' )
								break;
						}
						++iA;
					}
					fclose( fpFile );
				}
			}
		}
		// check for download file request
		else if ( !strcmp(paszArg[iA], "-g") )
		{
			if ( (iA+1) < iCountArg )
			{
				++iA;
				pszFileDownload = paszArg[iA];
			}
		}
		// check for playlist file request
		else if ( !strcmp(paszArg[iA], "-f") )
		{
			if ( (iA+1) < iCountArg )
			{
				++iA;
				pszFilePlaylist = paszArg[iA];
			}
		}
		// check for playlist order request
		else if ( !strcmp(paszArg[iA], "-o") )
		{
			if ( (iA+1) < iCountArg )
			{
				++iA;
				pszPlaylistOrder = paszArg[iA];
			}
		}
		// check for port base request
		else if ( !strcmp(paszArg[iA], "-p") )
		{
			if ( (iA+1) < iCountArg )
			{
				++iA;
				sscanf( paszArg[iA], "%x", &iPortBase );
			}
		}
		// check for io delay's
		else if ( !strcmp(paszArg[iA], "-di") )
		{
			if ( (iA+1) < iCountArg )
			{
				++iA;
				lTimeIODelayInit = atol( paszArg[iA] );
			}
		}
		else if ( !strcmp(paszArg[iA], "-dt") )
		{
			if ( (iA+1) < iCountArg )
			{
				++iA;
				lTimeIODelayTx = atol( paszArg[iA] );
			}
		}
		else if ( !strcmp(paszArg[iA], "-dr") )
		{
			if ( (iA+1) < iCountArg )
			{
				++iA;
				lTimeIODelayRx = atol( paszArg[iA] );
			}
		}
		// else help
		else
		{
			Help();
			CLEANUP_RETURN( FALSE );
		}
	}

	// setup
	pRio = new CRio;
	if ( !pRio )
	{
		ERRORSTR( "not enough memory\n" );
		CLEANUP_RETURN( FALSE );
	}
	CRio& cRio = *pRio;
	if ( !cRio.Set(iPortBase) )
	{
		ERRORSTR( "%s\n", cRio.GetErrorStr() );
		CLEANUP_RETURN( FALSE );
	}

	// if io delay's specified
	if ( lTimeIODelayInit >= 0 )
		cRio.SetIODelayInit( lTimeIODelayInit );
	if ( lTimeIODelayTx >= 0 )
		cRio.SetIODelayTx( lTimeIODelayTx );
	if ( lTimeIODelayRx >= 0 )
		cRio.SetIODelayRx( lTimeIODelayRx );

	// select internal or external flash memory
	if ( bVerbose )
		INFOSTR( "performing operations on %s flash ram\n", bUseExternalFlash ? "external" : "internal" );
	cRio.UseExternalFlash( bUseExternalFlash );

	// check device present
	if ( bVerbose )
		INFOSTR( "check device present\n" );
	if ( !cRio.CheckPresent() )
	{
		ERRORSTR( "%s\n", cRio.GetErrorStr() );
		CLEANUP_RETURN( FALSE );
	}

	// update directory flag
	BOOL bUpdateDirectory = FALSE;

	// get current directory
	if ( bVerbose )
		INFOSTR( "downloading directory\n" );
	if ( !cRio.RxDirectory() )
	{
		if ( cRio.GetErrorID() == CRIO_ERROR_CORRUPT )
			ERRORSTR( "%s\n", cRio.GetErrorStr() );
		else
		{
			ERRORSTR( "rx directory failed, %s\n", cRio.GetErrorStr() );
			CLEANUP_RETURN( FALSE );
		}
	}

	// if dump directory request
	if ( iSizeDumpDirectory )
		DumpDirectory( cRio, iPosDumpDirectory, iSizeDumpDirectory );

	// if init request
	if ( bInit )
	{
		if ( bVerbose )
			INFOSTR( "initializing with bad block check %s\n", bInitMarkBadBlock ? "enabled" : "disabled" );

		if ( !cRio.Initialize(bInitMarkBadBlock, bVerbose ? ProgressCallback : NULL) )
		{
			ERRORSTR( "Initialize failed, %s\n", cRio.GetErrorStr() );
			CLEANUP_RETURN( FALSE );
		}

		bUpdateDirectory = TRUE;
	}

	// if delete request
	if ( pszFileDelete )
	{
		if ( bVerbose )
			INFOSTR( "deleting %s\n", pszFileDelete );

		if ( !cRio.RemoveFile(pszFileDelete) )
		{
			ERRORSTR( "delete file failed, %s\n", cRio.GetErrorStr() );
			CLEANUP_RETURN( FALSE );
		}

		bUpdateDirectory = TRUE;
	}

	// if delete all request
	if ( bDeleteAll )
	{
		if ( bVerbose )
			INFOSTR( "deleting all files\n" );

		if ( !cRio.RemoveAllFiles() )
		{
			ERRORSTR( "delete all files failed, %s\n", cRio.GetErrorStr() );
			CLEANUP_RETURN( FALSE );
		}

		bUpdateDirectory = TRUE;
	}

	// if playlist request
	if ( pszFilePlaylist )
	{
		if ( !ProcessPlaylist(cRio, pszFilePlaylist, bVerbose) )
			CLEANUP_RETURN( FALSE );

		bUpdateDirectory = TRUE;
	}

	// if temp playlist request
	if ( pszFilePlaylistTemp )
	{
		if ( !ProcessPlaylist(cRio, pszFilePlaylistTemp, bVerbose) )
			CLEANUP_RETURN( FALSE );

		bUpdateDirectory = TRUE;
	}

	// if download request
	if ( pszFileDownload )
	{
		if ( bVerbose )
			INFOSTR( "downloading %s\n", pszFileDownload );

		if ( !cRio.RxFile(pszFileDownload, bVerbose ? ProgressCallback : NULL) )
		{
			ERRORSTR( "rx file failed, %s\n", cRio.GetErrorStr() );
			CLEANUP_RETURN( FALSE );
		}
	}

	// if playlist order request
	if ( pszPlaylistOrder )
	{
		if ( bVerbose )
			INFOSTR( "changing playlist order\n" );

		if ( !ChangePlaylistOrder(cRio, pszPlaylistOrder) )
			CLEANUP_RETURN( FALSE );

		bUpdateDirectory = TRUE;
	}

	// if directory update required
	if ( bUpdateDirectory )
	{
		if ( bVerbose )
			INFOSTR( "updating directory\n" );

		if ( !cRio.TxDirectory() )
		{
			ERRORSTR( "tx directory failed, %s\n", cRio.GetErrorStr() );
			CLEANUP_RETURN( FALSE );
		}
	}

	// if display directory request
	if ( bDisplayDir )
		DisplayDirectory( cRio, bVerbose );

	// restore
	CLEANUP_RETURN( TRUE );
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -