📄 installerdialog.cs
字号:
{
OpenFileDialog openFileDialog;
openFileDialog = new OpenFileDialog();
openFileDialog.Filter = "Nth files (*.nth)|*.nth";
openFileDialog.FilterIndex = 0;
openFileDialog.RestoreDirectory = true;
if (openFileDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
TextNth.Text = openFileDialog.FileName;
}
}
//=========================================================
// CommandInstall_Click
//
// Install required files to device
//
//=========================================================
private void CommandInstall_Click(object sender, System.EventArgs e)
{
int iDeviceID = 0;
int iMedia = 0;
int iSelection = 0;
int iResult = 0;
iSelection = ComboPhone.SelectedIndex;
if (iSelection == -1) return; // TODO: might not be correct. Was : Exit Sub
iMedia = CONADefinitions.API_MEDIA_ALL;
// Create FS connection
iResult = CONAFileSystem.CONAOpenFS(strSerialNumbers[iSelection], ref iMedia, ref Common.hFSHandle, ref iDeviceID);
if (iResult != PCCSErrors.CONA_OK) PCCAPIUtils.ShowErrorMessage("CONAOpenFS", iResult);
if (iResult == PCCSErrors.CONA_OK)
{
// Register file system notification callback function
pFSCallBack = Common.FSNotifyCallback;
iResult = CONAFileSystem.CONARegisterFSNotifyCallback(Common.hFSHandle, CONADefinitions.API_REGISTER, pFSCallBack);
if (iResult != PCCSErrors.CONA_OK) PCCAPIUtils.ShowErrorMessage("CONARegisterFSNotifyCallback", iResult);
CommandInstall.Enabled = false;
CommandCancel.Enabled = true;
labelWait.Visible = false;
ProgressBar1.Visible = true;
Cursor = Cursors.WaitCursor;
if (iInstallationType == INSTALL_TYPE_JAVA)
{
// Installing Java application
Common.InstallJavaApplication(TextJar.Text, TextJad.Text);
}
else if (iInstallationType == INSTALL_TYPE_NGAGE)
{
// Installing N-gage application
Common.InstallNGageApplication(TextNGage.Text);
}
else if (iInstallationType == INSTALL_TYPE_SYMBIAN)
{
// Installing Symbian application
Common.InstallSymbianApplication(TextSis.Text);
}
else if (iInstallationType == INSTALL_TYPE_THEMES)
{
// Installing theme
Common.InstallTheme(TextNth.Text);
}
iResult = CONAFileSystem.CONARegisterFSNotifyCallback(Common.hFSHandle, CONADefinitions.API_UNREGISTER, pFSCallBack);
if (iResult != PCCSErrors.CONA_OK) PCCAPIUtils.ShowErrorMessage("CONARegisterFSNotifyCallback", iResult);
iResult = CONAFileSystem.CONACloseFS(Common.hFSHandle);
if (iResult != PCCSErrors.CONA_OK) PCCAPIUtils.ShowErrorMessage("CONACloseFS", iResult);
}
this.Cursor = Cursors.Default;
CommandInstall.Enabled = true;
CommandCancel.Enabled = false;
labelWait.Visible = false;
ProgressBar1.Value = 0;
ProgressBar1.Visible = false;
}
//===================================================================
// CommandCancel_Click
//
// User has clicked Cancel button to cancel application installation
//===================================================================
private void CommandCancel_Click(object sender, System.EventArgs e)
{
bCancelled = true;
Cursor = Cursors.Default;
CommandInstall.Enabled = true;
CommandCancel.Enabled = false;
ProgressBar1.Visible = false;
}
//===================================================================
// CommandList_Click
//
// User has clicked List button to list installed applications
//===================================================================
private void CommandList_Click(object sender, System.EventArgs e)
{
int iSelection;
// Find out phone selected
iSelection = ComboPhone.SelectedIndex;
if (iSelection != -1)
{
// Phone is selected
ListDialog listDlg = new ListDialog();
int iDeviceID = 0;
int iMedia = 0;
int iResult = 0;
int icResult = 0;
int iCount = 0;
IntPtr resPtr = IntPtr.Zero;
int i = 0;
CONAApplicationInstallation.CONAPI_APPLICATION_INFO pApplication = new CONAApplicationInstallation.CONAPI_APPLICATION_INFO();
// Clear dialog application list
listDlg.ApplicationList.Items.Clear();
listDlg.strSerialNumber = strSerialNumbers[iSelection];
iMedia = CONADefinitions.API_MEDIA_ALL;
// Create FS connection
iResult = CONAFileSystem.CONAOpenFS(strSerialNumbers[iSelection], ref iMedia, ref Common.hFSHandle, ref iDeviceID);
if (iResult != PCCSErrors.CONA_OK)
{
PCCAPIUtils.ShowErrorMessage("CONAOpenFS", iResult);
}
else
{
// Register file system notification callback function
pFSCallBack = Common.FSNotifyCallback;
icResult = CONAFileSystem.CONARegisterFSNotifyCallback(Common.hFSHandle, CONADefinitions.API_REGISTER, pFSCallBack);
if (icResult != PCCSErrors.CONA_OK)
{
PCCAPIUtils.ShowErrorMessage("CONARegisterFSNotifyCallback", icResult);
}
// update UI
CommandInstall.Enabled = false;
CommandList.Enabled = false;
CommandCancel.Enabled = true;
labelWait.Visible = false;
ProgressBar1.Visible = true;
Cursor = Cursors.WaitCursor;
// List installed applications in phone
iCount = 0;
resPtr = IntPtr.Zero;
iResult = CONAApplicationInstallation.CONAListApplications(Common.hFSHandle, CONAApplicationInstallation.CONA_LIST_ALL_APPICATIONS, ref iCount, ref resPtr);
if (iResult == PCCSErrors.CONA_OK)
{
// Add each application found to the dialog application list box
if (iCount == 0)
{
listDlg.ApplicationList.Items.Add("No installed applications");
}
else
{
// Redim appUID table
listDlg.strAppUID = null;
listDlg.strAppUID = new string[iCount];
// Map pointer to application info structure
pApplication = (CONAApplicationInstallation.CONAPI_APPLICATION_INFO)Marshal.PtrToStructure(resPtr, typeof(CONAApplicationInstallation.CONAPI_APPLICATION_INFO));
// Loop trough array of application info
for (i = 0; i < iCount; i++)
{
// Calculate beginning of CONAPI_APPLICATION_INFO structure of item 'i'
Int64 iPtr = resPtr.ToInt64() + i * Marshal.SizeOf(typeof(CONAApplicationInstallation.CONAPI_APPLICATION_INFO));
// Convert integer to pointer
IntPtr tmpPtr = new IntPtr(iPtr);
// Copy data from buffer
pApplication = (CONAApplicationInstallation.CONAPI_APPLICATION_INFO)Marshal.PtrToStructure(tmpPtr, typeof(CONAApplicationInstallation.CONAPI_APPLICATION_INFO));
listDlg.ApplicationList.Items.Add(pApplication.pstrName);
// Save appUID
listDlg.strAppUID[i] = pApplication.pstrUID;
}
}
// Free reserved application info resources
iResult = CONAApplicationInstallation.CONAFreeApplicationInfoStructures(iCount, ref resPtr);
if (iResult != PCCSErrors.CONA_OK) PCCAPIUtils.ShowErrorMessage("CONAFreeApplicationInfoStructures", iResult);
}
else
{
PCCAPIUtils.ShowErrorMessage("CONAListApplications", iResult);
}
icResult = CONAFileSystem.CONARegisterFSNotifyCallback(Common.hFSHandle, CONADefinitions.API_UNREGISTER, pFSCallBack);
if (icResult != PCCSErrors.CONA_OK)
{
PCCAPIUtils.ShowErrorMessage("CONARegisterFSNotifyCallback", icResult);
}
// Close file system
icResult = CONAFileSystem.CONACloseFS(Common.hFSHandle);
if (icResult != PCCSErrors.CONA_OK)
{
PCCAPIUtils.ShowErrorMessage("CONACloseFS", icResult);
iResult = icResult;
}
// Clean up
this.Cursor = Cursors.Default;
CommandInstall.Enabled = true;
CommandList.Enabled = true;
CommandCancel.Enabled = false;
labelWait.Visible = false;
ProgressBar1.Value = 0;
ProgressBar1.Visible = false;
// If no errors, show application list dialog
if (iResult == PCCSErrors.CONA_OK)
{
listDlg.ShowDialog(this);
}
}
}
else
{
// No phone selected, inform user
MessageBox.Show(this, "No phone selected", "List phone applications");
}
}
//===================================================================
// ComboPhone_SelectedIndexChanged
//
// User has changed selected phone
//===================================================================
private void ComboPhone_SelectedIndexChanged(object sender, System.EventArgs e)
{
ComboType.Items.Clear();
// Find out phone selected
int iSelection = ComboPhone.SelectedIndex;
if (iSelection != -1)
{
int iResult = 0;
int iStructureType = 0;
IntPtr ptr = IntPtr.Zero;
CONADefinitions.CONAPI_DEVICE_GEN_INFO generalInfoStruct = new CONADefinitions.CONAPI_DEVICE_GEN_INFO();
iStructureType = CONADefinitions.CONAPI_DEVICE_GENERAL_INFO;
// Query device Info
iResult = CONADeviceManagement.CONAGetDeviceInfo(Common.hDMHandle, strSerialNumbers[iSelection], iStructureType, ref ptr);
if (iResult != PCCSErrors.CONA_OK)
{
PCCAPIUtils.ShowErrorMessage("CONAGetDeviceInfo", iResult);
}
else
{
// Map pointer to general info structure
generalInfoStruct = (CONADefinitions.CONAPI_DEVICE_GEN_INFO)Marshal.PtrToStructure(ptr, typeof(CONADefinitions.CONAPI_DEVICE_GEN_INFO));
// Check if application listing is supported
if ((generalInfoStruct.iFileSystemSupport & CONADefinitions.CONAPI_FS_LIST_APPLICATIONS) != 0)
{
CommandList.Enabled = true;
}
else
{
CommandList.Enabled = false;
}
if ((generalInfoStruct.iFileSystemSupport & CONADefinitions.CONAPI_FS_UNINSTALL_APPLICATIONS) != 0)
{
Common.bAppUninstallSupported = true;
}
else
{
Common.bAppUninstallSupported = false;
}
if ((generalInfoStruct.iFileSystemSupport & CONADefinitions.CONAPI_FS_INSTALL_JAVA_APPLICATIONS) != 0)
ComboType.Items.Add(strJavaItem);
if ((generalInfoStruct.iFileSystemSupport & CONADefinitions.CONAPI_FS_INSTALL_SIS_APPLICATIONS) != 0)
ComboType.Items.Add(strSymbianItem);
if ((generalInfoStruct.iType & CONADefinitions.CONAPI_SERIES40_DEVICE) != 0)
ComboType.Items.Add(strThemesItem);
// Test if phone supports sisx packages
if ((generalInfoStruct.iFileSystemSupport & CONADefinitions.CONAPI_FS_INSTALL_SISX_APPLICATIONS) != 0)
{
bPhoneSupportsSisX = true;
}
else
{
bPhoneSupportsSisX = false;
}
ComboType.Items.Add(strNGageItem);
iResult = CONADeviceManagement.CONAFreeDeviceInfoStructure(iStructureType, ptr);
if (iResult != PCCSErrors.CONA_OK)
{
PCCAPIUtils.ShowErrorMessage("CONAFreeDeviceInfoStructure", iResult);
}
ComboType.SelectedIndex = 0;
TypeSelectionChanged();
}
}
}
// Timer for updating phonelist from callback function
private void Timer1_Tick(object sender, System.EventArgs e)
{
if (bRefreshPhonecombo)
{
RefreshPhoneList();
bRefreshPhonecombo = false;
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -