去除 VS.Net 2003 项目的 VSS 息的脚本
文章来源:http://www.zaojuzi.com/nirenju/
从google搜到的,以前用过一次,后来找不到了,今天好不容易又找到,写在这儿算作备忘。
好像这段脚本是一个老外写的,VSS信息去除的比较彻底。使用方法:把这段代码保存为RemoveVssInfo.js,放到和xxx.sln文件相同的文件夹下,然后双击执行即可。
代码如下:
var deleteByForce = true;
var consoleOnly = true;
var defaultTimeOut = 1;
var showDetails = false;
var WSShell;
var fso;
var currentFolder;
var deletedFiles = 0;
var modifiedFiles = 0;
var ForReading = 1, ForWriting = 2, ForAppending = 8;
var CharSetDefault = -2, CharSetUnicode = -1, CharSetAscii = 0;
var AttrNormal = 0, AttrReadOnly = 1, AttrHidden = 2, AttrSystem = 4,
AttrVolume = 8, AttrDirectory = 16, AttrArchive = 32, AttrAlias = 1024,
AttrCompressed = 2048;
Init();
Main();
//Test();
/// Main ------------------------------------------------------
function Main() {
var text;
// say hello
text = "Remove from SourceSafe has started.";
Out(text,true);
COut("Working folder: \r\n"+ currentFolder);
// delete files
// *.suo, *.eto, *.vssscc, *.vspscc, vssver.scc, mssccprj.scc
DeleteFiles("[.]*([.]suo$|[.]eto$|[.]vssscc$|[.]vspscc$|vssver[.]scc$|mssccprj[.]scc$)");
// modify files
// *.etp, *.sln, *.csproj
ModifyFiles("[.]*([.]etp$|[.]sln$|[.]csproj$)");
// say goodbye
text = "Remove from SourceSafe has finished. \r\n\r\n"
+ "Deleted files: \t" + deletedFiles + "\r\n"
+ "Modified files: \t" + modifiedFiles + "\r\n";
Out(text,false);
}
function Init() {
// detect command line
try {
WScript.StdOut.WriteLine(" ");
} catch (e) {
consoleOnly = false;
}
// initialize
WSShell = new ActiveXObject("WScript.Shell");
fso = new ActiveXObject("Scripting.FileSystemObject");
currentFolder = GetCurrentFolder();
}
/// Files ------------------------------------------------------
// getcurrent folder
function GetCurrentFolder() {
return fso.GetFolder(fso.GetFile(WScript.ScriptFullName).ParentFolder);
}
// delete files by mask
function DeleteFiles(mask) {
var files = FindFiles(mask);
var i;
Out("Deleting files", true);
for (i=0; i<files.length; i++) {
try {
fso.DeleteFile(files[i], deleteByForce);
deletedFiles ++;
} catch (e) {
WScript.echo(e.Message);
}
}
if (deletedFiles == 0) {
COut("No files were deleted.");
}
}
// find files
function FindFiles(mask) {
return GetFiles(currentFolder, mask);
}
// determine, if filename matches given mask
function MatchesMask(file, mask) {
return new RegExp(mask).test(file);
}
// get files in current folder & subfolders
function GetFiles(folder, mask) {
var result = new Array();
// do files in current folder
var files = new Enumerator(folder.Files);
for (; !files.atEnd(); files.moveNext()) {
if (MatchesMask(files.item(), mask)) {
result.push("" + files.item());
}
}
// do subfolders in current folder
var folders = new Enumerator(folder.SubFolders);
for (; !folders.atEnd(); folders.moveNext()) {
result = result.concat(GetFiles(folders.item(), mask));
}
return result;
}
/// Output ------------------------------------------------------
// output
function Out(text, useTimeOut) {
if (useTimeOut) {
useTimeOut = defaultTimeOut;
} else {
useTimeOut = -1;
}
if (consoleOnly) {
WScript.StdOut.WriteLine(text);
} else {
WSShell.Popup(text, useTimeOut, "Remove from SourceSafe");
}
}
// output
function COut(text, useTimeOut) {
if (useTimeOut) {
useTimeOut = defaultTimeOut;
} else {
useTimeOut = -1;
}
if (consoleOnly) {
WScript.StdOut.WriteLine(text);
}
}
/// Modify ------------------------------------------------------
// modify all files matching given mask
function ModifyFiles(mask) {
var files = FindFiles(mask);
var i;
Out("Modifying files", true);
for (i=0; i<files.length; i++) {
// WScript.echo(files[i]);
// try {
ModifyFile(fso.GetFile(files[i]));
modifiedFiles ++;
// } catch (e) {
// WScript.echo(e.description);
// }
}
if (modifiedFiles == 0) {
COut("No files were modified.");
}
}
function ModifyFile(file) {
switch (fso.GetExtensionName(file.Path).toLowerCase()) {
case "etp":
ModifyFileETP(file);
break;
case "sln":
ModifyFileSLN(file);
break;
case "csproj":
ModifyFileCSPROJ(file);
break;
}
}
function ReadFile(file) {
var stream = file.OpenAsTextStream(ForReading, CharSetDefault);
text = stream.ReadAll();
stream.Close();
return text;
}
function WriteFile(file, text) {
var ro = ((file.Attributes & AttrReadOnly) != 0);
if (ro) file.Attributes -= AttrReadOnly;
var stream = file.OpenAsTextStream(ForWriting, CharSetDefault);
stream.Write(text);
stream.Close();
if (ro) file.Attributes += AttrReadOnly;
}
// remove element <SourceControlSettings></SourceControlSettings>
function ModifyFileETP(file) {
var text;
var re1 = new RegExp(‘(\\s*<SourceControlSettings(\\s[^>]*)?>[.\\s\\S\\r\\n]*<\\/SourceControlSettings>)‘,‘m‘);
text = ReadFile(file);
text = text.replace(re1, "");
WriteFile(file, text);
}
// remove section GlobalSection(SourceCodeControl) = preSolution EndGlobalSection
function ModifyFileSLN(file) {
var text;
var re1 = new RegExp(‘(\\s*GlobalSection\\(SourceCodeControl\\))[.\\r\\n\\s\\S]*?EndGlobalSection‘,‘m‘);
text = ReadFile(file);
text = text.replace(re1, "");
WriteFile(file, text);
}
// remove lines with SccProjectName, SccLocalPath, SccAuxPath, SccProvider
function ModifyFileCSPROJ(file) {
var text;
var re1 = new RegExp(‘(^\\s*SccProjectName = .*$)‘, ‘m‘);
var re2 = new RegExp(‘(^\\s*SccLocalPath = .*$)‘, ‘m‘);
var re3 = new RegExp(‘(^\\s*SccAuxPath = .*$)‘, ‘m‘);
var re4 = new RegExp(‘(^\\s*SccProvider = .*$)‘, ‘m‘);
text = ReadFile(file);
text = text.replace(re1, "");
text = text.replace(re2, "");
text = text.replace(re3, "");
text = text.replace(re4, "");
WriteFile(file, text);
}
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。