js文件操作

// (c)MicrosoftCorporation
varvsViewKindPrimary = " {00000000-0000-0000-0000-000000000000} " ;
varvsViewKindDebugging
= " {7651A700-06E5-11D1-8EBD-00A0C90F26EA} " ;
varvsViewKindCode
= " {7651A701-06E5-11D1-8EBD-00A0C90F26EA} " ;
varvsViewKindDesigner
= " {7651A702-06E5-11D1-8EBD-00A0C90F26EA} " ;
varvsViewKindTextView
= " {7651A703-06E5-11D1-8EBD-00A0C90F26EA} " ;

varGUID_ItemType_PhysicalFolder
= " {6BB5F8EF-4483-11D3-8BCF-00C04F8EC28C} " ;
varGUID_ItemType_VirtualFolder
= " {6BB5F8F0-4483-11D3-8BCF-00C04F8EC28C} " ;
varGUID_ItemType_PhysicalFile
= " {6BB5F8EE-4483-11D3-8BCF-00C04F8EC28C} " ;

varGUID_Deployment_TemplatePath
= " {54435603-DBB4-11D2-8724-00A0C9A8B90C} " ;

vargbExceptionThrown
= false ;

varvsCMFunctionConstructor
= 1 ;

varvsCMAddPositionInvalid
= - 3 ;
varvsCMAddPositionDefault
= - 2 ;
varvsCMAddPositionEnd
= - 1 ;
varvsCMAddPositionStart
= 0 ;
//
varvsCMAccessPublic = 1 ;
varvsCMAccessDefault
= 32 ;
//
varvsCMWhereInvalid = - 1 ;
varvsCMWhereDefault
= 0 ;
varvsCMWhereDeclaration
= 1 ;
varvsCMWhereDefinition
= 2 ;
//
varvsCMValidateFileExtNone = - 1 ;
varvsCMValidateFileExtCpp
= 0 ;
varvsCMValidateFileExtCppSource
= 1 ;
varvsCMValidateFileExtHtml
= 2 ;
//
varvsCMElementClass = 1 ;
varvsCMElementFunction
= 2 ;
varvsCMElementVariable
= 3 ;
varvsCMElementProperty
= 4 ;
varvsCMElementNamespace
= 5 ;
varvsCMElementInterface
= 8 ;
varvsCMElementStruct
= 11 ;
varvsCMElementUnion
= 12 ;
varvsCMElementIDLCoClass
= 33 ;
varvsCMElementVCBase
= 37 ;


// VS-specificHRESULTfailurecodes
//
varOLE_E_PROMPTSAVECANCELLED = - 2147221492 ;
varVS_E_PROJECTALREADYEXISTS
= - 2147753952 ;
varVS_E_PACKAGENOTLOADED
= - 2147753953 ;
varVS_E_PROJECTNOTLOADED
= - 2147753954 ;
varVS_E_SOLUTIONNOTOPEN
= - 2147753955 ;
varVS_E_SOLUTIONALREADYOPEN
= - 2147753956 ;
varVS_E_INCOMPATIBLEDOCDATA
= - 2147753962 ;
varVS_E_UNSUPPORTEDFORMAT
= - 2147753963 ;
varVS_E_WIZARDBACKBUTTONPRESS
= - 2147213313 ;
varVS_E_WIZCANCEL
= VS_E_WIZARDBACKBUTTONPRESS;

////////////////////////////////////////////////////// //


/* *****************************************************************************
Description:Setstheerrorinfo
nErrNumber:Errorcode
strErrDesc:Errordescription
*****************************************************************************
*/
functionSetErrorInfo(oErrorObj)
{
varoWizard;
try
{
oWizard
= wizard;
}
catch (e)
{
oWizard
= window.external;
}

try
{
varstrErrorText
= "" ;

if (oErrorObj.description.length != 0 )
{
strErrorText
= oErrorObj.description;
}
else
{
varstrErrorDesc
= GetRuntimeErrorDesc(oErrorObj.name);
if (strErrorDesc.length != 0 )
{
varL_strScriptRuntimeError_Text
= " 运行脚本时出错: " ;
strErrorText
= oErrorObj.name + L_strScriptRuntimeError_Text + strErrorDesc;
}
}

oWizard.SetErrorInfo(strErrorText,oErrorObj.number
& 0xFFFFFFFF );
}
catch (e)
{
varL_ErrSettingErrInfo_Text
= " 设置错误信息时出错。 " ;
oWizard.ReportError(L_ErrSettingErrInfo_Text);
}
}


/* *****************************************************************************
Description:Returnsadescriptionfortheexceptiontypegiven
strRuntimeErrorName:Thenameofthetypeofexceptionoccurred
****************************************************************************
*/
functionGetRuntimeErrorDesc(strRuntimeErrorName)
{
varL_strDesc_Text
= "" ;
switch (strRuntimeErrorName)
{
case " ConversionError " :
varL_ConversionError1_Text
= " 每当试图将对象转换为 " ;
varL_ConversionError2_Text
= " 它无法转换到的内容时,就会发生此错误。 " ;
L_strDesc_Text
= L_ConversionError1_Text + " " + L_ConversionError2_Text;
break ;
case " RangeError " :
varL_RangeError1_Text
= " 如果为函数提供的参数 " ;
varL_RangeError2_Text
= " 超出其允许范围,则出现此错误。例如, " ;
varL_RangeError3_Text
= " 如果试图构造的数组对象的长度不是 " ;
varL_RangeError4_Text
= " 有效的正整数,则出现此错误。 " ;
L_strDesc_Text
= L_RangeError1_Text + " " + L_RangeError2_Text + " " + L_RangeError3_Text + " " + L_RangeError4_Text;
break ;
case " ReferenceError " :
varL_ReferenceError1_Text
= " 如果检测到无效引用,则出现此错误。 " ;
varL_ReferenceError2_Text
= " 例如,如果所需引用为空,则出现此错误。 " ;
L_strDesc_Text
= L_ReferenceError1_Text + " " + L_ReferenceError2_Text;
break ;
case " RegExpError " :
varL_RegExpError1_Text
= " 如果因正则表达式而在编译时出错,则出现此错误; " ;
varL_RegExpError2_Text
= " 一旦正则表达式通过编译,就不会出现此错误。 " ;
varL_RegExpError3_Text
= " 例如,如果声明正则表达式所用的模式中存在以下三种情况,则出现此错误: " ;
varL_RegExpError4_Text
= " 一是无效语法;二是 " ;
varL_RegExpError5_Text
= " 除i、g或m以外的标志;三是多次包含同一标志。 " ;
L_strDesc_Text
= L_RegExpError1_Text + " " + L_RegExpError2_Text + " " + L_RegExpError3_Text + " " + L_RegExpError4_Text + " " + L_RegExpError5_Text;
break ;
case " SyntaxError " :
varL_SyntaxError1_Text
= " 如果对源文本进行分析后发现其语法不正确,则出现此错误。 " ;
varL_SyntaxError2_Text
= " 例如, " ;
varL_SyntaxError3_Text
= " 如果调用Eval函数时所用参数不是有效的程序文本,则出现此错误。 " ;
L_strDesc_Text
= L_SyntaxError1_Text + " " + L_SyntaxError2_Text + " " + L_SyntaxError3_Text;
break ;
case " TypeError " :
varL_TypeError1_Text
= " 只要操作数的实际类型与所需类型不匹配,就会出现此错误。 " ;
varL_TypeError2_Text
= " 例如,如果某个函数调用 " ;
varL_TypeError3_Text
= " 的不是一个对象,或者根本不支持该调用,则出现此错误。 " ;
L_strDesc_Text
= L_TypeError1_Text + " " + L_TypeError2_Text + " " + L_TypeError3_Text;
break ;
case " URIError " :
varL_URIError1_Text
= " 如果检测到非法的统一资源标识符(URI),则出现此错误。 " ;
varL_URIError2_Text
= " 例如,如果在编码或解码的字符串中发现非法字符,则 " ;
varL_URIError3_Text
= " 出现此错误。 " ;
L_strDesc_Text
= L_URIError1_Text + " " + L_URIError2_Text + " " + L_URIError3_Text;
break ;
default :
break ;
}
return L_strDesc_Text;
}

/* *****************************************************************************
Description:CreatestheTemplates.inffile.
Templates.infiscreatedbasedonTemplatesInf.txtandcontains
alistoffilenamestobecreatedbythewizard.
*****************************************************************************
*/
functionCreateInfFile()
{
try
{
varoFSO,TemplatesFolder,TemplateFiles,strTemplate;
oFSO
= new ActiveXObject( " Scripting.FileSystemObject " );

varTemporaryFolder
= 2 ;
varoFolder
= oFSO.GetSpecialFolder(TemporaryFolder);

varstrTempFolder
= oFSO.GetAbsolutePathName(oFolder.Path);
varstrWizTempFile
= strTempFolder + " \ " + oFSO.GetTempName();

varstrTemplatePath
= wizard.FindSymbol( " TEMPLATES_PATH " );
varstrInfFile
= strTemplatePath + " \Templates.inf " ;
wizard.RenderTemplate(strInfFile,strWizTempFile);

varoWizTempFile
= oFSO.GetFile(strWizTempFile);
return oWizTempFile;

}
catch (e)
{
throw e;
}
}

