SuperDesign/Source/RySmartEditor/SmartEditor/FrmFileBrowser_New.cs
zilinsoft c000c7ef1b ### 2025-01-08 星期三更新
------
#### RySmartEditor    V1.0.2501.0801
- *.[改进]复制文件到其它站点同位置功能支持复制文件夹。
#### SuperDesign    V3.0.2501.0801
- *.[新增]支持直接设置主项目的功能。
- *.[新增]新增支持设置在发布日志时是否更新版本号的功能。
- *.[新增]更新日志右键菜单支持快速添加日志前缀。
- *.[改进]更新日志保存时如果冲突,则显示数据库和本地日志内容进行对比。
- *.[修复]修复更新日志输入框粘贴文本会携带颜色的字体的BUG。
- *.[修复]修复打开Git时无法粘贴更新日志的BUG。
2025-01-08 16:55:25 +08:00

1293 lines
54 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using BrightIdeasSoftware;
using ObjectListViewDemo;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using ryCommon;
using System.Collections;
using System.Drawing.Drawing2D;
using WeifenLuo.WinFormsUI.Docking;
using .Tools.SmartEditor;
using .Manager;
using Newtonsoft.Json.Linq;
using System.Diagnostics;
using .Manager.FTP;
using ryCommonDb;
using ryControls;
using WinSCP;
using RySmartEditor.Controls;
using System.Reflection;
using static System.Windows.Forms.VisualStyles.VisualStyleElement.TextBox;
using ScintillaNET;
using WinShell;
using static System.Net.Mime.MediaTypeNames;
using System.Runtime.InteropServices.ComTypes;
using System.Threading;
namespace SuperDesign.Tools.SmartEditor
{
public partial class FrmFileBrowser_New : DockContent
{
public FrmFileBrowser_New()
{
InitializeComponent();
SetupColumns();
SetupList();
SetupDragAndDrop();
//olvFiles.FullRowSelect = false;
helper_tree = new SysImageListHelper(this.TreeDir);
olvFiles.CellEditActivation = ObjectListView.CellEditActivateMode.SingleClick;
TreeDir.AfterSelect += TreeDir_AfterSelect;
procUse = true;
CbbMatch.SelectedIndex = 0;
procUse = false;
}
private void TreeDir_AfterSelect(object sender, TreeViewEventArgs e)
{
var info = (MyFileSystemInfo)e.Node.Tag;
this.textBoxFolderPath.Text= info.FullName;
PopulateListFromPath(info.FullName);
if (e.Node.Nodes.Count == 0) { LoadDir(e.Node,1); }
}
SysImageListHelper helper_tree;
private void LoadDir(TreeNode parent,int index)
{
if (parent == null)
{
var drives = DriveInfo.GetDrives();
foreach (var drive in drives)
{
if (!drive.IsReady) { continue; }
MyFileSystemInfo info = new MyFileSystemInfo(drive.RootDirectory, "");
var node = new TreeNode(drive.Name.Trim('\\') + " " + drive.VolumeLabel)
{
ImageIndex = helper_tree.GetImageIndex(drive.Name)
};
node.SelectedImageIndex = node.ImageIndex;
node.Tag = info;
TreeDir.Nodes.Add(node);
if(index<1 && (drive.DriveFormat=="NTFS" || drive.DriveFormat == "FAT32"))
{
LoadDir(node,0);
}
}
}
else
{
var parent_info = (MyFileSystemInfo)parent.Tag;
try
{
var list = parent_info.AsDirectory.GetDirectories();
for (int i = 0; i < list.Length; i++)
{
MyFileSystemInfo info = new MyFileSystemInfo(list[i], "");
var node = new TreeNode(list[i].Name)
{
ImageIndex = helper_tree.GetImageIndex(list[i].FullName)
};
node.SelectedImageIndex = node.ImageIndex;
node.Tag = info;
parent.Nodes.Add(node);
if (index < 1)
{
LoadDir(node, 1);
}
}
}
catch(Exception ex)
{
if(index==0)
MessageBox.Show(ex.Message, "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning);
olvFiles.ClearObjects();
olvColumnName.Text = "文件名(" + olvFiles.GetItemCount() + ")";
}
}
}
private void SetupDragAndDrop()
{
// Drag and drop support
// Indicate that the OLV can be used to drag items out.
// You can write this code, or you can set IsSimpleDropSource to true (in the Designer).
this.olvFiles.DragSource = new SimpleDragSource();
// Indicate that the OLV can be accept items being dropped on it.
// These items could come from an ObjectListView or from some other control (or even
// from another application).
// If the drag source is an ObjectListView, you can listen for ModelCanDrop and
// ModelDropped events, which have some extra properties to make your life easier.
// If the drag source is not an ObjectListView, you have to listen for CanDrop and
// Dropped events, and figure out everything for yourself.
SimpleDropSink dropSink = new SimpleDropSink();
dropSink.CanDropOnItem = true;
//dropSink.CanDropOnSubItem = true;
dropSink.FeedbackColor = Color.IndianRed; // just to be different
this.olvFiles.DropSink = dropSink;
// For our purpose here, we will make it that if you drop one or more person
// onto someone, they all become married.
dropSink.ModelCanDrop += delegate (object sender, ModelDropEventArgs e) {
MyFileSystemInfo file = e.TargetModel as MyFileSystemInfo;
if (file == null)
e.Effect = DragDropEffects.None;
else
{
if (!file.IsDirectory)
{
e.Effect = DragDropEffects.None;
e.InfoMessage = "不能拖放到文件";
}
else
e.Effect = DragDropEffects.Link;
}
};
dropSink.ModelDropped += delegate (object sender, ModelDropEventArgs e) {
if (e.TargetModel == null)
return;
var item = (MyFileSystemInfo)e.TargetModel;
var from_list= e.SourceModels;
var del_list = new List<MyFileSystemInfo>();
for (int i = 0; i < from_list.Count; i++)
{
var from_item = (MyFileSystemInfo)from_list[i];
if (ryCommon.RyFiles.MoveFile(from_item.FullName, item.FullName) == 0)
{
del_list.Add(from_item);
}
else
{
MessageBox.Show("移动失败=>"+from_item.FullName, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
olvFiles.RemoveObjects(del_list);
};
}
private void SetupColumns()
{
// The column setup here is identical to the File Explorer example tab --
// nothing specific to the TreeListView.
// The only difference is that we don't setup anything to do with grouping,
// since TreeListViews can't show groups.
// Get the size of the file system entity.
// Folders and errors are represented as negative numbers
this.olvColumnSize.AspectGetter = delegate (object x) {
MyFileSystemInfo myFileSystemInfo = (MyFileSystemInfo)x;
return myFileSystemInfo.Length;
};
// Show the size of files as GB, MB and KBs. By returning the actual
// size in the AspectGetter, and doing the conversion in the
// AspectToStringConverter, sorting on this column will work off the
// actual sizes, rather than the formatted string.
this.olvColumnSize.AspectToStringConverter = delegate (object rowdata, object x) {
long sizeInBytes = (long)x;
if (sizeInBytes < 0) // folder or error
return "";
return RyFiles.GetFileSizeStr(sizeInBytes);
};
this.olvColumnCreated.GroupKeyGetter = delegate (object x) {
DateTime dt = ((MyFileSystemInfo)x).CreationTime;
return new DateTime(dt.Year, dt.Month, 1);
};
this.olvColumnCreated.GroupKeyToTitleConverter = delegate (object x) {
return ((DateTime)x).ToString("MMMM yyyy");
};
// Group by month-year, rather than date
this.olvColumnModified.GroupKeyGetter = delegate (object x) {
DateTime dt = ((MyFileSystemInfo)x).LastWriteTime;
return new DateTime(dt.Year, dt.Month, 1);
};
this.olvColumnModified.GroupKeyToTitleConverter = delegate (object x) {
return ((DateTime)x).ToString("MMMM yyyy");
};
// Show the system description for this object
this.olvColumnFileType.AspectGetter = delegate (object x) {
return ShellUtilities.GetFileType(((MyFileSystemInfo)x).FullName);
};
}
private void SetupList() {
// We want to draw the system icon against each file name. SysImageListHelper does this work for us.
SysImageListHelper helper = new SysImageListHelper(this.olvFiles);
this.olvColumnName.ImageGetter = delegate (object x) { return helper.GetImageIndex(((MyFileSystemInfo)x).FullName); };
// Show tooltips when the appropriate checkbox is clicked
this.olvFiles.ShowItemToolTips = true;
this.olvFiles.CellToolTipShowing += delegate (object sender, ToolTipShowingEventArgs e) {
//if (this.showToolTipsOnFiles)
var row = (MyFileSystemInfo)e.Model;
e.Text = String.Format("文件名:{0}\r\n修改时间:{1}\r\n创建时间:{2}\r\n大小:{3}\r\n类型:{4}", row.Name, row.LastWriteTime.ToString(), row.CreationTime.ToString(), RyFiles.GetFileSizeStr(row.Length), ShellUtilities.GetFileType(row.FullName));
};
// Show a menu -- but only when the user right clicks on the first column
this.olvFiles.CellRightClick += delegate (object sender, CellRightClickEventArgs e) {
System.Diagnostics.Trace.WriteLine(String.Format("right clicked {0}, {1}). model {2}", e.RowIndex, e.ColumnIndex, e.Model));
// if (e.ColumnIndex == 0)
// e.MenuStrip = this.contextMenuStrip2;
};
}
private bool CopyMode { get; set; } = true;
private readonly ArrayList copy_or_cut_list = new ArrayList();
private void FrmFileBrowser_Load(object sender, EventArgs e)
{
}
private void FrmFileBrowser_FormClosing(object sender, FormClosingEventArgs e)
{
//drag.ElevatedDragDrop -= Drag_ElevatedDragDrop;
}
private void ToolStripMenuItem1_Click(object sender, EventArgs e)
{
FrmTitle frm = new FrmTitle();
frm.TxtTitle.Text = Text;
frm.Text = "请输入重命名的文件浏览器名称";
if (frm.ShowDialog() == DialogResult.OK)
{
Text = frm.TxtTitle.Text;
}
frm.Dispose();
}
public string CurFolderPath { get; set; } = "";
/// <summary>
/// 将当前路径的内容加载到列表里
/// </summary>
/// <param name="path"></param>
private void PopulateListFromPath(string path) {
if (String.IsNullOrEmpty(path))
return;
CurFolderPath = path;
if (MenuDirHistory.Items.Count > 10)
{
MenuDirHistory.Items.RemoveAt(MenuDirHistory.Items.Count - 1);
}
olvFiles.SelectedObjects=null;
ToolStripMenuItem item_menu = new ToolStripMenuItem();
item_menu.Text = path;
item_menu.Click += Item_menu_Click;
MenuDirHistory.Items.Insert(0, item_menu);
DirectoryInfo pathInfo = new DirectoryInfo(path);
if (!pathInfo.Exists)
{
olvFiles.ClearObjects();
olvColumnName.Text = "文件名(" + olvFiles.GetItemCount() + ")";
return;
}
Stopwatch sw = new Stopwatch();
Cursor.Current = Cursors.WaitCursor;
sw.Start();
try
{
var folder_list = pathInfo.GetDirectories();
var file_list = pathInfo.GetFiles();
List<MyFileSystemInfo> list = new List<MyFileSystemInfo>();
foreach (var x in folder_list)
{
list.Add(new MyFileSystemInfo(x, ""));
}
foreach (var x in file_list)
{
list.Add(new MyFileSystemInfo(x, ""));
}
this.olvFiles.SetObjects(list);
olvColumnName.Text = "文件名("+olvFiles.GetItemCount()+")";
fileSystemWatcher1.Path = CurFolderPath;
}
catch { }
sw.Stop();
Cursor.Current = Cursors.Default;
}
/// <summary>
/// 初始化加载的路径
/// </summary>
public string InitPath { get; set; } = "";
/// <summary>
/// 初始化选择的路径
/// </summary>
public string Init_Selected_Path { get; set; } = "";
public void GotoPath(string folder, string selected_path) {
if (TreeDir.Nodes.Count == 0)
{
LoadDir(null, 0);
}
if (folder.Length == 0)
{ olvFiles.ClearObjects();textBoxFolderPath.Text = ""; olvColumnName.Text = "文件名(" + olvFiles.GetItemCount() + ")"; return; }
this.textBoxFolderPath.Text=folder;
GotoTreePath(folder);
SelectedPath(selected_path);
}
private void SelectedPath(string selected_path)
{
var list = olvFiles.ObjectsList;
for (int i = 0; i < list.Count; i++)
{
var item = (MyFileSystemInfo)list[i];
if (item.FullName.ToLower() == selected_path.ToLower())
{
olvFiles.SelectedObject = item;
olvFiles.EnsureModelVisible(item);
break;
}
}
}
private void BtnGo_Click(object sender, EventArgs e) {
string path = this.textBoxFolderPath.Text;
this.PopulateListFromPath(path);
GotoTreePath(path);
}
public void GotoTreePath(string path)
{
var split_path = path.Split('\\');
TreeNode parent = null;
for (int i = 0; i < split_path.Length; i++)
{
var path_item = split_path[i].ToLower();
if(parent!=null)
{
if(parent.Nodes.Count==0)
{
LoadDir(parent,1);
}
}
foreach (TreeNode item in (parent==null?TreeDir.Nodes: parent.Nodes))
{
var info = (MyFileSystemInfo)item.Tag;
if (info.Name.Trim('\\').ToLower() == path_item)
{
parent = item;
break;
}
}
}
if(parent!=null)
{
if (parent.Nodes.Count == 0)
{
LoadDir(parent, 1);
}
TreeDir.SelectedNode = parent;
//TreeDir.en
}
}
private void Item_menu_Click(object sender, EventArgs e)
{
textBoxFolderPath.Text = ((ToolStripMenuItem)sender).Text;
BtnGo.PerformClick();
}
private void BtnUp_Click(object sender, EventArgs e) {
DirectoryInfo di = Directory.GetParent(this.textBoxFolderPath.Text);
if (di == null)
System.Media.SystemSounds.Asterisk.Play();
else {
this.textBoxFolderPath.Text = di.FullName;
this.BtnGo.PerformClick();
}
}
private void OlvFiles_MouseDoubleClick(object sender, MouseEventArgs e) {
ClickFiles();
}
private void ClickFiles()
{
MyFileSystemInfo model = (MyFileSystemInfo)this.olvFiles.SelectedObject;
if (model != null)
{
if (System.IO.Directory.Exists(model.FullName))
{
this.textBoxFolderPath.Text = model.FullName;
this.BtnGo.PerformClick();
return;
}
var ext = System.IO.Path.GetExtension(model.FullName).ToLower();
if ((";.rar;.zip;.7z;.iso;.tar;.tgz;.gzip;.apk;" +
".jpg;.bmp;.gif;.png;.webp;.jpeg;.tif;.tiff;.ico;.wmf;" +
".mp4;.mkv;.rmvb;.flv;.3gp;.wmv;.f4v;.mpg;.mpeg;.mov;" +
".mp3;.wav;.flac;.ogg;.wma;" +
".xls;.xlsx;.doc;.docx;.ppt;.pptx;.csv;" +
".exe;.msi;.jar;.msixbundle;").IndexOfEx(";" + ext + ";") >= 0)
{
RyFiles.OpenFile(model.FullName);
return;
}
if (RyFiles.GetFileSize(model.FullName) >= 1024 * 1024 * 20)
{
MessageBox.Show("不支持打开超过20M的文本。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
return;
}
FrmMainEditor.MainEditor.OpenFile(model.FullName, false, false);
}
}
private void TextBoxFolderPath_KeyDown(object sender, KeyEventArgs e) {
if(e.KeyCode==Keys.Enter) {
BtnGo.PerformClick();
}
}
private void textBoxFolderPath_MouseDoubleClick(object sender, MouseEventArgs e) {
folderBrowserDialog1.SelectedPath= textBoxFolderPath.Text;
if (folderBrowserDialog1.ShowDialog()==DialogResult.OK) {
textBoxFolderPath.Text = folderBrowserDialog1.SelectedPath;
BtnGo.PerformClick();
}
}
private void ToolStripMenuItem_Click(object sender, EventArgs e) {
MyFileSystemInfo model = (MyFileSystemInfo)this.olvFiles.SelectedObject;
if (model != null) {
if (System.IO.Directory.Exists(model.FullName)) {
RyFiles.OpenFile(model.FullName);
return;
}
RyFiles.OpenFolderGotoFile(model.FullName);
}
}
public void UpdateFileInfo(string path) {
for (int i = 0; i < olvFiles.ObjectsList.Count; i++) {
var item = (MyFileSystemInfo)olvFiles.ObjectsList[i];
if (item.FullName.ToLower() == path.ToLower()) {
item.ReLoad();
olvFiles.RefreshObject(item);
olvFiles.Sort();
}
}
}
private void FTPToolStripMenuItem_Click(object sender, EventArgs e) {
var list = this.olvFiles.SelectedObjects;
List<UploadInfo> UploadList = new List<UploadInfo>();
for (int l = 0; l < list.Count; l++)
{
MyFileSystemInfo model = (MyFileSystemInfo)list[l];
if (model != null)
{
//if (System.IO.Directory.Exists(model.FullName))
//{
// MessageBox.Show("暂不支持上传文件夹=>" + model.FullName, "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
// continue ;
//}
string FilePath = model.FullName;
SiteInfo SiteInfo = new SiteInfo();
UploadInfo uploadinfo = null;
IDbInterface db = Itrycn_Db.CreateDataProvider(Itrycn_Db.dataType);
if (db.ConnDb(Itrycn_Db.User_SQLConn) == 1)
{
DataSet ds = db.ReadData("select * from Site");
if (ds.HaveData())
{
for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
{
DataRow reader = ds.Tables[0].Rows[i];
if (FilePath.IndexOfEx(reader["localPath"].ToString()) < 0)
{
continue;
}
#region
SiteInfo.Name = reader["name"].ToString();
SiteInfo.LocalPath = reader["localPath"].ToString();
SiteInfo.FtpDir = reader["ftpDir"].ToString();
SiteInfo.FtpId = reader["ftpId"].ToInt();
SiteInfo.Id = reader["Id"].ToInt();
break;
#endregion
}
}
ds.Dispose();
ds = db.ReadData("select * from Ftp where Id=" + SiteInfo.FtpId);
if (ds.HaveData())
{
DataRow row = ds.Tables[0].Rows[0];
var FtpInfo = new GameBackup3H3.DbOp.FTPInfo()
{
Id = row["id"].ToInt(),
Name = row["name"].ToString(),
IP = row["ip"].ToString(),
Port = row["port"].ToInt(),
RemoteDir = SiteInfo.FtpDir,
UserName = row["username"].ToString(),
Pwd = row["pwd"].ToString(),
Encrypt = row["encrypt"].ToInt(0, 2, 0),
AddTime = row["AddTime"].ToDateTime()
};
uploadinfo = new UploadInfo()
{
FtpInfo = FtpInfo,
RemotePath = SiteInfo.FtpDir.Trim('/') + "/" + FilePath.Replace(SiteInfo.LocalPath, "", true).Trim('\\').Replace("\\", "/"),
LocalPath = FilePath
};
}
ds.Dispose();
}
db.Free();
if (SiteInfo.FtpId > 0)
{
if (uploadinfo == null) { MessageBox.Show("没有找到对应站点信息=>" + model.FullName, "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning); }
else
{
UploadList.Add(uploadinfo);
}
}
else
{
MessageBox.Show("没有找到对应FTP信息=>" + model.FullName, "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
}
}
if (UploadList.Count > 0)
{
FrmUploadProg frm = new FrmUploadProg();
frm.UploadList.AddRange(UploadList);
if (frm.ShowDialog() == DialogResult.OK)
{
//MessageBox.Show("上传成功。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
else
{
MessageBox.Show("上传失败。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
frm.Dispose();
}
}
private void ToolStripMenuItem_Click(object sender, EventArgs e)
{
var list = this.olvFiles.SelectedObjects;
if (list.Count>0)
{
var text = "";
for (int i = 0; i < list.Count; i++)
{
var row = (MyFileSystemInfo)list[i];
if (text.Length > 0) { text += "\r\n"; }
text += row.Name;
}
RyFiles.CopyToClip(text);
}
}
private void ToolStripMenuItem_Click(object sender, EventArgs e)
{
MyFileSystemInfo model = (MyFileSystemInfo)this.olvFiles.SelectedObject;
if (model == null) { return; }
FrmTitle frm = new FrmTitle();
frm.Text = "请输入重命名的名称";
frm.TxtTitle.Text = model.Name;
if (frm.ShowDialog() == DialogResult.OK)
{
//int num = arrayList2.IndexOf(model);
var new_fullname = System.IO.Path.GetDirectoryName(model.FullName) + "\\" + RyFiles.ConvertToValidFileName(frm.TxtTitle.Text);
if (RyFiles.MoveFile(model.FullName, new_fullname) == 0)
{
//treeListView.RemoveObject(model);
model.ReLoad(new_fullname);
model.Name = model.Name;
olvFiles.RefreshObject(model);
UpdateNode(TreeDir.SelectedNode);
}
else
{
MessageBox.Show("重命名失败", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
}
frm.Dispose();
}
private void ToolStripMenuItem_Click(object sender, EventArgs e)
{
var list = this.olvFiles.SelectedObjects;
if (list.Count > 0)
{
switch (MessageBox.Show("确定要删除选定的"+ list.Count + "个文件吗?这将不可恢复?", "询问", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2))
{
case DialogResult.No:
return;
}
//var del_list=new List<MyFileSystemInfo>();
for (int i = 0; i < list.Count; i++)
{
var row = (MyFileSystemInfo)list[i];
RyFiles.DeleteFile(row.FullName);
//del_list.Add(row);
}
UpdateNode(TreeDir.SelectedNode);
//olvFiles.RemoveObjects(del_list);
}
}
private void contextMenuStrip1_Opening(object sender, CancelEventArgs e)
{
var list = this.olvFiles.SelectedObjects;
ToolStripMenuItem.Enabled = list.Count > 0;
ToolStripMenuItem.Enabled = list.Count==1;
ToolStripMenuItem.Enabled = list.Count == 1;
ToolStripMenuItem.Enabled = list.Count > 0;
ToolStripMenuItem.Enabled = list.Count > 0;
ToolStripMenuItem.Enabled = list.Count > 0;
ToolStripMenuItem.Enabled = copy_or_cut_list.Count > 0;
try
{
ToolStripMenuItem.Enabled = Clipboard.GetFileDropList().Count > 0;
}
catch { }
}
private void UpdateNode(TreeNode node)
{
if(node == null) return;
var parent_info = (MyFileSystemInfo)node.Tag;
var dirs = parent_info.AsDirectory.GetDirectories();
Dictionary<string, int> dict = new Dictionary<string, int>();
Dictionary<string, int> dict_now = new Dictionary<string, int>();
for (int i = 0; i < dirs.Length; i++)
{
dict[dirs[i].FullName] = 1;
}
for (int i = node.Nodes.Count-1; i>=0; i--)
{
var info = node.Nodes[i].Tag as MyFileSystemInfo;
if(!dict.ContainsKey(info.FullName))
{
node.Nodes[i].Remove();
}
else
{
dict_now[info.FullName] = 1;
}
}
for (int i = 0; i < dirs.Length; i++)
{
if (!dict_now.ContainsKey(dirs[i].FullName))
{
MyFileSystemInfo info = new MyFileSystemInfo(dirs[i], "");
var node2 = new TreeNode(dirs[i].Name)
{
ImageIndex = helper_tree.GetImageIndex(dirs[i].FullName)
};
node2.SelectedImageIndex = node.ImageIndex;
node2.Tag = info;
node.Nodes.Add(node2);
}
}
}
private void ToolStripMenuItem_Click(object sender, EventArgs e)
{
FrmTitle frm = new FrmTitle();
frm.Text = "请输入重命名的名称";
frm.TxtTitle.Text = "新建文件夹";
if (frm.ShowDialog() == DialogResult.OK)
{
var path = CurFolderPath + "\\" + frm.TxtTitle.Text;
if (System.IO.Directory.Exists(path))
{
MessageBox.Show("文件夹已存在", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
else
{
RyFiles.CreateDirectory(path);
var node = TreeDir.SelectedNode;
if(node!=null)
{
var info = (MyFileSystemInfo)node.Tag;
if(info.FullName.ToLower()== CurFolderPath.ToLower())
{
UpdateNode(node);
}
}
}
}
frm.Dispose();
}
private void ToolStripMenuItem_Click(object sender, EventArgs e)
{
System.Collections.Specialized.StringCollection list = new System.Collections.Specialized.StringCollection();
for (int i = 0; i < this.olvFiles.SelectedObjects.Count; i++)
{
var row = (MyFileSystemInfo)this.olvFiles.SelectedObjects[i];
list.Add(row.FullName);
}
DataObject data = new DataObject();
data.SetData("Preferred DropEffect", "COPY");
data.SetFileDropList(list);
Clipboard.SetDataObject(data);
}
private void ToolStripMenuItem_Click(object sender, EventArgs e)
{
var error = 0;
var item = (MyFileSystemInfo)olvFiles.SelectedObject;
var exist_mode = -1000;
for (int i = 0; i< copy_or_cut_list.Count;i++)
{
var row = (MyFileSystemInfo)copy_or_cut_list[i];
var to_name=CurFolderPath + "\\" + row.Name;
if(item!=null && item.IsDirectory)
{
to_name= item.FullName+ "\\" + row.Name;
}
if(!RyFiles.FileOrDirExist(to_name))
{
if (CopyMode)
{
if(RyFiles.CopyFileOrFolder(row.FullName, to_name) != 0) { error++; }
}
else
{
if(RyFiles.MoveFile(row.FullName, to_name)!=0) { error++; }
}
}
else
{
if (exist_mode == -1000)
{
switch (MessageBox.Show("文件已存在,需要如何处理?\r\n是替换文件\r\n否拷贝一份副本\r\n取消:忽略", "询问", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2, MessageBoxOptions.DefaultDesktopOnly))
{
case DialogResult.Cancel:
exist_mode = 0;
break;
case DialogResult.No:
exist_mode = -1;
break;
case DialogResult.Yes:
exist_mode = 1;
break;
}
}
if (exist_mode == 0)
{
error++;
}
else if (exist_mode == -1)
{
var index = 1;
while(true)
{
var path = System.IO.Path.GetDirectoryName(to_name) + System.IO.Path.GetFileNameWithoutExtension(to_name) + "_副本" + index + System.IO.Path.GetExtension(to_name);
if (!RyFiles.FileOrDirExist(path))
{
to_name = path;
break;
}
index++;
}
if (CopyMode)
{
if (RyFiles.CopyFileOrFolder(row.FullName, to_name) != 0) { error++; }
}
else
{
if (RyFiles.MoveFile(row.FullName, to_name) != 0) { error++; }
}
}
else if (exist_mode == 1)//替换文件
{
if (row.FullName != to_name)
{
if (CopyMode)
{
if (RyFiles.CopyFileOrFolder(row.FullName, to_name) != 0) { error++; }
}
else
{
if (RyFiles.MoveFile(row.FullName, to_name) != 0) { error++; }
}
}
}
}
}
if (item != null && item.IsDirectory)
{
olvFiles.RemoveObjects(copy_or_cut_list);
}
else
{
olvFiles.AddObjects(copy_or_cut_list);
}
UpdateNode(TreeDir.SelectedNode);
if (error>0)
{
MessageBox.Show("粘贴出现错误,总文件数"+copy_or_cut_list.Count+"项,共有" + error+"项错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
private void ToolStripMenuItem_Click(object sender, EventArgs e)
{
System.Collections.Specialized.StringCollection list = new System.Collections.Specialized.StringCollection();
for (int i = 0; i < this.olvFiles.SelectedObjects.Count; i++)
{
var row = (MyFileSystemInfo)this.olvFiles.SelectedObjects[i];
list.Add(row.FullName);
}
DataObject data = new DataObject();
data.SetData("Preferred DropEffect", "MOVE");
data.SetFileDropList(list);
Clipboard.SetDataObject(data);
}
private void OlvFiles_CellEditFinished(object sender, CellEditEventArgs e)
{
if(!e.Cancel)
{
var item = (MyFileSystemInfo)e.RowObject;
if(RyFiles.IsValidFileName(e.NewValue.ToString()))
{
var new_path = System.IO.Path.GetDirectoryName(item.FullName) + "\\" + e.NewValue.ToString();
if(RyFiles.MoveFile(item.FullName, new_path)==0)
{
item.ReLoad(new_path);
olvFiles.RefreshObject(item);
UpdateNode(TreeDir.SelectedNode);
}
}
}
}
private void ToolStripMenuItem_Click(object sender, EventArgs e)
{
if (TreeDir.SelectedNode == null) { return; }
TreeDir.SelectedNode.Nodes.Clear();
LoadDir(TreeDir.SelectedNode, 0);
}
private void FrmFileBrowser_New_Shown(object sender, EventArgs e)
{
if(TreeDir.Nodes.Count==0)
{
LoadDir(null, 0);
}
}
private void TreeDir_MouseDown(object sender, MouseEventArgs e)
{
if(e.Button== MouseButtons.Right)
{
var node= TreeDir.GetNodeAt(e.Location);
if (node != null) { TreeDir.SelectedNode = node; }
}
}
private void ToolStripMenuItem_Click(object sender, EventArgs e)
{
if (TreeDir.SelectedNode == null) { return; }
var info = (MyFileSystemInfo)TreeDir.SelectedNode.Tag;
RyFiles.OpenFile(info.FullName);
}
private void ToolStripMenuItem_Click(object sender, EventArgs e)
{
if (TreeDir.SelectedNode == null) { return; }
var info = (MyFileSystemInfo)TreeDir.SelectedNode.Tag;
using (CShellFolder sf = new CShellFolder())
{
sf.ShowMenu(info.FullName, MousePosition, Handle);
UpdateNode(TreeDir.SelectedNode);
}
}
readonly bool procUse = false;
private void TxtSearch_TextChanged2(object sender, EventArgs e)
{
TimedFilter(this.olvFiles, ((ryControls.TextBoxEx2)sender).Text, this.CbbMatch.SelectedIndex);
}
public void TimedFilter(BrightIdeasSoftware.ObjectListView olv, string txt, int matchKind)
{
BrightIdeasSoftware.TextMatchFilter filter = null;
if (!String.IsNullOrEmpty(txt))
{
switch (matchKind)
{
case 0:
default:
filter = BrightIdeasSoftware.TextMatchFilter.Contains(olv, txt);
break;
case 1:
filter = BrightIdeasSoftware.TextMatchFilter.Prefix(olv, txt);
break;
case 2:
filter = BrightIdeasSoftware.TextMatchFilter.Regex(olv, txt);
break;
}
}
// Text highlighting requires at least a default renderer
if (olv.DefaultRenderer == null)
olv.DefaultRenderer = new BrightIdeasSoftware.HighlightTextRenderer(filter);
Stopwatch stopWatch = new Stopwatch();
stopWatch.Start();
olv.AdditionalFilter = filter;
//olv.Invalidate();
stopWatch.Stop();
}
private void CbbMatch_SelectedIndexChanged(object sender, EventArgs e)
{
if (procUse) { return; }
TimedFilter(this.olvFiles, TxtSearch.Text, this.CbbMatch.SelectedIndex);
}
private void BtnGo_MouseDown(object sender, MouseEventArgs e)
{
if(e.Button == MouseButtons.Right) {
Button btn = (Button)sender;
Point p = new Point(0, btn.Height);
MenuDirHistory.Show(btn, p);
}
}
private void ToolStripMenuItem_Click(object sender, EventArgs e)
{
var data = Clipboard.GetDataObject();
if (data.GetDataPresent(DataFormats.FileDrop, true))
{
var isCut = false;
try
{
MemoryStream vMemoryStream = (MemoryStream)data.GetData( "Preferred DropEffect", true);
if (vMemoryStream != null)
{
DragDropEffects vDragDropEffects = (DragDropEffects)vMemoryStream.ReadByte();
if ((vDragDropEffects & DragDropEffects.Move) == DragDropEffects.Move)
{
isCut = true;
}
}
}
catch { }
string[] files = (string[])data.GetData(DataFormats.FileDrop);
if (files.Length > 0)
{
var error = 0;
var exist_mode = -1000;
for (int i = 0; i < files.Length; i++)
{
var to_name = CurFolderPath + "\\" + System.IO.Path.GetFileName(files[i]);
var isDir = System.IO.Directory.Exists(files[i]);
if (isDir)
{
if (RyFiles.FileOrDirExist(to_name))
{
if (to_name == files[i])
{
to_name = GetNewPath(files[i]);
}
else
{
if (exist_mode == -1000)
{
switch (MessageBox.Show("文件已存在,需要如何处理?\r\n是替换文件\r\n否拷贝一份副本\r\n取消:忽略", "询问", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2, MessageBoxOptions.DefaultDesktopOnly))
{
case DialogResult.Cancel:
exist_mode = 0;
break;
case DialogResult.No:
exist_mode = -1;
break;
case DialogResult.Yes:
exist_mode = 1;
break;
}
}
if (exist_mode == 0)
{
error++;
}
else if (exist_mode ==-1)
{
to_name = GetNewPath(files[i]);
}
else if (exist_mode == 1)//替换文件
{
}
}
}
}
else
{
if (RyFiles.FileOrDirExist(to_name))
{
if (to_name == files[i])
{
to_name = GetNewPath(files[i]);
}
else
{
if (exist_mode == -1000)
{
switch (MessageBox.Show("文件已存在,需要如何处理?\r\n是替换文件\r\n否拷贝一份副本\r\n取消:忽略", "询问", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2, MessageBoxOptions.DefaultDesktopOnly))
{
case DialogResult.Cancel:
exist_mode = 0;
break;
case DialogResult.No:
exist_mode = -1;
break;
case DialogResult.Yes:
exist_mode = 1;
break;
}
}
if (exist_mode == 0)
{
error++;
}
else if (exist_mode == -1)
{
to_name = GetNewPath(files[i]);
}
else if (exist_mode == 1)//替换文件
{
}
}
}
}
string GetNewPath(string fromPath)
{
var filename = System.IO.Path.GetFileNameWithoutExtension(fromPath);
var ext = System.IO.Path.GetExtension(fromPath);
string path;
var index = 1;
while (true)
{
path = CurFolderPath + "\\" + filename + "_副本" + index + ext;
if (RyFiles.FileOrDirExist(path))
{
index++;
}
else { break; }
}
return path;
}
if (isCut)//表示移动文件
{
if (files[i] != to_name)
{
if (RyFiles.MoveFile(files[i], to_name) != 0) { error++; }
}
}
else
{
if (RyFiles.CopyFileOrFolder(files[i], to_name) != 0) { error++; }
else
{
if(!System.IO.Directory.Exists(to_name) && System.IO.Directory.Exists(files[i]))
{
RyFiles.CreateDirectory(to_name);
}
}
}
}
if (error > 0)
{
MessageBox.Show("粘贴出现错误,总文件数" + files.Length + "项,共有" + error + "项错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
//BtnGo.PerformClick();
}
if(isCut)
{
Clipboard.Clear();
}
}
}
private void FileSystemWatcher1_Created(object sender, FileSystemEventArgs e)
{
if (System.IO.File.Exists(e.FullPath))
{
olvFiles.AddObject(new MyFileSystemInfo(new FileInfo(e.FullPath), ""));
}
else if (System.IO.Directory.Exists(e.FullPath))
{
olvFiles.AddObject(new MyFileSystemInfo(new DirectoryInfo(e.FullPath), ""));
}
olvColumnName.Text = "文件名(" + olvFiles.GetItemCount() + ")";
}
private void FileSystemWatcher1_Deleted(object sender, FileSystemEventArgs e)
{
var list = olvFiles.ObjectsList;
for (int i = 0; i < list.Count; i++)
{
var row = (MyFileSystemInfo)list[i];
if(row.FullName==e.FullPath)
{
olvFiles.RemoveObject(row);
break;
}
}
olvColumnName.Text = "文件名(" + olvFiles.GetItemCount() + ")";
}
private void FileSystemWatcher1_Renamed(object sender, RenamedEventArgs e)
{
var list = olvFiles.ObjectsList;
for (int i = 0; i < list.Count; i++)
{
var row = (MyFileSystemInfo)list[i];
if (row.FullName == e.OldFullPath)
{
row.ReLoad(e.FullPath);
break;
}
}
}
private void FileSystemWatcher1_Changed(object sender, FileSystemEventArgs e)
{
if(e.ChangeType== WatcherChangeTypes.Changed)
{
var list = olvFiles.ObjectsList;
for (int i = 0; i < list.Count; i++)
{
var row = (MyFileSystemInfo)list[i];
if (row.FullName == e.FullPath)
{
row.ReLoad(e.FullPath);
break;
}
}
}
}
private void OlvFiles_KeyDown(object sender, KeyEventArgs e)
{
if(e.KeyCode==Keys.V && e.Control)
{
ToolStripMenuItem.PerformClick();
}
else if (e.KeyCode == Keys.C && e.Control)
{
ToolStripMenuItem.PerformClick();
}
else if (e.KeyCode == Keys.S && e.Control)
{
ToolStripMenuItem.PerformClick();
}
else if (e.KeyCode == Keys.Enter)
{
ClickFiles();
}
else if (e.KeyCode == Keys.Back)
{
var folder = CurFolderPath.ToLower();
olvFiles.Enabled = false;
BtnUp.PerformClick();
olvFiles.Enabled = true;
olvFiles.Focus();
var list = olvFiles.ObjectsList;
for (int i = 0; i < list.Count; i++)
{
var row = (MyFileSystemInfo)list[i];
if (row.FullName.ToLower() == folder)
{
olvFiles.SelectedObject = row;
break;
}
}
}
else if (e.KeyCode == Keys.Delete)
{
ToolStripMenuItem.PerformClick();
}
}
private void ToolStripMenuItem_Click(object sender, EventArgs e)
{
var list = this.olvFiles.SelectedObjects;
if (list.Count > 0)
{
switch (MessageBox.Show("确定要复制" + list.Count + "个文件到其它站点相同位置吗?如果目标文件已经存在,将覆盖文件,这将不可恢复?", "询问", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2))
{
case DialogResult.No:
return;
}
this.Enabled = false;
Thread th = new Thread(Start);
th.Start();
void Start()
{
IDbInterface db = Itrycn_Db.CreateDataProvider(Itrycn_Db.dataType);
if (db.ConnDb(Itrycn_Db.User_SQLConn) == 1)
{
DataSet ds = db.ReadData("select * from Site");
if (ds.HaveData())
{
for (int m = 0; m < list.Count; m++)
{
var row = (MyFileSystemInfo)list[m];
var xd_path = "";
var cur_Id = -1;
for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
{
DataRow reader = ds.Tables[0].Rows[i];
if (row.FullName.IndexOfEx(reader["localPath"].ToString()) < 0)
{
continue;
}
xd_path = row.FullName.Replace(reader["localPath"].ToString(), "", true).Trim('\\');
cur_Id = reader["id"].ToInt();
break;
}
if (cur_Id == -1)
{
MessageBox.Show("当前选定的文件无法获取站点信息。", "无法获取站点", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
else
{
for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
{
DataRow reader = ds.Tables[0].Rows[i];
if (cur_Id == reader["id"].ToInt()) { continue; }
if (RyFiles.FileOrDirExist(reader["localPath"].ToString() + "\\" + xd_path))
{
//如果已存在,则先进行备份
RyFiles.DeleteFile(reader["localPath"].ToString() + "\\" + xd_path, true);
}
if (RyFiles.CopyFileOrFolder(row.FullName, reader["localPath"].ToString() + "\\" + xd_path) != 0)
{
MessageBox.Show("复制到以下位置出错\r\n" + reader["localPath"].ToString() + "\\" + xd_path, "复制出错", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
}
}
}
}
ds?.Dispose();
}
db.Free();
this.Invoke(new Action(() =>
{
this.Enabled = true;
UpdateNode(TreeDir.SelectedNode);
}));
}
//olvFiles.RemoveObjects(del_list);
}
}
//private void FileSystemWatcher1_Created(object sender, FileSystemEventArgs e)
//{
// if(CurFolderPath.Length>0 && e.FullPath.IndexOfEx(CurFolderPath)>=0)
// {
// UpdateNode(TreeDir.SelectedNode);
// }
//}
}
}