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

📄 filebrowser.vb

📁 以前做NOKIA手机与PC通信时所参考的源代码,里面包括两个程序,一个是手机文件夹浏览源码,另一个手机SIS安装程序.
💻 VB
📖 第 1 页 / 共 4 页
字号:
                End If
                pListener = New FileOperationListener
                pListener.StartListening(Me.Handle, hFS, "Moving", strPCFolder + "\" + strPCFile, "-->" + strPhoneFolder)
                iResult = CONAMoveFile(hFS, CONA_DIRECT_PC_TO_PHONE, strPCFile, strPCFolder, strPhoneFolder)
                pListener.StopListening()
                If iResult = CONA_OK Then
                    MsgBox("Move completed succesfully!")
                ElseIf iResult = ECONA_CANCELLED Then
                    MsgBox("Move was cancelled.")
                Else
                    ShowErrorMessage("FileBrowser::BTN_MovePCToPhone_Click(): CONAMoveFile failed!", iResult)
                End If
                ' show updated folder listing
                LBX_PCFiles.PopulateList("")
                LBX_PhoneFiles.ShowPhoneFolder(strPhoneFolder)
                iResult = CONACloseFS(hFS)
                If iResult <> CONA_OK Then
                    ShowErrorMessage("FileBrowser::BTN_MovePCToPhone_Click(): CONACloseFS failed!", iResult)
                End If
            Else
                ShowErrorMessage("FileBrowser::BTN_MovePCToPhone_Click(): CONAOpenFS failed!", iResult)
            End If
        End If
    End Sub

    '===================================================================
    ' BTN_MovePhoneToPC_Click
    '
    ' Moves selected phone file to selected pc folder
    '===================================================================
    Private Sub BTN_MovePhoneToPC_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles BTN_MovePhoneToPC.Click
        Dim pListener As FileOperationListener
        Dim file As String = LBX_PhoneFiles.GetCurrentFile()
        If file.Length() <= 0 Then
            MsgBox("Please select phone file to be moved.")
        Else
            Dim hFS As Integer
            Dim iMedia As Integer = API_MEDIA_ALL
            Dim iDeviceID As Integer
            Dim iResult As Integer = CONAOpenFS(LBX_PhoneFiles.GetCurrentSN(), iMedia, hFS, iDeviceID)
            If iResult = CONA_OK Then
                Dim strPhoneFile As String = LBX_PhoneFiles.GetCurrentFile()
                Dim strPhoneFolder As String = LBX_PhoneFiles.GetSelectedFolder()
                Dim strPCFolder As String = LBX_PCFiles.GetCurrentFolder()
                pListener = New FileOperationListener
                pListener.StartListening(Me.Handle, hFS, "Moving", strPhoneFolder + "\" + strPhoneFile, "-->" + strPCFolder)
                iResult = CONAMoveFile(hFS, CONA_DIRECT_PHONE_TO_PC, strPhoneFile, strPhoneFolder, strPCFolder)
                pListener.StopListening()
                If iResult = CONA_OK Then
                    MsgBox("Move completed succesfully!")
                ElseIf iResult = ECONA_CANCELLED Then
                    MsgBox("Move was cancelled.")
                Else
                    ShowErrorMessage("FileBrowser::BTN_MovePhoneToPC_Click(): CONAMoveFile failed!", iResult)
                End If
                ' show updated folder listing
                LBX_PCFiles.PopulateList("")
                LBX_PhoneFiles.ShowPhoneFolder(strPhoneFolder)
                iResult = CONACloseFS(hFS)
                If iResult <> CONA_OK Then
                    ShowErrorMessage("FileBrowser::BTN_MovePhoneToPC_Click(): CONACloseFS failed!", iResult)
                End If
            Else
                ShowErrorMessage("FileBrowser::BTN_MovePhoneToPC_Click(): CONAOpenFS failed!", iResult)
            End If
        End If
    End Sub

    '===================================================================
    ' BTN_Create_Click
    '
    ' Creates new folder to selected phone folder
    '===================================================================
    Private Sub BTN_Create_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles BTN_Create.Click
        Dim pListener As FileOperationListener
        Dim CreateDlg As FRM_Create = New FRM_Create
        CreateDlg.TXB_Name.Text = ""
        If CreateDlg.ShowDialog(Me) = Windows.Forms.DialogResult.OK Then
            Dim hFS As Integer
            Dim iMedia As Integer = API_MEDIA_ALL
            Dim iDeviceID As Integer
            Dim iResult As Integer = CONAOpenFS(LBX_PhoneFiles.GetCurrentSN(), iMedia, hFS, iDeviceID)
            If iResult = CONA_OK Then
                Dim strPhoneFolder As String = LBX_PhoneFiles.GetCurrentFolder()
                pListener = New FileOperationListener
                pListener.StartListening(Me.Handle, hFS, "Creating", strPhoneFolder + "\" + CreateDlg.TXB_Name.Text, "")
                iResult = CONACreateFolder(hFS, CreateDlg.TXB_Name.Text, strPhoneFolder)
                pListener.StopListening()
                If iResult = CONA_OK Then
                    MsgBox("Create folder completed succesfully!")
                ElseIf iResult = ECONA_CANCELLED Then
                    MsgBox("Create folder was cancelled.")
                Else
                    ShowErrorMessage("FileBrowser::BTN_Create_Click(): CONACreateFolder failed!", iResult)
                End If
                ' show updated folder listing
                LBX_PhoneFiles.ShowPhoneFolder(strPhoneFolder)
                iResult = CONACloseFS(hFS)
                If iResult <> CONA_OK Then
                    ShowErrorMessage("FileBrowser::BTN_Create_Click(): CONACloseFS failed!", iResult)
                End If
            Else
                ShowErrorMessage("FileBrowser::BTN_Create_Click(): CONAOpenFS failed!", iResult)
            End If
        End If
    End Sub

    '===================================================================
    ' BTN_Rename_Click
    '
    ' Renames a folder or file from phone. If the selected item is
    ' a phone, renames friendly name of phone 
    '===================================================================
    Private Sub BTN_Rename_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles BTN_Rename.Click
        Dim bIsFile As Boolean = True  ' selected item is file - not folder
        If LBX_PhoneFiles.SelectedIndex <> -1 Then
            Dim RenameDlg As FRM_Rename = New FRM_Rename
            RenameDlg.LBL_OldName.Text = LBX_PhoneFiles.GetCurrentFile()
            If RenameDlg.LBL_OldName.Text.Length <= 0 Then
                bIsFile = False ' selected item is folder - not file
                RenameDlg.LBL_OldName.Text = LBX_PhoneFiles.GetSelectedFolder()
            End If
            If RenameDlg.LBL_OldName.Text.Length > 0 Then
                If RenameDlg.ShowDialog(Me) = Windows.Forms.DialogResult.OK Then
                    Dim hFS As Integer
                    Dim iMedia As Integer = API_MEDIA_ALL
                    Dim iDeviceID As Integer
                    Dim iResult As Integer = CONAOpenFS(LBX_PhoneFiles.GetCurrentSN(), iMedia, hFS, iDeviceID)
                    If iResult = CONA_OK Then
                        If iResult = CONA_OK Then
                            Dim strPhoneFolder As String = LBX_PhoneFiles.GetCurrentFolder()

                            Dim strNewName As String = RenameDlg.TXB_NewName.Text
                            Dim strOldName As String = RenameDlg.LBL_OldName.Text
                            strOldName = strOldName.Substring(strOldName.LastIndexOf("\") + 1)
                            If bIsFile Then
                                iResult = CONARenameFile(hFS, strOldName, strNewName, strPhoneFolder)
                            Else
                                iResult = CONARenameFolder(hFS, strOldName, strNewName, strPhoneFolder)
                            End If
                            If iResult = CONA_OK Then
                                ' show updated folder listing
                                LBX_PhoneFiles.ShowPhoneFolder(strPhoneFolder)
                                MsgBox("Rename completed succesfully!")
                            Else
                                If bIsFile Then
                                    ShowErrorMessage("FileBrowser::BTN_Rename_Click(): CONARenameFile failed!", iResult)
                                Else
                                    ShowErrorMessage("FileBrowser::BTN_Rename_Click(): CONARenameFolder failed!", iResult)
                                End If
                            End If
                        Else
                            ShowErrorMessage("FileBrowser::BTN_Rename_Click(): CONAGetCurrentFolder failed!", iResult)
                        End If
                    End If
                    iResult = CONACloseFS(hFS)
                    If iResult <> CONA_OK Then
                        ShowErrorMessage("FileBrowser::BTN_Rename_Click(): CONACloseFS failed!", iResult)
                    End If
                End If
            Else
                MsgBox("No phone renaming")
            End If
        Else
            MsgBox("Please select file/folder to be renamed.")
        End If
    End Sub


    '===================================================================
    ' BTN_Delete_Click
    '
    ' Deletes selected phone file/folder
    '===================================================================
    Private Sub BTN_Delete_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles BTN_Delete.Click
        Dim pListener As FileOperationListener

        If LBX_PhoneFiles.GetState() = PHONELIST_STATE_PHONECONTENT Then
            Dim strMessage As String
            Dim hFS As Integer
            Dim iMedia As Integer = API_MEDIA_ALL
            Dim iDeviceID As Integer
            Dim iResult As Integer = CONAOpenFS(LBX_PhoneFiles.GetCurrentSN(), iMedia, hFS, iDeviceID)
            If iResult = CONA_OK Then
                Dim strSelectedtxt As String = ""
                Dim cursel As Integer = LBX_PhoneFiles.SelectedIndex
                If cursel <> -1 Then
                    strSelectedtxt = LBX_PhoneFiles.Items(cursel).ToString()
                End If
                Dim strSelectedFile As String = LBX_PhoneFiles.GetCurrentFile()
                If Len(strSelectedFile) > 0 Then
                    Dim strPhoneFile As String = LBX_PhoneFiles.GetCurrentFile()
                    Dim strPhoneFolder As String = LBX_PhoneFiles.GetSelectedFolder()
                    strMessage = "Are you sure you want to permanently delete file '"
                    strMessage &= strPhoneFile & "' from folder '" & strPhoneFolder & "'?"
                    If MsgBox(strMessage, MsgBoxStyle.YesNo) = MsgBoxResult.Yes Then
                        pListener = New FileOperationListener
                        pListener.StartListening(Me.Handle, hFS, "Deleting", strPhoneFolder + "\" + strPhoneFile, "")
                        iResult = CONADeleteFile(hFS, strPhoneFile, strPhoneFolder)
                        pListener.StopListening()
                        If iResult = CONA_OK Then
                            MsgBox("Delete file completed succesfully!")
                        ElseIf iResult = ECONA_CANCELLED Then
                            MsgBox("Delete file was cancelled.")
                        Else
                            ShowErrorMessage("FileBrowser::BTN_Delete_Click(): CONADeleteFile failed!", iResult)
                        End If
                        ' show updated folder listing
                        LBX_PhoneFiles.ShowPhoneFolder(strPhoneFolder)
                    End If
                ElseIf Len(strSelectedtxt) > 0 And strSelectedtxt <> "[..]" Then
                    Dim strPhoneFolder As String
                    strPhoneFolder = LBX_PhoneFiles.GetSelectedFolder()
                    Dim iLastSeparator As Integer = strPhoneFolder.LastIndexOf("\")
                    strPhoneFolder = strPhoneFolder.Remove(iLastSeparator, strPhoneFolder.Length - iLastSeparator)
                    Dim strFolder As String = LBX_PhoneFiles.GetItemData(LBX_PhoneFiles.SelectedIndex)
                    strMessage = "Are you sure you want to permanently delete folder '"
                    strMessage &= strFolder & "' from folder '" & strPhoneFolder & "'?"
                    If MsgBox(strMessage, MsgBoxStyle.YesNo) = MsgBoxResult.Yes Then
                        pListener = New FileOperationListener
                        pListener.StartListening(Me.Handle, hFS, "Deleting", strPhoneFolder + "\" + strFolder, "")
                        iResult = CONADeleteFolder(hFS, strFolder, CONA_DELETE_FOLDER_WITH_FILES, strPhoneFolder)
                        pListener.StopListening()
                        If iResult = CONA_OK Then
                            MsgBox("Delete folder completed succesfully!")
                        ElseIf iResult = ECONA_CANCELLED Then
                            MsgBox("Delete folder was cancelled.")
                        Else
                            ShowErrorMessage("FileBrowser::BTN_Delete_Click(): CONADeleteFolder failed!", iResult)
                        End If
                        ' show updated folder listing
                        LBX_PhoneFiles.ShowPhoneFolder(strPhoneFolder)
                    End If
                Else
                    MsgBox("Select file/folder to be deleted.")
                End If
                iResult = CONACloseFS(hFS)
                If iResult <> CONA_OK Then
                    ShowErrorMessage("FileBrowser::BTN_Delete_Click(): CONACloseFS failed!", iResult)
                End If
            Else
                ShowErrorMessage("FileBrowser::BTN_Delete_Click(): CONAOpenFS failed!", iResult)
            End If
        Else
            ' state is phonelist
            MsgBox("Please select phone file/folder to be deleted.")
        End If
    End Sub

    '===================================================================
    ' BTN_Cancel_Click
    '

⌨️ 快捷键说明

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