📄 mavusb.cpp
字号:
//
*pdwResult = FALSE;
return(FALSE);
}
//****************************************************************************
//
// The dialog box procedure for the update progress indicator.
//
//****************************************************************************
BOOL APIENTRY
UpdateProgressDlgProc(HWND hDlg, UINT message, UINT wParam, LONG lParam)
{
//
// Determine what to do based on the message we received.
//
switch(message)
{
//
// The dialog is being initialized.
//
case WM_INITDIALOG:
{
//
// Save the dialog box handle.
//
g_hDlg = hDlg;
//
// Schedule a WM_TIMER message to be sent to ourself in 100ms.
//
SetTimer(hDlg, 0, 100, NULL);
//
// Indicate that we are currently erasing the FLASH.
//
SetDlgItemText(hDlg, IDC_UPDATE_PROGRESS, "Erasing the FLASH...");
//
// Indicate that the first control in the dialog box should receive
// the keyboard focus.
//
return(TRUE);
}
//
// A command button or menu item was selected.
//
case WM_TIMER:
{
DWORD dwExitCode;
//
// Get the exit code from the download thread.
//
GetExitCodeThread(g_hThread, &dwExitCode);
//
// See if the download thread is still active.
//
if(dwExitCode != STILL_ACTIVE)
{
//
// The download thread has completed, so dismiss the progress
// dialog box.
//
EndDialog(hDlg, TRUE);
//
// We've handled this message.
//
return(TRUE);
}
//
// Schedule another WM_TIMER message to be sent in 100ms.
//
SetTimer(hDlg, 0, 100, NULL);
//
// We're done handling this message.
//
return(TRUE);
}
}
//
// Indicate that we did not handle the message.
//
return(FALSE);
}
//****************************************************************************
//
// Updates the software on the Internet audio player.
//
//****************************************************************************
BOOL
Update(HWND hWnd, char *pcFileName)
{
DWORD dwThreadID, dwResult;
unsigned long ulHardwareID;
//
// Allocate memory for the file data.
//
g_pvData = GlobalAlloc(GMEM_FIXED, 1024 * 1024);
if(!g_pvData)
{
return(FALSE);
}
//
// Open the host file.
//
g_hFile = CreateFile(pcFileName, GENERIC_READ, FILE_SHARE_READ, NULL,
OPEN_EXISTING, 0, NULL);
if(g_hFile == INVALID_HANDLE_VALUE)
{
GlobalFree(g_pvData);
return(FALSE);
}
//
// Get the length of the image.
//
g_ulLength = GetFileSize(g_hFile, NULL);
//
// Read data from the host file.
//
ReadFile(g_hFile, g_pvData, 1024, &dwResult, NULL);
//
// Seek back to the beginning of the file.
//
SetFilePointer(g_hFile, 0, NULL, FILE_BEGIN);
//
// Get the hardware ID from the player.
//
if(Maverick_GetDescriptor(USB_Vendor_Descriptor_HardwareID, 0,
(char *)&ulHardwareID, &dwResult) == 0)
{
CloseHandle(g_hFile);
GlobalFree(g_pvData);
return(FALSE);
}
//
// Make sure that the hardware ID of the player matches the hardware ID
// of the image being read, and that the length of the image makes sense.
//
if(((((unsigned long *)g_pvData)[9]) != g_ulLength) ||
(((unsigned long *)g_pvData)[10] != ulHardwareID))
{
//
// Display an error message in a message box.
//
if((((unsigned long *)g_pvData)[9]) == g_ulLength)
{
MessageBox(hWnd, "This software image is not compatible with the "
"player.", "Maverick(tm) Internet Audio Player", MB_OK);
}
else
{
MessageBox(hWnd, "Invalid software image file.",
"Maverick(tm) Internet Audio Player", MB_OK);
}
//
// Return a failure.
//
CloseHandle(g_hFile);
GlobalFree(g_pvData);
return(FALSE);
}
//
// Attempt to start the update.
//
if(Maverick_StartUpdate() == 0)
{
//
// Tell the user that the player does not support software updates.
//
MessageBox(hWnd, "The player does not support software updates.",
"Maverick(tm) Internet Audio Player", MB_OK);
//
// Return a failure.
//
GlobalFree(g_pvData);
CloseHandle(g_hFile);
return(FALSE);
}
//
// Create the thread which will actually update the software on the device.
//
g_hThread = CreateThread(NULL, 0, UpdateThread, (void *)&dwResult, 0,
&dwThreadID);
//
// Create the progress indicator dialog box.
//
DialogBox(g_hInstance, MAKEINTRESOURCE(IDD_UPDATE), hWnd,
UpdateProgressDlgProc);
//
// If we could not reconnect to the player, then display an error message
// and then exit the application.
//
if(dwResult == FALSE)
{
//
// Display an error message in the message box.
//
MessageBox(hWnd,
"Unable to reconnect to the Internet audio player..."
"exiting.", "Maverick(tm) Internet Audio Player", MB_OK);
//
// Exit the application.
//
PostQuitMessage(0);
}
//
// We've successfully updated the software.
//
return(TRUE);
}
//****************************************************************************
//
// Displays an open file dialog and downloads the selected files to the
// device.
//
//****************************************************************************
void
OpenFiles(HWND hWnd)
{
OPENFILENAME ofn;
char pcBuffer[4096], *pcFileNameStart;
unsigned long ulLength;
//
// Fill in the open file dialog box structure.
//
ofn.lStructSize = sizeof(ofn);
ofn.hwndOwner = hWnd;
ofn.hInstance = g_hInstance;
ofn.lpstrFilter = "Music Files (.mp3;.wma;.wav)\0"
"*.mp3;*.wma;*.wav\0"
"Play Lists (.m3u;.pls)\0"
"*.m3u;*.pls\0"
"All Files (*.*)\0"
"*.*\0";
ofn.lpstrCustomFilter = NULL;
ofn.nFilterIndex = 1;
ofn.lpstrFile = pcBuffer;
ofn.nMaxFile = 4096;
ofn.lpstrFileTitle = NULL;
ofn.lpstrInitialDir = NULL;
ofn.lpstrTitle = NULL;
ofn.Flags = OFN_FILEMUSTEXIST | OFN_PATHMUSTEXIST | OFN_EXPLORER |
OFN_ALLOWMULTISELECT;
ofn.lpTemplateName = NULL;
//
// The initial file name is empty.
//
pcBuffer[0] = 0;
//
// Display the open file dialog box.
//
if(GetOpenFileName(&ofn) != 0)
{
//
// A file (or files) were selected successfully. See if a single file
// or multiple files were selected.
//
if(ofn.lpstrFile[strlen(pcBuffer) + 1] == 0)
{
//
// A single file was selected, so download it now.
//
DoDownload(hWnd, pcBuffer);
}
else
{
//
// Multiple files were selected, so we need to construct the
// individual file names and download them one at a time. Get a
// pointer to the end of the path name (which is the beginning of
// the file name).
//
pcFileNameStart = pcBuffer + strlen(pcBuffer);
//
// While there are more file names, download the files.
//
while(*ofn.lpstrFile)
{
//
// Generate the name of the file to download.
//
if(!*pcFileNameStart)
{
//
// This is the first file, so simply replace the NULL at
// the end of the directory name with a '\'.
//
*pcFileNameStart = '\\';
//
// Move the file name pointer to the start of the next
// file name.
//
ofn.lpstrFile += strlen(pcBuffer) + 1;
}
else
{
//
// Get the length of this file name.
//
ulLength = strlen(ofn.lpstrFile) + 1;
//
// Copy this file name to the end of the directory name.
//
strcpy(pcFileNameStart + 1, ofn.lpstrFile);
//
// Move the file name pointer to the start of the next
// file name.
//
ofn.lpstrFile += ulLength;
}
//
// Download this file.
//
DoDownload(hWnd, pcBuffer);
}
}
}
//
// Re-load the list of files on the device.
//
LoadFileList();
}
//****************************************************************************
//
// The following variables contain the values retrieved from the user via the
// Audible dialog box.
//
//****************************************************************************
char g_pcAudibleTitle[256];
unsigned long g_ulAudibleStart;
unsigned long g_ulAudibleSections;
unsigned long g_pulAudibleSection[5];
//****************************************************************************
//
// The message handler for our Audible dialog box.
//
//****************************************************************************
BOOL APIENTRY
AudibleDlgProc(HWND hDlg, UINT message, UINT wParam, LONG lParam)
{
//
// Determine what to do based on the message we received.
//
switch(message)
{
//
// The dialog is being initialized.
//
case WM_INITDIALOG:
{
//
// Clear the text fields in the dialog box.
//
SetDlgItemText(hDlg, IDC_TITLE, "");
SetDlgItemInt(hDlg, IDC_START_TIME, 0, FALSE);
SetDlgItemInt(hDlg, IDC_NUM_SECTIONS, 0, FALSE);
SetDlgItemInt(hDlg, IDC_SECTION1, 0, FALSE);
SetDlgItemInt(hDlg, IDC_SECTION2, 0, FALSE);
SetDlgItemInt(hDlg, IDC_SECTION3, 0, FALSE);
SetDlgItemInt(hDlg, IDC_SECTION4, 0, FALSE);
SetDlgItemInt(hDlg, IDC_SECTION5, 0, FALSE);
//
// Indicate that the first control in the dialog box should receive
// the keyboard focus.
//
return(TRUE);
}
//
// A command button or menu item was selected.
//
case WM_COMMAND:
{
//
// See if the "OK" button was pressed, or escape was pressed.
//
if((LOWORD(wParam) == IDOK) || (LOWORD(wParam) == IDCANCEL))
{
//
// See if the "OK" button was pressed.
//
if(LOWORD(wParam) == IDOK)
{
//
// Retrieve the values from the dialog box.
//
GetDlgItemText(hDlg, IDC_TITLE, g_pcAudibleTitle, 256);
g_ulAudibleStart = GetDlgItemInt(hDlg, IDC_START_TIME,
NULL, FALSE);
g_ulAudibleSections = GetDlgItemInt(hDlg, IDC_NUM_SECTIONS,
NULL, FALSE);
g_pulAudibleSection[0] = GetDlgItemInt(hDlg, IDC_SECTION1,
NULL, FALSE);
g_pulAudibleSection[1] = GetDlgItemInt(hDlg, IDC_SECTION2,
NULL, FALSE);
g_pulAudibleSection[2] = GetDlgItemInt(hDlg, IDC_SECTION3,
NULL, FALSE);
g_pulAudibleSection[3] = GetDlgItemInt(hDlg, IDC_SECTION4,
NULL, FALSE);
g_pulAudibleSection[4] = GetDlgItemInt(hDlg, IDC_SECTION5,
NULL, FALSE);
}
//
// We are done with this dialog box, so dismiss it.
//
EndDialog(hDlg, LOWORD(wParam));
//
// Indicate that we've handled this message.
//
return(TRUE);
}
//
// We're done handling this message.
//
break;
}
}
//
// Indicate that we did not handle the message.
//
return(FALSE);
}
//****************************************************************************
//
// Displays an open file dialog and downloads the selected files to the
// device.
//
//****************************************************************************
void
OpenAudibleFile(HWND hWnd)
{
OPENFILENAME ofn;
char pcBuffer[4096], *pcDeviceName, cAudibleData[512];
tAudibleMetaData *pAudibleData = (tAudibleMetaData *)cAudibleData;
unsigned short pusDeviceName[128];
//
// Fill in the open file dialog box structure.
//
ofn.lStructSize = sizeof(ofn);
ofn.hwndOwner = hWnd;
ofn.hInstance = g_hInstance;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -