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

📄 filebrowser.cs

📁 以前做NOKIA手机与PC通信时所参考的源代码,里面包括两个程序,一个是手机文件夹浏览源码,另一个手机SIS安装程序.
💻 CS
📖 第 1 页 / 共 4 页
字号:
            this.Controls.Add(this.BTN_CopyPhoneToPC);
            this.Controls.Add(this.BTN_CopyPCToPhone);
            this.Controls.Add(this.LBX_PCFiles);
            this.Controls.Add(this.LBX_PhoneFiles);
            this.Controls.Add(this.ProgressBar1);
            this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
            this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
            this.MaximizeBox = false;
            this.MinimizeBox = false;
            this.Name = "FileBrowser";
            this.Text = "File Browser";
            this.Load += new System.EventHandler(this.FileBrowser_Load);
            this.ResumeLayout(false);
            this.PerformLayout();

        }

        #endregion

        [System.STAThread()]
        public static void Main()
        {
            // Starts the application.
            Application.Run(new FileBrowser());
        }

        //===================================================================
        // RefreshPhoneList
        //
        // Refresh phone list to list box
        //
        //===================================================================
        public void RefreshPhoneList()
        {
            if (LBX_PhoneFiles.GetState() == Common.PHONELIST_STATE_PHONELIST)
            {
                LBX_PhoneFiles.ListAllPhones();
            }
        }

        //===================================================================
        // StartProgress
        //
        // Sets progress bar visible and hides/unhides some buttons
        //
        //===================================================================
        public void StartProgress(string title, string line1, string line2)
        {
            Common.MainForm.LBX_PhoneFiles.ResetContent();
            Common.MainForm.LBX_PhoneFiles.Items.Add(title);
            Common.MainForm.LBX_PhoneFiles.Items.Add(line1);
            Common.MainForm.LBX_PhoneFiles.Items.Add(line2);
            Common.MainForm.Cursor = Cursors.WaitCursor;
            Common.MainForm.BTN_Create.Visible = false;
            Common.MainForm.BTN_Delete.Visible = false;
            Common.MainForm.BTN_Rename.Visible = false;
            Common.MainForm.BTN_Close.Visible = false;
            Common.MainForm.BTN_ItemInfo.Visible = false;
            Common.MainForm.checkBoxUseCache.Visible = false;
            Common.MainForm.BTN_Cancel.Visible = true;
            Common.MainForm.BTN_Cancel.Enabled = true;
            Common.MainForm.ProgressBar1.Minimum = 0;
            Common.MainForm.ProgressBar1.Maximum = 100;
            Common.MainForm.ProgressBar1.Value = 0;
            Common.MainForm.ProgressBar1.Visible = true;
        }

        //===================================================================
        // SetProgress
        //
        // Sets progress bar state
        //
        //===================================================================
        public void SetProgress(int iState)
        {
            ProgressBar1.Value = iState;
        }

        //===================================================================
        // StopProgress
        //
        // Hides progress bar and hides/unhides some buttons
        //
        //===================================================================
        public void StopProgress()
        {
            Common.MainForm.ProgressBar1.Visible = false;
            Common.MainForm.BTN_Create.Visible = true;
            Common.MainForm.BTN_Delete.Visible = true;
            Common.MainForm.BTN_Rename.Visible = true;
            Common.MainForm.BTN_Close.Visible = true;
            Common.MainForm.BTN_ItemInfo.Visible = true;
            Common.MainForm.checkBoxUseCache.Visible = true;
            Common.MainForm.BTN_Cancel.Visible = false;
            Common.MainForm.BTN_Cancel.Enabled = false;
            Common.MainForm.Cursor = Cursors.Default;
        }

        //===================================================================
        // SetCancelled
        //
        // Sets m_bCancelled value
        //
        //===================================================================
        public void SetCancelled(bool bCancelled)
        {
            m_bCancelled = bCancelled;
        }

        //===================================================================
        // IsCancelled
        //
        // Returns true if user has clicked Cancel button
        //
        //===================================================================
        public bool IsCancelled()
        {
            bool functionReturnValue = false;
            Application.DoEvents();
            functionReturnValue = m_bCancelled;
            m_bCancelled = false;
            return functionReturnValue;
        }

        //===================================================================
        // FileBrowser_Load
        //
        // Initialization of FileBrowser form
        //
        //===================================================================
        private void FileBrowser_Load(object sender, System.EventArgs e)
        {
            Common.MainForm = this;
            // Initializing PC file list:
            LBX_PCFiles.PopulateList("");
            LBL_PCFiles.Text = LBX_PCFiles.GetCurrentFolder();
            // Initializing phone file list:
            LBX_PhoneFiles.ListAllPhones();
            LBL_PhoneFiles.Text = LBX_PhoneFiles.GetCurrentFolder();

            Timer1.Enabled = true;
            Timer1.Start();
        }

        //===================================================================
        // BTN_CopyPCToPhone_Click
        //
        // Copies selected pc file to selected phone folder
        //===================================================================
        private void BTN_CopyPCToPhone_Click(object sender, System.EventArgs e)
        {
            FileOperationListener pListener;
            if (LBX_PCFiles.GetCurrentFile().Length <= 0)
            {
                MessageBox.Show("Please select PC file to be copied.");
            }
            else
            {
                int hFS=0;
                int iMedia = CONADefinitions.API_MEDIA_ALL;
                int iDeviceID=0;
                int iResult = CONAFileSystem.CONAOpenFS(LBX_PhoneFiles.GetCurrentSN(), ref iMedia, ref hFS, ref iDeviceID);
                if (iResult == PCCSErrors.CONA_OK)
                {
                    string strPCFile = LBX_PCFiles.GetCurrentFile();
                    // file name without path
                    string strPCFolder = LBX_PCFiles.GetCurrentFolder();
                    // e.g. 'c:\temp'
                    string strPhoneFolder = LBX_PhoneFiles.GetSelectedFolder();
                    if (strPhoneFolder.Length <= 0)
                    {
                        strPhoneFolder = LBX_PhoneFiles.GetCurrentFolder();
                    }
                    pListener = new FileOperationListener();
                    pListener.StartListening(this.Handle, hFS, "Copying", strPCFolder + "\\" + strPCFile, "-->" + strPhoneFolder);
                    iResult = CONAFileSystem.CONACopyFile(hFS, CONADefinitions.CONA_DIRECT_PC_TO_PHONE | CONADefinitions.CONA_RENAME, strPCFile, strPCFolder, strPhoneFolder);
                    pListener.StopListening();
                    if (iResult == PCCSErrors.CONA_OK)
                    {
                        MessageBox.Show("Copy completed succesfully!");
                    }
                    else if (iResult == PCCSErrors.ECONA_CANCELLED)
                    {
                        MessageBox.Show("Copy was cancelled.");
                    }
                    else
                    {
                        PCCAPIUtils.ShowErrorMessage("FileBrowser::BTN_CopyPCToPhone_Click(): CONACopyFile failed!", iResult);
                    }
                    // show updated folder listing
                    LBX_PhoneFiles.ShowPhoneFolder(strPhoneFolder);
                    iResult = CONAFileSystem.CONACloseFS(hFS);
                    if (iResult != PCCSErrors.CONA_OK)
                    {
                        PCCAPIUtils.ShowErrorMessage("FileBrowser::BTN_CopyPCToPhone_Click(): CONACloseFS failed!", iResult);
                    }
                }
                else
                {
                    PCCAPIUtils.ShowErrorMessage("FileBrowser::BTN_CopyPCToPhone_Click(): CONAOpenFS failed!", iResult);
                }
            }
        }

        //===================================================================
        // BTN_CopyPhoneToPC_Click
        //
        // Copies selected phone file to selected pc folder
        //===================================================================
        private void BTN_CopyPhoneToPC_Click(object sender, System.EventArgs e)
        {
            FileOperationListener pListener;
            string file = LBX_PhoneFiles.GetCurrentFile();
            if (file.Length <= 0)
            {
                MessageBox.Show("Please select phone file to be copied.");
            }
            else
            {
                int hFS=0;
                int iMedia = CONADefinitions.API_MEDIA_ALL;
                int iDeviceID=0;
                int iResult = CONAFileSystem.CONAOpenFS(LBX_PhoneFiles.GetCurrentSN(), ref iMedia, ref hFS, ref iDeviceID);
                if (iResult == PCCSErrors.CONA_OK)
                {
                    string strPhoneFile = LBX_PhoneFiles.GetCurrentFile();
                    string strPhoneFolder = LBX_PhoneFiles.GetSelectedFolder();
                    string strPCFolder = LBX_PCFiles.GetCurrentFolder();
                    pListener = new FileOperationListener();
                    pListener.StartListening(this.Handle, hFS, "Copying", strPhoneFolder + "\\" + strPhoneFile, "-->" + strPCFolder);
                    iResult = CONAFileSystem.CONACopyFile(hFS, CONADefinitions.CONA_DIRECT_PHONE_TO_PC | CONADefinitions.CONA_RENAME, strPhoneFile, strPhoneFolder, strPCFolder);
                    pListener.StopListening();
                    if (iResult == PCCSErrors.CONA_OK)
                    {
                        MessageBox.Show("Copy completed succesfully!");
                    }
                    else if (iResult == PCCSErrors.ECONA_CANCELLED)
                    {
                        MessageBox.Show("Copy was cancelled.");
                    }
                    else
                    {
                        PCCAPIUtils.ShowErrorMessage("FileBrowser::BTN_CopyPhoneToPC_Click(): CONACopyFile failed!", iResult);
                    }
                    // show updated folder listing
                    LBX_PCFiles.PopulateList("");
                    LBX_PhoneFiles.ShowPhoneFolder(strPhoneFolder);
                    iResult = CONAFileSystem.CONACloseFS(hFS);
                    if (iResult != PCCSErrors.CONA_OK)
                    {
                        PCCAPIUtils.ShowErrorMessage("FileBrowser::BTN_CopyPhoneToPC_Click(): CONACloseFS failed!", iResult);
                    }
                }
                else
                {
                    PCCAPIUtils.ShowErrorMessage("FileBrowser::BTN_CopyPhoneToPC_Click(): CONAOpenFS failed!", iResult);
                }
            }
        }

        //===================================================================
        // BTN_MovePCToPhone_Click
        //
        // Moves selected pc file to selected phone folder
        //===================================================================
        private void BTN_MovePCToPhone_Click(object sender, System.EventArgs e)
        {
            FileOperationListener pListener;
            if (LBX_PCFiles.GetCurrentFile().Length <= 0)
            {
                // No PC file selected
                MessageBox.Show("Please select PC file to be moved.");
            }
            else
            {
                int hFS=0;
                int iMedia = CONADefinitions.API_MEDIA_ALL;
                int iDeviceID=0;
                int iResult = CONAFileSystem.CONAOpenFS(LBX_PhoneFiles.GetCurrentSN(),ref iMedia, ref hFS, ref iDeviceID);
                if (iResult == PCCSErrors.CONA_OK)
                {
                    string strPCFile = LBX_PCFiles.GetCurrentFile();
                    // file name without path
                    string strPCFolder = LBX_PCFiles.GetCurrentFolder();
                    // e.g. 'c:\temp'
                    string strPhoneFolder = LBX_PhoneFiles.GetSelectedFolder();
                    if (strPhoneFolder.Length <= 0)
                    {

⌨️ 快捷键说明

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