/* *****************************************************************************
Description:Returnsauniquefilename
strDirectory:Directorytolookforfilenamein
strFileName:Filenametocheck.Ifunique,samefilenameisreturned.If
notunique,anumberfrom1-9999999willbeappended.Ifnot
passedin,auniquefilenameisreturnedviaGetTempName.
*****************************************************************************
*/
functionGetUniqueFileName(strDirectory,strFileName)
{
try
{
oFSO
= new ActiveXObject( " Scripting.FileSystemObject " );
if ( ! strFileName)
return oFSO.GetTempName();

if (strDirectory.length && strDirectory.charAt(strDirectory.length - 1 ) != " \ " )
strDirectory
+= " \ " ;

varstrFullPath
= strDirectory + strFileName;
varstrName
= strFileName.substring( 0 ,strFileName.lastIndexOf( " . " ));
varstrExt
= strFileName.substr(strFileName.lastIndexOf( " . " ));

varnCntr
= 0 ;
while (oFSO.FileExists(strFullPath))
{
nCntr
++ ;
strFullPath
= strDirectory + strName + nCntr + strExt;
}
if (nCntr)
return strName + nCntr + strExt;
else
return strFileName;
}
catch (e)
{
throw e;
}
}


/* *****************************************************************************
Description:Deletesthefilegiven
oFSO:FileSystemObject
strFile:Nameofthefiletobedeleted
*****************************************************************************
*/
functionDeleteFile(oFSO,strFile)
{
try
{
if (oFSO.FileExists(strFile))
{
varoFile
= oFSO.GetFile(strFile);
oFile.Delete();
}
}
catch (e)
{
throw e;
}
}

/* *****************************************************************************
Description:Returnsthehighestdispidfrommembersofthegiveninterface&
allitsbases
oInterface:Interfaceobject
*****************************************************************************
*/
functionGetMaxID(oInterface)
{
varcurrentMax
= 0 ;
try
{
varfuncs
= oInterface.Functions;
if (funcs != null )
{
varnTotal
= funcs.Count;
varnCntr;
for (nCntr = 1 ;nCntr <= nTotal;nCntr ++ )
{
varid
= funcs(nCntr).Attributes( " id " );
if (id != null )
{
varidval
= parseInt(id.Value);
if (idval > currentMax)
currentMax
= idval;
}
}
}
// REMOVEremovethisanduseChildrencollectionabove,ifit'simplemented
funcs = oInterface.Variables;
if (funcs != null )
{
varnTotal
= funcs.Count;
varnCntr;
for (nCntr = 1 ;nCntr <= nTotal;nCntr ++ )
{
varid
= funcs(nCntr).Attributes( " id " );
if (id != null )
{
varidval
= parseInt(id.Value);
if (idval > currentMax)
currentMax
= idval;
}
}
}
varnextBases
= oInterface.Bases;
varnTotal
= nextBases.Count;
varnCntr;
for (nCntr = 1 ;nCntr <= nTotal;nCntr ++ )
{
varnextObject
= nextBases(nCntr).Class;
if (nextObject != null && nextObject.Name != " IDispatch " )
{
varidval
= GetMaxID(nextObject);
if (idval > currentMax)
currentMax
= idval;
}
}
return currentMax;
}
catch (e)
{
throw e;
}
}


/* *****************************************************************************
Description:GeneratesaC++friendlyname
strName:Theold,unfriendlyname
*****************************************************************************
*/
functionCreateSafeName(strName)
{
try
{
varnLen
= strName.length;
varstrSafeName
= "" ;

for (nCntr = 0 ;nCntr < nLen;nCntr ++ )
{
varcChar
= strName.charAt(nCntr);
if ((cChar >= ' A ' && cChar <= ' Z ' ) || (cChar >= ' a ' && cChar <= ' z ' ) ||
(cChar
== ' _ ' ) || (cChar >= ' 0 ' && cChar <= ' 9 ' ))
{
// validcharacter,soaddit
strSafeName += cChar;
}
// otherwize,weskipit
}
if (strSafeName == "" )
{
// ifit'sempty,weaddMy
strSafeName = " My " ;
}
else if (strSafeName.charAt( 0 ) >= ' 0 ' && strSafeName.charAt( 0 ) <= ' 9 ' )
{
// ifitstartswithadigit,weprependMy
strSafeName = " My " + strSafeName;
}
return strSafeName;
}
catch (e)
{
throw e;
}
}


