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

📄 installerdialog.vb

📁 以前做NOKIA手机与PC通信时所参考的源代码,里面包括两个程序,一个是手机文件夹浏览源码,另一个手机SIS安装程序.
💻 VB
📖 第 1 页 / 共 4 页
字号:
    ' Opens file open dialog for selecting a file
    '
    '=========================================================
    Private Sub CommandNGage_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CommandNGage.Click
        Dim openFileDialog As OpenFileDialog
        openFileDialog = New OpenFileDialog
        openFileDialog.Filter = "N-Gage files (*.n-gage)|*.n-gage"
        openFileDialog.FilterIndex = 0
        openFileDialog.RestoreDirectory = True
        If openFileDialog.ShowDialog = Windows.Forms.DialogResult.OK Then
            TextNGage.Text = openFileDialog.FileName
        End If
    End Sub

    '=========================================================
    ' CommandNth_Click 
    '
    ' Opens file open dialog for selecting a file
    '
    '=========================================================
    Private Sub CommandNth_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles CommandNth.Click
        Dim openFileDialog As OpenFileDialog
        openFileDialog = New OpenFileDialog
        openFileDialog.Filter = "Nth files (*.nth)|*.nth"
        openFileDialog.FilterIndex = 0
        openFileDialog.RestoreDirectory = True
        If openFileDialog.ShowDialog() = Windows.Forms.DialogResult.OK Then
            TextNth.Text = openFileDialog.FileName
        End If
    End Sub

    '=========================================================
    ' CommandInstall_Click
    '
    ' Install required files to device
    '
    '=========================================================
    Private Sub CommandInstall_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles CommandInstall.Click
        Dim iDeviceID As Integer
        Dim iMedia As Integer
        Dim iSelection As Integer
        Dim iResult As Integer

        iSelection = ComboPhone.SelectedIndex
        If iSelection = -1 Then Exit Sub
        iMedia = API_MEDIA_ALL
        ' Create FS connection
        iResult = CONAOpenFS(strSerialNumbers(iSelection), iMedia, hFSHandle, iDeviceID)
        If iResult <> CONA_OK Then ShowErrorMessage("CONAOpenFS", iResult)
        If iResult = CONA_OK Then
            ' Register file system notification callback function
            pFSCallBack = AddressOf FSNotifyCallback
            iResult = CONARegisterFSNotifyCallback(hFSHandle, API_REGISTER, pFSCallBack)
            If iResult <> CONA_OK Then ShowErrorMessage("CONARegisterFSNotifyCallback", iResult)
            CommandInstall.Enabled = False
            CommandCancel.Enabled = True
            labelWait.Visible = False
            ProgressBar1.Visible = True
            Cursor = Cursors.WaitCursor
            If iInstallationType = INSTALL_TYPE_JAVA Then
                ' Installing Java application
                InstallJavaApplication(TextJar.Text, TextJad.Text)
            ElseIf iInstallationType = INSTALL_TYPE_NGAGE Then
                ' Installing N-gage application 
                InstallNGageApplication(TextNGage.Text)
            ElseIf iInstallationType = INSTALL_TYPE_SYMBIAN Then
                ' Installing Symbian application
                InstallSymbianApplication(TextSis.Text)
            ElseIf iInstallationType = INSTALL_TYPE_THEMES Then
                ' Installing theme
                InstallTheme(TextNth.Text)
            End If
            iResult = CONARegisterFSNotifyCallback(hFSHandle, API_UNREGISTER, pFSCallBack)
            If iResult <> CONA_OK Then ShowErrorMessage("CONARegisterFSNotifyCallback", iResult)
            iResult = CONACloseFS(hFSHandle)
            If iResult <> CONA_OK Then ShowErrorMessage("CONACloseFS", iResult)
        End If
        Me.Cursor = Cursors.Default
        CommandInstall.Enabled = True
        CommandCancel.Enabled = False
        labelWait.Visible = False
        ProgressBar1.Value = 0
        ProgressBar1.Visible = False
    End Sub

    '===================================================================
    ' CommandCancel_Click
    '
    ' User has clicked Cancel button to cancel application installation
    '===================================================================
    Private Sub CommandCancel_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles CommandCancel.Click
        bCancelled = True
        Cursor = Cursors.Default
        CommandInstall.Enabled = True
        CommandCancel.Enabled = False
        ProgressBar1.Visible = False
    End Sub
    '===================================================================
    ' CommandList_Click
    '
    ' User has clicked List button to list installed applications 
    '===================================================================
    Private Sub CommandList_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CommandList.Click
        Dim iSelection As Integer
        ' Find out phone selected
        iSelection = ComboPhone.SelectedIndex
        If iSelection <> -1 Then
            ' Phone is selected
            Dim listDlg As New ListDialog
            Dim iDeviceID As Integer
            Dim iMedia As Integer
            Dim iResult As Integer
            Dim icResult As Integer
            Dim iCount As Integer
            Dim resPtr As IntPtr
            Dim i As Integer
            Dim pApplication As CONAPI_APPLICATION_INFO
            ' Clear dialog application list
            listDlg.ApplicationList.Items.Clear()
            listDlg.strSerialNumber = strSerialNumbers(iSelection)
            iMedia = API_MEDIA_ALL
            ' Create FS connection
            iResult = CONAOpenFS(strSerialNumbers(iSelection), iMedia, hFSHandle, iDeviceID)
            If iResult <> CONA_OK Then
                ShowErrorMessage("CONAOpenFS", iResult)
            Else
                ' Register file system notification callback function
                pFSCallBack = AddressOf FSNotifyCallback
                icResult = CONARegisterFSNotifyCallback(hFSHandle, API_REGISTER, pFSCallBack)
                If icResult <> CONA_OK Then
                    ShowErrorMessage("CONARegisterFSNotifyCallback", icResult)
                End If
                ' 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 = 0
                iResult = CONAListApplications(hFSHandle, CONA_LIST_ALL_APPICATIONS, iCount, resPtr)
                If iResult = CONA_OK Then
                    ' Add each application found to the dialog application list box
                    If iCount = 0 Then
                        listDlg.ApplicationList.Items.Add("No installed applications")
                    Else
                        ' Redim appUID table
                        ReDim listDlg.strAppUID(iCount)
                        ' Map pointer to application info structure
                        pApplication = Marshal.PtrToStructure(resPtr, GetType(CONAPI_APPLICATION_INFO))
                        ' Loop trough array of application info
                        For i = 0 To iCount - 1
                            ' Calculate beginning of CONAPI_APPLICATION_INFO structure of item 'i'
                            Dim iPtr As Integer = resPtr.ToInt32 + i * Marshal.SizeOf(GetType(CONAPI_APPLICATION_INFO))
                            ' Convert integer to pointer
                            Dim tmpPtr As IntPtr = IntPtr.op_Explicit(iPtr)
                            ' Copy data from buffer
                            pApplication = Marshal.PtrToStructure(tmpPtr, GetType(CONAPI_APPLICATION_INFO))
                            listDlg.ApplicationList.Items.Add(pApplication.pstrName)
                            ' Save appUID
                            listDlg.strAppUID(i) = pApplication.pstrUID
                        Next
                    End If
                    ' Free reserved application info resources
                    iResult = CONAFreeApplicationInfoStructures(iCount, resPtr)
                    If iResult <> CONA_OK Then ShowErrorMessage("CONAFreeApplicationInfoStructures", iResult)
                Else
                    ShowErrorMessage("CONAListApplications", iResult)
                End If
                icResult = CONARegisterFSNotifyCallback(hFSHandle, API_UNREGISTER, pFSCallBack)
                If icResult <> CONA_OK Then
                    ShowErrorMessage("CONARegisterFSNotifyCallback", icResult)
                End If
                ' Close file system 
                icResult = CONACloseFS(hFSHandle)
                If icResult <> CONA_OK Then
                    ShowErrorMessage("CONACloseFS", icResult)
                    iResult = icResult
                End If
                ' Clean up
                Me.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 = CONA_OK Then
                    listDlg.ShowDialog(Me)
                End If
            End If
        Else
            ' No phone selected, inform user
            MessageBox.Show(Me, "No phone selected", "List phone applications")
        End If

    End Sub
    '===================================================================
    ' ComboPhone_SelectedIndexChanged
    '
    ' User has changed selected phone
    '===================================================================
    Private Sub ComboPhone_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboPhone.SelectedIndexChanged
        ComboType.Items.Clear()


        ' Find out phone selected
        Dim iSelection As Integer = ComboPhone.SelectedIndex
        If iSelection <> -1 Then
            Dim iResult As Integer
            Dim iStructureType As Integer
            Dim ptr As IntPtr
            Dim generalInfoStruct As CONAPI_DEVICE_GEN_INFO
            iStructureType = CONAPI_DEVICE_GENERAL_INFO
            ' Query device Info
            iResult = CONAGetDeviceInfo(hDMHandle, strSerialNumbers(iSelection), iStructureType, ptr)
            If iResult <> CONA_OK Then
                ShowErrorMessage("CONAGetDeviceInfo", iResult)
            Else
                ' Map pointer to general info structure
                generalInfoStruct = Marshal.PtrToStructure(ptr, GetType(CONAPI_DEVICE_GEN_INFO))
                ' Check if application listing is supported
                If generalInfoStruct.iFileSystemSupport And CONAPI_FS_LIST_APPLICATIONS Then
                    CommandList.Enabled = True
                Else
                    CommandList.Enabled = False
                End If
                If generalInfoStruct.iFileSystemSupport And CONAPI_FS_UNINSTALL_APPLICATIONS Then
                    bAppUninstallSupported = True
                Else
                    bAppUninstallSupported = False
                End If
                If generalInfoStruct.iFileSystemSupport And CONAPI_FS_INSTALL_JAVA_APPLICATIONS Then
                    ComboType.Items.Add(strJavaItem)
                End If
                If generalInfoStruct.iFileSystemSupport And CONAPI_FS_INSTALL_SIS_APPLICATIONS Then
                    ComboType.Items.Add(strSymbianItem)
                End If
                If generalInfoStruct.iType And CONAPI_SERIES40_DEVICE Then
                    ComboType.Items.Add(strThemesItem)
                End If
                ' Test if phone supports sisx packages
                If generalInfoStruct.iFileSystemSupport And CONAPI_FS_INSTALL_SISX_APPLICATIONS Then
                    bPhoneSupportsSisX = True
                Else
                    bPhoneSupportsSisX = False
                End If
                ComboType.Items.Add(strNGageItem)
                iResult = CONAFreeDeviceInfoStructure(iStructureType, ptr)
                If iResult <> CONA_OK Then
                    ShowErrorMessage("CONAFreeDeviceInfoStructure", iResult)
                End If
                ComboType.SelectedIndex = 0
                TypeSelectionChanged()
            End If
        End If
    End Sub

    ' Timer for updating phonelist from callback function
    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        If bRefreshPhonecombo Then
            RefreshPhoneList()
            bRefreshPhonecombo = False
        End If
    End Sub
End Class

⌨️ 快捷键说明

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