去除 vs.net 2003 项目的 VSS 信息的脚本(收藏)
这个脚本是在 codeproject 上面看到的,是一个文章的回复里面某老外贴的脚本,其作用是彻底去除 vs.net 2003 项目的 VSS 信息。我经常需要使用,所以发在这里做一个备份。
首先把这些代码保存为 RemoveVssInfo.js,放到和 xxx.sln 项目文件同一个目录里面。然后双击执行即可。代码如下:
首先把这些代码保存为 RemoveVssInfo.js,放到和 xxx.sln 项目文件同一个目录里面。然后双击执行即可。代码如下:
/// Global ------------------------------------------------------
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);
}
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);
}