📄 applicationinstallerdlg.cpp
字号:
DWORD dwDeviceCount = 0;
CONAPI_DEVICE* pDevices = NULL;
m_comboPhones.ResetContent();
m_dwConnectionCount = 0;
dwRet = CONAGetDeviceCount(m_hDMHandle, &dwDeviceCount);
if( dwRet != CONA_OK ) ErrorMessageDlg(_T("CONAGetDeviceCount"), dwRet);
if( dwRet == CONA_OK && dwDeviceCount > 0 )
{
// Get list of currently connected devices
pDevices = new CONAPI_DEVICE[dwDeviceCount];
dwRet = CONAGetDevices(m_hDMHandle, &dwDeviceCount, pDevices);
if( dwRet != CONA_OK )
ErrorMessageDlg(_T("CONAGetDevices"), dwRet);
else
{
// Add each device to the phone combo box
while ( dwDeviceIndex < dwDeviceCount )
{
// Add all connections of the phone
for(DWORD i=0; i < pDevices[dwDeviceIndex].dwNumberOfItems; i++)
{
CString str = pDevices[dwDeviceIndex].pItems[i].pstrDeviceName;
m_comboPhones.AddString(str);
m_strSerialNumberTable[m_dwConnectionCount] = pDevices[dwDeviceIndex].pstrSerialNumber;
m_dwMediaTable[m_dwConnectionCount] = pDevices[dwDeviceIndex].pItems[i].dwMedia;
CONAPI_DEVICE_GEN_INFO* pInfo = NULL;
dwRet = CONAGetDeviceInfo(m_hDMHandle, m_strSerialNumberTable[m_dwConnectionCount], CONAPI_DEVICE_GENERAL_INFO, (LPVOID*)&pInfo);
if (dwRet == CONA_OK)
{
m_dwType[m_dwConnectionCount] = pInfo->dwType;
m_dwFileSystemSupport[m_dwConnectionCount] = pInfo->dwFileSystemSupport;
}
else
{
m_dwType[m_dwConnectionCount] = 0;
m_dwFileSystemSupport[m_dwConnectionCount] = 0;
ErrorMessageDlg(L"CONAGetDeviceInfo failed!", dwRet);
}
if (pInfo != NULL)
{ // Release allocated resources
dwRet = CONAFreeDeviceInfoStructure(CONAPI_DEVICE_GENERAL_INFO, (LPVOID)pInfo);
if (dwRet != CONA_OK)
{
ErrorMessageDlg(L"CONAFreeDeviceInfoStructure failed!", dwRet);
}
}
m_dwConnectionCount++;
}
dwDeviceIndex++;
}
// Free memory allocated by CONAGetDevices
CONAFreeDeviceStructure(dwDeviceCount, pDevices);
if( dwRet != CONA_OK ) ErrorMessageDlg(_T("CONAFreeDeviceStructure"), dwRet);
}
// Delete dynamically allocated memory
if (pDevices)
{
delete[] pDevices;
pDevices = NULL;
}
// Make UI changes
m_comboPhones.EnableWindow(TRUE);
m_comboPhones.SetCurSel(0);
m_btnInstall.EnableWindow(TRUE);
}
if( dwRet == CONA_OK && dwDeviceCount == 0 )
{
m_comboPhones.AddString(_T("No phones connected"));
m_comboPhones.EnableWindow(FALSE);
m_comboPhones.SetCurSel(0);
m_btnInstall.EnableWindow(FALSE);
}
OnCbnSelchangeComboPhone();
OnTypeSelected(); // Make some UI changes
}
//=========================================================
// OnButtonSis
//
// Opens file open dialog for selecting a file
//
//=========================================================
void CApplicationInstallerDlg::OnButtonSis()
{
CFileDialog filedlg(TRUE, NULL, NULL, OFN_HIDEREADONLY, _T("Sis files (*.sis)|*.sis||"), this);
if( filedlg.DoModal() == IDOK) m_editSIS.SetWindowText(filedlg.GetPathName());
}
//=========================================================
// OnButtonJar
//
// Opens file open dialog for selecting a file
//
//=========================================================
void CApplicationInstallerDlg::OnButtonJar()
{
CFileDialog filedlg(TRUE, NULL, NULL, OFN_HIDEREADONLY, _T("Jar files (*.jar)|*.jar||"), this);
if( filedlg.DoModal() == IDOK) m_editJAR.SetWindowText(filedlg.GetPathName());
}
//=========================================================
// OnButtonJad
//
// Opens file open dialog for selecting a file
//
//=========================================================
void CApplicationInstallerDlg::OnButtonJad()
{
CFileDialog filedlg(TRUE, NULL, NULL, OFN_HIDEREADONLY, _T("Jad files (*.jad)|*.jad||"), this);
if( filedlg.DoModal() == IDOK) m_editJAD.SetWindowText(filedlg.GetPathName());
}
//=========================================================
// OnButtonNth
//
// Opens file open dialog for selecting a file
//
//=========================================================
void CApplicationInstallerDlg::OnBnClickedButtonNth()
{
CFileDialog filedlg(TRUE, NULL, NULL, OFN_HIDEREADONLY, _T("Nth files (*.nth)|*.nth||"), this);
if( filedlg.DoModal() == IDOK) m_editNTH.SetWindowText(filedlg.GetPathName());
}
//=========================================================
// OnButtonNGage
//
// Opens file open dialog for selecting a file
//
//=========================================================
void CApplicationInstallerDlg::OnBnClickedButtonNGage()
{
CFileDialog filedlg(TRUE, NULL, NULL, OFN_HIDEREADONLY, _T("N-Gage files (*.N-Gage)|*.N-Gage||"), this);
if( filedlg.DoModal() == IDOK) m_editNTH.SetWindowText(filedlg.GetPathName());
}
//=========================================================
// OnButtonCancel
//
// Cancel application install
//
//=========================================================
void CApplicationInstallerDlg::OnButtonCancel()
{
g_bCancel = TRUE;
}
//=========================================================
// OnInstall
//
// Install required files to device
//
//=========================================================
void CApplicationInstallerDlg::OnInstall()
{
DWORD dwRet = CONA_OK;
DWORD dwRet2 = CONA_OK;
int iSelection = CB_ERR;
WCHAR* pstrSerialNumber = NULL;
DWORD dwMedia = 0;
DWORD dwApplicationType = 0;
DWORD dwOptions = CONA_DEFAULT_FOLDER|CONA_OVERWRITE|CONA_WAIT_THAT_USER_ACTION_IS_DONE;
LPVOID pApplicationStruct = NULL;
FSHANDLE hFSHandle = NULL;
DWORD dwDeviceID = 0;
WCHAR strSourceFolder[MAX_PATH] = _T("");
WCHAR strJar[MAX_PATH] = {0};
WCHAR strJad[MAX_PATH] = {0};
WCHAR strSis[MAX_PATH] = {0};
WCHAR strNth[MAX_PATH] = {0};
WCHAR strNgage[MAX_PATH] = {0};
WCHAR strTmp[MAX_PATH] = {0};
WCHAR *strNgageFileName;
CONAPI_APPLICATION_JAVA javaFiles = {0};
CONAPI_APPLICATION_SIS sisFiles = {0};
CONAPI_APPLICATION_FILE nthFiles = {0};
iSelection = m_comboPhones.GetCurSel();
if( iSelection == CB_ERR ) return; // No phone selected
// Make UI changes
m_btnInstall.EnableWindow(FALSE);
m_btnCancel.EnableWindow(TRUE);
m_progressBar.ShowWindow(TRUE);
m_sWait.ShowWindow(FALSE);
CWaitCursor waitcursor;
g_bCancel = FALSE;
// Open file system connection
pstrSerialNumber = m_strSerialNumberTable[iSelection].GetBuffer(MIN_BUFFER);
dwMedia = m_dwMediaTable[iSelection];
FSAPI_Initialize(FSAPI_VERSION_32, NULL);
dwRet = CONAOpenFS(pstrSerialNumber, &dwMedia, &hFSHandle, &dwDeviceID);
if( dwRet != CONA_OK ) ErrorMessageDlg(_T("CONAOpenFS"), dwRet);
if( dwRet == CONA_OK )
{
// Register file system callback function
dwRet = CONARegisterFSNotifyCallback(hFSHandle, API_REGISTER, (PFN_CONA_FS_CALLBACK)FileOperationCallback);
if( dwRet != CONA_OK ) ErrorMessageDlg(_T("CONARegisterFSNotifyCallback"), dwRet);
// Allocate strings
DWORD dwInstallType = (DWORD)m_comboTypes.GetItemData(m_comboTypes.GetCurSel());
if( dwRet == CONA_OK && dwInstallType == INSTALL_TYPE_JAVA )
{
m_editJAR.GetWindowText(strJar, MAX_PATH);
m_editJAD.GetWindowText(strJad, MAX_PATH);
dwApplicationType = CONA_APPLICATION_TYPE_JAVA;
pApplicationStruct = &javaFiles;
javaFiles.pstrFileNameJad = PathFindFileName(strJad);
javaFiles.pstrFileNameJar = PathFindFileName(strJar);
wcscpy_s(strTmp, strJar);
}
if( dwRet == CONA_OK && dwInstallType == INSTALL_TYPE_SIS )
{
m_editSIS.GetWindowText(strSis, MAX_PATH);
dwApplicationType = CONA_APPLICATION_TYPE_SIS;
pApplicationStruct = &sisFiles;
sisFiles.pstrFileNameSis = PathFindFileName(strSis);
wcscpy_s(strTmp, strSis);
}
if( dwRet == CONA_OK && dwInstallType == INSTALL_TYPE_THEMES )
{
m_editNTH.GetWindowText(strNth, MAX_PATH);
dwApplicationType = CONA_APPLICATION_TYPE_THEMES;
pApplicationStruct = &nthFiles;
nthFiles.pstrFileName = PathFindFileName(strNth);
wcscpy_s(strTmp, strNth);
}
if( dwRet == CONA_OK && dwInstallType == INSTALL_TYPE_NGAGE )
{
m_editNGAGE.GetWindowText(strNgage, MAX_PATH);
strNgageFileName = PathFindFileName(strNgage);
wcscpy_s(strTmp, strNgage);
}
PathRemoveFileSpec(strTmp); // Remove filename, just path is left
wcscat_s(strSourceFolder, strTmp);
// Install application
if( dwRet == CONA_OK )
{
// NGage
if( dwApplicationType == INSTALL_TYPE_NGAGE )
{
WCHAR *pstrFileName = strNgageFileName;
WCHAR *pstrSourcePath = CONAAllocString(strSourceFolder);
WCHAR *pstrTargetPath = CONAAllocString(L"\\\\E:\\N-Gage\\");
DWORD dwOptions = CONA_DIRECT_PC_TO_PHONE;
dwOptions |= CONA_OVERWRITE;
dwRet = CONACopyFile( hFSHandle,
dwOptions, // options
pstrFileName, // filename
pstrSourcePath, // source path
pstrTargetPath //target path
);
}
// other
else
{
dwRet = CONAInstallApplication( hFSHandle,
dwApplicationType,
pApplicationStruct,
dwOptions,
strSourceFolder,
NULL // TargetFolder
);
if( dwRet == ECONA_CANCELLED )
{
// Installation was cancelled
AfxMessageBox( _T("Application installation cancelled") );
}
else if( dwRet == CONA_OK_BUT_USER_ACTION_NEEDED )
{
// Either device does not support waiting or
// the maximum waiting time has exceeded
AfxMessageBox( _T("User action needed on the device side") );
}
else if( dwRet != CONA_OK )
{
// An error occurred
ErrorMessageDlg(_T("CONAInstallApplication"), dwRet);
}
}
}
// Unregister file system callback function
dwRet2 = CONARegisterFSNotifyCallback(hFSHandle, API_UNREGISTER, (PFN_CONA_FS_CALLBACK)FileOperationCallback);
if( dwRet2 != CONA_OK ) ErrorMessageDlg(_T("CONARegisterFSNotifyCallback"), dwRet2);
// Close file system connection
if( hFSHandle )
{
dwRet2 = CONACloseFS(hFSHandle);
if( dwRet2 != CONA_OK ) ErrorMessageDlg(_T("CONACloseFS"), dwRet2);
}
}
if( dwRet == CONA_OK ) AfxMessageBox( _T("Application installed successfully") );
FSAPI_Terminate(NULL);
// Make UI changes
m_btnInstall.EnableWindow(TRUE);
m_btnCancel.EnableWindow(FALSE);
m_progressBar.SetPos(0);
m_progressBar.ShowWindow(FALSE);
m_sWait.ShowWindow(FALSE);
return;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -