VS项目重命名工具

VS项目整体重命名工具

  不再为项目重命名和修改命名空间而烦恼,简单几个字,但是开发加上测试大量项目,前前后后竟然跨越了1个月,汗。。。不过
真正的开发时间可能2-3天的样子。

 一.介绍

  1.虽然说我们平常不会经常出现项目重命名的情况,但是一旦出现,修改起来还是一项比较大的工程,并且还不一定修改完整。

  2.当团队发展到一定程度的时候,基本上都有了自己固定的一些WEB/Winform开发框架和通用项目模版,这样就会出现修改项目名称,命名空间等结构的情况。

  3.哒哒哒哒哒哒,不说第三了。亲,没了。@_@

二.功能

  1.自动重命名关联的各种文件,并且支持自定义扩展。

  2.自动检测文件编码格式,处理读取不同编码格式时出现的乱码问题。(当项目内包含中文的时候)

  3.自动修改sln和csproj文件中的引用关系,并且根据文件名称修改文件夹名称。

  4.清理BIN目录和OBJ目录,已经项目产生的不必要的垃圾文件,可单独使用。

  5.每个csproj都是执行单独修改,然后更新关联引用,并记住修改过的引用。

  6.输入项目新名词的文本框加入了选词功能(文本框本身双击内容是全选的效果)。

  7.自己试一下把。+_+

 三.演示与截图

1.VS的观察

更新前的VS项目解决方案更新后的VS项目解决方案

2.系统资源管理器的观察

更新前的文件夹结构更新后的文件夹结构

3.软件使用截图

  1.打开软件显示很简单的打开解决方案的视图。

  

  2.选择解决方案打开后,会自动加载该目下所有的csproj文件。

  

3.点击【软件设置】会出现其他需要修改关联的文件后缀名,你也可以直接写文件全名。
  你也可以给输入新名称的文本框添加选词分隔符,以达到你所需要的自动选词效果。

 四.代码和思路

  1.文本框智能选词功能的实现。

  1 public delegate void AutoSelectTextBoxDoubleclick(object sender, MouseEventArgs e);
2 /// <summary>
3 /// 智能选择文本控件,亲,这个类copy走就可以使用哟
4 /// </summary>
5 public class AutoSelectTextBox : TextBox
6 {
7 const int WM_LBUTTONDBLCLK = 0x0203;
8 MouseEventArgs e;
9
10 /// <summary>
11 /// 是否启用智能选择
12 /// </summary>
13 [System.ComponentModel.Description("是否启用智能选择")]
14 public bool EnableAutoSelect
15 {
16 get;
17 set;
18 }
19
20 private List<char> splitChar;
21
22 /// <summary>
23 /// 选择判断分隔符,默认 . 号
24 /// </summary>
25 [System.ComponentModel.Description("判断选择分隔符,默认 . 号")]
26 [System.ComponentModel.Browsable(false)]
27 public List<char> SplitChar
28 {
29 get { return splitChar; }
30 set { splitChar = value; }
31 }
32
33 /// <summary>
34 /// 智能选择文本框双击事件
35 /// </summary>
36 public event AutoSelectTextBoxDoubleclick AutoSelectTextMouseDoubleclick;
37
38 protected override void WndProc(ref Message m)
39 {
40
41 if (EnableAutoSelect && m.Msg == WM_LBUTTONDBLCLK)
42 {
43 Point p = this.PointToClient(MousePosition);
44 e = new MouseEventArgs(MouseButtons.Left, 2, p.X, p.Y, 0);
45 if (AutoSelectTextMouseDoubleclick != null)
46 {
47 AutoSelectTextMouseDoubleclick(this, e);
48 }
49 else
50 {
51 MouseDoubleClickAutoSelect(e);
52 }
53 return;
54
55 }
56 else
57 {
58 base.WndProc(ref m);
59 }
60 }
61
62 /// <summary>
63 /// 智能选择实现
64 /// </summary>
65 private void MouseDoubleClickAutoSelect(MouseEventArgs e)
66 {
67 if (this.Text != "")
68 {
69 int pint = this.GetCharIndexFromPosition(e.Location);
70 int len = this.Text.Length;
71 int left = pint, right = pint;
72
73 while (left >= 0)
74 {
75 char lchar = this.Text[left];
76 if (CheckSpiltChar(lchar))
77 {
78 break;
79 }
80 left--;
81 }
82 while (right <= len - 1)
83 {
84 char rchar = this.Text[right];
85 if (CheckSpiltChar(rchar))
86 {
87 break;
88 }
89 right++;
90 }
91 //必须有字符可选
92 if (right - (left + 1) > 0)
93 {
94 this.Select(left + 1, right - (left + 1));
95 }
96 }
97
98 }
99
100
101
102 /// <summary>
103 /// 检查
104 /// </summary>
105 /// <param name="source"></param>
106 /// <returns></returns>
107 private bool CheckSpiltChar(char source)
108 {
109 if (SplitChar != null)
110 {
111 foreach (char c in SplitChar)
112 {
113 if (char.Equals(source, c))
114 {
115 return true;
116 }
117 }
118 return false;
119 }
120 else
121 {
122 return char.Equals(source, '.');
123 }
124 }
125
126 }

  解释:该自动完成选词功能需要重写文本框的消息机制,其中 WM_LBUTTONDBLCLK = 0x0203 为鼠标双击消息,然后重写WndProc该事件。
为什么我重新写双击消息,而不是用文本框本身的双击事件,是因为本身的双击事件会处理一些其他内容,并且会出现先选中全部内容然后再自动选词的闪烁问题,
有兴趣的同学可以试一下就知道了。

  2.老调重弹自动识别文件编码问题,大部分的解决方案都不太理想,基本都是读取文件2-4位,判断字节大小,来决定文件编码类型。
这样的思路只是其中之一,当我郁闷至极的时候突然想到ITextSharp控件(重量级语言高亮编辑器),找到源码,发现了一块编码自动识别的功能。

  下面代码是ITextSharp控件中文件编码识别的源码,这个我发现比百度和google出来的效果好很多,基本上无识别错误情况,基本100%识别正确。
但是带来的后果是要检查一段内容前面很大一段内容,用性能换编码识别精度。

  1 public static StreamReader OpenStream(Stream fs, Encoding defaultEncoding)
2 {
3 if (fs == null)
4 throw new ArgumentNullException("fs");
5
6 if (fs.Length >= 2)
7 {
8 // the autodetection of StreamReader is not capable of detecting the difference
9 // between ISO-8859-1 and UTF-8 without BOM.
10 int firstByte = fs.ReadByte();
11 int secondByte = fs.ReadByte();
12 switch ((firstByte << 8) | secondByte)
13 {
14 case 0x0000: // either UTF-32 Big Endian or a binary file; use StreamReader
15 case 0xfffe: // Unicode BOM (UTF-16 LE or UTF-32 LE)
16 case 0xfeff: // UTF-16 BE BOM
17 case 0xefbb: // start of UTF-8 BOM
18 // StreamReader autodetection works
19 fs.Position = 0;
20 return new StreamReader(fs);
21 default:
22 return AutoDetect(fs, (byte)firstByte, (byte)secondByte, defaultEncoding);
23 }
24 }
25 else
26 {
27 if (defaultEncoding != null)
28 {
29 return new StreamReader(fs, defaultEncoding);
30 }
31 else
32 {
33 return new StreamReader(fs);
34 }
35 }
36 }
37
38 static StreamReader AutoDetect(Stream fs, byte firstByte, byte secondByte, Encoding defaultEncoding)
39 {
40 int max = (int)Math.Min(fs.Length, 500000); // look at max. 500 KB
41 const int ASCII = 0;
42 const int Error = 1;
43 const int UTF8 = 2;
44 const int UTF8Sequence = 3;
45 int state = ASCII;
46 int sequenceLength = 0;
47 byte b;
48 for (int i = 0; i < max; i++)
49 {
50 if (i == 0)
51 {
52 b = firstByte;
53 }
54 else if (i == 1)
55 {
56 b = secondByte;
57 }
58 else
59 {
60 b = (byte)fs.ReadByte();
61 }
62 if (b < 0x80)
63 {
64 // normal ASCII character
65 if (state == UTF8Sequence)
66 {
67 state = Error;
68 break;
69 }
70 }
71 else if (b < 0xc0)
72 {
73 // 10xxxxxx : continues UTF8 byte sequence
74 if (state == UTF8Sequence)
75 {
76 --sequenceLength;
77 if (sequenceLength < 0)
78 {
79 state = Error;
80 break;
81 }
82 else if (sequenceLength == 0)
83 {
84 state = UTF8;
85 }
86 }
87 else
88 {
89 state = Error;
90 break;
91 }
92 }
93 else if (b >= 0xc2 && b < 0xf5)
94 {
95 // beginning of byte sequence
96 if (state == UTF8 || state == ASCII)
97 {
98 state = UTF8Sequence;
99 if (b < 0xe0)
100 {
101 sequenceLength = 1; // one more byte following
102 }
103 else if (b < 0xf0)
104 {
105 sequenceLength = 2; // two more bytes following
106 }
107 else
108 {
109 sequenceLength = 3; // three more bytes following
110 }
111 }
112 else
113 {
114 state = Error;
115 break;
116 }
117 }
118 else
119 {
120 // 0xc0, 0xc1, 0xf5 to 0xff are invalid in UTF-8 (see RFC 3629)
121 state = Error;
122 break;
123 }
124 }
125 fs.Position = 0;
126 switch (state)
127 {
128 case ASCII:
129 case Error:
130 // when the file seems to be ASCII or non-UTF8,
131 // we read it using the user-specified encoding so it is saved again
132 // using that encoding.
133 if (IsUnicode(defaultEncoding))
134 {
135 // the file is not Unicode, so don't read it using Unicode even if the
136 // user has choosen Unicode as the default encoding.
137
138 // If we don't do this, SD will end up always adding a Byte Order Mark
139 // to ASCII files.
140 defaultEncoding = Encoding.Default; // use system encoding instead
141 }
142 return new StreamReader(fs, defaultEncoding);
143 default:
144 return new StreamReader(fs);
145 }
146 }

ITextSharp文件识别基本思路:
  1.传入需要读取文件流,并且传入一个你认为合适的编码方式,当然你可以传入NULL。

  2.读取文件前面2个字节(这个是大部分解析编码需要做的事情),读取进来的字节向左移8位,然后与第二个字节进行 | 运算,主要用途是
  检测StreamReader是否在iso - 8859 - 1和utf - 8之间的编码范围,并且不包含BOM。
忘记了C#这些运算的可以看看,http://www.cnblogs.com/NatureSex/archive/2011/04/21/2023768.html

  3.当位移出来的结果等于0x0000,0xfffe,0xfeff,0xefbb时,是StreamReader可以进行自动读取范围内的。如果不在范围内时再进行读取偏移检测,
  具体怎么检测的,这个有点难度,本人也只是看懂了一点点,主要是系统编码知识欠缺。

 五.下载

下载地址:VS重命名工具   喜欢的朋友记得推荐一下哟

源码就不放了,文件没有混淆也没有加密,自己反编译统统都有。

VS项目重命名工具的更多相关文章

  1. VS中C++ 项目重命名

    应该都有过这样的经历,在Visual studio中创建解决方案,添加几个项目进去,然后开始愉快的敲代码....写代码正欢的时候,却总是感觉那里有些不舒服,一细看,这项目名称取的真心挫,修改个吧.直接 ...

  2. eclipse怎么对项目重命名,eclipse怎么重命名类

    eclipse怎么对项目重命名,eclipse怎么重命名类

  3. 项目重命名&复制项目&删除项目

          项目重命名&复制项目&删除项目 CreateTime--2016年10月15日17:25:43 Author:Marydon 1.修改项目名或者复制的项目名 第一步: my ...

  4. 文件重命名工具(ReNamer)7.2中文绿色便携专业版

    ReNamer 是一个非常强大和灵活的文件重命名工具,它提供所有标准的重命名过程,包括前缀.后缀.替换.大小写更改以及删除括号内容.添加编号规则.更改文件扩展名等.对于高级用户,支持正则表达式和 Pa ...

  5. 在Visual Studio 2010中进行“项目重命名”的有效工具

    地址:http://www.cnblogs.com/dudu/archive/2011/12/11/visual_studio_2010_project_rename.html 提示:这个工具一次 r ...

  6. iOS项目重命名以及Xcode修改Scheme名称图文详解 (yoowei)

    在iOS开发中,有时候想改一下项目的名字,都会遇到很多麻烦.温馨提醒:记得备份. 看到项目名称,总感觉有点low,所以尝试着要将其更改一下. 项目原结构如下: 更改后的项目结构如下: 下面开始更改操作 ...

  7. 从零开始学android开发-项目重命名

    --修改项目名称 选中项目-[refactor]-[rename] --修改package名称 选中需要重命名的包-[refactor]-[rename] --修改gen下面的名称 打开Android ...

  8. javaWeb项目重命名的问题

    tomcat项目名称修改 步骤: 1.对工程重命名(选择工程,右键Refactor->Rename)      2.修改Web路径(选择工程,右键Properties->MyEclipse ...

  9. Python 入门学习(贰)文件/文件夹正则表达式批量重命名工具

    基于 Udacity 的 Python 入门课程 Programming Foundations with Python 基于 Python 2.7 思路 Project 2 是一个去除文件名中所有数 ...

随机推荐

  1. eclipse不自动弹出提示(Alt+/ 快捷键失效)

    转自:http://www.cnblogs.com/shaweng/archive/2013/09/26/3340016.html 主要有一下几种方法:    1.次方法用于没有一点提示的情况:依次打 ...

  2. The Impact of Garbage Collection on Application Performance

    As we’ve seen, the performance of the garbage collector is not determined by the number of dead obje ...

  3. bzoj1412

    比较裸的最小割 注意狼和羊的领地可以通过空地相连 ;       dx:..] ,,,-);       dy:..] ,,,); type node=record        next,point ...

  4. 【jQuery】

    TryjQuery:jQuery官方推出的教学视频http://blog.jobbole.com/37699/ jQuery 1.11 / 2.1 beta 版发布,全面支持异步模块加载  √http ...

  5. jquery Ajax应用总结

    常见应用: 下面是Jquery中AJAX参数详细列表: 参数名 类型 描述 url String (默认: 当前页地址) 发送请求的地址. type String (默认: "GET&quo ...

  6. apache开源项目--Sirona

    Apache Sirona 为 Java 应用程序提供了一个简单但可扩展的监控解决方案. apache / sirona

  7. c语言之extern关键字

    1.定义 extern,外面的.外来的意思.那它有什么作用呢?举个例子:假设你在大街上看到一个黑皮肤绿眼睛红头发的美女(外星人?)或者帅哥.你的第一反应就是这人不是国产的. extern就相当于他们的 ...

  8. (2015年郑州轻工业学院ACM校赛题) J 堆

    判断是否是一个堆,把树构造好遍历一遍就OK了 #include<stdio.h> #include<iostream> #include<stack> #inclu ...

  9. 巧用CSS文件愚人节恶搞(转)

    明天就是4月1日愚人节了,也就是那个可适度开玩笑.整蛊的日子了.如果你想和那些要上网的朋友或同事开个极客式玩笑,那就来试试这个国外网友Wes Bos分享的 CSS 文件吧. 一.打开浏览器的 Cust ...

  10. Ext入门学习系列(五)表格控件(2)

    上节学习了Ext中表格控件,从创建,到定义数据源.绑定显示,大体明白了一个基本的表格控件是怎么实现的.而我们用表格控件多用于从各种数据源接收数据并显示出来,并不是写死的.本章我们就不同数据源的不同实现 ...