📄 achieveoperation.cs
字号:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
using System.IO;
using System.Windows.Forms;
namespace Scanner
{
public partial class PrintFrom
{
public void openfile()
{
StringBuilder str = new StringBuilder();
if (rtbfile.Checked)
{
fileopendlg = new OpenFileDialog();
fileopendlg.Filter = "C++源文件(*.cpp,*.h)|*.cpp;*.h";
if (fileopendlg.ShowDialog() == DialogResult.OK)
{
path = fileopendlg.FileName;
txtpath.Text = path;
txttext.Text = fo.Read(path);
}
}
else if (rtbDirection.Checked)
{
directiondialog = new FolderBrowserDialog();
if (directiondialog.ShowDialog() == DialogResult.OK)
{
path = directiondialog.SelectedPath;
txtpath.Text = path;
DirectoryInfo dir = new DirectoryInfo(path);
FileInfo[] fi = dir.GetFiles();
if (fi.Length > 0)
{
str.Append("文件列表----------------------------------------");
str.Append("\r\n");
foreach (FileInfo f in fi)
{
if (f.Extension.CompareTo(".cpp") == 0 || f.Extension.CompareTo(".h") == 0)
{
try
{
str.Append("文件名:");
str.Append(f.Name.PadRight(25));
str.Append(" 文件大小:");
str.Append(f.Length);
str.Append("字节");
str.Append("\r\n");
}
catch (IOException ex)
{
throw ex;
}
}
}
txttext.Text = str.ToString();
}
else
{
str.Append("目录中不包含C++源文件,请重新选择文件目录");
txttext.Text = str.ToString();
}
}
}
else
{
str.Append("请选择浏览的是文件,还是目录复选框");
txttext.Text = str.ToString();
}
}
public void printsource()
{
if (Path != "" && path != null)
{
if (rtbfile.Checked)
{
PrintFile(Path);
}
if (rtbDirection.Checked)
{
DirectoryInfo dir = new DirectoryInfo(path);
FileInfo[] fi = dir.GetFiles();
if (fi.Length > 0)
{
StringBuilder str = new StringBuilder();
foreach (FileInfo f in fi)
{
PrintFile(f.FullName);
}
}
}
}
else
{
MessageBox.Show("请选择你打印的C++源文件或源文件所在的文件夹");
}
}
public void printspliter()
{
if (Path != "" && Path != null)
{
if (rtbfile.Checked)
{
string temp = Printsplit(Path);
txttext.Text = temp;
/*
savefiledlg = new SaveFileDialog();
savefiledlg.Title = "打印文件副本另存为";
savefiledlg.Filter = "文本文件(*.txt)|*.txt";
if (savefiledlg.ShowDialog() == DialogResult.OK)
{
fo.Write(temp, savefiledlg.FileName);
PrintFile(savefiledlg.FileName);
}
*/
}
if (rtbDirection.Checked)
{
StringBuilder content = new StringBuilder();
/*
directiondialog = new FolderBrowserDialog();
directiondialog.Description = "请选择文件列表标识符副本的储存目录";
if (directiondialog.ShowDialog() == DialogResult.OK)
{
string selectpath = directiondialog.SelectedPath;
*/
DirectoryInfo dir = new DirectoryInfo(Path);
FileInfo[] fi = dir.GetFiles();
if (fi.Length > 0)
{
foreach (FileInfo f in fi)
{
if (f.Extension.CompareTo(".cpp") == 0 || f.Extension.CompareTo(".h") == 0)
{
content.Append("文件:");
content.Append(f.FullName);
content.Append("\r\n");
content.Append("--------------------------------------------------------------");
content.Append("\r\n");
content.Append(Printsplit(f.FullName));
content.Append("\r\n");
content.Append("--------------------------------------------------------------");
content.Append("\r\n");
}
}
txttext.Text = content.ToString();
/*
fo.Write(content.ToString(), selectpath + "文件副本.txt");
Printsplit(selectpath + "文件副本.txt");
*/
}
/*
}
*/
}
}
else
{
MessageBox.Show("请选择你要打印的标识符C++源文件或源文件所在的文件夹");
}
}
public void deepcompress()
{
if (Path != "" && path != null)
{
if (rtbfile.Checked)
{
savefiledlg = new SaveFileDialog();
SaveDlgFilter(Path, ref savefiledlg, 0);
if (savefiledlg.ShowDialog() == DialogResult.OK)
{
fo.compress(Path, savefiledlg.FileName);
MessageBox.Show("文件压缩成功");
StringBuilder message = new StringBuilder();
message.Append("压缩文件已被保存到:");
message.Append(savefiledlg.FileName);
txttext.Text = message.ToString();
}
}
if (rtbDirection.Checked)
{
directiondialog = new FolderBrowserDialog();
directiondialog.Description = "请选择压缩文件列表的储存目录";
if (directiondialog.ShowDialog() == DialogResult.OK)
{
string selectpath = directiondialog.SelectedPath;
DirectoryInfo dir = new DirectoryInfo(Path);
FileInfo[] fi = dir.GetFiles();
if (fi.Length > 0)
{
StringBuilder str = new StringBuilder();
string strsource = "原文件路径";
string strDesc = "压缩文件路径";
string strcompressprecent = "压缩率(%)";
str.Append(strsource.PadRight(40));
str.Append(strDesc.PadRight(30));
str.Append(strcompressprecent);
str.Append("\r\n");
foreach (FileInfo f in fi)
{
if (f.Extension.CompareTo(".cpp") == 0 || f.Extension.CompareTo(".h") == 0)
{
StringBuilder sb = new StringBuilder();
sb.Append(selectpath);
sb.Append("\\");
sb.Append(f.Name);
string s = sb.ToString();
if (File.Exists(s))
{
if (MessageBox.Show("文件已存在,次操作会覆盖原来的文件,是否继续") == DialogResult.OK)
File.Delete(s);
else
continue;
}
str.Append(f.FullName.PadRight(40));
str.Append(s.PadRight(40));
int newsize = fo.compress(f.FullName, s);
int oldsize = (int)f.Length;
int compress = (oldsize - newsize) * 100 / oldsize;
str.Append(compress.ToString());
str.Append("\r\n");
}
}
txttext.Text = str.ToString();
MessageBox.Show("文件压缩成功");
StringBuilder message = new StringBuilder();
message.Append("压缩文件已被保存到:");
message.Append(selectpath);
txttext.Text = message.ToString();
}
}
}
}
else
{
MessageBox.Show("请选择你要压缩的C++源文件或源文件所在的文件夹");
}
}
public void simplecompress()
{
if (Path != "" && Path != null)
{
directiondialog = new FolderBrowserDialog();
directiondialog.Description = "请选择压缩文件列表的储存目录";
if (directiondialog.ShowDialog() == DialogResult.OK)
{
string selectpath = directiondialog.SelectedPath;
if (rtbfile.Checked)
{
fo.SingleHighCompress(Path, selectpath);
MessageBox.Show("文件压缩成功");
StringBuilder message = new StringBuilder();
message.Append("压缩文件已被保存到:");
message.Append(selectpath);
txttext.Text = message.ToString();
}
if (rtbDirection.Checked)
{
int size = fo.MultiHighCompress(Path, selectpath);
StringBuilder str = new StringBuilder();
str.Append("\r\n");
str.Append("压缩后上述文件列表总大小为:");
str.Append(size.ToString());
str.Append("字节");
txttext.Text += str.ToString();
MessageBox.Show("文件压缩成功");
StringBuilder message = new StringBuilder();
message.Append("压缩文件已被保存到:");
message.Append(selectpath);
txttext.Text = message.ToString();
}
}
}
else
{
MessageBox.Show("请选择你要压缩的C++源文件或源文件所在的文件夹");
}
}
public void btnprint()
{
listviewoperation.Dock = DockStyle.None;
btnprintoperation.Dock = DockStyle.Top;
btnsimplecompress.Dock = DockStyle.Bottom;
btndeepcompress.SendToBack();
btndeepcompress.Dock = DockStyle.Bottom;
listviewoperation.BringToFront();
listviewoperation.Dock = DockStyle.Bottom;
listviewoperation.Clear();
listviewoperation.Items.Add("打印源文件", "FileSource", 0);
listviewoperation.Items.Add("打印源目录", "FileSource", 7);
listviewoperation.Items.Add("过滤源文件", "FileSplit", 1);
listviewoperation.Items.Add("过滤文件夹", "FolderSplit", 2);
}
public void btnsimple()
{
listviewoperation.Dock = DockStyle.None;
btnsimplecompress.Dock = DockStyle.Top;
btnprintoperation.SendToBack();
btnprintoperation.Dock = DockStyle.Top;
btndeepcompress.Dock = DockStyle.Bottom;
listviewoperation.Dock = DockStyle.Bottom;
listviewoperation.Clear();
listviewoperation.Items.Add("源文件压缩", "SFileCompress", 3);
listviewoperation.Items.Add("文件夹压缩", "SFolderCompress", 4);
}
public void btndeep()
{
listviewoperation.Dock = DockStyle.None;
btndeepcompress.SendToBack();
btndeepcompress.Dock = DockStyle.Top;
btnsimplecompress.SendToBack();
btnsimplecompress.Dock = DockStyle.Top;
btnprintoperation.SendToBack();
btnprintoperation.Dock = DockStyle.Top;
listviewoperation.Dock = DockStyle.Bottom;
listviewoperation.Clear();
listviewoperation.Items.Add("源文件压缩", "DFileCompress", 5);
listviewoperation.Items.Add("文件夹压缩", "DolderCompress", 6);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -