private void lvwRemote_AfterLabelEdit(object sender, LabelEditEventArgs e) { if (e.CancelEdit) { return; } if (null == e.Label || 1 != lvwRemote.SelectedItems.Count || e.Item != lvwRemote.SelectedItems[0].Index || e.Label == lvwRemote.SelectedItems[0].Text) { e.CancelEdit = true; return; } List <char> l = new List <char>(Path.GetInvalidFileNameChars()); foreach (char c in e.Label) { if (l.Contains(c)) { e.CancelEdit = true; return; } } ListViewItem lvi = lvwRemote.SelectedItems[0]; BaiduPCSUtil.BaiduFileInfo bdfi = lvi.Tag as BaiduPCSUtil.BaiduFileInfo; if (null == bdfi) { e.CancelEdit = true; return; } if (!m_baidu.Rename(bdfi.m_path, e.Label)) { MessageBox.Show("重命名发生错误:" + m_baidu.LastErrorStr); } e.CancelEdit = true; lblStatus.Text = "所有操作已完成"; btnRemoteRefresh_Click(null, null); }
private void btnRemoteMkdir_Click(object sender, EventArgs e) { if (m_is_recycle_bin) { return; } string str_dir = Interaction.InputBox("请输入新文件夹的名称", "新文件夹名称", "新建文件夹"); if ("" == str_dir) { return; } List <char> l = new List <char>(Path.GetInvalidFileNameChars()); foreach (char c in str_dir) { if (l.Contains(c)) { MessageBox.Show("新文件夹包含非法字符!"); return; } } if (!m_baidu.IsLogin()) { return; } BaiduPCSUtil.BaiduFileInfo bdfi = new BaiduPCSUtil.BaiduFileInfo(); bool ret = m_baidu.MkDir(m_remote_current_path + "/" + str_dir, ref bdfi); if (!ret) { MessageBox.Show("创建文件夹失败:" + m_baidu.LastErrorStr); } lblStatus.Text = "所有操作已完成"; btnRemoteRefresh_Click(null, null); }
private void lvwRemote_MouseDoubleClick(object sender, MouseEventArgs e) { if (m_is_recycle_bin) { return; } if (1 != lvwRemote.SelectedItems.Count) { return; } ListViewItem lvi = lvwRemote.SelectedItems[0]; if (".." == lvi.Text) { if ("/" != m_remote_current_path) { string[] arr_path = m_remote_current_path.Split("/".ToCharArray(), StringSplitOptions.RemoveEmptyEntries); m_remote_current_path = "/" + string.Join("/", arr_path, 0, arr_path.Length - 1); } btnRemoteRefresh_Click(null, null); return; } BaiduPCSUtil.BaiduFileInfo bdfi = lvi.Tag as BaiduPCSUtil.BaiduFileInfo; if (null == bdfi) { return; } if (0 == bdfi.m_is_dir) { return; } m_remote_current_path = bdfi.m_path; btnRemoteRefresh_Click(null, null); }
private void btnDownload_Click(object sender, EventArgs e) { if ("" == m_local_current_path) { return; } if (lvwRemote.SelectedItems.Count <= 0) { return; } if (!m_baidu.IsLogin()) { return; } List <BaiduPCSUtil.BaiduFileInfo> lst_path = new List <BaiduPCSUtil.BaiduFileInfo>(); foreach (ListViewItem lvi in lvwRemote.SelectedItems) { BaiduPCSUtil.BaiduFileInfo bdfi = lvi.Tag as BaiduPCSUtil.BaiduFileInfo; if (null == bdfi) { continue; } lst_path.Add(bdfi); } int threads_max = 2; switch (cmbRemoteThreads.SelectedIndex) { case 1: threads_max = 1; break; case 2: threads_max = 10; break; default: break; } gbLocal.Enabled = false; gbRemote.Enabled = false; pbStatus.Visible = true; lblPause.Visible = true; lblStop.Visible = true; m_last_size = 0; m_last_time = DateTime.Now; long ticks = DateTime.Now.Ticks; bool ret = m_baidu.Download(m_remote_current_path, lst_path, m_local_current_path, threads_max); if (!ret) { MessageBox.Show("下载文件失败:" + m_baidu.LastErrorStr); } pbStatus.Visible = false; lblPause.Visible = false; lblStop.Visible = false; gbLocal.Enabled = true; gbRemote.Enabled = true; btnLocalRefresh_Click(null, null); lblStatus.Text = "所有操作已完成,耗时 " + (DateTime.Now.Ticks - ticks) / TimeSpan.TicksPerMillisecond + " 毫秒!"; }
private void btnRemoteDelete_Click(object sender, EventArgs e) { if ("" == m_remote_current_path) { return; } if (lvwRemote.SelectedItems.Count <= 0) { return; } if (lvwRemote.SelectedItems.Count > 1) { MessageBox.Show("为防止误操作,限制一次只能删除一个文件(夹)!"); return; } BaiduPCSUtil.BaiduFileInfo bdfi = lvwRemote.SelectedItems[0].Tag as BaiduPCSUtil.BaiduFileInfo; if (null == bdfi) { return; } //if (!m_baidu.IsLogin()) //{ // return; //} if (m_is_recycle_bin) { if (DialogResult.Yes != MessageBox.Show( "是否确认永久删除 " + bdfi.m_path + "?", "删除确认", MessageBoxButtons.YesNo, MessageBoxIcon.Stop, MessageBoxDefaultButton.Button2)) { return; } if (!m_baidu.Delete(bdfi)) { MessageBox.Show("删除文件失败:" + m_baidu.LastErrorStr); } btnRemoteRecycleBin_Click(null, null); GetQuotaInfo(); } else { if (DialogResult.Yes != MessageBox.Show( "是否确认把 " + bdfi.m_path + " 移到回收站?", "删除确认", MessageBoxButtons.YesNo, MessageBoxIcon.Stop, MessageBoxDefaultButton.Button2)) { return; } if (!m_baidu.Delete(bdfi.m_path)) { MessageBox.Show("删除文件失败:" + m_baidu.LastErrorStr); } btnRemoteRefresh_Click(null, null); } }