3 ' vbslib ver1.00 2008/2/11
\r
4 ' Copyright (c) 2008, T's-Neko
\r
5 ' All rights reserved. 3-clause BSD license.
\r
7 Dim g_fs, g_log, e, g_workfolder
\r
9 Set g_fs = CreateObject("Scripting.FileSystemObject")
\r
15 '********************************************************************************
\r
16 ' <<< Error Code >>>
\r
17 '********************************************************************************
\r
19 ' vbObjectError = &h80040000
\r
20 Const E_AssertFail = &h80041001
\r
21 Const E_FileNotExist = 2
\r
22 Const E_TestFail = &h80041003
\r
23 Const E_BuildFail = &h80041004
\r
24 Const E_OutOfWorkFolder = &h80041005
\r
25 Const E_ProgTerminated = &hC0000005
\r
26 Const E_NotFoundSymbol = &h80041006
\r
27 Const E_ProgRetNotZero = &h80041007
\r
29 '********************************************************************************
\r
30 ' <<< File Object >>>
\r
31 '********************************************************************************
\r
37 '********************************************************************************
\r
38 ' <<< [ChgToCommandPrompt] If VBS file was double clicked, Run a command prompt >>>
\r
39 '********************************************************************************
\r
40 Sub ChgToCommandPrompt
\r
41 If LCase( Right( WScript.FullName, 11 ) ) = "wscript.exe" Then
\r
43 cmd = "cscript.exe " & Chr(34) & WScript.ScriptFullName & Chr(34)
\r
44 WScript.Quit CreateObject("WScript.Shell").Run( cmd, 1, True )
\r
50 '********************************************************************************
\r
52 '********************************************************************************
\r
53 Function input( ByVal msg )
\r
56 Wscript.StdOut.Write msg
\r
58 On Error Resume Next
\r
60 input = Wscript.StdIn.ReadLine
\r
62 e = Err.Number : Err.Clear : On Error GoTo 0
\r
64 If e <> 62 Then Err.Raise e '62= End Of File (StdIn, ^C)
\r
71 '********************************************************************************
\r
73 '********************************************************************************
\r
75 input "
\91±
\8ds
\82·
\82é
\82É
\82Í Enter
\83L
\81[
\82ð
\89\9f\82µ
\82Ä
\82
\82¾
\82³
\82¢ . . ."
\r
80 '********************************************************************************
\r
82 '********************************************************************************
\r
83 Sub echo( ByVal msg )
\r
85 If Not IsEmpty( g_log ) Then g_log.WriteLine msg
\r
89 '********************************************************************************
\r
90 ' <<< [cd] change current directory >>>
\r
93 '********************************************************************************
\r
97 Set sh = WScript.CreateObject("WScript.Shell")
\r
98 sh.CurrentDirectory = dir
\r
104 '********************************************************************************
\r
105 ' <<< [pushd] push and change current directory >>>
\r
108 '********************************************************************************
\r
109 Dim g_pushd_stack()
\r
110 Dim g_pushd_stack_n
\r
112 Sub pushd( ByVal dir )
\r
115 g_pushd_stack_n = g_pushd_stack_n + 1
\r
116 Redim Preserve g_pushd_stack( g_pushd_stack_n )
\r
118 Set sh = WScript.CreateObject("WScript.Shell")
\r
119 g_pushd_stack( g_pushd_stack_n ) = sh.CurrentDirectory
\r
120 sh.CurrentDirectory = dir
\r
126 '********************************************************************************
\r
127 ' <<< [popd] pop current directory >>>
\r
128 '********************************************************************************
\r
132 If g_pushd_stack_n < 1 Then Exit Sub
\r
134 Set sh = WScript.CreateObject("WScript.Shell")
\r
135 sh.CurrentDirectory = g_pushd_stack( g_pushd_stack_n )
\r
137 g_pushd_stack_n = g_pushd_stack_n - 1
\r
143 '********************************************************************************
\r
144 ' <<< [set_workfolder] Set modifiable base folder path >>>
\r
146 ' - if work path set current directory, path = ""
\r
147 '********************************************************************************
\r
148 Sub set_workfolder( ByVal path )
\r
153 g_workfolder = g_fs.GetAbsolutePathName( path )
\r
158 '********************************************************************************
\r
161 ' - src : source file or folder path or wild card
\r
162 ' - dst : destination folder path or renaming file path
\r
164 ' - reference: vbslib.svg#copy
\r
165 '********************************************************************************
\r
166 Sub copy( ByVal src, ByVal dst )
\r
168 If g_fs.FolderExists( dst ) Then
\r
169 chk_in_workfolder g_fs.BuildPath( dst, "a" )
\r
171 chk_in_workfolder dst
\r
175 ' If src had Wild card
\r
176 If IsWildcard( src ) Then
\r
180 If Not g_fs.FolderExists( dst ) Then mkdir dst
\r
182 g_fs.CopyFile src, dst, True
\r
183 g_fs.CopyFolder src, dst, True
\r
187 ElseIf g_fs.FileExists( src ) Then
\r
191 If g_fs.FolderExists( dst ) Then
\r
192 dst = g_fs.BuildPath( dst, g_fs.GetFileName( src ) )
\r
194 dst_fo = g_fs.GetParentFolderName( dst )
\r
195 If Not g_fs.FolderExists( dst_fo ) Then mkdir dst_fo
\r
198 g_fs.CopyFile src, dst, True
\r
202 ElseIf g_fs.FolderExists( src ) Then
\r
204 If Not g_fs.FolderExists( dst ) Then mkdir dst
\r
206 g_fs.CopyFolder src, g_fs.BuildPath( dst, g_fs.GetFileName( src ) ), True
\r
211 g_fs.CopyFile src, dst, True ' Error occurs
\r
218 '********************************************************************************
\r
220 '********************************************************************************
\r
221 Sub move( ByVal src, ByVal dst )
\r
223 If g_fs.FolderExists( dst ) Then
\r
224 chk_in_workfolder g_fs.BuildPath( dst, "a" )
\r
226 chk_in_workfolder dst
\r
230 ' If src had Wild card
\r
231 If IsWildcard( src ) Then
\r
235 If Not g_fs.FolderExists( dst ) Then mkdir dst
\r
237 g_fs.MoveFile src, dst
\r
238 g_fs.MoveFolder src, dst
\r
242 ElseIf g_fs.FileExists( src ) Then
\r
246 If g_fs.FolderExists( dst ) Then
\r
247 dst = g_fs.BuildPath( dst, g_fs.GetFileName( src ) )
\r
249 dst_fo = g_fs.GetParentFolderName( dst )
\r
250 If Not g_fs.FolderExists( dst_fo ) Then mkdir dst_fo
\r
253 g_fs.MoveFile src, dst
\r
257 ElseIf g_fs.FolderExists( src ) Then
\r
259 If Not g_fs.FolderExists( dst ) Then mkdir dst
\r
261 g_fs.MoveFolder src, g_fs.BuildPath( dst, g_fs.GetFileName( src ) )
\r
266 g_fs.MoveFile src, dst ' Error occurs
\r
273 '********************************************************************************
\r
275 '********************************************************************************
\r
276 Function exist( ByVal path )
\r
277 If IsWildcard( path ) Then
\r
278 Dim folder, fnames()
\r
279 ExpandWildcard folder, fnames, path
\r
280 exist = Array_count( fnames ) <> 0
\r
282 exist = ( g_fs.FileExists( path ) = True ) Or ( g_fs.FolderExists( path ) = True )
\r
286 '********************************************************************************
\r
287 ' <<< [chk_exist] >>>
\r
288 '********************************************************************************
\r
289 Sub chk_exist( ByVal path )
\r
290 If Not exist( path ) Then raise E_FileNotExist, path & " not found"
\r
293 '********************************************************************************
\r
294 ' <<< [chk_in_workfolder] Check not to modify out of working folder >>>
\r
296 ' - If path is out of workfolder, raise error of E_OutOfWorkFolder.
\r
297 '********************************************************************************
\r
298 Sub chk_in_workfolder( ByVal path )
\r
301 If g_workfolder = "" Then
\r
302 Set sh = WScript.CreateObject("WScript.Shell")
\r
303 work = sh.CurrentDirectory
\r
306 work = g_workfolder
\r
308 work = g_fs.BuildPath( work, "a" )
\r
309 work = Left( work, Len(work) - 1 )
\r
311 path = g_fs.GetAbsolutePathName( path )
\r
313 If work <> Left( path, Len( work ) ) Then
\r
314 raise E_OutOfWorkFolder, path & " is out of working folder"
\r
320 '********************************************************************************
\r
321 ' <<< [fc] diff text file >>>
\r
323 ' - return : True=same, False=different
\r
324 '********************************************************************************
\r
325 Function fc( ByVal pathA, ByVal pathB )
\r
328 If g_fs.FileExists( pathA ) Then
\r
331 If Not g_fs.FileExists( pathB ) Then fc=False : Exit Function
\r
333 Set sh = WScript.CreateObject("WScript.Shell")
\r
334 r = sh.Run( "fc.exe """ + pathA + """ """ + pathB + """", 7, True )
\r
335 If r = E_ProgTerminated Then raise E_ProgTerminated, "Program Terminated"
\r
340 ElseIf g_fs.FolderExists( pathA ) Then
\r
342 Dim foldersA, foldersB, folderA, folderB, foA, foB, step, f
\r
343 If Not g_fs.FolderExists( pathB ) Then fc=False : Exit Function
\r
345 pathA = g_fs.GetAbsolutePathName( pathA )
\r
346 pathB = g_fs.GetAbsolutePathName( pathB )
\r
347 GetSubFolders foldersA, pathA
\r
348 GetSubFolders foldersB, pathB
\r
350 If Array_count( foldersA ) <> Array_count( foldersB ) Then fc=False : Exit Function
\r
352 For Each folderA In foldersA
\r
353 step = Mid( folderA, Len( pathA ) + 1 )
\r
357 folderB = g_fs.BuildPath( pathB, step )
\r
360 Set foA = g_fs.GetFolder( folderA )
\r
361 Set foB = g_fs.GetFolder( folderB )
\r
363 If foA.Files.Count <> foB.Files.Count Then fc=False : Exit Function
\r
364 For Each f In foA.Files
\r
365 If Not fc( f.Path, folderB + Mid( f.Path, Len( folderA ) + 1 ) ) Then
\r
366 fc=False : Exit Function
\r
373 fc = False : Exit Function
\r
380 '********************************************************************************
\r
381 ' <<< [find] find lines including keyword >>>
\r
382 '********************************************************************************
\r
383 Function find( ByVal keyword, ByVal path )
\r
385 Set f = g_fs.OpenTextFile( path )
\r
388 Do Until f.AtEndOfStream
\r
390 If InStr( line, keyword ) > 0 Then ret = ret + line
\r
400 '********************************************************************************
\r
401 ' <<< [find_c] find lines count including keyword >>>
\r
402 '********************************************************************************
\r
403 Function find_c( ByVal keyword, ByVal path )
\r
405 Set f = g_fs.OpenTextFile( path )
\r
408 Do Until f.AtEndOfStream
\r
410 If InStr( line, keyword ) > 0 Then ret = ret + 1
\r
420 '********************************************************************************
\r
422 '********************************************************************************
\r
423 Sub del( ByVal path )
\r
425 ' If path had Wild card
\r
426 If IsWildCard( path ) Then
\r
427 Dim folder, fname, fnames()
\r
429 ExpandWildcard folder, fnames, path
\r
430 For Each fname in fnames
\r
431 del g_fs.BuildPath( folder, fname )
\r
434 ' If path was file or folder path
\r
437 If g_fs.FileExists( path ) Then
\r
438 chk_in_workfolder path
\r
439 g_fs.DeleteFile path
\r
440 ElseIf g_fs.FolderExists( path ) Then
\r
449 '********************************************************************************
\r
452 ' - return : count of made folder
\r
454 ' - This is able to make nested folder.
\r
455 '********************************************************************************
\r
456 Function mkdir( ByVal fo )
\r
457 Dim i, n, names(), fo2
\r
459 chk_in_workfolder fo
\r
462 fo2 = g_fs.GetAbsolutePathName( fo )
\r
464 If g_fs.FolderExists( fo2 ) Then Exit Do
\r
467 Redim Preserve names(n)
\r
468 names(n) = g_fs.GetFileName( fo2 )
\r
469 fo2 = g_fs.GetParentFolderName( fo2 )
\r
474 For n=n To 1 Step -1
\r
475 fo2 = g_fs.BuildPath( fo2, names(n) )
\r
476 g_fs.CreateFolder fo2
\r
481 '********************************************************************************
\r
483 '********************************************************************************
\r
484 Sub rmdir( ByVal path )
\r
485 Dim path2, iFolder, nFolder, fo, subf, f, file
\r
487 If Not g_fs.FolderExists( path ) Then Exit Sub
\r
489 chk_in_workfolder path
\r
494 If Right( path2, 1 ) = "\" Then path2 = Left( path2, Len( path2 ) - 1 )
\r
497 ReDim folderPathes(nFolder)
\r
498 folderPathes(nFolder) = path2
\r
502 While iFolder <= nFolder
\r
503 Set fo = g_fs.GetFolder( folderPathes(iFolder) )
\r
504 For Each subf in fo.SubFolders
\r
505 nFolder = nFolder + 1
\r
506 ReDim Preserve folderPathes(nFolder)
\r
507 folderPathes(nFolder) = subf.Path
\r
509 iFolder = iFolder + 1
\r
512 ' Remove read only attribute of all files in sub folders
\r
513 For iFolder = 1 To nFolder
\r
514 Set fo = g_fs.GetFolder( folderPathes(iFolder) )
\r
515 For Each f in fo.Files
\r
516 Set file = g_fs.GetFile( f.Path )
\r
517 file.Attributes = file.Attributes And Not ReadOnly
\r
522 g_fs.DeleteFolder( path )
\r
525 '********************************************************************************
\r
526 ' <<< [GetSubFolders] >>>
\r
528 ' - folders : (out) array of folder pathes
\r
529 ' - path : base folder path
\r
530 '********************************************************************************
\r
531 Sub GetSubFolders( folders, ByVal path )
\r
532 Array_toEmpty folders
\r
533 EnumSubFolders folders, g_fs.GetFolder( path )
\r
536 Sub EnumSubFolders( folders, fo )
\r
539 Array_push folders, fo.Path
\r
541 For Each subfo in fo.SubFolders
\r
542 EnumSubFolders folders, subfo
\r
546 '********************************************************************************
\r
547 ' <<< [IsWildcard] >>>
\r
548 '********************************************************************************
\r
549 Function IsWildcard( ByVal path )
\r
550 IsWildcard = InStr( path, "?" ) <> 0 Or InStr( path, "*" ) <> 0
\r
555 '********************************************************************************
\r
556 ' <<< [ExpandWildcard] >>>
\r
557 '********************************************************************************
\r
558 Sub ExpandWildcard( folder, fnames, ByVal wildcard )
\r
561 folder = g_fs.GetParentFolderName( g_fs.GetAbsolutePathName( wildcard ) )
\r
563 Set re = CreateObject("VBScript.RegExp")
\r
565 s = g_fs.GetFileName( wildcard )
\r
566 re.Pattern = "\\" : s = re.Replace( s, "\\" )
\r
567 re.Pattern = "\." : s = re.Replace( s, "\." )
\r
568 re.Pattern = "\$" : s = re.Replace( s, "\$" )
\r
569 re.Pattern = "\^" : s = re.Replace( s, "\^" )
\r
570 re.Pattern = "\{" : s = re.Replace( s, "\{" )
\r
571 re.Pattern = "\}" : s = re.Replace( s, "\}" )
\r
572 re.Pattern = "\[" : s = re.Replace( s, "\[" )
\r
573 re.Pattern = "\]" : s = re.Replace( s, "\]" )
\r
574 re.Pattern = "\(" : s = re.Replace( s, "\(" )
\r
575 re.Pattern = "\)" : s = re.Replace( s, "\)" )
\r
576 re.Pattern = "\|" : s = re.Replace( s, "\|" )
\r
577 re.Pattern = "\+" : s = re.Replace( s, "\+" )
\r
578 re.Pattern = "\*" : s = re.Replace( s, ".*" )
\r
579 re.Pattern = "\?" : s = re.Replace( s, "." )
\r
583 Array_toEmpty fnames
\r
584 Set fo = g_fs.GetFolder( folder )
\r
585 For Each f in fo.Files
\r
586 If re.Test( f.Name ) Then Array_push fnames, f.Name
\r
588 For Each f in fo.SubFolders
\r
589 If re.Test( f.Name ) Then Array_push fnames, f.Name
\r
594 '********************************************************************************
\r
596 '********************************************************************************
\r
597 Sub start( ByVal cmdline )
\r
600 Set sh = WScript.CreateObject("WScript.Shell")
\r
601 sh.Run cmdline, 1, False
\r
608 '********************************************************************************
\r
609 ' <<< [call_exe] >>>
\r
611 ' - It is possible to call .bat file.
\r
612 ' - cmdline is able to have environment variable.
\r
613 ' ex) call_exe """%ProgramFiles%\Movie Maker\moviemk.exe"""
\r
614 '********************************************************************************
\r
615 Function call_exe( ByVal cmdline )
\r
618 Set sh = WScript.CreateObject("WScript.Shell")
\r
620 cmdline = sh.ExpandEnvironmentStrings( cmdline )
\r
621 r = sh.Run( cmdline, 1, True )
\r
623 If r = E_ProgTerminated Then raise E_ProgTerminated, "Program Terminated"
\r
631 '********************************************************************************
\r
632 ' <<< [call_exe_r] redirect >>>
\r
633 '********************************************************************************
\r
634 Function call_exe_r( ByVal cmdline, ByVal inpath, ByVal outpath, ByVal errpath )
\r
635 Dim sh, ex, r, f, prev_txt
\r
637 If inpath <> "" Then raise E_AssertFail, "Not supported"
\r
639 Set sh = WScript.CreateObject( "WScript.Shell" )
\r
640 cmdline = sh.ExpandEnvironmentStrings( cmdline )
\r
642 Set ex = sh.Exec( cmdline )
\r
643 Do While ex.Status = 0
\r
647 If outpath <> "" Then
\r
650 If g_fs.FileExists( outpath ) Then
\r
651 Set f = g_fs.OpenTextFile( outpath, 1 )
\r
652 On Error Resume Next
\r
653 prev_txt = f.ReadAll
\r
654 e.Copy( Err ) : On Error GoTo 0 : If e.num <> 0 Then
\r
655 If e.num <> &h3E Then e.Raise
\r
660 Set f = g_fs.CreateTextFile( outpath, True, False )
\r
662 Do Until ex.StdOut.AtEndOfStream
\r
663 f.WriteLine ex.StdOut.ReadLine
\r
666 If outpath <> errpath Then
\r
670 If g_fs.FileExists( errpath ) Then
\r
671 Set f = g_fs.OpenTextFile( errpath, 1 )
\r
672 On Error Resume Next
\r
673 prev_txt = f.ReadAll
\r
674 e.Copy( Err ) : On Error GoTo 0 : If e.num <> 0 Then
\r
675 If e.num <> &h3E Then e.Raise
\r
681 Set f = g_fs.CreateTextFile( errpath, True, False )
\r
683 Do Until ex.StdErr.AtEndOfStream
\r
684 f.WriteLine ex.StdErr.ReadLine
\r
689 call_exe_r = ex.ExitCode
\r
693 '********************************************************************************
\r
694 ' <<< [call_vbs] >>>
\r
695 ' - path is able to have environment variable.
\r
696 ' ex) """%ProgramFiles%\Movie Maker\moviemk.exe"""
\r
697 '********************************************************************************
\r
698 Function call_vbs( ByVal path, ByVal func, ByVal param )
\r
699 Dim sh, oldDir, f, funcX, in_call
\r
702 Set sh = WScript.CreateObject("WScript.Shell")
\r
703 oldDir = sh.CurrentDirectory
\r
705 path = sh.ExpandEnvironmentStrings( path )
\r
706 path = g_fs.GetAbsolutePathName( path )
\r
709 On Error Resume Next 'try
\r
711 sh.CurrentDirectory = g_fs.GetParentFolderName( path )
\r
713 If Err=0 Then Set f = g_fs.OpenTextFile( g_fs.GetFileName( path ) ) : ExecuteGlobal f.ReadAll()
\r
714 If Err=&h411 Then Err.Clear ' Symbol Overrided
\r
715 If Err=0 Then Set funcX = GetRef( func )
\r
716 If Err=0 Then in_call = True : call_vbs = funcX( param )
\r
717 If Err=0 Then in_call = False
\r
719 e.Copy( Err ) : On Error GoTo 0 : If e.num <> 0 Then 'catch
\r
721 e.Source = func + " in " + path
\r
722 If path=WScript.ScriptFullName Then
\r
723 echo "If you want to debug, Call directory " + func + " before On Error Resume Next."
\r
725 echo "If you want to debug, Start "+g_fs.GetFileName(path)+" directly."
\r
728 If e.num = 5 Then raise E_NotFoundSymbol, "Not found func name '" + func + "' in " + path
\r
733 sh.CurrentDirectory = oldDir
\r
735 If e.num <> 0 Then e.Raise
\r
741 '********************************************************************************
\r
742 ' <<< [call_vbs_exe] >>>
\r
743 ' - path is able to have environment variable.
\r
744 ' ex) """%ProgramFiles%\Movie Maker\moviemk.exe"""
\r
745 ' - This function craetes new process.
\r
746 '********************************************************************************
\r
747 Function call_vbs_exe( ByVal path )
\r
748 Dim sh, oldDir, f, funcX, ex, log_bk_path, t, param
\r
750 Set sh = WScript.CreateObject("WScript.Shell")
\r
753 ' Nest test_log.txt
\r
754 If Not IsEmpty( g_log ) Then
\r
758 log_bk_path = "test_log_bk.txt"
\r
759 Set f = g_fs.GetFile( Test_DefLogFName )
\r
760 If exist( log_bk_path ) Then g_fs.DeleteFile log_bk_path
\r
761 f.Name = log_bk_path
\r
768 ' Change current directory
\r
769 oldDir = sh.CurrentDirectory
\r
771 path = sh.ExpandEnvironmentStrings( path )
\r
772 path = g_fs.GetAbsolutePathName( path )
\r
775 sh.CurrentDirectory = g_fs.GetParentFolderName( path )
\r
779 If log_bk_path <> "" Then param = " //nologo -sub_test" Else param = "" End If
\r
780 Set ex = sh.Exec( "CScript """ + path + """" + param )
\r
782 Do While ex.Status = 0
\r
786 Do Until ex.StdOut.AtEndOfStream
\r
787 echo ex.StdOut.ReadLine
\r
791 ' Return current directory
\r
792 sh.CurrentDirectory = oldDir
\r
795 ' Un-nest test_log.txt
\r
796 If log_bk_path <> "" Then
\r
797 If g_fs.FileExists( Test_DefLogFName ) Then
\r
798 Set f = g_fs.OpenTextFile( log_bk_path, 1 )
\r
805 Set f = g_fs.OpenTextFile( Test_DefLogFName, 1 )
\r
810 Set g_log = g_fs.CreateTextFile( Test_DefLogFName, 1 )
\r
813 g_fs.DeleteFile log_bk_path
\r
817 ' Get and raise error level
\r
818 If ex.ExitCode <> 0 Then
\r
819 raise E_ProgRetNotZero, CStr( ex.ExitCode )
\r
826 '********************************************************************************
\r
827 ' <<< [include] >>>
\r
828 '********************************************************************************
\r
829 Sub include( ByVal path )
\r
832 Set sh = WScript.CreateObject("WScript.Shell")
\r
834 path = sh.ExpandEnvironmentStrings( path )
\r
837 On Error Resume Next
\r
839 If Err=0 Then Set f = g_fs.OpenTextFile( g_fs.GetFileName( path ) ) : ExecuteGlobal f.ReadAll()
\r
840 If Err=&h411 Then Err.Clear ' Symbol Overrided
\r
842 e.Copy( Err ) : On Error GoTo 0
\r
843 If e.num=&h400 Or e.num=&h3EA Then e.Description = e.Description + " " + path ' No Statement
\r
844 If e.num <> 0 Then e.Raise
\r
847 '********************************************************************************
\r
848 ' <<< [env] Expand environment strings >>>
\r
849 '********************************************************************************
\r
850 Function env( ByVal s )
\r
851 Set sh = WScript.CreateObject("WScript.Shell")
\r
853 env = sh.ExpandEnvironmentStrings( s )
\r
858 '********************************************************************************
\r
859 ' <<< [devenv] Visual Studio 2005 command line build >>>
\r
862 ' devenv "sample.sln /rebuild", "Release"
\r
864 '********************************************************************************
\r
865 Sub devenv( ByVal param, ByVal config )
\r
867 Set sh = WScript.CreateObject("WScript.Shell")
\r
869 cmdline = Chr(34) + sh.RegRead( "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\VisualStudio\8.0\"+_
\r
870 "InstallDir" ) + "devenv.exe" + Chr(34) +_
\r
871 " " + param + " " + Chr(34) + config + Chr(34)
\r
872 r = call_exe( cmdline )
\r
874 If r <> 0 Then raise E_BuildFail, "devenv failed " + param + " in " + sh.CurrentDirectory
\r
879 '********************************************************************************
\r
880 ' <<< [devenv_clean] Visual Studio 2005 clean >>>
\r
883 ' devenv_clean "sample.sln"
\r
885 '********************************************************************************
\r
886 Sub devenv_clean( ByVal sln )
\r
887 devenv sln+" /clean", "Release"
\r
889 devenv sln+" /clean", "Debug"
\r
896 '********************************************************************************
\r
897 ' <<< [SendKeys] Send keyboard code stroke to OS >>>
\r
898 '********************************************************************************
\r
899 Sub SendKeys( ByVal window_title, ByVal keycords, ByVal late_time )
\r
901 Set sh = WScript.CreateObject("WScript.Shell")
\r
903 WScript.Sleep late_time
\r
904 sh.AppActivate( window_title )
\r
906 sh.SendKeys keycords
\r
912 '********************************************************************************
\r
914 '********************************************************************************
\r
915 Sub Sleep( ByVal msec )
\r
917 Set sh = WScript.CreateObject("WScript.Shell")
\r
925 '********************************************************************************
\r
926 ' <<< [WaitForFile] Wait for make the file >>>
\r
927 '********************************************************************************
\r
928 Sub WaitForFile( ByVal path )
\r
929 While g_fs.FileExists( path ) = False
\r
937 '********************************************************************************
\r
938 ' <<< [CreateFile] Create 1 line text file >>>
\r
939 '********************************************************************************
\r
940 Sub CreateFile( ByVal path, ByVal text )
\r
943 chk_in_workfolder path
\r
945 path = g_fs.GetAbsolutePathName( path )
\r
946 folder = g_fs.GetParentFolderName( path )
\r
949 Set t = g_fs.CreateTextFile( path, True, False )
\r
956 '********************************************************************************
\r
957 ' <<< [Array_toEmpty] >>>
\r
958 '********************************************************************************
\r
959 Sub Array_toEmpty( arr )
\r
963 '********************************************************************************
\r
964 ' <<< [Array_push] >>>
\r
965 '********************************************************************************
\r
966 Sub Array_push( arr, item )
\r
967 ReDim Preserve arr( UBound(arr) + 1 )
\r
968 arr( UBound(arr) ) = item
\r
971 '********************************************************************************
\r
972 ' <<< [Array_pop] >>>
\r
973 '********************************************************************************
\r
974 Function Array_pop( arr )
\r
975 Array_pop = arr( UBound(arr) )
\r
976 ReDim Preserve arr( UBound(arr) - 1 )
\r
979 '********************************************************************************
\r
980 ' <<< [Array_count] >>>
\r
981 '********************************************************************************
\r
982 Function Array_count( arr )
\r
983 Array_count = UBound(arr) + 1
\r
986 '********************************************************************************
\r
987 ' <<< [Array_echo] >>>
\r
988 '********************************************************************************
\r
989 Sub Array_echo( arr )
\r
992 WScript.Echo "count = " & Array_count( arr )
\r
993 ' WScript.Echo "LBound = " & LBound( arr ) & ", UBound = " & UBound( arr )
\r
995 WScript.Echo "each = " & i
\r
999 '********************************************************************************
\r
1000 ' <<< [raise] >>>
\r
1002 ' - e_num : E_AssertFail, E_TestFail ...
\r
1003 '********************************************************************************
\r
1004 Sub raise( ByVal e_num, ByVal e_desc )
\r
1005 Err.Raise e_num, "[ERROR] VBSLib", e_desc
\r
1010 '********************************************************************************
\r
1012 '********************************************************************************
\r
1015 Public num ' Err.Number
\r
1016 Public Description ' Err.Description (Error Message)
\r
1017 Public Source ' Err.Source
\r
1018 Public ErrID ' count of (num <> 0) in each first Copy after Clear
\r
1019 Public RaiseID ' count of (num <> 0) in Copy
\r
1021 Private Sub Class_Initialize
\r
1022 num = 0 : Description = "" : ErrID = 0 : RaiseID = 0
\r
1025 Public Sub Copy( err )
\r
1027 Description = err.Description
\r
1028 Source = err.Source
\r
1029 if num <> 0 Then RaiseID = RaiseID + 1 : if RaiseID = 1 Then ErrID = ErrID + 1
\r
1031 If ErrID = 1 Then Stop ' if debug, Enable this line and "If e.ErrID <> ErrID_of_this-1 Then On Error Resume Next" in caller
\r
1037 msg = "[ERROR] 0x" & Hex(num) & " " & Description & " ErrID=" & ErrID
\r
1039 If Not IsEmpty( g_log ) Then g_log.WriteLine msg
\r
1042 Public Sub OverRaise( e_num, e_desc )
\r
1043 num = vbObjectError + e_num
\r
1044 Description = e_desc
\r
1049 Err.Raise num, Source, Description
\r
1053 num = 0 : Description = "" : RaiseID = 0
\r
1058 '********************************************************************************
\r
1059 ' <<< [Test_init] >>>
\r
1060 '********************************************************************************
\r
1064 Const Test_DefLogFName = "test_log.txt"
\r
1067 Dim sub_test ' Boolean
\r
1069 Set g_log = g_fs.CreateTextFile( Test_DefLogFName, True, False )
\r
1072 If WScript.Arguments.Count >= 1 Then
\r
1073 If WScript.Arguments(0) = "-sub_test" Then sub_test = True
\r
1076 If Not sub_test Then echo "Test Start"
\r
1085 '********************************************************************************
\r
1086 ' <<< [Test_do] >>>
\r
1088 ' If test failed, raise E_TestFail, ""
\r
1089 '********************************************************************************
\r
1090 Sub Test_do( ByVal vbs_path, ByVal func, ByVal param )
\r
1091 echo "=========================================================="
\r
1092 echo "Test: " & vbs_path & " - " & func & " " & param
\r
1094 On Error Resume Next
\r
1095 call_vbs vbs_path, func, param
\r
1096 e.Copy( Err ) : On Error GoTo 0 : If e.num <> 0 Then
\r
1097 if e.num = vbObjectError Then
\r
1098 echo "[SKIP] " & e.Description
\r
1099 Test_nSkip = Test_nSkip + 1
\r
1102 Test_nNG = Test_nNG + 1
\r
1106 Test_nPass = Test_nPass + 1
\r
1114 '********************************************************************************
\r
1115 ' <<< [Test_exe] >>>
\r
1117 ' - func and param is dummy.
\r
1118 '********************************************************************************
\r
1119 Sub Test_exe( ByVal vbs_path, ByVal func, ByVal param )
\r
1121 On Error Resume Next
\r
1122 call_vbs_exe vbs_path
\r
1123 e.Copy( Err ) : On Error GoTo 0 : If e.num <> 0 Then
\r
1124 if e.num = vbObjectError Then
\r
1125 echo "[SKIP] " & e.Description
\r
1126 Test_nSkip = Test_nSkip + 1
\r
1129 Test_nNG = Test_nNG + 1
\r
1133 Test_nPass = Test_nPass + 1
\r
1140 '********************************************************************************
\r
1141 ' <<< [Test_skip] >>>
\r
1142 '********************************************************************************
\r
1143 Sub Test_skip( ByVal desc )
\r
1144 Err.Raise vbObjectError, "VBSLib", desc
\r
1149 '********************************************************************************
\r
1150 ' <<< [Test_finish] >>>
\r
1151 '********************************************************************************
\r
1153 Dim sub_test ' Boolean
\r
1156 If WScript.Arguments.Count >= 1 Then
\r
1157 If WScript.Arguments(0) = "-sub_test" Then sub_test = True
\r
1161 echo "=========================================================="
\r
1162 echo "Test Finish (Pass=" & Test_nPass & ", SKIP=" & Test_nSkip & ", ERROR=" & Test_nNG & ")"
\r
1164 If Test_nNG = 0 Then WScript.Quit 0 Else WScript.Quit 1 End If
\r