[译]在提交给CodeProject之前剥离不需要文件的zip的工具
By robot-v1.0
本文链接 https://www.kyfws.com/applications/a-tool-to-strip-zips-of-unwanted-files-before-subm-zh/
版权声明 本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!
- 5 分钟阅读 - 2360 个词 阅读量 0[译]在提交给CodeProject之前剥离不需要文件的zip的工具
原文地址:https://www.codeproject.com/Articles/7115/A-tool-to-strip-zips-of-unwanted-files-before-subm
原文作者:Nish Nishant
译文由本站 robot-v1.0 翻译
前言
The CPZipStripper tool with source code
带源代码的CPZipStripper工具
图1-红色文件将被剥除(Fig. 1 - The red colored files will get stripped)
介绍(Introduction)
CPZipStripper是我在CP上编辑和提交文章时一直使用的简单工具,它的全部作用是从zip中删除不需要的文件,例如debug和obj文件夹文件,suo文件,pdb文件,aps文件等.仅举几例.它是一键式工具-因此您不必浪费时间在WinZip或类似工具中打开zip,然后手动删除不需要的文件.(The CPZipStripper is a simple tool I’ve been using when editing and submitting articles on CP, and all it does is to remove unwanted files from the zips - like debug and obj folder files, suo files, pdb files, aps files etc. to name a few. It’s a one-click tool - so you don’t have to waste time opening the zip in WinZip or some such tool and then manually deleting unwanted files.)
如果文章作者在将其发送给我们之前在其zip上使用此工具,那就太好了,这样编辑人员收到的邮件的大小将大大减少.(It would be very nice if article authors would use this tool on their zips before sending it to us, so that the size of the mails received by the editors will be considerably lesser.)
安装(Installation)
将release.zip中的三个文件解压缩到您选择的任何永久文件夹中:(Unzip the three files in release.zip to any permanent folder of your choice :-)
- CPZipStripper.exe-这是主要的可执行文件(针对FW 1.1的.NET IL exe)(CPZipStripper.exe - This is the main executable (.NET IL exe targetted at FW 1.1))
- CPZipStripperCfg.xml-配置文件(CPZipStripperCfg.xml - Configuration file)
- ICSharpCode.SharpZipLib.dll-我用于访问zip文件的DLL((ICSharpCode.SharpZipLib.dll - the DLL that I use for accessing the zip files () 夏普拉链库(SharpZipLib) )()) 现在只需运行一次CPZipStripper.exe并退出.就这样.(Now just run CPZipStripper.exe once and exit. That’s all.)
使用工具(Using the tool)
您可以将zip拖放到程序窗口中,或者右键单击一个zip文件并选择"使用ZipStrip打开"选项,但是要添加上下文菜单项,您至少需要运行一次该程序-因为它没有单独的安装程序.(You can either drag/drop a zip into the program window or right click a zip file and choose the “Open with ZipStrip” option, but for the context menu item to get added, you’ll need to run the program at least once - as it does not have a separate installer.)
图2-资源管理器中zip文件的上下文菜单项(Fig. 2 - Context menu item for zip files in Explorer)
按钮(The buttons)
-
修改配置(Modify Config)-这将在Windows XML编辑器中打开config XML文件-如果您没有,则会报告错误.如果是这样,请在记事本中手动打开XML文件并进行更改.(- This will open the config XML file in your windows XML editor - if you don’t have one, it will report an error. If so, manually open the XML file in Notepad and make your changes.)
- 扩展节点列出了所有需要删除的扩展(The extensions node lists all extensions that need to be deleted)
- 路径节点列出了要删除的所有路径(因此,如果在那里有调试,则其提取路径包含调试的任何文件都将被删除)(The paths node lists all paths that you want to be deleted (thus if you have debug in there, any file whose extract path contains debug is deleted))
- “文件"节点列出了要删除的所有特定文件名(The files node lists any specific filenames that you want deleted)
-
刷新列表框(Refresh Listbox)-如果zip文件已更改或您对XML配置文件进行了修改,请点击"刷新列表框"按钮(- If the zip file has changed or you have made modifications to the XML config file, please hit the “Refresh Listbox” button)
-
删除不需要的文件(Strip Unwanted files)-这将删除所有不需要的文件(在列表框中以红色显示),并将zip替换为干净的文件,但还会备份旧文件.(- This will remove all the unwanted files (shown in red in the listbox) and will replace the zip with a clean file, but also backs up the old file.)
-
退出程序(Exit Program)-使用这种情况,因为它会关闭程序;-)(- Use this one with case, as it closes the program ;-))
有趣的点(Interesting points)
这是我学到的一些奇怪的东西:-)(Here are some odd things I learned :-))
处理拖放操作确实比我预期的要容易.首先,您需要设置(Handling drag/drop was really easier than I expected it to be. First you need to set the) Form
的(’s) AllowDrop
财产(property to) true
.然后处理(. Then just handle the) DragEnter
和(and) DragDrop
事件.(events.)
private void MainForm_DragDrop(object sender,
System.Windows.Forms.DragEventArgs e)
{
Array arr = (Array)e.Data.GetData(DataFormats.FileDrop);
if(arr != null)
{
//Doing it asynchronously else Explorer will freeze too
BeginInvoke(new DroppedFileHandler(FilterZip),
new object[] {arr.GetValue(0).ToString()});
}
}
private void MainForm_DragEnter(object sender,
System.Windows.Forms.DragEventArgs e)
{
//To change the mouse cursor if there are any files
e.Effect = e.Data.GetDataPresent(DataFormats.FileDrop) ?
DragDropEffects.Copy : DragDropEffects.None;
}
如果您对通用功能感兴趣,该通用功能可让您为特定文件类型添加上下文菜单项:-(If you are interested in a generic function that will let you add a context menu item for a specific file type :-)
看到我的博客条目:(See my blog entry :) 一个简单的C#函数,可在资源管理器中添加上下文菜单项(A simple C# function to add context menu items in Explorer) 这是功能.(and here’s the function.)
private bool AddContextMenuItem(string Extension,
string MenuName, string MenuDescription,
string MenuCommand)
{
bool ret = false;
RegistryKey rkey = Registry.ClassesRoot.OpenSubKey(
Extension);
if(rkey != null)
{
string extstring = rkey.GetValue("").ToString();
rkey.Close();
if( extstring != null )
{
if( extstring.Length > 0 )
{
rkey = Registry.ClassesRoot.OpenSubKey(extstring,true);
if(rkey != null)
{
string strkey = "shell\\" + MenuName + "\\command";
RegistryKey subky = rkey.CreateSubKey(strkey);
if(subky != null)
{
subky.SetValue("",MenuCommand);
subky.Close();
subky = rkey.OpenSubKey("shell\\" + MenuName, true);
if(subky != null)
{
subky.SetValue("",MenuDescription);
subky.Close();
}
ret = true;
}
rkey.Close();
}
}
}
}
return ret;
}
结论(Conclusion)
UI看起来不多,但是该工具对我有用.通过文章论坛让我知道是否有人有任何建议/反馈.(The UI is not much to look at, but the tool’s worked for me. Let me know if anyone has any suggestions/feedback through the article forum.)
结论后(dan g的工具)(Post-Conclusion (dan g’s tool))
虽然我的工具旨在从zip文件中删除不需要的文件,(While my tool is meant for stripping unwanted files from zip files,) 丹克(dan g) 在CP上有一篇很棒的文章,描述了一种三合一工具,可用于打包VC ++和.NET项目文件.我强烈要求人们看一看:(has an excellent article here on CP, describing a 3-in-1 tool that can be used to package VC++ and .NET project files. I strongly urge people to take a look at that one :-)
- http://www.codeproject.com/tools/projectzipremoded.asp(http://www.codeproject.com/tools/projectzipremoded.asp) 毕竟,预防胜于治疗,对吗?(After all, prevention is better than cure, eh?)
许可
本文以及所有相关的源代码和文件均已获得The Code Project Open License (CPOL)的许可。
C# C++ Windows .NET .NET1.1 Visual-Studio VS.NET2003 Dev 新闻 翻译