/* *****************************************************************************
Description:Calledfromthewizardshtmlscriptwhen'Finish'isclicked.This
functioninturncallsthewizardcontrol'sFinish().
document:HTMLdocumentobject
*****************************************************************************
*/
functionOnWizFinish(document)
{
document.body.style.cursor
= ' wait ' ;
try
{
window.external.Finish(document,
" ok " );
}
catch (e)
{
document.body.style.cursor
= ' default ' ;
if (e.description.length != 0 )
SetErrorInfo(e.description,e.number);
return e.number;
}
}

/* *****************************************************************************
Description:ReturnsaFunctionobjectbasedonthegivenname
oClass:Classobject
strFuncName:Nameofthefunction
oProj:Selectedproject
*****************************************************************************
*/
functionGetMemberFunction(oClass,strFuncName,oProj)
{
try
{
varoFunctions;
if (oClass)
oFunctions
= oClass.Functions;
else
{
if ( ! oProj)
return false ;
oFunctions
= oProj.CodeModel.Functions;
}

for (varnCntr = 1 ;nCntr <= oFunctions.Count;nCntr ++ )
{
if (oFunctions(nCntr).Name == strFuncName)
return oFunctions(nCntr);
}
return false ;
}
catch (e)
{
throw e;
}
}


/* ****************************************************************************
ThefollowingsectioncontainsfunctionsthatareusedbyCSharpProjects
andCSharpAdditems.IfyouliketoaddanewfunctionthatisCSharp
specific,pleaseadditbeyondthispointofthisfile.

-CSHARPSECTION-
*****************************************************************************
*/

/* *****************************************************************************
Description:CreatesaC#project
strProjectName:ProjectName
strProjectPath:Thepaththattheprojectwillbecreatedin
strTemplateFile:Projecttemplatefilee.g."defualt.csproj"
*****************************************************************************
*/
functionCreateCSharpProject(strProjectName,strProjectPath,strTemplateFile)
{
try
{
// Makesureuserseesui.
dte.SuppressUI = false ;
varstrProjTemplatePath
= wizard.FindSymbol( " PROJECT_TEMPLATE_PATH " ) + " \ " ;
varstrProjTemplate
= strProjTemplatePath + strTemplateFile;
varSolution
= dte.Solution;
varstrSolutionName
= "" ;
if (wizard.FindSymbol( " CLOSE_SOLUTION " ))
{
Solution.Close();
strSolutionName
= wizard.FindSymbol( " VS_SOLUTION_NAME " );
if (strSolutionName.length)
{

varstrSolutionPath
= strProjectPath.substr( 0 ,strProjectPath.length - strProjectName.length);
Solution.Create(strSolutionPath,strSolutionName);
}
}

strProjectNameWithExt
= strProjectName + " .csproj " ;

varoTarget
= wizard.FindSymbol( " TARGET " );
varoPrj;
if (wizard.FindSymbol( " WIZARD_TYPE " ) == vsWizardAddSubProject) // vsWizardAddSubProject
{
varnPos
= strProjectPath.search( " http:// " );
varprjItem
if (nPos == 0 )
prjItem
= oTarget.AddFromTemplate(strProjTemplate,strProjectPath + " / " + strProjectNameWithExt);
else
prjItem
= oTarget.AddFromTemplate(strProjTemplate,strProjectPath + " \ " + strProjectNameWithExt);
oPrj
= prjItem.SubProject;
}
else
{
oPrj
= oTarget.AddFromTemplate(strProjTemplate,strProjectPath,strProjectNameWithExt);
}
varstrNameSpace
= "" ;
strNameSpace
= oPrj.Properties( " RootNamespace " ).Value;
wizard.AddSymbol(
" SAFE_NAMESPACE_NAME " ,strNameSpace);

return oPrj;
}
catch (e)
{
// propagateallerrorsbacktothecaller
throw e;
}
}

/* *****************************************************************************
Description:
oProj:Projectobject
*****************************************************************************
*/
functionGetUIReferencesNode(oProj)
{
varL_strReferencesNode_Text
= " 引用 " ; // Thisstringneedstobelocalized
try
{
varUIItemX
= GetUIItem(oProj,L_strReferencesNode_Text);
return UIItemX.UIHierarchyItems;
}
catch (e)
{
}
}

/* *****************************************************************************
Description:Returnstheparentoftheinputhierarchyitem.Theparent
maybeafolder,orasuperprojectorthesolution.
oProj:Projectobject
*****************************************************************************
*/
functiongetParent(obj)
{
varparent
= obj.Collection.parent;
//
// isobjaproject?
//
if (parent == dte)
{
//
// isobjasub-project?
//
if (obj.ParentProjectItem)
{
parent
= obj.ParentProjectItem.Collection.parent;
}
else
{
//
color: #
分享到:
评论

你可能感兴趣的:(正则表达式,脚本)