這個指令碼只滿足了我要完成的工作的一部分內容,其餘內容必須在公司才能完成及調試了。
指令碼運行需要有如下條件:
與指令碼在同一級目錄下的 ctags.exe ,需要5.8以後版本的。主要是要支援正則,支援 - R選項後面帶目錄路徑的。
同一級目錄下要有logic檔案夾,檔案夾內要有符合文法的logic檔案。
指令碼如下:
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' 初始化一些全域變數''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''Dim FSODim WshShell, oExecSet WshShell = CreateObject("WScript.Shell")Set FSO = CreateObject("Scripting.FileSystemObject")''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' 展示邏輯的方式''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''Const SW_LOGIC_IN_DLG = 0Const INSERT_LOGIC_TO_SCRIPT = 1Const OPEN_LOGIC_FILE = 2''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' Window Style''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''Const SW_HIDE = 0Const SW_SHOW = 1Const SW_MIN = 2Const SW_MAX = 3''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' 由 Drive.DriveType 返回的常數''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''Const DriveTypeRemovable = 1Const DriveTypeFixed = 2Const DriveTypeNetwork = 3Const DriveTypeCDROM = 4Const DriveTypeRAMDisk = 5''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' 由 File.Attributes 返回的常數''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''Const FileAttrNormal = 0Const FileAttrReadOnly = 1Const FileAttrHidden = 2Const FileAttrSystem = 4Const FileAttrVolume = 8Const FileAttrDirectory = 16Const FileAttrArchive = 32 Const FileAttrAlias = 64Const FileAttrCompressed = 128''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' 用來開啟檔案的常數''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''Const OpenFileForReading = 1 Const OpenFileForWriting = 2 Const OpenFileForAppending = 8 Function GenerateFileInformation(File) Dim S S = NewLine & "Path:" & TabStop & File.Path S = S & NewLine & "Name:" & TabStop & File.Name S = S & NewLine & "Type:" & TabStop & File.Type S = S & NewLine & "Attribs:" & TabStop & ShowFileAttr(File) S = S & NewLine & "Created:" & TabStop & File.DateCreated S = S & NewLine & "Accessed:" & TabStop & File.DateLastAccessed S = S & NewLine & "Modified:" & TabStop & File.DateLastModified S = S & NewLine & "Size" & TabStop & File.Size & NewLine GenerateFileInformation = SEnd FunctionFunction GetFolderLastModifyTime (FolderPath) If (FSO.FileExists("tags")) Then Set File = FSO.GetFile("tags") lastModTime = File.DateLastModified 'MsgBox lastModTime Else msg = filespec & " doesn't exist." 'MsgBox msg End If Set Folder = FSO.GetFolder(FolderPath) folderModTime = Folder.DateLastModified lTime = Folder.DateLastModified Set Files = Folder.Files For Each File In Files If lTime < File.DateLastModified Then lTime = File.DateLastModified End If Next GetFolderLastModifyTime = lTimeEnd FunctionFunction FlashTagFile (tagFileName, FolderPath) If (FSO.FileExists(tagFileName)) Then Set File = FSO.GetFile(tagFileName) lastModTime = File.DateLastModified Else strCmd = "ctags.exe --langdef=logic --langmap=logic:.logic --regex-logic=""/^\s*(Logic|Join)\s+(\w+)\s+\{/\2/L,Logic/"" -n -R " & FolderPath oExec = WshShell.Run(strCmd, SW_HIDE, True) FlashTagFile = True Exit Function End If If lastModTime < GetFolderLastModifyTime(FolderPath) Then strCmd = "ctags.exe --langdef=logic --langmap=logic:.logic --regex-logic=""/^\s*(Logic|Join)\s+(\w+)\s+\{/\2/L,Logic/"" -n -R " & FolderPath oExec = WshShell.Run(strCmd, SW_HIDE, True) FlashTagFile = True Else FlashTagFile = False End If End FunctionFunction LocationLogic (logicName, logicFileName, lineNum) LocationLogic = "It's just a empty Function now!" & vbCrLf _ & "It will find [" & logicName & "] in file [" & logicFileName & "]. line : " & lineNum End FunctionFunction GetLogicInfo (logicName, tagFileName) Dim oRe, oMatch, oMatches Set tagFile = FSO.GetFile(tagFileName) Set TextStream = FSO.OpenTextFile(tagFileName, OpenFileForReading) allLogicInfo = TextStream.ReadAll TextStream.Close ' the format as below 'testLogic010logic\Logic0.logic24;"L Set oRe = New RegExp oRe.Pattern = logicName & "\s+(.*?)\s+(\d+);""\s+(\w)" ' 得到 Matches 集合 oRe.IgnoreCase = False ' 設定是否區分大小寫。 oRe.Global = False ' 設定全程匹配。 Set oMatches = oRe.Execute(allLogicInfo) If oMatches.Count = 0 Then MsgBox "Can not find this logic <" & logicName & ">" GetLogicInfo = "" Exit Function Else Set oMatch = oMatches(0) filePath = oMatch.SubMatches(0) lineNum = oMatch.SubMatches(1) End If GetLogicInfo = LocationLogic(logicName, filePath, lineNum) Set oRe = Nothing End FunctionFunction GetLogicNameFromGTR () ' It is empty now GetLogicNameFromGTR = "testLogic99956" End FunctionFunction GetLogicFilePath () ' 這種方式能夠讀取的註冊表有限制,功能更強的方式是採用winmgmts對象讀取,但是沒有這個簡單 GetLogicFilePath = WshShell.RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Evernote\Installer") GetLogicFilePath = "logic" End FunctionFunction InsertLogicInfoToScript (logicInfo) ' It is empty now InsertLogicInfoToScript = "It is empty now" End FunctionFunction OpenLogicFileInGTR () ' 尋找邏輯檔案及邏輯所在行數的方法與函數GetLogicInfo一樣 InsertLogicInfoToScript = "It is empty now" End FunctionFunction Main () Set objArgs = WScript.Arguments If objArgs.Count > 0 Then showMethod = objArgs(I) End If logicName = GetLogicNameFromGTR() FlashTagFile "tags", GetLogicFilePath() logicInfo = GetLogicInfo(logicName, "tags") Select Case showMethod ' 64 means show "Information Mark" icon. 'Case SW_LOGIC_IN_DLG WshShell.popup(logicInfo, 10, "邏輯提示,10秒後消失", 64) Case INSERT_LOGIC_TO_SCRIPT InsertLogicInfoToScript logicInfo Case OPEN_LOGIC_FILE OpenLogicFileInGTR Case Else WshShell.popup logicInfo, 10, "邏輯提示,10秒後消失", 64 End SelectEnd FunctionStartTime = TimerMainEndTime = TimerTimeIt = EndTime - StartTimeMsgBox "cast time " & TimeIt