3 ' vbslib ver3.01 Dec.15, 2009
\r
4 ' Copyright (c) 2008-2009, T's-Neko at Sage Plaisir 21 (Japan)
\r
5 ' All rights reserved. Based on 3-clause BSD license.
\r
8 Dim g_vbslib_main_Path
\r
9 g_vbslib_main_Path = g_SrcPath
\r
13 '********************************************************************************
\r
14 ' <<< Global variables >>>
\r
15 '********************************************************************************
\r
17 Dim g_WritablePathes
\r
18 Dim g_Err2, g_EchoObj
\r
23 Dim g_CurrentWritables
\r
24 Dim g_FileSystemRetryMSec
\r
25 Dim g_Player '// as Vbslib_Player
\r
27 Function InitializeModule
\r
28 ReDim g_WritablePathes(-1)
\r
29 Set g_CurrentWritables = new CurrentWritables : ErrCheck
\r
30 Set g_EchoObj = new EchoObj : ErrCheck
\r
31 Set g_Err2 = new Err2 : ErrCheck
\r
32 Set g_CUI = new CUI : ErrCheck
\r
33 g_FileSystemRetryMSec = 10*1000
\r
35 Dim g_InitializeModule
\r
36 Set g_InitializeModule = GetRef( "InitializeModule" )
\r
38 Function FinalizeModule( ThisPath, Reason )
\r
40 g_Err2.OnSuccessFinish
\r
42 g_Err2.OnErrorFinish
\r
46 Dim g_FinalizeModule: Set g_FinalizeModule = GetRef( "FinalizeModule" )
\r
47 Dim g_FinalizeLevel: g_FinalizeLevel = 100 ' If smaller, called early
\r
52 Const F_SubFolder = 4
\r
54 Const g_PauseMsg = "
\91±
\8ds
\82·
\82é
\82É
\82Í Enter
\83L
\81[
\82ð
\89\9f\82µ
\82Ä
\82
\82¾
\82³
\82¢ . . . "
\r
55 Const g_PauseMsgStone = 24
\r
59 '********************************************************************************
\r
60 ' <<< Error Code >>>
\r
61 '********************************************************************************
\r
63 Dim E_Others : E_Others = 1
\r
65 Dim E_AssertFail : E_AssertFail = &h80041001
\r
66 Dim E_TestFail : E_TestFail = &h80041003
\r
67 Dim E_BuildFail : E_BuildFail = &h80041004
\r
68 Dim E_OutOfWritable : E_OutOfWritable = &h80041005
\r
69 Dim E_NotFoundSymbol : E_NotFoundSymbol = &h80041006
\r
70 Dim E_ProgRetNotZero : E_ProgRetNotZero = &h80041007
\r
71 Dim E_Unexpected : E_Unexpected = &h80041008
\r
73 Dim E_WIN32_FILE_NOT_FOUND: E_WIN32_FILE_NOT_FOUND = &h80070002
\r
74 Dim E_WIN32_DIRECTORY : E_WIN32_DIRECTORY = &h8007010B
\r
76 Dim E_ProgTerminated : E_ProgTerminated = &hC0000005
\r
78 Dim E_FileNotExist : E_FileNotExist = 53
\r
79 Dim E_EndOfFile : E_EndOfFile = 62
\r
80 Dim E_WriteAccessDenied : E_WriteAccessDenied = 70
\r
81 Dim E_PathNotFound : E_PathNotFound = 76
\r
82 Dim E_AlreadyExist : E_AlreadyExist = 58
\r
86 '********************************************************************************
\r
87 ' <<< File Object >>>
\r
88 '********************************************************************************
\r
94 '*-------------------------------------------------------------------------*
\r
95 '* ### <<<< Debugging >>>>
\r
96 '*-------------------------------------------------------------------------*
\r
100 '********************************************************************************
\r
101 ' <<< [g_count_up] >>>
\r
102 '********************************************************************************
\r
105 Function g_count_up( i )
\r
106 If i > UBound( g_count ) Then Redim Preserve g_count(i)
\r
107 g_count_up = g_count(i) + 1
\r
108 g_count(i) = g_count_up
\r
113 '********************************************************************************
\r
114 ' <<< [SetTestMode] >>>
\r
115 '********************************************************************************
\r
116 Dim F_NotRandom : F_NotRandom = 1
\r
117 Dim g_TestModeFlags
\r
119 Sub SetTestMode( Flags )
\r
120 g_TestModeFlags = Flags
\r
125 '*-------------------------------------------------------------------------*
\r
126 '* ### <<<< User Interface >>>>
\r
127 '*-------------------------------------------------------------------------*
\r
131 '********************************************************************************
\r
132 ' <<< [EchoObj] Class >>>
\r
133 '********************************************************************************
\r
136 Public m_bDisableEchoOff
\r
143 '********************************************************************************
\r
145 '********************************************************************************
\r
146 Function echo( ByVal msg )
\r
147 If g_EchoObj.m_bEchoOff Then Exit Function
\r
149 If not IsEmpty( msg ) Then
\r
150 msg = GetEchoString( msg )
\r
152 If g_CommandPrompt = 0 Then
\r
153 If IsEmpty( g_EchoObj.m_Buf ) Then
\r
154 g_EchoObj.m_Buf = msg
\r
156 g_EchoObj.m_Buf = g_EchoObj.m_Buf & vbCRLF & msg
\r
158 g_EchoObj.m_BufN = g_EchoObj.m_BufN + 1
\r
159 If g_EchoObj.m_BufN >= 20 Then echo_flush
\r
164 If not IsEmpty( g_Test ) Then g_Test.WriteLogLine msg
\r
171 '********************************************************************************
\r
172 ' <<< [GetEchoString] >>>
\r
173 '********************************************************************************
\r
174 Function GetEchoString( ByVal msg )
\r
175 If IsObject( msg ) Then msg = msg.Value
\r
177 If IsNull( msg ) Then
\r
179 ElseIf VarType( msg ) = vbBoolean Then
\r
180 If msg Then msg = "True" _
\r
182 ElseIf IsArray( msg ) Then
\r
183 Dim a : Set a = new ArrayClass : ErrCheck
\r
185 msg = GetEchoString( a )
\r
188 GetEchoString = msg
\r
193 '********************************************************************************
\r
194 ' <<< [echo_flush] >>>
\r
195 '********************************************************************************
\r
197 If g_CommandPrompt = 0 and g_EchoObj.m_BufN > 0 Then
\r
198 If MsgBox( g_EchoObj.m_Buf, vbOKCancel, WScript.ScriptName ) = vbCancel Then
\r
201 g_EchoObj.m_Buf = Empty
\r
202 g_EchoObj.m_BufN = 0
\r
209 '********************************************************************************
\r
210 ' <<< [EchoOff] >>>
\r
211 '********************************************************************************
\r
215 Private Sub Class_Initialize
\r
216 m_Prev = g_EchoObj.m_bEchoOff
\r
217 g_EchoObj.m_bEchoOff = not g_EchoObj.m_bDisableEchoOff
\r
220 Private Sub Class_Terminate
\r
221 g_EchoObj.m_bEchoOff = m_Prev
\r
227 '********************************************************************************
\r
228 ' <<< [DisableEchoOff] >>>
\r
229 '********************************************************************************
\r
231 g_EchoObj.m_bDisableEchoOff = True
\r
236 '********************************************************************************
\r
237 ' <<< [echo_r] >>>
\r
238 ' return: output message
\r
239 '********************************************************************************
\r
240 Function echo_r( ByVal msg, redirect_path )
\r
242 Const ForAppending = 8
\r
244 If IsObject( msg ) Then msg = msg.Value
\r
246 If g_debug Then WScript.Echo msg
\r
248 If IsEmpty( redirect_path ) Then
\r
249 ElseIf redirect_path = "" Then
\r
250 If Not g_debug Then WScript.Echo msg
\r
252 Set f = g_fs.OpenTextFile( redirect_path, ForAppending, True, False )
\r
261 '********************************************************************************
\r
262 ' <<< old I/F [echo_c] >>>
\r
263 '********************************************************************************
\r
264 Function echo_c( ByVal msg )
\r
265 If g_cut_old Then Stop
\r
266 echo_c = echo( msg )
\r
271 '********************************************************************************
\r
273 '********************************************************************************
\r
277 Set f = g_fs.OpenTextFile( path )
\r
279 Do Until f.AtEndOfStream
\r
286 '********************************************************************************
\r
288 '********************************************************************************
\r
290 If g_CommandPrompt = 0 Then
\r
291 echo "
\91±
\8ds
\82·
\82é
\82É
\82Í Enter
\83L
\81[
\82ð
\89\9f\82µ
\82Ä
\82
\82¾
\82³
\82¢ . . ."
\r
294 g_CUI.input_sub g_PauseMsg, False
\r
300 '********************************************************************************
\r
301 ' <<< [pause2] >>>
\r
302 '********************************************************************************
\r
304 If WScript.Arguments.Named("wscript")=1 Then input g_PauseMsg
\r
309 '********************************************************************************
\r
311 '********************************************************************************
\r
312 Function input( ByVal msg )
\r
314 input = g_CUI.input( msg )
\r
320 '********************************************************************************
\r
321 ' <<< [set_input] >>>
\r
322 '********************************************************************************
\r
323 Sub set_input( Keys )
\r
325 g_CUI.m_Auto_Keys = Keys
\r
331 '********************************************************************************
\r
332 ' <<< [InputPath] >>>
\r
333 '********************************************************************************
\r
334 Const F_ChkFileExists = 1
\r
335 Const F_ChkFolderExists = 2
\r
336 Const F_AllowEnterOnly = 4
\r
338 Function InputPath( Prompt, Flags )
\r
342 path = input( Prompt )
\r
343 path = Trim( path )
\r
345 If path = "" and ( Flags and F_AllowEnterOnly ) Then Exit Do
\r
347 If Left( path, 1 ) = """" and Right( path, 1 ) = """" Then _
\r
348 path = Mid( path, 2, Len( path ) - 2 )
\r
350 If Flags = 0 Then Exit Do
\r
351 If Flags and F_ChkFileExists Then
\r
352 If g_fs.FileExists( path ) Then Exit Do
\r
354 If Flags and F_ChkFolderExists Then
\r
355 If g_fs.FolderExists( path ) Then Exit Do
\r
363 '********************************************************************************
\r
364 ' <<< [SendKeys] Send keyboard code stroke to OS >>>
\r
365 '********************************************************************************
\r
366 Sub SendKeys( ByVal window_title, ByVal keycords, ByVal late_time )
\r
367 WScript.Sleep late_time
\r
368 If window_title <> "" Then
\r
369 If not g_sh.AppActivate( window_title ) Then _
\r
370 Raise E_NotFoundSymbol, "<ERROR msg='
\83E
\83B
\83\93\83h
\83E
\81E
\83^
\83C
\83g
\83\8b\82ª
\8c©
\82Â
\82©
\82è
\82Ü
\82¹
\82ñ' title='"& window_title &"'/>"
\r
373 g_sh.SendKeys keycords
\r
378 '*-------------------------------------------------------------------------*
\r
379 '* ### <<<< [CUI] Class >>>>
\r
380 '*-------------------------------------------------------------------------*
\r
384 Public m_Auto_InputFunc ' as string of auto input function name
\r
385 Public m_Auto_Src ' as string of path
\r
386 Public m_Auto_Keys ' as string of auto input keys
\r
387 Public m_Auto_KeyEnter ' as string of the character of replacing to enter key
\r
388 Public m_Auto_DebugCount ' as integer
\r
392 '********************************************************************************
\r
393 ' <<< [CUI::Class_Initialize] >>>
\r
394 '********************************************************************************
\r
395 Private Sub Class_Initialize
\r
396 Me.m_Auto_Keys = ""
\r
397 Me.m_Auto_KeyEnter = "."
\r
398 Me.m_Auto_DebugCount = Empty
\r
403 '********************************************************************************
\r
404 ' <<< [CUI::input] >>>
\r
405 '********************************************************************************
\r
406 Public Function input( ByVal msg )
\r
407 input = input_sub( msg, not IsEmpty( WScript.Arguments.Named.Item("GUI_input") ) )
\r
410 Public Function input_sub( ByVal msg, bGUI_input )
\r
414 If not IsEmpty( g_EchoObj.m_Buf ) Then msg = g_EchoObj.m_Buf + vbCRLF + msg
\r
415 g_EchoObj.m_Buf = Empty
\r
416 g_EchoObj.m_BufN = 0
\r
418 If msg = g_PauseMsg and Not IsEmpty( m_Auto_Keys ) And m_Auto_Keys <> "" Then
\r
419 '// Owner process does not wait in EchoStream
\r
420 Wscript.StdOut.Write Left( g_PauseMsg, g_PauseMsgStone )+"*"+Chr(8)+_
\r
421 Mid( g_PauseMsg, g_PauseMsgStone+1 )
\r
423 Wscript.StdOut.Write msg
\r
426 On Error Resume Next
\r
428 If Not IsEmpty( m_Auto_Keys ) And m_Auto_Keys <> "" Then
\r
429 If Not IsEmpty( m_Auto_KeyEnter ) Then
\r
430 e = InStr( m_Auto_Keys, m_Auto_KeyEnter )
\r
432 input_sub = m_Auto_Keys
\r
433 m_Auto_Keys = Empty
\r
435 input_sub = Left( m_Auto_Keys, e - 1 )
\r
436 m_Auto_Keys = Mid( m_Auto_Keys, e + 1 )
\r
439 input_sub = m_Auto_Keys
\r
440 m_Auto_Keys = Empty
\r
443 If IsEmpty( m_Auto_DebugCount ) Then
\r
444 Wscript.StdOut.WriteLine input_sub
\r
445 ElseIf m_Auto_DebugCount > 1 Then
\r
446 Wscript.StdOut.WriteLine input_sub
\r
447 m_Auto_DebugCount = m_Auto_DebugCount - 1
\r
449 Wscript.StdOut.Write input_sub
\r
451 input_sub = InputBox( msg, WScript.ScriptName, "" )
\r
452 Wscript.StdOut.WriteLine input_sub
\r
454 input_sub = StdIn_ReadLine_ForJP()
\r
456 Wscript.StdOut.WriteLine ""
\r
459 ElseIf IsEmpty( m_Auto_InputFunc ) Then
\r
461 input_sub = InputBox( msg, WScript.ScriptName, "" )
\r
462 Wscript.StdOut.WriteLine input_sub
\r
464 input_sub = StdIn_ReadLine_ForJP()
\r
467 If IsEmpty( m_Auto_Src ) Then
\r
468 Set InputFunc = GetRef( m_Auto_InputFunc )
\r
469 If Err.Number = 5 Then Wscript.StdOut.WriteLine vbCR+vbLF+"Not found function of """+_
\r
470 m_Auto_InputFunc +"""": Err.Clear
\r
471 If Not IsEmpty( InputFunc ) Then input_sub = InputFunc( msg )
\r
473 input_sub = call_vbs_t( m_Auto_Src, m_Auto_InputFunc, msg )
\r
474 If Err.Number = 5 Then Wscript.StdOut.WriteLine vbCR+vbLF+"Not found function of """+_
\r
475 m_Auto_InputFunc +""" in """+m_Auto_Src+"""" : Err.Clear
\r
476 If IsEmpty( input_sub ) Then Wscript.StdOut.Write msg : input_sub = StdIn_ReadLine_ForJP()
\r
480 e = Err.Number : Err.Clear : On Error GoTo 0
\r
482 If e <> 62 Then Err.Raise e '62= End Of File (StdIn, ^C)
\r
490 '********************************************************************************
\r
491 ' <<< [CUI::SetAutoKeysFromMainArg] >>>
\r
492 '********************************************************************************
\r
493 Public Sub SetAutoKeysFromMainArg
\r
494 If not IsEmpty( Me.m_Auto_Keys ) and Me.m_Auto_Keys = "" Then
\r
495 Me.m_Auto_Keys = WScript.Arguments.Named.Item("set_input")
\r
496 Me.m_Auto_DebugCount = WScript.Arguments.Named.Item("set_input_debug")
\r
506 '********************************************************************************
\r
507 ' <<< [StdIn_ReadLine_ForJP] >>>
\r
508 '********************************************************************************
\r
509 Function StdIn_ReadLine_ForJP()
\r
511 Const msg1 = "
\83R
\83}
\83\93\83h
\83v
\83\8d\83\93\83v
\83g
\82â InputBox
\82Å
\82Í
\81A254
\95¶
\8e\9a\88È
\8fã
\82Í
\93ü
\82è
\82Ü
\82¹
\82ñ
\81B"
\r
512 Const msg2 = "
\83R
\83}
\83\93\83h
\83v
\83\8d\83\93\83v
\83g
\82Å
\82Í
\81A
\89p
\95¶
\8e\9a\88È
\8aO
\82Ì
\8fê
\8d\87\81A128
\95¶
\8e\9a\88È
\8fã
\82Í
\93ü
\82è
\82Ü
\82¹
\82ñ
\81B"
\r
513 Const msg3 = "
\82à
\82¤
\88ê
\93x
\93ü
\97Í
\82µ
\82Ä
\82
\82¾
\82³
\82¢
\81B"
\r
516 r = WScript.StdIn.ReadLine
\r
518 If Len( r ) >= 254 Then
\r
519 WScript.StdOut.WriteLine msg1
\r
520 WScript.StdOut.Write msg3 + ">"
\r
521 ElseIf Len( r ) > 128 Then
\r
523 a = Asc( Mid( r, i, 1 ) )
\r
524 If a < 0 or a > 127 Then
\r
525 r = InputBox( msg2+msg3, WScript.ScriptName )
\r
526 While Len( r ) >= 254
\r
527 r = InputBox( msg1+msg3, WScript.ScriptName )
\r
529 WScript.StdOut.Write msg3 +">"+ r +vbCRLF
\r
539 StdIn_ReadLine_ForJP = r
\r
544 '*-------------------------------------------------------------------------*
\r
545 '* ### <<<< File >>>>
\r
546 '*-------------------------------------------------------------------------*
\r
550 '********************************************************************************
\r
551 ' <<< [AppKeyClass] >>>
\r
552 '********************************************************************************
\r
553 Const F_AskIfWarn = 0
\r
554 Const F_ErrIfWarn = 1
\r
555 Const F_IgnoreIfWarn = 2
\r
556 Const F_BreakIfWarn = 3
\r
561 Private m_WritableMode ' as Flags
\r
562 Private m_NewWritables()
\r
563 Public m_BreakByFName ' as string
\r
565 Private Sub Class_Initialize()
\r
566 m_WritableMode = F_AskIfWarn
\r
567 ReDim m_NewWritables(-1)
\r
570 Public Function SetKey( Key )
\r
571 If not IsEmpty( m_Key ) Then Err.Raise 1,,"Double Key"
\r
576 Public Sub SetKey_sub( Key )
\r
577 If not IsEmpty( m_Key ) Then Err.Raise 1,,"Double Key"
\r
578 m_bAppKey = ( Key Is g_AppKey )
\r
582 Public Function IsSame( Key )
\r
583 IsSame = ( m_Key Is Key ) and Key.IsSame_sub( Me )
\r
585 Public Function IsSame_sub( Key )
\r
586 IsSame_sub = ( m_Key Is Key )
\r
589 Public Sub CheckGlobalAppKey()
\r
590 If not m_bAppKey Then _
\r
591 MsgBox "[ERROR] This is not AppKey from main2"
\r
592 If not IsSame( g_AppKey ) Then _
\r
593 MsgBox "[ERROR] g_AppKey was overrided by unknown"
\r
595 Private Sub Class_Terminate()
\r
596 If m_bAppKey Then CheckGlobalAppKey
\r
600 '********************************************************************************
\r
601 ' <<< [AppKeyClass::NewWritable] >>>
\r
602 '********************************************************************************
\r
603 Public Function NewWritable( Pathes )
\r
604 Me.CheckGlobalAppKey
\r
605 Dim m : Set m = new Writables : ErrCheck
\r
606 m.SetPathes Me, Pathes
\r
607 Set NewWritable = m
\r
611 '********************************************************************************
\r
612 ' <<< [AppKeyClass::SetWritableMode] >>>
\r
613 '********************************************************************************
\r
614 Public Sub SetWritableMode( Flags )
\r
615 If g_AppKey Is Me Then
\r
616 If Flags = F_IgnoreIfWarn Then
\r
619 m_Key.SetWritableMode( Flags )
\r
625 Case F_AskIfWarn : echo ">SetWritableMode F_AskIfWarn"
\r
626 Case F_ErrIfWarn : echo ">SetWritableMode F_ErrIfWarn"
\r
627 Case F_IgnoreIfWarn:echo ">SetWritableMode F_IgnoreIfWarn"
\r
628 Case F_BreakIfWarn :echo ">SetWritableMode F_BreakIfWarn"
\r
629 Case Else : Err.Raise 1
\r
632 m_WritableMode = Flags
\r
635 Public Function GetWritableMode()
\r
636 If g_AppKey Is Me Then
\r
637 GetWritableMode = m_Key.GetWritableMode()
\r
639 GetWritableMode = m_WritableMode
\r
644 '********************************************************************************
\r
645 ' <<< [AppKeyClass::AddNewWritableFolder] >>>
\r
646 '********************************************************************************
\r
647 Public Sub AddNewWritableFolder( Path )
\r
648 AddNewWritableFolder_sub Path, Empty
\r
650 Public Sub AddNewWritableFolder_sub( Path, Opt )
\r
651 If g_AppKey Is Me Then m_Key.AddNewWritableFolder_sub Path, Opt : Exit Sub
\r
653 Dim abs_path, passed_path, out, b
\r
656 If g_debug_or_test Then
\r
657 If StrComp( g_AppKey.m_BreakByFName, g_fs.GetFileName( Path ), vbTextCompare ) = 0 Then
\r
658 echo_r "Break by """ + g_AppKey.m_BreakByFName + """", ""
\r
664 '// If the folder in writable folder, Do nothing
\r
665 abs_path = g_CurrentWritables.CheckWritable( Path, Opt )
\r
666 If IsEmpty( abs_path ) Then Exit Sub
\r
669 '// If it is not able to add new writable, raise warning.
\r
670 If not IsEmpty( g_CurrentWritables.CheckAddNewWritable( abs_path, out ) ) Then
\r
671 b=True: If not( IsEmpty( g_TempFile ) )Then b=( g_TempFile.m_FolderPath <> abs_path )
\r
672 If b Then '// C-language's ||
\r
673 CheckWritable abs_path : Exit Sub
\r
675 out = g_TempFile.m_FolderPath
\r
680 '// Add to m_NewWritables
\r
681 '// (sample) writable="C:\A\*", passed="C:\A", abs="C:\A\B" ... new="C:\A\B\"
\r
682 '// (sample) writable="C:\A\*", passed="C:\A", abs="C:\A\B\a.txt" ... new="C:\A\B\"
\r
683 '// (sample) writable="C:\A\*", passed="C:\A", abs="C:\A\B\C\a.txt" ... new="C:\A\B\"
\r
684 '// (sample) writable="C:\*", passed="C:", abs="C:\A\B\C\a.txt" ... new="C:\A\"
\r
686 ReDim Preserve m_NewWritables( UBound( m_NewWritables ) + 1 )
\r
688 Dim i : i = InStr( Len(passed_path)+2, abs_path, "\" )
\r
690 m_NewWritables( UBound( m_NewWritables ) ) = abs_path + "\"
\r
692 m_NewWritables( UBound( m_NewWritables ) ) = Left( abs_path, i )
\r
699 '********************************************************************************
\r
700 ' <<< [AppKeyClass::CheckNewWritable] >>>
\r
701 '********************************************************************************
\r
702 Public Function CheckNewWritable( AbsPath )
\r
703 If g_AppKey Is Me Then CheckNewWritable = m_Key.CheckNewWritable( AbsPath ) : Exit Function
\r
707 For Each writable In m_NewWritables
\r
708 If StrComp( writable, Left( AbsPath, Len( writable ) ), 1 ) = 0 Then Exit Function
\r
710 CheckNewWritable = AbsPath
\r
714 '********************************************************************************
\r
715 ' <<< [AppKeyClass::Ask] >>>
\r
716 '********************************************************************************
\r
717 Public Sub Ask( CheckPath )
\r
718 If g_AppKey Is Me Then m_Key.Ask( CheckPath ) : Exit Sub
\r
720 Dim msg2 : msg2 = "" : If exist( CheckPath ) Then msg2 = "Cannot overwrite, "
\r
723 For Each writable In g_CurrentWritables.CurrentPathes
\r
724 If Right( writable, 3 ) = "\*\" Then
\r
725 If Left( writable, Len(writable) - 2 ) = Left( CheckPath, Len( writable ) - 2 ) or _
\r
726 Left( writable, Len(writable) - 3 ) = CheckPath Then
\r
727 If g_fs.FileExists( CheckPath ) Then
\r
728 msg2 = "Cannot overwrite NOT NEW file, "
\r
730 msg2 = "Cannot overwrite NOT NEW folder, "
\r
736 If m_WritableMode <> F_ErrIfWarn Then
\r
737 echo_r GetWarningMessage( msg2, CheckPath ), ""
\r
740 If m_WritableMode = F_AskIfWarn Then
\r
744 If g_CommandPrompt = 0 Then
\r
745 s = InputBox( "
\92¼
\91O
\82Ì
\83_
\83C
\83A
\83\8d\83O
\83E
\83B
\83\93\83h
\83E
\82É
\95\
\8e¦
\82µ
\82½
\83p
\83X
\82É
\83t
\83@
\83C
\83\8b\82ð
\8fo
\97Í
\82µ
\82Ü
\82·
\81B" & vbCRLF & _
\r
746 "(Y)
\82Í
\82¢
\81B
\83t
\83@
\83C
\83\8b\8fo
\97Í
\82ð
\8b\96\89Â
\82µ
\82Ü
\82·" & vbCRLF & "(A)
\88È
\8cã
\81A
\82·
\82×
\82Ä
\82Í
\82¢" & vbCRLF & _
\r
747 "(N)
\82¢
\82¢
\82¦
\81B
\83v
\83\8d\83O
\83\89\83\80\82ð
\8fI
\97¹
\82µ
\82Ü
\82·" & vbCRLF & "(R)
\83p
\83X
\82ð
\82à
\82¤
\88ê
\93x
\95\
\8e¦
\82µ
\82Ü
\82·", _
\r
748 "[WARNING] " +msg2+ "Out of Writable", "Y" )
\r
750 s = InputBox( "
\83R
\83}
\83\93\83h
\83v
\83\8d\83\93\83v
\83g
\82É
\95\
\8e¦
\82µ
\82½
\83p
\83X
\82É
\83t
\83@
\83C
\83\8b\82ð
\8fo
\97Í
\82µ
\82Ü
\82·
\81B" & vbCRLF & _
\r
751 "(Y)
\82Í
\82¢
\81B
\83t
\83@
\83C
\83\8b\8fo
\97Í
\82ð
\8b\96\89Â
\82µ
\82Ü
\82·" & vbCRLF & "(A)
\88È
\8cã
\81A
\82·
\82×
\82Ä
\82Í
\82¢" & vbCRLF & _
\r
752 "(N)
\82¢
\82¢
\82¦
\81B
\83v
\83\8d\83O
\83\89\83\80\82ð
\8fI
\97¹
\82µ
\82Ü
\82·" & vbCRLF & "(R)
\83p
\83X
\82ð
\82à
\82¤
\88ê
\93x
\95\
\8e¦
\82µ
\82Ü
\82·", _
\r
753 "[WARNING] " +msg2+ "Out of Writable", "Y" )
\r
756 If s="Y" or s="y" Then
\r
758 ElseIf s="A" or s="a" Then
\r
759 SetWritableMode F_IgnoreIfWarn
\r
761 ElseIf s="R" or s="r" Then
\r
762 MsgBox CheckPath, vbOKOnly, "[WARNING] Out of Writable"
\r
764 Err.Raise E_OutOfWritable,, "Out of Writable """ & CheckPath & """"
\r
765 ' Watch g_CurrentWritables.CurrentPathes and CheckPath
\r
770 If m_WritableMode = F_BreakIfWarn Then Stop '// Look at caller function using debugger
\r
771 If m_WritableMode = F_BreakIfWarn or m_WritableMode = F_ErrIfWarn Then
\r
772 echo_r GetWarningMessage( msg2, CheckPath ), ""
\r
773 Err.Raise E_OutOfWritable,, msg2+"Out of Writable """ & CheckPath & """"
\r
774 ' Watch g_CurrentWritables.CurrentPathes and Path (CheckPath)
\r
779 Public Function GetWarningMessage( msg2, CheckPath )
\r
782 s = "<Warning msg='" +msg2+ "Out of Writable, see the help of SetWritableMode.'" +_
\r
783 " path='" & CheckPath & "'>"+vbCRLF
\r
785 For Each writable In g_CurrentWritables.CurrentPathes
\r
786 s=s+ " <Writable path='"+ writable +"'/>"+vbCRLF
\r
788 GetWarningMessage = s+ "</Warning>"
\r
793 '********************************************************************************
\r
794 ' <<< [AppKeyClass::InPath] >>>
\r
795 '********************************************************************************
\r
796 Public Function InPath( ChkPathes, WritablePathes )
\r
797 If TypeName( ChkPathes ) = "ArrayClass" Then
\r
798 InPath = InPath( ChkPathes.m_Array, WritablePathes )
\r
801 If TypeName( WritablePathes ) = "ArrayClass" Then
\r
802 InPath = InPath( ChkPathes, WritablePathes.m_Array )
\r
808 '// ChkPathes To abs path
\r
809 If IsArray( ChkPathes ) Then
\r
810 ReDim cs( UBound( ChkPathes ) )
\r
811 For i=0 To UBound( cs )
\r
812 cs(i) = g_fs.GetAbsolutePathName( ChkPathes(i) ) + "\"
\r
816 cs(0) = g_fs.GetAbsolutePathName( ChkPathes ) + "\"
\r
820 '// WritablePathes To abs path
\r
821 If IsArray( WritablePathes ) Then
\r
822 ReDim ws( UBound( WritablePathes ) )
\r
823 For i=0 To UBound( ws )
\r
824 ws(i) = g_fs.GetAbsolutePathName( WritablePathes(i) ) + "\"
\r
828 ws(0) = g_fs.GetAbsolutePathName( WritablePathes ) + "\"
\r
836 If Left( c, Len(w) ) = w Then b = True : Exit For
\r
838 If not b Then InPath = False : Exit Function
\r
847 '********************************************************************************
\r
848 ' <<< [AppKeyClass::BreakByPath] >>>
\r
849 '********************************************************************************
\r
850 Public Function BreakByPath( Path )
\r
851 If StrComp( m_BreakByFName, g_fs.GetFileName( Path ), vbTextCompare ) = 0 Then
\r
852 echo_r "Break by """ + g_AppKey.m_BreakByFName + """", ""
\r
860 '********************************************************************************
\r
861 ' <<< [AppKeyClass::BreakByWildcard] >>>
\r
862 '********************************************************************************
\r
863 Public Function BreakByWildcard( Path, Flags )
\r
864 Dim folder, fnames()
\r
867 ExpandWildcard Path, Flags, folder, fnames
\r
868 For Each fname in fnames
\r
869 If StrComp( m_BreakByFName, g_fs.GetFileName( fname ), vbTextCompare ) = 0 Then
\r
870 echo_r "Break by """ + g_AppKey.m_BreakByFName + """", ""
\r
880 '********************************************************************************
\r
881 ' <<< [Writables] Class >>>
\r
882 '********************************************************************************
\r
887 Public Sub SetPathes( AppKey, Pathes )
\r
890 If not IsEmpty( m_AppKey ) Then Err.Raise 1,,"Double key"
\r
891 If not g_AppKey.IsSame( AppKey ) Then Err.Raise 1,,"Invalied AppKey"
\r
893 GetObject_g_TempFile
\r
895 If IsArray( Pathes ) Then
\r
896 ReDim m_Pathes( UBound( Pathes ) + 1 )
\r
897 For i=0 To UBound( Pathes )
\r
898 abs_path = GetAbsPath( Pathes(i), Empty )
\r
899 g_CurrentWritables.AskFileAccess abs_path
\r
900 m_Pathes(i) = abs_path + "\"
\r
902 ElseIf TypeName( Pathes ) = "ArrayClass" Then
\r
903 ReDim m_Pathes( UBound( Pathes.m_Array ) + 1 )
\r
904 For i=0 To UBound( Pathes.m_Array )
\r
905 abs_path = GetAbsPath( Pathes(i), Empty )
\r
906 g_CurrentWritables.AskFileAccess abs_path
\r
907 m_Pathes(i) = abs_path + "\"
\r
910 ReDim m_Pathes( 1 )
\r
911 abs_path = GetAbsPath( Pathes, Empty )
\r
912 g_CurrentWritables.AskFileAccess abs_path
\r
913 m_Pathes(0) = abs_path + "\"
\r
916 m_Pathes( UBound( m_Pathes ) ) = g_TempFile.m_FolderPath '// Last is Temp
\r
918 Set m_AppKey = AppKey
\r
921 Public Function Enable()
\r
922 Dim st : Set st = new WritablesStack : ErrCheck
\r
923 st.PushPathes m_AppKey, m_Pathes
\r
930 '********************************************************************************
\r
931 ' <<< [WritablesStack] Class >>>
\r
932 '********************************************************************************
\r
933 Class WritablesStack
\r
937 Public Sub PushPathes( AppKey, Pathes )
\r
938 Set m_Pathes = new ArrayClass : ErrCheck
\r
939 m_Pathes.Copy Pathes
\r
940 Set m_AppKey = AppKey
\r
941 g_CurrentWritables.PushPathes AppKey, Pathes
\r
944 Private Sub Class_Terminate()
\r
945 g_CurrentWritables.PopPathes m_AppKey, m_Pathes
\r
951 '********************************************************************************
\r
952 ' <<< [CurrentWritables] Class >>>
\r
953 '********************************************************************************
\r
954 Class CurrentWritables
\r
955 Private m_PathesStack ' as ArrayClass of ArrayClass
\r
957 Private m_ProgramFiles
\r
960 Private m_LOCALAPPDATA
\r
962 Public Property Get CurrentPathes
\r
963 If m_PathesStack.Count > 0 Then
\r
964 CurrentPathes = m_PathesStack.m_Array( m_PathesStack.Count-1 ).m_Array
\r
966 CurrentPathes = m_PathesStack.m_Array
\r
969 Public Property Get PathesStack : Set PathesStack = m_PathesStack : End Property
\r
972 Private Sub Class_Initialize()
\r
973 Set m_PathesStack = new ArrayClass : ErrCheck
\r
975 m_ProgramFiles = g_sh.ExpandEnvironmentStrings( "%ProgramFiles%" )
\r
976 m_windir = g_sh.ExpandEnvironmentStrings( "%windir%" )
\r
977 m_APPDATA = g_sh.ExpandEnvironmentStrings( "%APPDATA%" )
\r
978 m_LOCALAPPDATA = g_sh.ExpandEnvironmentStrings( "%LOCALAPPDATA%" )
\r
980 If m_ProgramFiles = "%ProgramFiles%" Then m_ProgramFiles = Empty
\r
981 If m_windir = "%windir%" Then m_windir = Empty
\r
982 If m_APPDATA = "%APPDATA%" Then m_APPDATA = Empty
\r
983 If m_LOCALAPPDATA = "%LOCALAPPDATA%" Then m_LOCALAPPDATA = Empty
\r
987 Public Sub PushPathes( AppKey, Pathes )
\r
989 If not g_AppKey.IsSame( AppKey ) Then Err.Raise 1,,"Invalied AppKey"
\r
990 Dim new_pathes : Set new_pathes = new ArrayClass : ErrCheck
\r
991 new_pathes.Copy Pathes
\r
992 m_PathesStack.Push new_pathes
\r
996 Public Sub PopPathes( AppKey, Pathes )
\r
999 If not g_AppKey.IsSame( AppKey ) Then Err.Raise 1,,"Invalied AppKey"
\r
1001 For i=m_PathesStack.Count-1 To 0 Step -1
\r
1002 If Pathes.Count = m_PathesStack.m_Array(i).Count Then
\r
1003 For j=0 To Pathes.Count-1
\r
1004 If Pathes.m_Array(j) <> m_PathesStack.m_Array(i).m_Array(j) Then Exit For
\r
1006 If j = Pathes.Count Then Exit For '// If same all Pathes
\r
1009 If i = -1 Then Err.Raise 1
\r
1011 For i=i To m_PathesStack.Count-2
\r
1012 Set m_PathesStack.m_Array(i) = m_PathesStack.m_Array(i+1)
\r
1018 Public Function CheckWritable( Path, Opt )
\r
1019 Dim abs_path, writable, s
\r
1020 abs_path = g_fs.GetAbsolutePathName( Path )
\r
1021 If Right( Path, 2 ) = "\." Then abs_path = abs_path + "\."
\r
1023 For Each writable In Me.CurrentPathes
\r
1024 If StrComp( writable, Left( abs_path, Len( writable ) ), 1 ) = 0 Then Exit Function
\r
1027 s = abs_path + "\"
\r
1028 For Each writable In Me.CurrentPathes
\r
1029 If StrComp( writable, s, 1 ) = 0 Then Exit Function
\r
1033 s = abs_path : If Right( s, 2 ) = "\." Then s = Left( s, Len( s ) - 1 )
\r
1034 For Each writable In Me.CurrentPathes
\r
1035 If StrComp( s, Left( writable, Len( s ) ), 1 ) = 0 Then Exit Function
\r
1039 abs_path = g_AppKey.CheckNewWritable( abs_path )
\r
1040 If IsEmpty( abs_path ) Then Exit Function
\r
1042 If Right( abs_path, 2 ) = "\." Then abs_path = Left( abs_path, Len( abs_path ) - 2 )
\r
1043 CheckWritable = abs_path
\r
1047 Public Function CheckAddNewWritable( Path, out_PassedPath )
\r
1048 Dim abs_path, writable
\r
1049 abs_path = g_fs.GetAbsolutePathName( Path )
\r
1050 If Right( Path, 2 ) = "\." Then abs_path = abs_path + "\."
\r
1052 If not exist( Path ) Then
\r
1053 '// If the folder already exists, do not writable
\r
1055 For Each writable In Me.CurrentPathes
\r
1056 If Right( writable, 3 ) = "\*\" Then
\r
1057 If Left( writable, Len(writable) - 2 ) = Left( abs_path, Len( writable ) - 2 ) or _
\r
1058 Left( writable, Len(writable) - 3 ) = abs_path Then
\r
1059 out_PassedPath = Left( writable, Len(writable) - 3 )
\r
1066 If Right( abs_path, 2 ) = "\." Then abs_path = Left( abs_path, Len( abs_path ) - 2 )
\r
1067 CheckAddNewWritable = abs_path
\r
1071 Public Sub AskFileAccess( AbsPath )
\r
1072 If Left( AbsPath, Len( g_TempFile.m_FolderPath ) + 1 ) = g_TempFile.m_FolderPath + "\" Then _
\r
1075 If not IsEmpty( m_ProgramFiles ) Then _
\r
1076 If Left( AbsPath, Len( m_ProgramFiles ) ) = m_ProgramFiles or _
\r
1077 Left( m_ProgramFiles, Len( AbsPath ) ) = AbsPath Then _
\r
1078 g_AppKey.Ask AbsPath
\r
1080 If not IsEmpty( m_windir ) Then _
\r
1081 If Left( AbsPath, Len( m_windir ) ) = m_windir or _
\r
1082 Left( m_windir, Len( AbsPath ) ) = AbsPath Then _
\r
1083 g_AppKey.Ask AbsPath
\r
1085 If not IsEmpty( m_APPDATA ) Then _
\r
1086 If Left( AbsPath, Len( m_APPDATA ) ) = m_APPDATA or _
\r
1087 Left( m_APPDATA, Len( AbsPath ) ) = AbsPath Then _
\r
1088 g_AppKey.Ask AbsPath
\r
1090 If not IsEmpty( m_LOCALAPPDATA ) Then _
\r
1091 If Left( AbsPath, Len( m_LOCALAPPDATA ) ) = m_LOCALAPPDATA or _
\r
1092 Left( m_LOCALAPPDATA, Len( AbsPath ) ) = AbsPath Then _
\r
1093 g_AppKey.Ask AbsPath
\r
1100 '********************************************************************************
\r
1101 ' <<< [SetWritableMode] >>>
\r
1102 '********************************************************************************
\r
1103 Sub SetWritableMode( Flags )
\r
1104 g_AppKey.SetWritableMode Flags
\r
1108 '********************************************************************************
\r
1109 ' <<< [CheckWritable] Check not to modify out of working folder >>>
\r
1111 ' - If path is out of workfolder, raise error of E_OutOfWritable.
\r
1112 ' - This function is overritable, because other APIs calling this and g_CurrentWritables
\r
1114 '********************************************************************************
\r
1115 Sub CheckWritable( Path )
\r
1118 abs_path = g_CurrentWritables.CheckWritable( Path, Empty )
\r
1119 If IsEmpty( abs_path ) Then Exit Sub
\r
1120 g_AppKey.Ask abs_path
\r
1125 '********************************************************************************
\r
1126 ' <<< [set_workfolder] old function >>>
\r
1127 '********************************************************************************
\r
1128 Sub set_workfolder( ByVal dir )
\r
1129 If g_cut_old Then Stop
\r
1133 Class WorkFolderStack
\r
1134 Private Sub Class_Initialize()
\r
1135 If g_cut_old Then Stop
\r
1137 Public Sub set_( x ) : End Sub
\r
1140 '********************************************************************************
\r
1141 ' <<< [SetBreakByFName] >>>
\r
1142 '********************************************************************************
\r
1143 Sub SetBreakByFName( FName )
\r
1144 g_AppKey.m_BreakByFName = FName
\r
1148 '********************************************************************************
\r
1149 ' <<< [cd] change current directory >>>
\r
1152 '********************************************************************************
\r
1153 Sub cd( ByVal dir )
\r
1154 echo ">cd """ & dir & """"
\r
1158 On Error Resume Next
\r
1159 g_sh.CurrentDirectory = dir
\r
1160 en = Err.Number : ed = Err.Description : On Error GoTo 0
\r
1161 If en = E_WIN32_FILE_NOT_FOUND or en = E_WIN32_DIRECTORY Then _
\r
1162 Err.Raise en,, "
\83t
\83H
\83\8b\83_
\82Å
\82Í
\82 \82è
\82Ü
\82¹
\82ñ : " & dir
\r
1163 If en <> 0 Then Err.Raise en,,ed
\r
1169 '********************************************************************************
\r
1170 ' <<< [CurDirStack] >>>
\r
1171 '********************************************************************************
\r
1176 Private Sub Class_Initialize
\r
1177 m_Prev = g_sh.CurrentDirectory
\r
1180 Private Sub Class_Terminate
\r
1181 g_sh.CurrentDirectory = m_Prev
\r
1187 '********************************************************************************
\r
1188 ' <<< [pushd] push and change current directory >>>
\r
1191 '********************************************************************************
\r
1192 Dim g_pushd_stack()
\r
1193 Dim g_pushd_stack_n
\r
1195 Sub pushd( ByVal dir )
\r
1196 echo ">pushd " & dir
\r
1199 g_pushd_stack_n = g_pushd_stack_n + 1
\r
1200 Redim Preserve g_pushd_stack( g_pushd_stack_n )
\r
1202 Set sh = WScript.CreateObject("WScript.Shell")
\r
1203 g_pushd_stack( g_pushd_stack_n ) = sh.CurrentDirectory
\r
1204 sh.CurrentDirectory = dir
\r
1210 '********************************************************************************
\r
1211 ' <<< [popd] pop current directory >>>
\r
1212 '********************************************************************************
\r
1217 If g_pushd_stack_n < 1 Then Exit Sub
\r
1219 Set sh = WScript.CreateObject("WScript.Shell")
\r
1220 sh.CurrentDirectory = g_pushd_stack( g_pushd_stack_n )
\r
1222 g_pushd_stack_n = g_pushd_stack_n - 1
\r
1228 '********************************************************************************
\r
1231 ' - src : source file or folder path or wild card
\r
1232 ' - dst : destination folder path or renaming file path
\r
1234 ' - reference: vbslib.svg#copy
\r
1235 '********************************************************************************
\r
1236 Sub copy( ByVal src, ByVal dst )
\r
1239 ' If src had Wild card
\r
1240 If IsWildcard( src ) Then
\r
1244 echo ">copy """ & src & """, """ & dst & """"
\r
1245 If Not g_fs.FolderExists( dst ) Then Set en=new EchoOff : mkdir dst : en=Empty
\r
1246 If Not g_fs.FolderExists( GetParentAbsPath( src ) ) Then _
\r
1247 Err.Raise E_PathNotFound,,"
\83p
\83X
\82ª
\8c©
\82Â
\82©
\82è
\82Ü
\82¹
\82ñ
\81B"
\r
1249 g_AppKey.AddNewWritableFolder dst + "\." '// "\." is for able to make writable folder
\r
1250 If g_debug_or_test Then g_AppKey.BreakByWildcard src, F_File
\r
1252 On Error Resume Next
\r
1253 g_fs.CopyFile src, dst, True
\r
1254 en = Err.Number : ed = Err.Description : On Error GoTo 0
\r
1255 If en = E_FileNotExist Then en = 0
\r
1256 If en <> 0 Then Err.Raise en,,ed
\r
1258 Dim i_retry '// 1
\89ñ
\96Ú
\82É E_WriteAccessDenied
\82É
\82È
\82é
\82±
\82Æ
\82ª
\82½
\82Ü
\82É
\82 \82é
\82½
\82ß
\r
1259 For i_retry = 1 To 2
\r
1260 On Error Resume Next
\r
1261 g_fs.CopyFolder src, dst, True
\r
1262 en = Err.Number : ed = Err.Description : On Error GoTo 0
\r
1263 If en = E_PathNotFound Then en = 0
\r
1264 If i_retry >= 2 and en <> E_WriteAccessDenied Then
\r
1265 If en <> 0 Then Err.Raise en,,ed
\r
1267 If en = 0 Then Exit For
\r
1269 echo_r "<WARNING msg='" & ed & "' msg2='
\8dÄ
\8e\8e\8ds
\82µ
\82Ä
\82¢
\82Ü
\82·'/>", ""
\r
1270 Sleep g_FileSystemRetryMSec
\r
1274 ElseIf g_fs.FileExists( src ) Then
\r
1278 If g_fs.FolderExists( dst ) Then
\r
1279 dst = g_fs.BuildPath( dst, g_fs.GetFileName( src ) )
\r
1281 dst_fo = GetParentAbsPath( dst )
\r
1282 If dst_fo <> "" And Not g_fs.FolderExists( dst_fo ) Then _
\r
1283 Set en=new EchoOff : mkdir dst_fo : en=Empty
\r
1286 echo ">copy """ & src & """, """ & dst & """"
\r
1287 If not g_fs.FileExists( dst ) Then
\r
1288 g_AppKey.AddNewWritableFolder dst + "\." '// "\." is for able to make writable folder
\r
1290 g_AppKey.AddNewWritableFolder dst
\r
1293 On Error Resume Next
\r
1294 g_fs.CopyFile src, dst, True
\r
1295 en = Err.Number : ed = Err.Description : On Error GoTo 0
\r
1296 If en = 70 Then ed = ed + " : " + dst
\r
1297 If en <> 0 Then Err.Raise en,,ed
\r
1300 ' If src is folder
\r
1301 ElseIf g_fs.FolderExists( src ) Then
\r
1303 If Not g_fs.FolderExists( dst ) Then Set en=new EchoOff : mkdir dst : en=Empty
\r
1305 echo ">copy """ & src & """, """ & dst & """"
\r
1306 g_AppKey.AddNewWritableFolder dst
\r
1307 If g_debug_or_test Then g_AppKey.BreakByWildcard src+"\*", F_File or F_SubFolder
\r
1309 g_fs.CopyFolder src, g_fs.BuildPath( dst, g_fs.GetFileName( src ) ), True
\r
1314 echo ">copy """ & src & """, """ & dst & """"
\r
1315 g_AppKey.AddNewWritableFolder dst + "\." '// "\." is for able to make writable folder
\r
1316 g_fs.CopyFile src, dst, True ' Error occurs
\r
1323 '********************************************************************************
\r
1325 '********************************************************************************
\r
1326 Sub move( ByVal src, ByVal dst )
\r
1328 ' If src had Wild card
\r
1329 If IsWildcard( src ) Then
\r
1333 If Not g_fs.FolderExists( dst ) Then mkdir dst
\r
1334 echo ">move """ & src & """, """ & dst & """"
\r
1335 If Not g_fs.FolderExists( g_fs.GetParentFolderName( src ) ) Then _
\r
1336 Err.Raise E_PathNotFound,,"
\83p
\83X
\82ª
\8c©
\82Â
\82©
\82è
\82Ü
\82¹
\82ñ
\81B"
\r
1338 g_AppKey.AddNewWritableFolder dst + "\." '// "\." is for able to make writable folder
\r
1339 If g_debug_or_test Then g_AppKey.BreakByWildcard src, F_File
\r
1341 On Error Resume Next
\r
1342 g_fs.MoveFile src, dst
\r
1343 g_fs.MoveFolder src, dst
\r
1344 en = Err.Number : ed = Err.Description : On Error GoTo 0
\r
1345 If en = E_PathNotFound Then en = 0
\r
1346 If en = E_FileNotExist Then en = 0
\r
1347 If en <> 0 Then Err.Raise en,,ed
\r
1351 ElseIf g_fs.FileExists( src ) Then
\r
1355 If g_fs.FolderExists( dst ) Then
\r
1356 dst = g_fs.BuildPath( dst, g_fs.GetFileName( src ) )
\r
1358 dst_fo = GetParentAbsPath( dst )
\r
1359 If Not g_fs.FolderExists( dst_fo ) Then mkdir dst_fo
\r
1362 echo ">move """ & src & """, """ & dst & """"
\r
1363 g_AppKey.AddNewWritableFolder src
\r
1364 If IsWildcard( src ) or not g_fs.FileExists( dst ) Then
\r
1365 g_AppKey.AddNewWritableFolder dst + "\." '// "\." is for able to make writable folder
\r
1367 g_AppKey.AddNewWritableFolder dst
\r
1371 g_fs.MoveFile src, dst
\r
1374 ' If src is folder
\r
1375 ElseIf g_fs.FolderExists( src ) Then
\r
1377 If Not g_fs.FolderExists( dst ) Then mkdir dst
\r
1379 echo ">move """ & src & """, """ & dst & """"
\r
1380 g_AppKey.AddNewWritableFolder dst
\r
1381 If g_debug_or_test Then g_AppKey.BreakByWildcard src+"\*", F_File or F_SubFolder
\r
1383 g_fs.MoveFolder src, g_fs.BuildPath( dst, g_fs.GetFileName( src ) )
\r
1388 echo ">move """ & src & """, """ & dst & """"
\r
1389 g_AppKey.AddNewWritableFolder dst + "\." '// "\." is for able to make writable folder
\r
1390 g_fs.MoveFile src, dst ' Error occurs
\r
1397 '********************************************************************************
\r
1399 '********************************************************************************
\r
1400 Sub ren( src, dst )
\r
1401 echo ">ren """ & src & """, """ & dst & """"
\r
1404 If g_fs.FileExists( src ) Then
\r
1405 g_AppKey.AddNewWritableFolder src
\r
1406 Set f = g_fs.GetFile( src )
\r
1407 f.Name = g_fs.GetFileName( dst )
\r
1409 g_AppKey.AddNewWritableFolder src + "\." '// "\." is for able to make writable folder
\r
1410 Set f = g_fs.GetFolder( src )
\r
1411 f.Name = g_fs.GetFileName( dst )
\r
1417 '********************************************************************************
\r
1418 ' <<< [SafeFileUpdate] >>>
\r
1419 '********************************************************************************
\r
1420 Sub SafeFileUpdate( FromTmpFilePath, ToUpdateFilePath )
\r
1421 echo ">SafeFileUpdate """ & FromTmpFilePath & """, """ & ToUpdateFilePath & """"
\r
1422 Dim en,ed,en2,ed2,i,path
\r
1425 path = GetParentAbsPath( ToUpdateFilePath ) + "\" + _
\r
1426 g_fs.GetBaseName( ToUpdateFilePath ) + "." & i & "." + g_fs.GetExtensionName( ToUpdateFilePath )
\r
1427 If not exist( path ) Then Exit For
\r
1429 If exist( path ) Then Err.Raise E_Other,,"
\83o
\83b
\83N
\83A
\83b
\83v
\82Ì
\83t
\83@
\83C
\83\8b\96¼
\82ª
\8dì
\82ê
\82Ü
\82¹
\82ñ
\81B
\81F" + ToUpdateFilePath
\r
1431 On Error Resume Next
\r
1432 g_fs.CopyFile ToUpdateFilePath, path, False
\r
1433 en = Err.Number : ed = Err.Description : On Error GoTo 0
\r
1434 If en <> 0 Then Err.Raise en,,"
\83o
\83b
\83N
\83A
\83b
\83v
\83R
\83s
\81[
\82É
\8e¸
\94s
\82µ
\82Ü
\82µ
\82½
\81B"+vbCR+vbLF+_
\r
1435 "
\83o
\83b
\83N
\83A
\83b
\83v
\8c³
\81F"+ToUpdateFilePath+vbCR+vbLF+ "
\83o
\83b
\83N
\83A
\83b
\83v
\90æ
\81F"+path+vbCR+vbLF+ ed
\r
1437 del_to_trashbox path
\r
1439 On Error Resume Next
\r
1440 g_fs.CopyFile FromTmpFilePath, ToUpdateFilePath, True
\r
1441 en2 = Err.Number : ed2 = Err.Description : On Error GoTo 0
\r
1443 On Error Resume Next
\r
1444 g_fs.DeleteFile FromTmpFilePath
\r
1445 en = Err.Number : ed = Err.Description : On Error GoTo 0
\r
1447 If en2 <> 0 Then Err.Raise en2,,"
\8fã
\8f\91\82«
\83R
\83s
\81[
\82É
\8e¸
\94s
\82µ
\82Ü
\82µ
\82½
\81B
\83S
\83~
\94 \82É
\93ü
\82ê
\82½
\8c³
\82Ì
\83t
\83@
\83C
\83\8b\82ð
\95\9c\8a\88\82³
\82¹
\82Ä
\82
\82¾
\82³
\82¢
\81B"+vbCR+vbLF+_
\r
1448 "
\83R
\83s
\81[
\8c³
\81F"+FromTmpFilePath+vbCR+vbLF+ "
\83R
\83s
\81[
\90æ
\81F"+ToUpdateFilePath+vbCR+vbLF+ ed2
\r
1450 If en <> 0 Then WScript.Echo "
\8dX
\90V
\82Í
\90¬
\8c÷
\82µ
\82Ü
\82µ
\82½
\82ª
\81A
\88ê
\8e\9e\83t
\83@
\83C
\83\8b\82Ì
\8dí
\8f\9c\82É
\8e¸
\94s
\82µ
\82Ü
\82µ
\82½
\81B"+vbCR+vbLF+_
\r
1451 "
\88ê
\8e\9e\83t
\83@
\83C
\83\8b\81F"+FromTmpFilePath+vbCR+vbLF+ "
\8dX
\90V
\8dÏ
\82Ý
\83t
\83@
\83C
\83\8b\81F"+ToUpdateFilePath+vbCR+vbLF+ ed
\r
1457 '********************************************************************************
\r
1459 '********************************************************************************
\r
1460 Sub del( ByVal path )
\r
1461 echo ">del """ & path & """"
\r
1462 Dim ec : Set ec = new EchoOff
\r
1464 ' If path had Wild card
\r
1465 If IsWildCard( path ) Then
\r
1466 Dim folder, fname, fnames()
\r
1468 ExpandWildcard path, F_File, folder, fnames
\r
1469 For Each fname in fnames
\r
1470 del g_fs.BuildPath( folder, fname )
\r
1473 ExpandWildcard path, F_Folder, folder, fnames
\r
1474 For Each fname in fnames
\r
1475 del g_fs.BuildPath( folder, fname )
\r
1478 ' If path was file or folder path
\r
1481 If g_fs.FileExists( path ) Then
\r
1482 g_AppKey.AddNewWritableFolder path
\r
1483 g_fs.DeleteFile path
\r
1484 ElseIf g_fs.FolderExists( path ) Then
\r
1493 '********************************************************************************
\r
1494 ' <<< [del_subfolder] >>>
\r
1495 '********************************************************************************
\r
1496 Sub del_subfolder( ByVal path )
\r
1497 echo ">del_subfolder """ & path & """"
\r
1498 Dim folder, fname, fnames()
\r
1500 ExpandWildcard path, F_File Or F_SubFolder, folder, fnames
\r
1501 For Each fname in fnames
\r
1502 del g_fs.BuildPath( folder, fname )
\r
1505 ExpandWildcard path, F_Folder Or F_SubFolder, folder, fnames
\r
1506 For Each fname in fnames
\r
1507 del g_fs.BuildPath( folder, fname )
\r
1513 '********************************************************************************
\r
1514 ' <<< [del_to_trashbox] >>>
\r
1515 '********************************************************************************
\r
1516 Sub del_to_trashbox( ByVal path )
\r
1517 echo ">del_to_trashbox """ & path & """"
\r
1519 Dim sh_ap, TrashBox, folder, item, fname
\r
1520 Set sh_ap = CreateObject("Shell.Application")
\r
1521 Const ssfBITBUCKET = 10
\r
1523 g_AppKey.AddNewWritableFolder path + "\." '// "\." is for able to make writable folder
\r
1526 '//=== Check deletable by rename for Windows XP
\r
1527 On Error Resume Next
\r
1528 ren path, g_fs.GetFileName( path ) + "_deleting"
\r
1529 en = Err.Number : ed = Err.Description : On Error GoTo 0
\r
1530 If en = 70 Then Err.Raise 17,,"
\83S
\83~
\94 \82Ö
\88Ú
\93®
\82Å
\82«
\82Ü
\82¹
\82ñ : " + path
\r
1531 If en = 76 Then Exit Sub ' not found path
\r
1532 If en <> 0 Then Err.Raise en,,ed
\r
1533 On Error Resume Next
\r
1534 ren path + "_deleting", g_fs.GetFileName( path )
\r
1535 en = Err.Number : ed = Err.Description : On Error GoTo 0
\r
1536 If en <> 0 and en <> E_OutOfWritable Then Err.Raise en,,ed
\r
1539 '//=== move to trashbox
\r
1540 path = g_fs.GetAbsolutePathName( path )
\r
1541 fname = g_fs.GetFileName( path )
\r
1542 Set folder = sh_ap.NameSpace( g_fs.GetParentFolderName( path ) )
\r
1543 If folder is Nothing Then Exit Sub
\r
1544 Set item = folder.Items.Item( fname )
\r
1545 If item is Nothing Then Exit Sub
\r
1547 Set TrashBox = sh_ap.NameSpace( ssfBITBUCKET )
\r
1548 TrashBox.MoveHere item
\r
1551 '//=== for Windows Vista
\r
1552 ' If exist( path ) Then Err.Raise 17,,"
\83S
\83~
\94 \82Ö
\88Ú
\93®
\82Å
\82«
\82Ü
\82¹
\82ñ : " + path
\r
1555 '//=== for Windows XP
\r
1558 Set item = folder.Items.Item( fname )
\r
1559 If item is Nothing Then Exit Do
\r
1566 '********************************************************************************
\r
1567 ' <<< [del_confirmed] >>>
\r
1568 '********************************************************************************
\r
1569 Function del_confirmed( Path )
\r
1570 echo ">del_confirmed """ & Path & """"
\r
1571 If exist( Path ) Then
\r
1572 Dim r : r = input( "
\8dí
\8f\9c\82µ
\82Ä
\82æ
\82ë
\82µ
\82¢
\82Å
\82·
\82©
\81H : " + Path + " (Y/N)" )
\r
1573 del_confirmed = ( r="Y" or r="y" )
\r
1574 If del_confirmed Then del Path
\r
1576 del_confirmed = True
\r
1582 '********************************************************************************
\r
1583 ' <<< [mkdir] >>>
\r
1584 '********************************************************************************
\r
1585 Function mkdir( ByVal Path )
\r
1586 echo ">mkdir """ & Path & """"
\r
1587 Dim i, n, names(), fo2
\r
1589 g_AppKey.AddNewWritableFolder_sub Path + "\.", 1
\r
1591 If g_fs.FolderExists( Path ) Then mkdir = 0 : Exit Function
\r
1594 fo2 = g_fs.GetAbsolutePathName( Path )
\r
1596 If g_fs.FolderExists( fo2 ) Then Exit Do
\r
1599 Redim Preserve names(n)
\r
1600 names(n) = g_fs.GetFileName( fo2 )
\r
1601 fo2 = g_fs.GetParentFolderName( fo2 )
\r
1606 For n=n To 1 Step -1
\r
1607 fo2 = g_fs.BuildPath( fo2, names(n) )
\r
1608 g_fs.CreateFolder fo2
\r
1615 '********************************************************************************
\r
1616 ' <<< [mkdir_for] >>>
\r
1617 '********************************************************************************
\r
1618 Sub mkdir_for( Path )
\r
1621 s = g_fs.GetParentFolderName( Path )
\r
1622 If s = "" Then Exit Sub
\r
1628 '********************************************************************************
\r
1629 ' <<< [rmdir] >>>
\r
1630 '********************************************************************************
\r
1631 Sub rmdir( ByVal Path )
\r
1632 echo ">rmdir """ & Path & """"
\r
1633 Dim path2, iFolder, nFolder, fo, subf, f, file
\r
1635 If Not g_fs.FolderExists( Path ) Then Exit Sub
\r
1636 g_AppKey.AddNewWritableFolder Path + "\." '// "\." is for able to make writable folder
\r
1641 If Right( path2, 1 ) = "\" Then path2 = Left( path2, Len( path2 ) - 1 )
\r
1644 ReDim folderPathes(nFolder)
\r
1645 folderPathes(nFolder) = path2
\r
1647 ' Enum sub folders
\r
1649 While iFolder <= nFolder
\r
1650 Set fo = g_fs.GetFolder( folderPathes(iFolder) )
\r
1651 For Each subf in fo.SubFolders
\r
1652 nFolder = nFolder + 1
\r
1653 ReDim Preserve folderPathes(nFolder)
\r
1654 folderPathes(nFolder) = subf.Path
\r
1656 iFolder = iFolder + 1
\r
1659 ' Remove read only attribute of all files in sub folders
\r
1660 For iFolder = 1 To nFolder
\r
1661 Set fo = g_fs.GetFolder( folderPathes(iFolder) )
\r
1662 For Each f in fo.Files
\r
1663 Set file = g_fs.GetFile( f.Path )
\r
1664 If g_debug_or_test Then g_AppKey.BreakByPath( f.Path )
\r
1665 file.Attributes = file.Attributes And Not ReadOnly
\r
1671 Dim i_retry '// 1
\89ñ
\96Ú
\82É E_WriteAccessDenied
\82É
\82È
\82é
\82±
\82Æ
\82ª
\82½
\82Ü
\82É
\82 \82é
\82½
\82ß
\r
1672 For i_retry = 1 To 2
\r
1673 On Error Resume Next
\r
1674 g_fs.DeleteFolder( Path )
\r
1675 en = Err.Number : ed = Err.Description : On Error GoTo 0
\r
1676 If i_retry >= 2 and en <> E_WriteAccessDenied Then
\r
1677 If en = E_WriteAccessDenied Then ed = "Denied to delete the folder: "+ Path
\r
1678 If en <> 0 Then Err.Raise en,,ed
\r
1680 If en = 0 Then Exit For
\r
1682 echo_r "<WARNING msg='" & ed & "' msg2='
\8dÄ
\8e\8e\8ds
\82µ
\82Ä
\82¢
\82Ü
\82·'/>", ""
\r
1683 Sleep g_FileSystemRetryMSec
\r
1689 '********************************************************************************
\r
1690 ' <<< [exist] >>>
\r
1691 '********************************************************************************
\r
1692 Function exist( ByVal path )
\r
1693 If IsWildcard( path ) Then
\r
1694 Dim folder, fnames()
\r
1695 ExpandWildcard path, F_File or F_Folder, folder, fnames
\r
1696 exist = UBound( fnames ) <> -1
\r
1698 exist = ( g_fs.FileExists( path ) = True ) Or ( g_fs.FolderExists( path ) = True )
\r
1704 '********************************************************************************
\r
1705 ' <<< [fc] file compare as binary >>>
\r
1707 ' - return : True=same, False=different
\r
1708 '********************************************************************************
\r
1709 Function fc( path_a, path_b )
\r
1710 fc = fc_r( path_a, path_b, "" )
\r
1715 '********************************************************************************
\r
1716 ' <<< [fc_r] file compare as binary >>>
\r
1718 ' - return : True=same, False=different
\r
1719 '********************************************************************************
\r
1720 Function fc_r( path_a, path_b, redirect_path )
\r
1721 Dim opt : Set opt = new fc_option : ErrCheck
\r
1723 opt.m_RedirectPath = redirect_path
\r
1724 fc_r = fc_ex( path_a, path_b, opt )
\r
1728 '********************************************************************************
\r
1729 ' <<< [fc_ex] file compare as binary >>>
\r
1730 '********************************************************************************
\r
1731 Function fc_ex( PathA, PathB, Opt )
\r
1732 Dim cmdline, opt_echo, redirect_path, b_stdout
\r
1736 '//=== set cmdline from Opt.m_IniPath
\r
1737 cmdline = """" + g_vbslib_ver_folder + "feq.exe"""
\r
1738 If not IsEmpty( Opt ) Then
\r
1739 If not IsEmpty( Opt.m_IniPath ) Then
\r
1740 cmdline = cmdline + " /ini:""" + Opt.m_IniPath + """"
\r
1741 opt_echo = " /ini:" + g_fs.GetFileName( Opt.m_IniPath )
\r
1744 cmdline = cmdline + " """ + PathA + """ """ + PathB + """"
\r
1747 '//=== set redirect_path from Opt.m_RedirectPath
\r
1748 If not IsEmpty( Opt ) Then
\r
1749 redirect_path = Opt.m_RedirectPath
\r
1750 b_stdout = Opt.m_bStdOut
\r
1755 b = True : If Not IsEmpty( Opt ) Then b = (Opt.m_RedirectPath = "")
\r
1756 If b Then '// IsEmpty or
\r
1757 echo ">fc " + opt_echo + " """ + PathA + """ """ + PathB + """"
\r
1759 Dim f : Set f = g_fs.OpenTextFile( redirect_path, 8, True, False )
\r
1760 f.WriteLine ">fc " + opt_echo + " """ + PathA + """ """ + PathB + """"
\r
1767 chk_exist_in_lib "feq.exe"
\r
1768 Set ex = g_sh.Exec( cmdline )
\r
1769 If not IsEmpty( redirect_path ) Then redirect_path = g_sh.ExpandEnvironmentStrings( redirect_path )
\r
1770 fc_ex = ( WaitForFinishAndRedirect( ex, redirect_path ) = 0 )
\r
1775 '********************************************************************************
\r
1776 ' <<< [fc_option] >>>
\r
1777 '********************************************************************************
\r
1780 Public m_RedirectPath
\r
1786 '********************************************************************************
\r
1787 ' <<< [find] find lines including keyword >>>
\r
1788 '********************************************************************************
\r
1789 Function find( ByVal keyword, ByVal path )
\r
1791 Set f = g_fs.OpenTextFile( path )
\r
1794 Do Until f.AtEndOfStream
\r
1796 If InStr( line, keyword ) > 0 Then ret = ret + line
\r
1806 '********************************************************************************
\r
1807 ' <<< [find_c] find lines count including keyword >>>
\r
1808 '********************************************************************************
\r
1809 Function find_c( ByVal keyword, ByVal path )
\r
1811 Set f = g_fs.OpenTextFile( path )
\r
1814 Do Until f.AtEndOfStream
\r
1816 If InStr( line, keyword ) > 0 Then ret = ret + 1
\r
1826 '********************************************************************************
\r
1828 '********************************************************************************
\r
1829 Sub grep( Keyword, FolderPath, OutFName, Opt )
\r
1830 Dim ds_:Set ds_= New CurDirStack : ErrCheck
\r
1831 del "_grep_out.txt"
\r
1833 del "_grep_out.txt"
\r
1834 RunProg "cmd /C for /R %i in (*) do find """ + Keyword + """ ""%i"" >> _grep_out.txt", ""
\r
1836 move FolderPath + "\_grep_out.txt", "."
\r
1837 If OutFName <> "_grep_out.txt" Then ren "_grep_out.txt", OutFName
\r
1842 '********************************************************************************
\r
1844 '********************************************************************************
\r
1845 Sub sort( InPath, OutPath )
\r
1846 RunProg "cmd /C sort """ + InPath + """ /o """ + OutPath + """", ""
\r
1851 '********************************************************************************
\r
1852 ' <<< [CreateFile] Create 1 line text file >>>
\r
1853 '********************************************************************************
\r
1854 Function CreateFile( ByVal Path, ByVal Text )
\r
1857 t = InStr( Text, vbCRLF )
\r
1858 If t = 0 Then t = Text+"""" Else t = Left( Text, t-1 ) + """+vbCRLF+..."
\r
1859 echo ">CreateFile """ & Path & """, """ & t
\r
1861 If IsWildcard( Path ) Then Path = GetTempPath( Path ) : echo "Create """ & Path & """"
\r
1863 Dim ec : Set ec = new EchoOff : ErrCheck
\r
1865 g_AppKey.AddNewWritableFolder Path
\r
1867 Path = g_fs.GetAbsolutePathName( Path )
\r
1868 folder = g_fs.GetParentFolderName( Path )
\r
1869 If not g_fs.FolderExists( folder ) Then mkdir folder
\r
1871 Set t = g_fs.CreateTextFile( Path, True, (g_TextFileCreateFormat = F_Unicode) )
\r
1880 '********************************************************************************
\r
1881 ' <<< [ReadFile] >>>
\r
1882 '********************************************************************************
\r
1883 Function ReadFile( Path )
\r
1888 On Error Resume Next
\r
1889 Set f = g_fs.OpenTextFile( Path, 1, False, -2 )
\r
1890 en = Err.Number : ed = Err.Description : On Error GoTo 0
\r
1891 If en = E_FileNotExist or en = E_PathNotFound Then Exit Function
\r
1892 '// E_PathNotFound is not found parent folder
\r
1893 If en <> 0 Then Err.Raise en,,ed
\r
1895 ReadFile = ReadAll( f )
\r
1900 '********************************************************************************
\r
1901 ' <<< [type_] >>>
\r
1902 '********************************************************************************
\r
1904 echo ">type_ """ & Path & """"
\r
1905 echo ReadFile( Path )
\r
1910 '********************************************************************************
\r
1911 ' <<< [OpenForRead] >>>
\r
1912 '********************************************************************************
\r
1913 Function OpenForRead( Path )
\r
1914 echo ">OpenForRead """ & Path & """"
\r
1917 On Error Resume Next
\r
1918 Set OpenForRead = g_fs.OpenTextFile( Path,,,-2 )
\r
1919 en = Err.Number : ed = Err.Description : On Error GoTo 0
\r
1920 If en = E_FileNotExist or en = E_PathNotFound Then Err.raise en,,ed+" : "+Path
\r
1921 If en <> 0 Then Err.Raise en,,ed
\r
1926 '********************************************************************************
\r
1927 ' <<< [OpenForWrite] >>>
\r
1928 '********************************************************************************
\r
1929 Const F_Shift_JIS = &h1000
\r
1930 Const F_Unicode = 2
\r
1931 Const F_Append = 4
\r
1933 Function OpenForWrite( ByVal Path, Flags )
\r
1934 echo ">OpenForWrite """ & Path & """"
\r
1936 Dim bUnicode : bUnicode = ((Flags and F_Unicode) = F_Unicode)
\r
1937 Dim bAppend : bAppend = ((Flags and F_Append) = F_Append)
\r
1938 If ( Flags and (F_Shift_JIS or F_Unicode) ) = 0 Then _
\r
1939 bUnicode = (g_TextFileCreateFormat = F_Unicode)
\r
1941 If IsWildcard( Path ) Then Path = GetTempPath( Path ) : echo "Create """ & Path & """"
\r
1943 g_AppKey.AddNewWritableFolder Path
\r
1945 On Error Resume Next
\r
1947 Set OpenForWrite = g_fs.OpenTextFile( Path, 8, True, -2 )
\r
1949 Set OpenForWrite = g_fs.CreateTextFile( Path, True, bUnicode )
\r
1951 en = Err.Number : ed = Err.Description : On Error GoTo 0
\r
1953 If en = E_PathNotFound Then
\r
1954 Dim fo : fo = g_fs.GetParentFolderName( Path )
\r
1955 If not g_fs.FolderExists( fo ) Then
\r
1957 On Error Resume Next
\r
1958 Set OpenForWrite = g_fs.CreateTextFile( Path, True, bUnicode )
\r
1959 en = Err.Number : ed = Err.Description : On Error GoTo 0
\r
1962 If en <> 0 Then Err.Raise en,,ed
\r
1967 '********************************************************************************
\r
1968 ' <<< [GetTempPath] >>>
\r
1969 '********************************************************************************
\r
1970 Class TempFileClass
\r
1971 Public m_FolderPath
\r
1972 Public m_LimitDate
\r
1978 Function GetTempPath( Param )
\r
1979 Dim param_abs, path, t, i, fo, f
\r
1981 GetObject_g_TempFile
\r
1983 '//=== Delete old files
\r
1984 If not g_fs.FolderExists( g_TempFile.m_FolderPath ) Then _
\r
1985 mkdir g_TempFile.m_FolderPath
\r
1987 Set fo = g_fs.GetFolder( g_TempFile.m_FolderPath )
\r
1988 For Each f in fo.Files
\r
1989 If f.DateLastModified < g_TempFile.m_LimitDate Then
\r
1990 g_fs.DeleteFile f.Path
\r
1993 For Each f in fo.SubFolders
\r
1994 If f.DateLastModified < g_TempFile.m_LimitDate Then
\r
1995 g_fs.DeleteFolder f.Path
\r
2000 '//=== path : Make unique path
\r
2002 param_abs = GetAbsPath( Param, g_TempFile.m_FolderPath +"\"+ _
\r
2003 Right( "0" & (Year(t) mod 100), 2 ) & _
\r
2004 Right( "0" & Month(t), 2 ) & Right( "0" & Day(t), 2 ) )
\r
2006 t = Right( "0" & (Year(t) mod 100), 2 ) & _
\r
2007 Right( "0" & Month(t), 2 ) & Right( "0" & Day(t), 2 ) & "_" & _
\r
2008 Right( "0" & Hour(t), 2 ) & Right( "0" & Minute(t), 2 ) & "_"
\r
2011 path = Replace( param_abs, "*", t & i )
\r
2012 If not exist( path ) Then Exit Do
\r
2014 If InStr( param_abs, "*" ) = 0 Then Exit Do
\r
2016 GetTempPath = path
\r
2021 '********************************************************************************
\r
2022 ' <<< [GetObject_g_TempFile] >>>
\r
2023 '********************************************************************************
\r
2024 Sub GetObject_g_TempFile()
\r
2025 If IsEmpty( g_TempFile ) Then
\r
2026 Set g_TempFile = new TempFileClass : ErrCheck
\r
2027 If IsDefined( "Setting_getTemp" ) Then
\r
2029 Setting_getTemp out1, out2
\r
2030 g_TempFile.m_FolderPath = out1
\r
2031 g_TempFile.m_LimitDate = out2
\r
2034 If IsEmpty( g_TempFile.m_FolderPath ) Then _
\r
2035 g_TempFile.m_FolderPath = env( "%Temp%\Report" )
\r
2036 If IsEmpty( g_TempFile.m_LimitDate ) Then _
\r
2037 g_TempFile.m_LimitDate = DateAdd( "d", -2, Now() )
\r
2039 If InStr( g_TempFile.m_FolderPath, "Temp" ) = 0 Then
\r
2040 echo "Not found ""Temp"" in temporary folder path in %Temp% or Setting_getTemp."
\r
2041 echo "Is this temporary folder path to delete? : " + g_TempFile.m_FolderPath
\r
2042 echo "
\82±
\82ê
\82Í
\8dí
\8f\9c\82µ
\82Ä
\82à
\82æ
\82¢
\88ê
\8e\9e\83t
\83H
\83\8b\83_
\82Ì
\83p
\83X
\82Å
\82·
\82©
\81H : " + g_TempFile.m_FolderPath
\r
2046 g_AppKey.AddNewWritableFolder g_TempFile.m_FolderPath + "\."
\r
2051 '********************************************************************************
\r
2052 ' <<< [ReadAll] >>>
\r
2053 '********************************************************************************
\r
2054 Function ReadAll( FileStream )
\r
2058 On Error Resume Next
\r
2059 ReadAll = FileStream.ReadAll
\r
2060 en = Err.Number : ed = Err.Description : On Error GoTo 0
\r
2061 If en = E_EndOfFile Then en = 0
\r
2062 If en <> 0 Then Err.Raise en,,ed
\r
2067 '********************************************************************************
\r
2068 ' <<< [Txt2BinTxt] >>>
\r
2069 '********************************************************************************
\r
2070 Sub Txt2BinTxt( SrcPath, DstPath )
\r
2072 Dim txt2bintxt_exe : txt2bintxt_exe = g_vbslib_ver_folder + "txt2bintxt.exe"
\r
2074 If not g_fs.FileExists( txt2bintxt_exe ) Then _
\r
2075 Err.Raise 1,, "not found txt2bintxt.exe in vbslib folder"
\r
2077 r = RunProg( """"+txt2bintxt_exe+""" """+SrcPath+""" """+DstPath+"""", Empty )
\r
2078 If r<>0 Then Err.Raise 1,, "error 0x" & Hex(r) & " in txt2bintxt.exe"
\r
2083 '********************************************************************************
\r
2084 ' <<< [WriteVBSLibHeader] >>>
\r
2085 '********************************************************************************
\r
2086 Sub WriteVBSLibHeader( OutFileStream, Opt )
\r
2089 Set f = g_fs.OpenTextFile( WScript.ScriptFullName )
\r
2090 Do Until f.AtEndOfStream
\r
2094 If InStr( line, "g_CommandPrompt =" ) > 0 and not IsEmpty( Opt ) Then
\r
2095 If not IsEmpty( Opt.m_OverCommandPrompt ) Then
\r
2096 line = " g_CommandPrompt = " & Opt.m_OverCommandPrompt
\r
2099 If InStr( line, "main()" ) > 0 Then Exit Do
\r
2100 If InStr( line, "main2(" ) > 0 Then Exit Do
\r
2102 OutFileStream.WriteLine line
\r
2107 Class WriteVBSLibHeader_Option
\r
2108 Public m_OverCommandPrompt
\r
2113 '********************************************************************************
\r
2114 ' <<< [GetAbsPath] >>>
\r
2115 '********************************************************************************
\r
2116 Function GetAbsPath( StepPath, ByVal BasePath )
\r
2117 Dim i, ii, i3, sep_ch, path
\r
2120 If IsEmpty( BasePath ) Then BasePath = g_sh.CurrentDirectory
\r
2121 If IsAbsPath( StepPath ) Then BasePath = Empty
\r
2124 '//=== sep_ch = separetor "\" or "/"
\r
2125 If IsEmpty( BasePath ) Then
\r
2126 i = InStr( StepPath, "\" )
\r
2127 ii = InStr( StepPath, "/" )
\r
2129 i = InStr( BasePath, "\" )
\r
2130 ii = InStr( BasePath, "/" )
\r
2134 If i > ii Then sep_ch = "/" Else sep_ch = "\"
\r
2139 If ii > 0 Then sep_ch = "/" Else sep_ch = "\"
\r
2141 '(debug point) watch "sep_ch"
\r
2144 '//=== Joint and Replace to sep_ch
\r
2145 If Right( BasePath, 1 ) = sep_ch or IsEmpty( BasePath ) Then
\r
2146 path = BasePath + StepPath
\r
2148 path = BasePath + sep_ch + StepPath
\r
2150 If sep_ch = "\" Then
\r
2151 path = Replace( path, "/", "\" )
\r
2153 path = Replace( path, "\", "/" )
\r
2155 '(debug point) watch "path"
\r
2159 i_root = InStr( path, sep_ch )
\r
2160 If Mid( path, i_root+1, 1 ) = sep_ch Then
\r
2161 i = InStr( i_root+2, path, sep_ch )
\r
2165 path = path + sep_ch
\r
2166 i_root = Len( path ) + 1
\r
2173 i = InStr( path, sep_ch+"."+sep_ch )
\r
2174 If i = 0 Then Exit Do
\r
2175 path = Left( path, i ) + Mid( path, i+3 )
\r
2177 If Right( path, 2 ) = sep_ch+"." Then path = Left( path, Len(path)-2 )
\r
2180 '//=== Cut xxx\..\
\r
2182 i = InStr( path, sep_ch+".."+sep_ch )
\r
2183 If i = 0 Then Exit Do
\r
2186 ii = InStr( i3+1, path, sep_ch )
\r
2187 If ii = 0 Then Exit Do
\r
2189 If i = i_root Then
\r
2190 path = Left( path, i ) + Mid( path, i+4 ) '// Cut "\..\"
\r
2192 path = Left( path, i3 ) + Mid( path, i+4 ) '// Cut xxx\..\
\r
2202 If Right( path, 3 ) = sep_ch+".." Then
\r
2203 i = Len( path ) - 2
\r
2204 If i = i_root Then
\r
2205 path = Left( path, i )
\r
2207 i = InStrRev( path, sep_ch, i-1 )
\r
2208 If i = i_root Then
\r
2209 path = Left( path, i )
\r
2211 path = Left( path, i-1 )
\r
2217 If Right( path, 1 ) = ":" Then path = path + sep_ch
\r
2220 '(debug point) watch "path"
\r
2227 '********************************************************************************
\r
2228 ' <<< [GetStepPath] >>>
\r
2229 ' - AbsPath, BasePath, (return) as string
\r
2230 '********************************************************************************
\r
2231 Function GetStepPath( AbsPath, BasePath )
\r
2232 Dim AbsPathU, BasePathU, path, sep_ch, i, ii
\r
2234 AbsPathU = UCase(AbsPath)
\r
2235 If IsEmpty( BasePath ) Then
\r
2236 BasePathU = UCase(g_sh.CurrentDirectory)
\r
2238 BasePathU = UCase(BasePath)
\r
2242 '// sep_ch = separetor "\" or "/"
\r
2243 i = InStr( AbsPath, "\" )
\r
2244 ii = InStr( AbsPath, "/" )
\r
2247 If i > ii Then sep_ch = "/" Else sep_ch = "\"
\r
2252 If ii > 0 Then sep_ch = "/" Else sep_ch = "\"
\r
2254 '(debug point) watch "sep_ch"
\r
2257 '// path = common parent folder path. The last character is not sep_ch
\r
2259 If Right( BasePathU, 1 ) = sep_ch Then path = Left( BasePathU, Len(BasePathU)-1 )
\r
2261 If path = Left( AbsPathU, Len(path) ) Then Exit Do
\r
2262 path = g_fs.GetParentFolderName( path )
\r
2264 If path = "" Then GetStepPath = AbsPath : Exit Function
\r
2265 If Right( path, 1 ) = sep_ch Then path = Left( path, Len(path)-1 )
\r
2266 '(debug point) watch "path"
\r
2269 '// GetStepPath = step path without ..\
\r
2270 GetStepPath = Mid( AbsPath, Len(path) + 2 )
\r
2271 '(debug point) watch "GetStepPath"
\r
2274 '// GetStepPath: Add "..\"
\r
2275 path = Mid( BasePath, Len(path) + 2 )
\r
2277 If path = "" Then Exit Do
\r
2278 path = g_fs.GetParentFolderName( path )
\r
2279 GetStepPath = ".." + sep_ch + GetStepPath
\r
2281 '(debug point) watch "GetStepPath"
\r
2284 If GetStepPath = "" Then GetStepPath = "."
\r
2289 '********************************************************************************
\r
2290 ' <<< [GetParentAbsPath] >>>
\r
2291 '********************************************************************************
\r
2292 Function GetParentAbsPath( Path )
\r
2293 GetParentAbsPath = g_fs.GetParentFolderName( g_fs.GetAbsolutePathName( Path ) )
\r
2298 '********************************************************************************
\r
2299 ' <<< [IsAbsPath] >>>
\r
2300 '********************************************************************************
\r
2301 Function IsAbsPath( Path )
\r
2302 Dim bs : bs = InStr( Path, "\" )
\r
2303 Dim sl : sl = InStr( Path, "/" )
\r
2304 Dim co : co = InStr( Path, ":" )
\r
2306 IsAbsPath = ( co > 0 and ( bs = co+1 or sl = co+1 ) )
\r
2310 '********************************************************************************
\r
2311 ' <<< [FindParent] >>>
\r
2312 '********************************************************************************
\r
2313 Function FindParent( TargetStepPath, StartFolderPath )
\r
2314 Dim base : base = GetAbsPath( StartFolderPath, Empty )
\r
2318 path = base + "\" + TargetStepPath
\r
2319 If g_fs.FileExists( path ) or g_fs.FolderExists( path ) Then Exit Do
\r
2320 base = g_fs.GetParentFolderName( base )
\r
2321 If base = "" Then Raise E_PathNotFound, _
\r
2322 "<ERROR msg='No FindParent' target='" + TargetStepPath + "'/>"
\r
2330 '********************************************************************************
\r
2331 ' <<< [GetTagJumpPath] >>>
\r
2332 '********************************************************************************
\r
2333 Function GetTagJumpPath( PathAndLine )
\r
2334 Dim i : i = InStrRev( PathAndLine, "(" )
\r
2336 GetTagJumpPath = Left( PathAndLine, i-1 )
\r
2338 GetTagJumpPath = PathAndLine
\r
2343 '********************************************************************************
\r
2344 ' <<< [IsWildcard] >>>
\r
2345 '********************************************************************************
\r
2346 Function IsWildcard( ByVal path )
\r
2347 IsWildcard = InStr( path, "?" ) <> 0 Or InStr( path, "*" ) <> 0
\r
2352 '********************************************************************************
\r
2353 ' <<< [ExpandWildcard] >>>
\r
2354 '********************************************************************************
\r
2355 Sub ExpandWildcard( ByVal wildcard_path, flags, folder, fnames )
\r
2358 folder = g_fs.GetParentFolderName( g_fs.GetAbsolutePathName( wildcard_path ) )
\r
2360 Set re = CreateObject("VBScript.RegExp")
\r
2362 s = g_fs.GetFileName( wildcard_path )
\r
2363 re.Pattern = "\\" : s = re.Replace( s, "\\" )
\r
2364 re.Pattern = "\." : s = re.Replace( s, "\." )
\r
2365 re.Pattern = "\$" : s = re.Replace( s, "\$" )
\r
2366 re.Pattern = "\^" : s = re.Replace( s, "\^" )
\r
2367 re.Pattern = "\{" : s = re.Replace( s, "\{" )
\r
2368 re.Pattern = "\}" : s = re.Replace( s, "\}" )
\r
2369 re.Pattern = "\[" : s = re.Replace( s, "\[" )
\r
2370 re.Pattern = "\]" : s = re.Replace( s, "\]" )
\r
2371 re.Pattern = "\(" : s = re.Replace( s, "\(" )
\r
2372 re.Pattern = "\)" : s = re.Replace( s, "\)" )
\r
2373 re.Pattern = "\|" : s = re.Replace( s, "\|" )
\r
2374 re.Pattern = "\+" : s = re.Replace( s, "\+" )
\r
2375 re.Pattern = "\*" : s = re.Replace( s, ".*" )
\r
2376 re.Pattern = "\?" : s = re.Replace( s, "." )
\r
2378 re.Pattern = "^" + s
\r
2379 If Left( re.Pattern, 3 ) = "^.*" Then re.Pattern = Mid( re.Pattern, 4 )
\r
2381 re.IgnoreCase = True
\r
2382 ReDim fnames( -1 )
\r
2384 ExpandWildcard_sub re, flags, folder, "", fnames
\r
2388 Sub ExpandWildcard_sub( re, flags, folder, step_folder, fnames )
\r
2391 If not g_fs.FolderExists( folder ) Then Exit Sub
\r
2393 Set fo = g_fs.GetFolder( folder )
\r
2394 If flags And F_File Then
\r
2395 For Each f in fo.Files
\r
2396 If re.Test( f.Name ) Then
\r
2397 ReDim Preserve fnames( UBound(fnames) + 1 )
\r
2398 fnames( UBound(fnames) ) = step_folder + f.Name
\r
2402 If flags And F_Folder Then
\r
2403 For Each f in fo.SubFolders
\r
2404 If re.Test( f.Name ) Then
\r
2405 ReDim Preserve fnames( UBound(fnames) + 1 )
\r
2406 fnames( UBound(fnames) ) = step_folder + f.Name
\r
2411 If flags And F_SubFolder Then
\r
2412 For Each f in fo.SubFolders
\r
2413 ExpandWildcard_sub re, flags, f.Path, step_folder + f.Name + "\", fnames
\r
2420 '********************************************************************************
\r
2421 ' <<< [GetSubFolders] >>>
\r
2423 ' - folders : (out) array of folder pathes
\r
2424 ' - path : base folder path
\r
2425 '********************************************************************************
\r
2426 Sub GetSubFolders( folders, ByVal path )
\r
2428 EnumSubFolders folders, g_fs.GetFolder( path )
\r
2431 Sub EnumSubFolders( folders, fo )
\r
2434 ReDim Preserve folders( UBound(folders) + 1 )
\r
2435 folders( UBound(folders) ) = fo.Path
\r
2437 For Each subfo in fo.SubFolders
\r
2438 EnumSubFolders folders, subfo
\r
2444 '********************************************************************************
\r
2445 ' <<< [EnumFolderObject] >>>
\r
2447 ' out_Folders as Folder
\r
2448 ' FolderPath as string
\r
2450 ' For Each fo In folders
\r
2451 ' For Each f In fo.Files
\r
2452 ' n = f.DateLastModified
\r
2455 '********************************************************************************
\r
2456 Sub EnumFolderObject( FolderPath, out_Folders )
\r
2457 Dim i_set, i_get, n, f
\r
2459 ReDim out_Folders(0)
\r
2460 Set out_Folders(0) = g_fs.GetFolder( FolderPath )
\r
2461 i_set = 1 : i_get = 0
\r
2463 While i_get <= UBound( out_Folders )
\r
2464 n = out_Folders( i_get ).SubFolders.Count
\r
2465 ReDim Preserve out_Folders( UBound( out_Folders ) + n )
\r
2466 For Each f In out_Folders( i_get ).SubFolders
\r
2467 Set out_Folders( i_set ) = f
\r
2476 '********************************************************************************
\r
2477 ' <<< [RemoveWildcard] >>>
\r
2478 '********************************************************************************
\r
2479 Sub RemoveWildcard( WildCard, fnames )
\r
2480 Dim s, path, fname, i, n, wc, wc_len
\r
2483 '//=== check by with wildcard
\r
2484 If Left( WildCard, 1 ) = "*" Then
\r
2485 wc = LCase( Mid( WildCard, 2 ) ) : wc_len = Len( wc )
\r
2486 n = UBound( fnames )
\r
2490 fname = g_fs.GetFileName( path )
\r
2491 If LCase( Right( fname, wc_len ) ) = wc Then fnames(i) = Empty : Exit Do
\r
2492 path = g_fs.GetParentFolderName( path )
\r
2493 If path = "" Then Exit Do
\r
2498 '//=== check by no wildcard
\r
2500 wc = LCase( WildCard )
\r
2501 n = UBound( fnames )
\r
2505 fname = g_fs.GetFileName( path )
\r
2506 If LCase( fname ) = wc Then fnames(i) = Empty : Exit Do
\r
2507 path = g_fs.GetParentFolderName( path )
\r
2508 If path = "" Then Exit Do
\r
2514 '//=== shrink the array
\r
2516 For i = 0 To UBound( fnames )
\r
2517 If not IsEmpty( fnames(i) ) Then fnames(n) = fnames(i) : n = n + 1
\r
2519 Redim Preserve fnames( n - 1 )
\r
2524 '********************************************************************************
\r
2525 ' <<< [MeltCSV] >>>
\r
2526 '********************************************************************************
\r
2527 Function MeltCSV( Line, in_out_Start )
\r
2532 If i=0 Then Exit Function
\r
2535 '//=== Skip space character
\r
2537 c = Mid( Line, i, 1 )
\r
2538 If c<>" " and c<>vbTab Then Exit Do
\r
2544 '//=== If enclosed by " "
\r
2548 c = Mid( Line, i, 1 )
\r
2549 If c = "" Then Exit Do
\r
2552 c = Mid( Line, i, 1 )
\r
2553 If c = """" Then s = s + c Else Exit Do
\r
2562 If c = "" Then in_out_Start = 0 : Exit Function
\r
2563 If c = "," Then in_out_Start = i+1 : Exit Function
\r
2565 c = Mid( Line, i, 1 )
\r
2569 '//=== If no value
\r
2571 in_out_Start = i+1 : Exit Function
\r
2573 in_out_Start = 0 : Exit Function
\r
2576 '//=== If NOT enclosed by " "
\r
2579 If c = "" or c = "," Then Exit Do
\r
2582 c = Mid( Line, i, 1 )
\r
2585 MeltCSV = Trim( s )
\r
2587 If c = "" Then in_out_Start = 0 : Exit Function
\r
2588 If c = "," Then in_out_Start = i+1 : Exit Function
\r
2594 '********************************************************************************
\r
2595 ' <<< [CSVText] >>>
\r
2596 '********************************************************************************
\r
2597 Function CSVText( s )
\r
2598 If InStr( s, """" ) = 0 and InStr( s, "," ) = 0 and InStr( s, vbCRLF ) = 0 and _
\r
2599 Left( s, 1 ) <> " " and Right( s, 1 ) <> " " Then CSVText = s : Exit Function
\r
2600 CSVText = """" + Replace( s, """", """""" ) + """"
\r
2603 '********************************************************************************
\r
2604 ' <<< [XmlAttr] >>>
\r
2605 '********************************************************************************
\r
2606 Function XmlAttr( s )
\r
2607 XmlAttr = Replace( s, "&", "&" )
\r
2608 XmlAttr = Replace( XmlAttr, """", """ )
\r
2609 XmlAttr = Replace( XmlAttr, "<", "<" )
\r
2612 '********************************************************************************
\r
2613 ' <<< [XmlText] >>>
\r
2614 '********************************************************************************
\r
2615 Function XmlText( s )
\r
2616 XmlText = Replace( s, "&", "&" )
\r
2617 XmlText = Replace( XmlText, "<", "<" )
\r
2618 XmlText = Replace( XmlText, ">", ">" )
\r
2621 '********************************************************************************
\r
2622 ' <<< [LoadXML] >>>
\r
2623 '********************************************************************************
\r
2624 Const F_NoRoot = 1
\r
2625 Const F_Str = &h8000
\r
2627 Function LoadXML( PathOrStr, Opt )
\r
2628 Dim xml, r, t, i, c, f
\r
2629 Const start_tag = "<Dummy_Root_>"
\r
2630 Const end_tag = "</Dummy_Root_>"
\r
2632 If Opt and F_Str Then
\r
2633 i=1 : Do : c = Mid( PathOrStr, i, 1 ) : If c<>" " and c<>vbTab Then Exit Do
\r
2635 If (Opt and F_NoRoot) or c<>"<" Then
\r
2636 t = start_tag + PathOrStr + end_tag
\r
2641 Set f = OpenForRead( PathOrStr )
\r
2643 i=1 : Do : c = Mid( t, i, 1 ) : If c<>" " and c<>vbTab Then Exit Do
\r
2645 If (Opt and F_NoRoot) or c<>"<" Then
\r
2646 t = start_tag + t + end_tag
\r
2650 Set xml = CreateObject("MSXML2.DOMDocument")
\r
2651 r = xml.loadXML( t )
\r
2653 t = start_tag + t + end_tag
\r
2654 r = xml.loadXML( t )
\r
2656 If not r Then Raise 1,"""" + PathOrStr + """
\82ª Unicode
\82Å
\82È
\82¢
\82©
\81A
\90³
\82µ
\82¢ XML
\8c`
\8e®
\82É
\82È
\82Á
\82Ä
\82¢
\82Ü
\82¹
\82ñ"
\r
2657 Set LoadXML = xml.lastChild '// If firstChild, <?xml> may be got.
\r
2661 'Function LoadXML( Path, Opt )
\r
2664 ' If not g_fs.FileExists( Path ) Then Err.Raise 53,,"""" + Path + """
\82ª
\8c©
\82Â
\82©
\82è
\82Ü
\82¹
\82ñ"
\r
2665 ' Set xml = WScript.CreateObject("MSXML2.DOMDocument")
\r
2666 ' r = xml.load( Path )
\r
2667 ' If r=0 Then Err.Raise 53,,"""" + Path + """
\82ª Unicode
\82Å
\82È
\82¢
\82©
\81A
\90³
\82µ
\82¢ XML
\8c`
\8e®
\82Å
\82Í
\82 \82è
\82Ü
\82¹
\82ñ"
\r
2668 ' Set LoadXML = xml.firstChild
\r
2673 '*-------------------------------------------------------------------------*
\r
2674 '* ### <<<< Function call and include >>>>
\r
2675 '*-------------------------------------------------------------------------*
\r
2679 '********************************************************************************
\r
2680 ' <<< [call_vbs] >>>
\r
2681 '********************************************************************************
\r
2682 Function call_vbs( path, func, param )
\r
2683 echo ">call_vbs """ & path & """, " & func
\r
2685 call_vbs = call_vbs_d( path, func, param )
\r
2687 call_vbs = call_vbs_t( path, func, param )
\r
2693 '*-------------------------------------------------------------------------*
\r
2694 '* ### <<<< Support of vbsool >>>>
\r
2695 '*-------------------------------------------------------------------------*
\r
2699 '********************************************************************************
\r
2700 ' <<< [ObjToXML] >>>
\r
2701 '********************************************************************************
\r
2702 Function ObjToXML( TagName, Objs, Opt )
\r
2706 If not IsEmpty( TagName ) Then out = "<" + TagName + ">" + vbCRLF
\r
2707 If IsArray( Objs ) Then
\r
2708 For Each o In Objs : If not IsEmpty(o) Then ObjToXML1 o, out
\r
2710 ElseIf TypeName( Objs ) = "ArrayClass" Then
\r
2711 For Each o In Objs.m_Array : ObjToXML1 o, out : Next
\r
2712 ElseIf IsObject( Objs ) Then
\r
2713 ObjToXML1 Objs, out
\r
2715 If not IsEmpty( TagName ) Then out = out + "</" + TagName + ">" + vbCRLF
\r
2716 ObjToXML = Left( out, Len( out ) - 2 )
\r
2720 Sub ObjToXML1( Obj, Out )
\r
2723 Out = Out + "<" + TypeName( Obj )
\r
2725 On Error Resume Next
\r
2727 en = Err.Number : ed = Err.Description : On Error GoTo 0
\r
2728 If en = 0 Then Out = Out + " Name=""" & XmlAttr( Obj.Name ) & """"
\r
2729 If en = 438 Then en = 0
\r
2730 If en <> 0 Then Err.Raise en,,ed
\r
2732 On Error Resume Next
\r
2733 ed = Obj.DefinePath
\r
2734 en = Err.Number : ed = Err.Description : On Error GoTo 0
\r
2735 If en = 0 Then Out = Out + " DefinePath=""" & XmlAttr( Obj.DefinePath ) & """"
\r
2736 If en = 438 Then en = 0
\r
2737 If en <> 0 Then Err.Raise en,,ed
\r
2739 Out = Out + "/>" + vbCRLF
\r
2746 '********************************************************************************
\r
2747 ' <<< [get_Object] >>>
\r
2748 '********************************************************************************
\r
2749 Function get_Object( Name )
\r
2752 On Error Resume Next
\r
2753 Dim get_func : Set get_func = GetRef( "get_" + Name )
\r
2754 en = Err.Number : ed = Err.Description : On Error GoTo 0
\r
2755 If en = 5 Then Err.Raise en,,ed + " : Not defined 'get_" + Name + "'"
\r
2756 If en <> 0 Then Err.Raise en,,ed
\r
2758 Set get_Object = get_func()
\r
2762 '********************************************************************************
\r
2763 ' <<< [get_ObjectFromFile] >>>
\r
2764 '********************************************************************************
\r
2765 Function get_ObjectFromFile( ModulePath, Name )
\r
2768 g_SrcPath = g_fs.GetAbsolutePathName( ModulePath )
\r
2769 If g_debug Then echo ">include """ + g_SrcPath + """"
\r
2770 Set f = g_fs.OpenTextFile( g_SrcPath )
\r
2772 ExecuteGlobal "'// " + g_SrcPath +vbCRLF+ f.ReadAll()
\r
2774 ExecuteGlobal f.ReadAll()
\r
2777 Dim get_func : Set get_func = GetRef( "get_" + Name )
\r
2778 Set get_ObjectFromFile = get_func()
\r
2783 '********************************************************************************
\r
2784 ' <<< [get_NameDelegator] >>>
\r
2785 '********************************************************************************
\r
2786 Dim g_NameDic : Set g_NameDic = CreateObject( "Scripting.Dictionary" )
\r
2788 Function get_NameDelegator( Name, TrueName, InterfaceName )
\r
2789 If g_NameDic.Exists( Name +"__"+ TrueName ) Then
\r
2790 Set get_NameDelegator = g_NameDic.Item( Name +"__"+ TrueName +"_"+ InterfaceName )
\r
2794 Set get_NameDelegator = new_X( InterfaceName + "_Delegator" ) : With get_NameDelegator
\r
2796 .m_Delegate = TrueName '// if validated was need.
\r
2797 If not g_bNeedValidateDelegate Then _
\r
2798 Set .m_Delegate = get_Object( TrueName ) '// if validated was not need.
\r
2801 Set g_NameDic.Item( Name +"__"+ TrueName +"_"+ InterfaceName ) = get_NameDelegator
\r
2805 Const F_ValidateOnlyDelegate = &h40000000
\r
2806 Dim g_bNeedValidateDelegate
\r
2809 Function NameDelegator_getTrueName( m )
\r
2810 If VarType( m.m_Delegate ) = vbString Then
\r
2811 NameDelegator_getTrueName = m.m_Delegate
\r
2813 NameDelegator_getTrueName = m.m_Delegate.TrueName
\r
2818 Sub NameDelegator_validate( m, Flags )
\r
2819 If VarType( m.m_Delegate ) = vbString Then
\r
2820 Set m.m_Delegate = get_Object( m.m_Delegate )
\r
2822 If ( Flags and F_ValidateOnlyDelegate ) = 0 Then _
\r
2823 m.m_Delegate.Validate Flags
\r
2827 Function NameDelegator_getXML( m )
\r
2828 If VarType( m.m_Delegate ) = vbString Then
\r
2829 NameDelegator_getXML = "<" + TypeName( m ) + _
\r
2830 " Name='" + m.Name + "' TrueName='" + m.TrueName + "'/>"
\r
2832 NameDelegator_getXML = "<" + TypeName( m ) + _
\r
2833 " Name='" + m.Name + "' TrueName='" + m.TrueName + "'>" +vbCRLF+_
\r
2834 m.m_Delegate.xml + vbCRLF + "</" + TypeName( m ) + ">"
\r
2840 '********************************************************************************
\r
2841 ' <<< [new_X] >>>
\r
2842 '********************************************************************************
\r
2843 Function new_X( Name )
\r
2846 On Error Resume Next
\r
2847 Dim new_f : Set new_f = GetRef( "new_" + Name )
\r
2848 en = Err.Number : ed = Err.Description : On Error GoTo 0
\r
2849 If en = 5 Then Err.Raise en,,ed + " : Not defined 'new_" + Name + "'"
\r
2850 If en <> 0 Then Err.Raise en,,ed
\r
2852 Set new_X = new_f()
\r
2857 '********************************************************************************
\r
2858 ' <<< [include_objs] >>>
\r
2859 '********************************************************************************
\r
2860 Dim g_included_paths : Set g_included_paths = CreateObject( "Scripting.Dictionary" )
\r
2862 Sub include_objs( Wildcard, Flags, out_GetObjectFuncs )
\r
2863 Dim ds_:Set ds_= new CurDirStack
\r
2864 Dim folder_path, fname_key_s, folders, fo, f, fi, t, en, ed
\r
2865 Dim fname_key : Set fname_key = new StrMatchKey
\r
2867 If g_fs.FolderExists( Wildcard ) Then
\r
2868 folder_path = Wildcard : fname_key_s = "*_obj.vbs"
\r
2870 folder_path = GetParentAbsPath( Wildcard ) : fname_key_s = g_fs.GetFileName( Wildcard )
\r
2872 fname_key.Keyword = LCase( fname_key_s )
\r
2874 ReDim out_GetObjectFuncs(-1)
\r
2876 EnumFolderObject folder_path, folders '// [out] folders
\r
2877 For Each fo In folders
\r
2878 For Each f In fo.Files
\r
2879 If fname_key.IsMatch( f.Name ) Then
\r
2880 g_SrcPath = f.Path
\r
2882 If IsEmpty( g_included_paths.Item( g_SrcPath ) ) Then
\r
2884 If g_debug Then echo ">include """ + f.Path + """"
\r
2886 ExecuteGlobal "Sub get_StaticObjects(a,b) : End Sub"
\r
2888 Set fi = g_fs.OpenTextFile( g_SrcPath )
\r
2889 If g_debug Then t = "'// " + g_SrcPath +vbCRLF+ fi.ReadAll() Else t = fi.ReadAll()
\r
2891 g_sh.CurrentDirectory = fo.Path
\r
2893 If not IsEmpty( g_debug_vbs_path ) and _
\r
2894 InStr( g_SrcPath, g_debug_vbs_path ) > 0 Then
\r
2895 InvestigateInterpretError2 g_SrcPath, en, ed
\r
2897 On Error Resume Next
\r
2898 ExecuteGlobal t '// Interpret g_SrcPath
\r
2899 en = Err.Number : ed = Err.Description : On Error GoTo 0
\r
2901 InvestigateInterpretError g_SrcPath, en, ed
\r
2905 ReDim Preserve out_GetObjectFuncs( UBound( out_GetObjectFuncs ) + 1 )
\r
2906 Set out_GetObjectFuncs( UBound( out_GetObjectFuncs ) ) = GetRef( "get_StaticObjects" )
\r
2908 Set g_included_paths.Item( g_SrcPath ) = out_GetObjectFuncs( UBound( out_GetObjectFuncs ) )
\r
2910 ReDim Preserve out_GetObjectFuncs( UBound( out_GetObjectFuncs ) + 1 )
\r
2911 Set out_GetObjectFuncs( UBound( out_GetObjectFuncs ) ) = g_included_paths.Item( g_SrcPath )
\r
2921 '********************************************************************************
\r
2922 ' <<< [get_ObjectsFromFile] >>>
\r
2923 '********************************************************************************
\r
2924 Sub get_ObjectsFromFile( GetObjectFuncs, InterfaceName, out_Objs )
\r
2925 If VarType( GetObjectFuncs ) = vbString Then
\r
2927 include_objs GetObjectFuncs, Empty, create_funcs '// [out] create_funcs
\r
2928 get_ObjectsFromFile_sub create_funcs, InterfaceName, out_Objs
\r
2930 get_ObjectsFromFile_sub GetObjectFuncs, InterfaceName, out_Objs
\r
2934 Sub get_ObjectsFromFile_sub( GetObjectFuncs, InterfaceName, out_Objs )
\r
2937 ReDim out_Objs(-1)
\r
2938 For Each func In GetObjectFuncs
\r
2940 Call func( InterfaceName, objs ) '// [out] objs
\r
2941 AddArrElem out_Objs, objs
\r
2947 '********************************************************************************
\r
2948 ' <<< [get_DefineInfoObject] >>>
\r
2949 '********************************************************************************
\r
2950 Class DefineInfoClass
\r
2954 Sub get_DefineInfoObject( in_out_Object, FullPath )
\r
2955 If not IsEmpty( in_out_Object ) and not g_bInvestigateInterpretError Then _
\r
2956 Raise 1, "2nd execute(include)"
\r
2957 Set in_out_Object = new DefineInfoClass
\r
2958 in_out_Object.FullPath = FullPath
\r
2962 '********************************************************************************
\r
2963 ' <<< [InvestigateInterpretError] >>>
\r
2964 '********************************************************************************
\r
2965 Dim g_debug_vbs_path
\r
2966 Dim g_debug_vbs_err_num
\r
2967 Dim g_bInvestigateInterpretError
\r
2969 Sub InvestigateInterpretError( Path, en, ed )
\r
2973 echo ">InvestigateInterpretError """ + Path + """"
\r
2974 g_bInvestigateInterpretError = True
\r
2976 Set f = g_fs.OpenTextFile( Path ) : t = f.ReadAll() : f.Close
\r
2978 On Error Resume Next
\r
2980 en2 = Err.Number : ed2 = Err.Description : On Error GoTo 0
\r
2983 Err.Raise en,,"<ERROR msg='"+ ed +"' include_path="+vbCRLF+"'"+ g_SrcPath +_
\r
2984 "'"+vbCRLF+"hint='2
\89ñ
\96Ú
\82Ì ExecuteGlobal
\82Å
\82Í
\83G
\83\89\81[
\82ª
\8fo
\82Ü
\82¹
\82ñ
\82Å
\82µ
\82½
\81B"+_
\r
2985 "
\8e\9f\82Ì
\83R
\81[
\83h
\82ð main
\8aÖ
\90\94\82É
\8bL
\8fq
\82µ
\82Ä
\8dÄ
\8eÀ
\8ds
\82µ
\82Ä
\82
\82¾
\82³
\82¢' add_code=" +vbCRLF+_
\r
2986 "'g_debug_vbs_path = """ + Path + """'/>"
\r
2989 echo GetErrStr( en, ed )
\r
2992 '// Try to display error line
\r
2993 RunProg "wscript.exe """ + Path + """", ""
\r
2996 '// Error of Duplicate Name
\r
2997 If en2 = 1041 Then
\r
2998 Err.Raise en,,"<ERROR msg='"+ ed +"' include_path="+vbCRLF+"'"+ g_SrcPath +_
\r
2999 "'"+vbCRLF+"hint='
\8e\9f\82Ì
\83R
\81[
\83h
\82ð main
\8aÖ
\90\94\82É
\8bL
\8fq
\82µ
\82Ä
\8dÄ
\8eÀ
\8ds
\82µ
\82Ä
\82
\82¾
\82³
\82¢' add_code=" +vbCRLF+_
\r
3000 "'g_debug_vbs_path = """ + Path + """ : g_debug_vbs_err_num = 1041'/>"
\r
3004 '// Try to break at error line ([attention] 2nd execute may different behavior)
\r
3005 Set f = g_fs.OpenTextFile( Path ) : t = f.ReadAll() : f.Close
\r
3006 ExecuteGlobal "'// This is 2nd execute(include) from InvestigateInterpretError." +vbCRLF + t
\r
3009 '// This is no new hint
\r
3010 Err.Raise en,,"<ERROR msg='"+ ed +"' include_path="+vbCRLF+"'"+ g_SrcPath + "'/>"
\r
3015 '********************************************************************************
\r
3016 ' <<< [InvestigateInterpretError2] >>>
\r
3017 '********************************************************************************
\r
3018 Sub InvestigateInterpretError2( Path, en, ed )
\r
3021 If g_debug_vbs_err_num = 1041 Then
\r
3023 InvestigateDuplicatedNameError g_SrcPath, en, ed
\r
3025 ElseIf g_debug_vbs_err_num = -1041 Then
\r
3026 Stop ' This is 1st include. Next is ...
\r
3027 g_debug_vbs_err_num = 1041
\r
3028 Set f = g_fs.OpenTextFile( Path ) : t = f.ReadAll() : f.Close
\r
3029 ExecuteGlobal t '// Interpret g_SrcPath
\r
3032 Set f = g_fs.OpenTextFile( Path ) : t = f.ReadAll() : f.Close
\r
3033 ExecuteGlobal t '// Interpret g_SrcPath
\r
3038 '********************************************************************************
\r
3039 ' <<< [InvestigateDuplicatedNameError] >>>
\r
3040 '********************************************************************************
\r
3041 Sub InvestigateDuplicatedNameError( Path, en, ed )
\r
3044 Set f = g_fs.OpenTextFile( Path )
\r
3045 Do Until f.AtEndOfStream
\r
3047 i = InStr( t, "Class" )
\r
3048 If i = 0 Then i = InStr( t, "Dim" )
\r
3052 If Mid(t,i,1)=" " Then Exit Do
\r
3056 If Mid(t,i,1)<>" " Then Exit Do
\r
3063 If not( (c>="A" and c<="Z") or (c>="a" and c<="z") or (c>="0" and c<="9") or c="_" ) Then _
\r
3068 If InStr( t, "Class" ) > 0 Then
\r
3069 c = "Class " + Mid( t, i, j-i ) + " : End Class"
\r
3071 c = "Dim " + Mid( t, i, j-i )
\r
3073 echo ">ExecuteGlobal """ + c + """"
\r
3080 Err.Raise en,,"<ERROR msg='"+ ed +"' include_path="+vbCRLF+"'"+ g_SrcPath +_
\r
3081 "'"+vbCRLF+"hint='2
\89ñ include
\82µ
\82Ä
\82¢
\82é
\89Â
\94\
\90«
\82ª
\82 \82è
\82Ü
\82·
\81B"+_
\r
3082 "
\8e\9f\82Ì
\83R
\81[
\83h
\82ð main
\8aÖ
\90\94\82É
\8bL
\8fq
\82µ
\82Ä
\8dÄ
\8eÀ
\8ds
\82µ
\82Ä
\82
\82¾
\82³
\82¢' add_code=" +vbCRLF+_
\r
3083 "'g_debug_vbs_path = """ + Path + """ : g_debug_vbs_err_num = -1041'/>"
\r
3088 '*-------------------------------------------------------------------------*
\r
3089 '* ### <<<< Process >>>>
\r
3090 '*-------------------------------------------------------------------------*
\r
3094 '********************************************************************************
\r
3095 ' <<< [env] Expand environment strings >>>
\r
3096 '********************************************************************************
\r
3098 If IsEmpty( s ) Then Exit Function '// for avoid to s=""
\r
3100 Dim p1, p2, symbol, value
\r
3103 p1 = InStr( i, s, "%" )
\r
3105 env = env & Mid( s, i )
\r
3108 env = env & Mid( s, i, p1 - i )
\r
3109 p2 = InStr( p1+1, s, "%" )
\r
3113 symbol = Mid( s, p1+1, p2-p1-1 )
\r
3114 value = GetVar( symbol )
\r
3115 If IsEmpty( value ) Then _
\r
3116 Err.Raise E_NotFoundSymbol,, "<ERROR msg='not found var symbol' symbol='"+ symbol +"'/>"
\r
3126 '********************************************************************************
\r
3127 ' <<< [start] >>>
\r
3128 '********************************************************************************
\r
3129 Sub start( cmdline )
\r
3130 echo ">start " & cmdline
\r
3131 cmdline = g_sh.ExpandEnvironmentStrings( cmdline )
\r
3135 On Error Resume Next
\r
3137 g_sh.Run cmdline,, FALSE
\r
3139 en = Err.Number : ed = Err.Description : On Error GoTo 0
\r
3140 If en = E_WIN32_FILE_NOT_FOUND Then _
\r
3141 Err.Raise en,,"
\83t
\83@
\83C
\83\8b\82©
\83t
\83H
\83\8b\83_
\82ª
\8c©
\82Â
\82©
\82è
\82Ü
\82¹
\82ñ : " + cmdline
\r
3142 If en <> 0 Then Err.Raise en,,ed
\r
3147 '********************************************************************************
\r
3148 ' <<< [RunProg] >>>
\r
3149 '********************************************************************************
\r
3150 Function RunProg( ByVal cmdline, stdout_stderr_redirect )
\r
3153 '// Set debug mode
\r
3154 If stdout_stderr_redirect = "_debug" Then
\r
3155 dbg_cmd = "cmd /K " : stdout_stderr_redirect = ""
\r
3161 '// Echo command line
\r
3162 echo ">current dir = """ & g_sh.CurrentDirectory & """"
\r
3163 If stdout_stderr_redirect = "" Then
\r
3164 echo ">RunProg " & cmdline
\r
3166 echo ">RunProg " & cmdline+" >> """+stdout_stderr_redirect+""""
\r
3171 cmdline = g_sh.ExpandEnvironmentStrings( cmdline )
\r
3174 '// avoid to stop by StdIn
\r
3175 if ( Left( cmdline, 7 ) = "cscript" ) Then _
\r
3176 cmdline = cmdline + " /GUI_input:1"
\r
3179 '// Create new process
\r
3181 Set ex = g_sh.Exec( cmdline )
\r
3182 stdout_stderr_redirect = g_sh.ExpandEnvironmentStrings( stdout_stderr_redirect )
\r
3183 RunProg = WaitForFinishAndRedirect( ex, stdout_stderr_redirect )
\r
3190 '********************************************************************************
\r
3191 ' <<< [WaitForFinishAndRedirect] >>>
\r
3192 'http://itpro.nikkeibp.co.jp/article/COLUMN/20080805/312155/?ST=develop&P=2
\r
3193 '********************************************************************************
\r
3194 Function WaitForFinishAndRedirect( ex, path )
\r
3198 If g_debug and IsEmpty( g_ChildHead ) Then g_ChildHead = ">|"
\r
3200 If path <> "" and path <> "nul" Then
\r
3201 Dim ec : Set ec = new EchoOff
\r
3202 Set f = OpenForWrite( path, F_Append )
\r
3206 Do While ex.Status = 0
\r
3207 If path = "nul" or IsEmpty( path ) Then
\r
3208 Do Until ex.StdOut.AtEndOfStream : ex.StdOut.ReadLine : Loop
\r
3209 Do Until ex.StdErr.AtEndOfStream : ex.StdErr.ReadLine : Loop
\r
3210 ElseIf path = "" Then
\r
3211 EchoStream ex.StdOut, WScript.StdOut, ex, g_ChildHead
\r
3212 EchoStream ex.StdErr, WScript.StdErr, ex, g_ChildHead
\r
3214 Do Until ex.StdOut.AtEndOfStream : f.WriteLine ex.StdOut.ReadLine : Loop
\r
3215 Do Until ex.StdErr.AtEndOfStream : f.WriteLine ex.StdErr.ReadLine : Loop
\r
3219 If path = "nul" or IsEmpty( path ) Then
\r
3220 Do Until ex.StdOut.AtEndOfStream : ex.StdOut.ReadLine : Loop
\r
3221 Do Until ex.StdErr.AtEndOfStream : ex.StdErr.ReadLine : Loop
\r
3222 ElseIf path = "" Then
\r
3223 EchoStream ex.StdOut, WScript.StdOut, ex, g_ChildHead
\r
3224 EchoStream ex.StdErr, WScript.StdErr, ex, g_ChildHead
\r
3226 Do Until ex.StdOut.AtEndOfStream : f.WriteLine ex.StdOut.ReadLine : Loop
\r
3227 Do Until ex.StdErr.AtEndOfStream : f.WriteLine ex.StdErr.ReadLine : Loop
\r
3229 WaitForFinishAndRedirect = ex.ExitCode
\r
3234 '********************************************************************************
\r
3235 ' <<< [EchoStream] echo supported No vbCRLF >>>
\r
3236 '********************************************************************************
\r
3237 Dim g_EchoStreamBuf
\r
3238 Sub EchoStream( StreamIn, StreamOut, ex, Prompt )
\r
3241 Do Until StreamIn.AtEndOfStream
\r
3242 c = StreamIn.Read(1)
\r
3243 If c <> vbCR and c <> vbLF Then
\r
3244 If g_EchoStreamBuf = "" Then StreamOut.Write Prompt
\r
3245 g_EchoStreamBuf = g_EchoStreamBuf + c
\r
3248 '// pause
\82Ì
\82Ý
\91Î
\89\9e\r
3249 If Left( g_EchoStreamBuf, 6 ) = "
\91±
\8ds
\82·
\82é
\82É
\82Í" Then
\r
3251 If g_EchoStreamBuf="
\91±
\8ds
\82·
\82é
\82É
\82Í
\89½
\82©
\83L
\81[
\82ð
\89\9f\82µ
\82Ä
\82
\82¾
\82³
\82¢ . . . " Then i = 1
\r
3252 If g_EchoStreamBuf=Left(g_PauseMsg,g_PauseMsgStone)+"*"+Chr(8) Then i = 3
\r
3253 If g_EchoStreamBuf=g_PauseMsg Then i = 2
\r
3256 If ex.Status = 0 Then
\r
3258 WScript.StdIn.ReadLine '// Waiting Enter from only main process
\r
3260 ex.StdIn.Write vbCR
\r
3263 ex.StdIn.Write vbCRLF
\r
3267 If not IsEmpty( g_Test ) Then g_Test.WriteLogLine g_EchoStreamBuf
\r
3268 g_EchoStreamBuf = ""
\r
3275 StreamOut.Write vbLF
\r
3276 If not IsEmpty( g_Test ) Then g_Test.WriteLogLine g_EchoStreamBuf
\r
3277 g_EchoStreamBuf = ""
\r
3286 '********************************************************************************
\r
3287 ' <<< [ArgumentExist] >>>
\r
3288 '********************************************************************************
\r
3289 Function ArgumentExist( name )
\r
3291 For Each key in WScript.Arguments.Named
\r
3292 If key = name Then ArgumentExist = True : Exit Function
\r
3294 ArgumentExist = False
\r
3299 '********************************************************************************
\r
3300 ' <<< [GetSearchOpenCmdLine] >>>
\r
3301 '********************************************************************************
\r
3302 Function GetSearchOpenCmdLine( PathAndName )
\r
3305 Dim i_sep, i_sharp, i_kakko, name_type, line_num
\r
3306 Const no_name_type = 0, line_type = 2, str_type = 3
\r
3309 '//=== Get path and name
\r
3310 i_sep = InStrRev( PathAndName, "\" )
\r
3311 i_sharp = InStrRev( PathAndName, "#" )
\r
3312 If i_sep >= i_sharp Then '// NoName = (7,5), (0,0), (7,0)
\r
3313 path = PathAndName : name = Empty
\r
3314 Else '// WithName = (5,7), (0,7)
\r
3315 path = Left( PathAndName, i_sharp - 1 )
\r
3316 name = Mid( PathAndName, i_sharp + 1 )
\r
3320 '//=== Get line number
\r
3321 If IsEmpty( name ) and Right( PathAndName, 1 ) = ")" Then
\r
3322 i_kakko = InStrRev( PathAndName, "(" )
\r
3323 line_num = Mid( PathAndName, i_kakko + 1 )
\r
3324 line_num = CInt( Left( line_num, Len( line_num ) - 1 ) )
\r
3325 '// not use TagJumpPath
\r
3326 path = Left( PathAndName, i_kakko - 1 )
\r
3331 path = GetAbsPath( path, Empty )
\r
3332 If not g_fs.FileExists( path ) Then _
\r
3333 Raise E_FileNotExist, "<ERROR msg='
\83t
\83@
\83C
\83\8b\82ª
\8c©
\82Â
\82©
\82è
\82Ü
\82¹
\82ñ' path='"+ path +"'/>"
\r
3336 '//=== Get command line template
\r
3337 If not IsDefined( "Setting_getEditorCmdLine" ) Then
\r
3338 cmd = """C:\Windows\notepad.exe"" ""%1"""
\r
3340 cmd = Setting_getEditorCmdLine( 3 )
\r
3341 name_type = str_type
\r
3342 If InStr( cmd, "%2" ) = 0 Then cmd = Empty
\r
3343 If IsEmpty( cmd ) and ( not IsEmpty( line_num ) or not IsEmpty( name ) ) Then
\r
3344 cmd = Setting_getEditorCmdLine( 2 )
\r
3345 name_type = line_type
\r
3347 If IsEmpty( cmd ) Then
\r
3348 cmd = Setting_getEditorCmdLine( 1 )
\r
3349 name_type = no_name_type
\r
3351 If IsEmpty( cmd ) Then
\r
3352 cmd = Setting_getEditorCmdLine( 0 )
\r
3353 cmd = """" + cmd + """ ""%1"""
\r
3355 If IsEmpty( cmd ) Then
\r
3356 cmd = """C:\Windows\notepad.exe"" ""%1"""
\r
3361 '//=== Replace command line
\r
3362 Select Case name_type
\r
3363 Case str_type : cmd = Replace( cmd, "%2", name )
\r
3365 If IsEmpty( line_num ) Then line_num = GetLineOfSearchOpen( path, name )
\r
3366 cmd = Replace( cmd, "%d", CStr( line_num ) )
\r
3368 GetSearchOpenCmdLine = Replace( cmd, "%1", path )
\r
3372 Function GetLineOfSearchOpen( Path, Name )
\r
3375 Set f = OpenForRead( Path )
\r
3377 Do Until f.AtEndOfStream
\r
3378 line = f.ReadLine()
\r
3379 If InStr( line, Name ) > 0 Then
\r
3380 GetLineOfSearchOpen = i
\r
3386 GetLineOfSearchOpen = 1
\r
3391 '********************************************************************************
\r
3392 ' <<< [GetDiffCmdLine] >>>
\r
3393 '********************************************************************************
\r
3394 Function GetDiffCmdLine( PathA, PathB )
\r
3395 If not IsDefined( "Setting_getDiffCmdLine" ) Then
\r
3396 echo "Diff """ + PathA + """ """ + PathB + """"
\r
3399 cmd = Setting_getDiffCmdLine( 2 )
\r
3400 cmd = Replace( cmd, "%1", GetTagJumpPath( PathA ) )
\r
3401 cmd = Replace( cmd, "%2", GetTagJumpPath( PathB ) )
\r
3402 GetDiffCmdLine = cmd
\r
3407 '********************************************************************************
\r
3408 ' <<< [GetDiffCmdLine3] >>>
\r
3409 '********************************************************************************
\r
3410 Function GetDiffCmdLine3( PathA, PathB, PathC )
\r
3411 If not IsDefined( "Setting_getDiffCmdLine" ) Then
\r
3412 echo "Diff """ + PathA + """ """ + PathB + """"
\r
3415 cmd = Setting_getDiffCmdLine( 3 )
\r
3416 cmd = Replace( cmd, "%1", GetTagJumpPath( PathA ) )
\r
3417 cmd = Replace( cmd, "%2", GetTagJumpPath( PathB ) )
\r
3418 cmd = Replace( cmd, "%3", GetTagJumpPath( PathC ) )
\r
3419 GetDiffCmdLine3 = cmd
\r
3424 '********************************************************************************
\r
3425 ' <<< [GetDiffCmdLineMulti] >>>
\r
3426 '********************************************************************************
\r
3427 Function GetDiffCmdLineMulti( Files )
\r
3430 echo "--------------------------------------------------------"
\r
3431 For i=0 To UBound( Files )
\r
3432 echo (i+1) & ". " & Files(i)(0)
\r
3434 op = CInt2( input( "Select number>" ) ) - 1
\r
3435 echo "--------------------------------------------------------"
\r
3438 Select Case UBound( Files(op)(1) )
\r
3440 Case 1: '// 2 files
\r
3441 GetDiffCmdLineMulti = GetDiffCmdLine( _
\r
3442 GetAbsPath( Files(op)(1)(0) +"\"+ Files(op)(0), Empty ), _
\r
3443 GetAbsPath( Files(op)(1)(1) +"\"+ Files(op)(0), Empty ) )
\r
3445 Case 2: '// 3 files
\r
3446 GetDiffCmdLineMulti = GetDiffCmdLine3( _
\r
3447 GetAbsPath( Files(op)(1)(0) +"\"+ Files(op)(0), Empty ), _
\r
3448 GetAbsPath( Files(op)(1)(1) +"\"+ Files(op)(0), Empty ), _
\r
3449 GetAbsPath( Files(op)(1)(2) +"\"+ Files(op)(0), Empty ) )
\r
3459 '*-------------------------------------------------------------------------*
\r
3460 '* ### <<<< Wait >>>>
\r
3461 '*-------------------------------------------------------------------------*
\r
3465 '********************************************************************************
\r
3466 ' <<< [Sleep] >>>
\r
3467 '********************************************************************************
\r
3468 Sub Sleep( ByVal msec )
\r
3469 echo ">Sleep " & msec
\r
3470 WScript.Sleep msec
\r
3475 '********************************************************************************
\r
3476 ' <<< [WaitForFile] Wait for make the file >>>
\r
3477 '********************************************************************************
\r
3478 Function WaitForFile( Path )
\r
3479 echo ">WaitForFile " & Path
\r
3482 '//=== Wait for file exists
\r
3484 While g_fs.FileExists( Path ) = False
\r
3485 WScript.Sleep 1000
\r
3486 f=f+1 : If f=3 Then WScript.Echo ">WaitForFile " & Path & " ..."
\r
3490 '//=== Open file supported lock
\r
3492 On Error Resume Next
\r
3493 Set f = g_fs.OpenTextFile( Path )
\r
3494 en = Err.Number : ed = Err.Description : On Error GoTo 0
\r
3495 If en <> E_WriteAccessDenied Then
\r
3496 If en <> 0 Then Err.Raise en,,ed
\r
3501 '//=== Read file supported lock
\r
3503 On Error Resume Next
\r
3504 WaitForFile = f.ReadLine
\r
3505 en = Err.Number : ed = Err.Description : On Error GoTo 0
\r
3506 If en <> E_EndOfFile Then
\r
3507 If en <> 0 Then Err.Raise en,,ed
\r
3515 '//=== Delete file
\r
3517 While g_fs.FileExists( Path )
\r
3518 WScript.Sleep 200 '// Delete may have delay ?
\r
3524 '*-------------------------------------------------------------------------*
\r
3525 '* ### <<<< Sound >>>>
\r
3526 '*-------------------------------------------------------------------------*
\r
3530 '********************************************************************************
\r
3532 '********************************************************************************
\r
3534 Player_validate '// g_Player
\r
3536 With g_Player.m_Obj
\r
3538 '// .PreviewMode = True '// Cannot play movie because WSH does not have window.
\r
3544 '********************************************************************************
\r
3545 ' <<< [SystemSound] >>>
\r
3546 '********************************************************************************
\r
3547 Sub SystemSound( Sound )
\r
3548 Const base = "HKEY_CURRENT_USER\AppEvents\Schemes\Apps\"
\r
3549 Const current = "\.Current\"
\r
3550 Const E_PathNotFound = &h80070002
\r
3552 Dim en,ed, parent, reg_path, file_path
\r
3554 For Each parent In Array( ".Default", "Explorer", "devenv", "dexplore", "sapisvr" )
\r
3555 reg_path = base + parent +"\"+ Sound + current
\r
3556 On Error Resume Next
\r
3557 file_path = env( g_sh.RegRead( reg_path ) )
\r
3558 en = Err.Number : ed = Err.Description : On Error GoTo 0
\r
3559 If en = 0 Then Exit For
\r
3560 If en <> E_PathNotFound Then Err.Raise en,,ed
\r
3562 If file_path <> "" and file_path <> reg_path Then Play file_path
\r
3566 '********************************************************************************
\r
3567 ' <<< [WaitForSound] >>>
\r
3568 '********************************************************************************
\r
3569 Sub WaitForSound( Timeout_msec )
\r
3570 Player_validate '// g_Player
\r
3572 Dim i : i = CInt( Timeout_msec / 250 )
\r
3573 If IsEmpty( Timeout_msec ) Then i=9
\r
3574 For i=i To 1 Step -1
\r
3575 If g_Player.m_Obj.PlayState = 1 Then Exit For
\r
3576 If g_Player.m_Obj.PlayState = 10 Then Raise E_PathNotFound, _
\r
3577 "<ERROR msg='Cannot play the file' path='" + g_Player.m_Obj.URL + "'/>"
\r
3579 If IsEmpty( Timeout_msec ) Then i=9
\r
3581 g_Player.m_Obj.Controls.Stop
\r
3584 '********************************************************************************
\r
3585 ' <<< [SetVolume] >>>
\r
3586 '********************************************************************************
\r
3587 Sub SetVolume( Volume )
\r
3588 Player_validate '// g_Player
\r
3589 g_Player.m_Obj.Settings.Volume = Volume
\r
3594 '********************************************************************************
\r
3595 ' <<< [Player_validate] >>>
\r
3596 '********************************************************************************
\r
3597 Sub Player_validate()
\r
3598 If IsEmpty( g_Player ) Then Set g_Player = new Vbslib_Player
\r
3601 Class Vbslib_Player
\r
3604 Private Sub Class_Initialize()
\r
3605 Set m_Obj = CreateObject( "WMPlayer.OCX" )
\r
3606 m_Obj.Settings.Volume = 100
\r
3609 Private Sub Class_Terminate()
\r
3611 For i=1 To 12 '// 12 = 3second for sound effects. Music will stop.
\r
3612 If m_Obj.PlayState = 1 or m_Obj.PlayState = 10 Then Exit For
\r
3621 '*-------------------------------------------------------------------------*
\r
3622 '* ### <<<< Variable, Array and collection >>>>
\r
3623 '*-------------------------------------------------------------------------*
\r
3627 '********************************************************************************
\r
3628 ' <<< [DicItem] >>>
\r
3629 '********************************************************************************
\r
3630 Function DicItem( Dic, Key )
\r
3631 If not Dic.Exists( Key ) Then Exit Function
\r
3632 If IsObject( Dic.Item( Key ) ) Then Set DicItem = Dic.Item( Key ) Else DicItem = Dic.Item( Key )
\r
3637 '********************************************************************************
\r
3638 ' <<< [DicToArr] >>>
\r
3639 '********************************************************************************
\r
3640 Sub DicToArr( Dic, Arr )
\r
3641 Dim keys : keys = Dic.Keys()
\r
3644 ReDim Arr( UBound( keys ) )
\r
3646 For Each key in keys
\r
3647 Set Arr(i) = new DicElem : ErrCheck
\r
3648 Arr(i).m_Key = key
\r
3649 If IsObject( Dic.Item(key) ) Then
\r
3650 Set Arr(i).m_Item = Dic.Item(key)
\r
3652 Arr(i).m_Item = Dic.Item(key)
\r
3664 '********************************************************************************
\r
3665 ' <<< [DicKeyToArr] >>>
\r
3666 '********************************************************************************
\r
3667 Sub DicKeyToArr( Dic, Arr )
\r
3668 Dim keys : keys = Dic.Keys()
\r
3671 ReDim Arr( UBound( keys ) )
\r
3673 For Each key in keys
\r
3681 '********************************************************************************
\r
3682 ' <<< [DicItemToArr] >>>
\r
3683 '********************************************************************************
\r
3684 Sub DicItemToArr( Dic, Arr )
\r
3685 Dim keys : keys = Dic.Keys()
\r
3688 ReDim Arr( UBound( keys ) )
\r
3690 For Each key in keys
\r
3691 If IsObject( Dic.Item(key) ) Then
\r
3692 Set Arr(i) = Dic.Item(key)
\r
3694 Arr(i) = dic.Item(key)
\r
3702 '********************************************************************************
\r
3703 ' <<< [CopyArr] >>>
\r
3704 '********************************************************************************
\r
3705 Sub CopyArr( Dst, Src )
\r
3706 If g_cut_old Then Stop ' Do not Dim a(). Dim a,b : b = Array( 1, 2 ) : a = b
\r
3708 If IsArray( Src ) Then
\r
3711 ReDim Dst( UBound( Src ) )
\r
3712 For i=UBound( Src ) To 0 Step -1
\r
3713 If IsObject( Src(i) ) Then Set Dst(i) = Src(i) Else Dst(i) = Src(i)
\r
3717 If IsObject( Src ) Then Set Dst(0) = Src Else Dst(0) = Src
\r
3722 '********************************************************************************
\r
3723 ' <<< [AddArrElem] >>>
\r
3724 '********************************************************************************
\r
3725 Sub AddArrElem( Dst, Src )
\r
3726 If TypeName( Dst ) = "Dictionary" Then
\r
3729 If IsArray( Src ) Then
\r
3730 For Each obj In Src : If not IsEmpty( obj ) Then
\r
3731 If IsObject( obj ) Then Set Dst.Item( obj.Name ) = obj Else Dst.Item( obj ) = True
\r
3733 ElseIf TypeName( Src ) = "Dictionary" Then
\r
3734 For Each key In Src.Keys()
\r
3735 If IsObject( Src.Item( key ) ) Then
\r
3736 Set Dst.Item( key ) = Src.Item( key )
\r
3738 Dst.Item( key ) = Src.Item( key )
\r
3742 If IsObject( Src ) Then Set Dst.Item( Src.Name ) = Src Else Dst.Item( Src.Name ) = True
\r
3747 n = UBound( Dst ) + 1
\r
3748 If IsArray( Src ) Then
\r
3749 ReDim Preserve Dst( n + UBound( Src ) )
\r
3750 For i=UBound( Src ) To 0 Step -1
\r
3751 If IsObject( Src(i) ) Then Set Dst(n+i) = Src(i) Else Dst(n+i) = Src(i)
\r
3753 ElseIf not IsEmpty( Src ) Then
\r
3754 ReDim Preserve Dst( n )
\r
3755 If IsObject( Src ) Then Set Dst(n) = Src Else Dst(n) = Src
\r
3762 '********************************************************************************
\r
3763 ' <<< [IsSameArray] >>>
\r
3764 '********************************************************************************
\r
3765 Function IsSameArray( Arr1, Arr2 )
\r
3768 If IsEmpty( Arr1 ) <> IsEmpty( Arr2 ) Then IsSameArray = False : Exit Function
\r
3769 If IsEmpty( Arr1 ) Then IsSameArray = True : Exit Function
\r
3771 If IsArray( Arr1 ) Then
\r
3772 If IsArray( Arr2 ) Then
\r
3773 If UBound( Arr1 ) <> UBound( Arr2 ) Then IsSameArray = False : Exit Function
\r
3775 If UBound( Arr1 ) <> UBound( Arr2.m_Array ) Then IsSameArray = False : Exit Function
\r
3777 low = LBound( Arr1 ) : up = UBound( Arr1 )
\r
3779 If IsArray( Arr2 ) Then
\r
3780 If UBound( Arr1.m_Array ) <> UBound( Arr2 ) Then IsSameArray = False : Exit Function
\r
3782 If UBound( Arr1.m_Array ) <> UBound( Arr2.m_Array ) Then IsSameArray = False : Exit Function
\r
3784 low = 0 : up = UBound( Arr1.m_Array )
\r
3788 If Arr1(i) <> Arr2(i) Then IsSameArray = False : Exit Function
\r
3790 IsSameArray = True
\r
3796 '********************************************************************************
\r
3797 ' <<< [QuickSort_fromDic] >>>
\r
3798 'dic as Scripting.Dictionary
\r
3799 'out_arr as [out] object array
\r
3800 '********************************************************************************
\r
3801 Sub QuickSort_fromDic( dic, out_arr, compare_func, param )
\r
3802 Dim i, i_last, elem
\r
3803 i_last = dic.Count - 1
\r
3804 Redim out_arr( i_last )
\r
3807 For Each elem In dic.Items
\r
3808 Set out_arr(i) = elem
\r
3812 QuickSort out_arr, 0, i_last, compare_func, param
\r
3818 '********************************************************************************
\r
3819 ' <<< [QuickSort] >>>
\r
3820 '********************************************************************************
\r
3821 Sub QuickSort( arr, i_left, i_right, compare_func, param )
\r
3822 Dim pivot, i_pivot, i_big_eq, i_small, sw, n_min_count
\r
3824 If i_left >= i_right Then Exit Sub ' rule-b'
\r
3826 i_pivot = ( i_left + i_right ) \ 2
\r
3827 Set pivot = arr( i_pivot )
\r
3831 ' Const watch_sort_id = 6 '//**********************************
\r
3832 ' Dim sort_debug_id, sort_debug_id2
\r
3833 ' g_SortDebugID = g_SortDebugID + 1
\r
3834 ' sort_debug_id = g_SortDebugID
\r
3835 ' Dim i, sym, value
\r
3836 ' echo "QuickSort start (" & sort_debug_id & ") ----------------------"
\r
3837 ' For i = i_left To i_right
\r
3838 ' QuickSort_Debug_getSym arr, i, sym, value
\r
3839 ' If i = i_pivot Then value = value & " (pivot)"
\r
3840 ' echo "(" & i & ") " & sym & " = " & value
\r
3842 ' If sort_debug_id = watch_sort_id Then Stop
\r
3845 '//=== Split to [ arr(i_left) ][ smaller than ][ arr(i_pivot) ][ greater equal ][ arr(i_right) ]
\r
3846 i_big_eq = i_left : i_small = i_right
\r
3849 '// Plus i_big_eq. Result is that ( *i_big_eq >= *i_pivot ).
\r
3851 If compare_func( arr(i_big_eq), pivot, param ) >= 0 Then Exit Do
\r
3852 i_big_eq = i_big_eq + 1
\r
3855 '// Minus i_small. Result is that ( *i_pivot > *i_small ).
\r
3857 If i_small < i_left Then Exit Do
\r
3858 If compare_func( arr(i_small), pivot, param ) < 0 Then Exit Do
\r
3859 i_small = i_small - 1
\r
3864 ' If sort_debug_id = watch_sort_id Then
\r
3865 ' sort_debug_id2 = sort_debug_id2 + 1
\r
3866 ' echo "QuickSort swap (" & sort_debug_id & "-" & sort_debug_id2 & ")-----------------"
\r
3867 ' For i = i_left To i_right
\r
3868 ' QuickSort_Debug_getSym arr, i, sym, value
\r
3869 ' If i = i_small Then value = value & " (i_small)"
\r
3870 ' If i = i_big_eq Then value = value & " (i_big_eq)"
\r
3871 ' If i = i_pivot Then value = value & " (i_pivot)"
\r
3872 ' echo "(" & i & ") " & sym & " = " & value
\r
3878 If i_small < i_big_eq Then
\r
3879 If i_left <= i_small Then
\r
3883 '// If *i_pivot is minimum Then (4) collect minimuns at left
\r
3885 Set sw = arr(i_left) : Set arr(i_left) = arr(i_pivot) : Set arr(i_pivot) = sw
\r
3886 i_big_eq = i_big_eq + 1
\r
3887 n_min_count = n_min_count + 1
\r
3890 i_small = i_right '// i_small is iterater to same value as minimum
\r
3892 If i_big_eq >= i_small Then Exit Do
\r
3894 '// while ( *i_big_eq == *i_left ) i_big_eq++
\r
3895 If compare_func( arr(i_big_eq), pivot, param ) = 0 Then
\r
3896 i_big_eq = i_big_eq + 1
\r
3897 n_min_count = n_min_count + 1
\r
3899 '// Swap *i_big_eq and *i_small
\r
3902 If i_small <= i_big_eq Then Exit Do
\r
3903 If compare_func( arr(i_small), pivot, param ) = 0 Then
\r
3904 Set sw = arr(i_small) : Set arr(i_small) = arr(i_big_eq) : Set arr(i_big_eq) = sw
\r
3907 i_small = i_small - 1
\r
3909 If i_small <= i_big_eq Then Exit Do
\r
3916 '// If i_big_eq < i_pivot < i_small Then (1) Swap *i_big_eq and *i_small
\r
3917 ElseIf i_big_eq < i_pivot and i_pivot < i_small Then
\r
3918 Set sw = arr(i_big_eq) : Set arr(i_big_eq) = arr(i_small) : Set arr(i_small) = sw
\r
3919 i_big_eq = i_big_eq + 1 : i_small = i_small - 1
\r
3922 '// If i_big_eq = i_pivot < i_small Then (2A) Rotate3 *i_small -> *i_pivot -> *(i_pivot+1); i_pivot++
\r
3923 ElseIf i_big_eq = i_pivot and i_pivot < i_small Then
\r
3924 If i_pivot + 1 < i_small Then
\r
3925 Set sw = arr(i_pivot+1) : Set arr(i_pivot+1) = arr(i_pivot)
\r
3926 Set arr(i_pivot) = arr(i_small) : Set arr(i_small) = sw
\r
3927 i_big_eq = i_big_eq + 1 : i_pivot = i_pivot + 1
\r
3930 '// If i_big_eq = i_pivot and i_pivot+1 = i_small Then (2B) Swap *i_big_eq and *i_small
\r
3931 '// (If rotate3, The result is Not swaped)
\r
3933 Set sw = arr(i_big_eq) : Set arr(i_big_eq) = arr(i_small) : Set arr(i_small) = sw
\r
3934 i_big_eq = i_big_eq + 1
\r
3939 '// If i_big_eq < i_small < i_pivot Then (3) Rotate3 *i_small -> *i_big_eq -> *i_pivot; i_pivot--
\r
3940 ElseIf i_big_eq < i_small and i_small < i_pivot Then
\r
3941 Set sw = arr(i_pivot) : Set arr(i_pivot) = arr(i_big_eq)
\r
3942 Set arr(i_big_eq) = arr(i_small) : Set arr(i_small) = sw
\r
3943 i_big_eq = i_big_eq + 1 : i_small = i_small - 1 : i_pivot = i_pivot - 1
\r
3954 ' echo "QuickSort middle (" & sort_debug_id & ") ----------------------"
\r
3955 ' For i = i_left To i_right
\r
3956 ' QuickSort_Debug_getSym arr, i, sym, value
\r
3957 ' If i = i_big_eq-1 Then value = value & " (i_big_eq-1)"
\r
3958 ' If i = i_big_eq Then value = value & " (i_big_eq)"
\r
3959 ' echo "(" & i & ") " & sym & " = " & value
\r
3961 ' If sort_debug_id = watch_sort_id Then Stop
\r
3964 QuickSort arr, (i_left + n_min_count), i_big_eq-1, compare_func, param ' rule-b
\r
3965 QuickSort arr, i_big_eq, i_right, compare_func, param ' rule-b
\r
3969 ' echo "QuickSort end (" & sort_debug_id & ")----------------------"
\r
3970 ' For i = i_left To i_right
\r
3971 ' QuickSort_Debug_getSym arr, i, sym, value
\r
3972 ' echo "(" & i & ") " & sym & " = " & value
\r
3975 ' For i_small = i_left To i_right - 1
\r
3976 ' If compare_func( arr(i_small), arr(i_small + 1), param ) > 0 Then Error
\r
3983 'Dim g_SortDebugID
\r
3984 'Sub QuickSort_Debug_getSym( Arr, Index, out_Symbol, out_Value )
\r
3985 ' out_Symbol = Index
\r
3986 ' out_Value = Arr(Index).id
\r
3991 '********************************************************************************
\r
3992 ' <<< [ShakerSort_fromDic] >>>
\r
3993 'dic as Scripting.Dictionary
\r
3994 'out_arr as [out] object array
\r
3995 '********************************************************************************
\r
3996 Sub ShakerSort_fromDic( dic, out_arr, sign, compare_func, param )
\r
3997 Dim i, i_last, elem
\r
3998 i_last = dic.Count - 1
\r
3999 Redim out_arr( i_last )
\r
4003 For Each elem In dic.Items
\r
4004 Set out_arr(i) = elem
\r
4009 For Each elem In dic.Items
\r
4010 Set out_arr(i) = elem
\r
4015 ShakerSort out_arr, 0, i_last, compare_func, param
\r
4020 '********************************************************************************
\r
4021 ' <<< [ShakerSort] >>>
\r
4022 '********************************************************************************
\r
4023 Sub ShakerSort( arr, ByVal i_left, ByVal i_right, compare_func, param )
\r
4028 For i=i_left+1 To i_right
\r
4029 If compare_func( arr(i-1), arr(i), param ) > 0 Then
\r
4030 Set sw = arr(i-1) : Set arr(i-1) = arr(i) : Set arr(i) = sw
\r
4034 If i_swap = i_left+1 Then Exit Do
\r
4035 i_right = i_swap-1
\r
4037 i_swap = i_right-1
\r
4038 For i=i_right-1 To i_left Step -1
\r
4039 If compare_func( arr(i), arr(i+1), param ) > 0 Then
\r
4040 Set sw = arr(i) : Set arr(i) = arr(i+1) : Set arr(i+1) = sw
\r
4044 If i_swap = i_right-1 Then Exit Do
\r
4051 '********************************************************************************
\r
4052 ' <<< [CInt2] >>>
\r
4054 '********************************************************************************
\r
4055 Function CInt2( v )
\r
4058 On Error Resume Next
\r
4060 en = Err.Number : ed = Err.Description : On Error GoTo 0
\r
4061 If en = 13 Then '// if sym is not number
\r
4063 ElseIf en <> 0 Then Err.Raise en,,ed End If
\r
4068 '********************************************************************************
\r
4069 ' <<< [MeltQuot] >>>
\r
4070 '********************************************************************************
\r
4071 Function MeltQuot( Line, in_out_Start )
\r
4078 c = Mid( Line, i, 1 )
\r
4079 If c = "" Then in_out_Start = 0 : Exit Function
\r
4080 If c = """" Then Exit Do
\r
4086 '//=== Search the end of "
\r
4089 c = Mid( Line, i, 1 )
\r
4090 If c = "" Then in_out_Start = 0 : Exit Do
\r
4091 If c = """" Then in_out_Start = i + 1 : Exit Do
\r
4096 '//=== Get the string
\r
4097 MeltQuot = Mid( Line, j, i - j )
\r
4103 '********************************************************************************
\r
4104 ' <<< [CreateGuid] >>>
\r
4105 '********************************************************************************
\r
4108 Function CreateGuid()
\r
4109 If g_TestModeFlags and F_NotRandom Then
\r
4110 g_TypeLib = g_TypeLib + 1
\r
4111 CreateGuid = "00000000-0000-0000-0000-" & Right( "000000000000" & g_TypeLib, 12 )
\r
4113 If IsEmpty( g_TypeLib ) Then Set g_TypeLib = CreateObject("Scriptlet.TypeLib")
\r
4114 CreateGuid = Mid( g_TypeLib.Guid, 2, 36 )
\r
4120 '********************************************************************************
\r
4121 ' <<< [ReplaceTextFile] >>>
\r
4122 '********************************************************************************
\r
4128 Sub new_ReplaceItem( objs, n )
\r
4129 Dim i:ReDim objs(n-1):For i=0 To n-1:Set objs(i)=new ReplaceItem :Next : ErrCheck
\r
4132 Sub ReplaceTextFile( SrcPath, TmpDstPath, bDstWillBeExist, ReplaceList, Opt )
\r
4133 echo ">ReplaceTextFile """ & SrcPath & """, """ & TmpDstPath & """, " & bDstWillBeExist
\r
4134 Dim rep, item, line
\r
4136 Set rep = StartReplace( SrcPath, TmpDstPath, bDstWillBeExist )
\r
4137 Do Until rep.r.AtEndOfStream
\r
4138 line = rep.r.ReadLine
\r
4139 For Each item In ReplaceList
\r
4140 line = Replace( line, item.Src, item.Dst )
\r
4142 rep.w.WriteLine line
\r
4149 '********************************************************************************
\r
4150 ' <<< [StartReplace] >>>
\r
4151 '********************************************************************************
\r
4152 Function StartReplace( SrcPath, TmpDstPath, bDstWillBeExist )
\r
4153 echo ">StartReplace """ & SrcPath & """, """ & TmpDstPath & """, " & bDstWillBeExist
\r
4154 Dim ec : Set ec = new EchoOff : ErrCheck
\r
4155 Dim m : Set m = new StartReplaceObj : ErrCheck
\r
4156 m.Init1 SrcPath, TmpDstPath, bDstWillBeExist
\r
4157 Set StartReplace = m
\r
4162 '********************************************************************************
\r
4163 ' <<< [StartReplace2] >>>
\r
4164 '********************************************************************************
\r
4165 Function StartReplace2( SrcPath, MidPath, Flags, TmpDstPath, bDstWillBeExist )
\r
4166 echo ">StartReplace2 """ & SrcPath & """, """ & MidPath & """, """ & TmpDstPath & """, " & bDstWillBeExist
\r
4167 Dim ec : Set ec = new EchoOff : ErrCheck
\r
4168 Dim m : Set m = new StartReplaceObj : ErrCheck
\r
4169 m.Init2 SrcPath, MidPath, Flags, TmpDstPath, bDstWillBeExist
\r
4170 Set StartReplace2 = m
\r
4174 Dim F_Txt2BinTxt : F_Txt2BinTxt = 2
\r
4177 Class StartReplaceObj
\r
4178 Public m_SrcPath ' as string
\r
4179 Public m_TmpDstPath ' as string
\r
4180 Public m_bDstWillBeExist ' as boolean
\r
4182 Public m_MidPath ' as string
\r
4183 Public m_Flags ' as bitfield
\r
4185 Public r ' as TextStream of m_SrcPath
\r
4186 Public w ' as TextStream of m_TmpDstPath
\r
4188 Private m_bFinished
\r
4191 Public Sub Init1( SrcPath, TmpDstPath, bDstWillBeExist )
\r
4193 Dim ec : Set ec = new EchoOff : ErrCheck
\r
4195 m_SrcPath = SrcPath
\r
4196 m_TmpDstPath = TmpDstPath
\r
4197 m_bDstWillBeExist = bDstWillBeExist
\r
4199 mkdir g_fs.GetParentFolderName( g_fs.GetAbsolutePathName( m_TmpDstPath ) )
\r
4200 Set Me.r = OpenForRead( m_SrcPath )
\r
4202 On Error Resume Next
\r
4203 Set Me.w = g_fs.CreateTextFile( m_TmpDstPath, bDstWillBeExist, (g_TextFileConvertFormat = F_Unicode) )
\r
4204 en = Err.Number : ed = Err.Description : On Error GoTo 0
\r
4205 If en = E_AlreadyExist Then Err.Raise en,, "
\8aù
\82É
\93¯
\96¼
\82Ì
\83t
\83@
\83C
\83\8b\82ª
\91¶
\8dÝ
\82µ
\82Ä
\82¢
\82Ü
\82·
\81B: " + m_TmpDstPath
\r
4206 If en <> 0 Then Err.Raise en,,ed
\r
4210 Public Sub Init2( SrcPath, MidPath, Flags, TmpDstPath, bDstWillBeExist )
\r
4211 Init1 SrcPath, MidPath, bDstWillBeExist
\r
4212 m_MidPath = MidPath
\r
4213 m_TmpDstPath = TmpDstPath
\r
4214 m_Flags = Flags or 1
\r
4218 Public Sub Finish()
\r
4219 Dim ec : Set ec = new EchoOff : ErrCheck
\r
4223 If not IsEmpty( m_MidPath ) Then
\r
4224 If m_Flags and F_Txt2BinTxt Then
\r
4225 Txt2BinTxt m_MidPath, m_TmpDstPath
\r
4227 copy m_MidPath, m_TmpDstPath
\r
4232 If not m_bDstWillBeExist Then
\r
4233 copy m_TmpDstPath, m_SrcPath
\r
4236 m_bFinished = True
\r
4240 Public Sub ExitFinish( Opt )
\r
4241 m_bFinished = True
\r
4243 If not IsEmpty( m_MidPath ) Then del m_MidPath
\r
4248 Private Sub Class_Terminate()
\r
4249 Dim en,ed : en = Err.Number : ed = Err.Description
\r
4250 On Error Resume Next ' This clears the error
\r
4253 If en <> 0 and en <> 21 Then del m_TmpDstPath
\r
4254 ErrorCheckInTerminate
\r
4255 If en = 0 and not m_bFinished Then NotCallFinish
\r
4256 On Error GoTo 0 : If en <> 0 Then Err.Raise en,,ed
\r
4264 '********************************************************************************
\r
4265 ' <<< [TextFileCreateFormat] >>>
\r
4266 '********************************************************************************
\r
4267 Dim g_TextFileCreateFormat
\r
4268 Class TextFileCreateFormat
\r
4270 Private Sub Class_Initialize() : m_Prev = g_TextFileCreateFormat : End Sub
\r
4271 Public Sub Set_( Format ) : g_TextFileCreateFormat = Format : End Sub
\r
4272 Private Sub Class_Terminate : g_TextFileCreateFormat = m_Prev : End Sub
\r
4277 '********************************************************************************
\r
4278 ' <<< [TextFileConvertFormat] >>>
\r
4279 '********************************************************************************
\r
4280 Dim g_TextFileConvertFormat
\r
4281 Class TextFileConvertFormat
\r
4283 Private Sub Class_Initialize() : m_Prev = g_TextFileConvertFormat : End Sub
\r
4284 Public Sub Set_( Format ) : g_TextFileConvertFormat = Format : End Sub
\r
4285 Private Sub Class_Terminate : g_TextFileConvertFormat = m_Prev : End Sub
\r
4290 '-------------------------------------------------------------------------
\r
4291 ' ### <<<< [ArrayClass] Class >>>>
\r
4292 '-------------------------------------------------------------------------
\r
4297 Private Sub Class_Initialize
\r
4298 ReDim m_Array( -1 )
\r
4301 Public Default Property Get Item( i )
\r
4302 If IsObject( m_Array(i) ) Then Set Item = m_Array(i) Else Item = m_Array(i)
\r
4305 Public Property Let Item( i, value )
\r
4306 m_Array(i) = value
\r
4309 Public Sub ToEmpty()
\r
4310 ReDim m_Array( -1 )
\r
4313 Public Sub ReDim_( UBoundValue )
\r
4314 ReDim Preserve m_Array( UBoundValue )
\r
4317 Public Sub Add( elem )
\r
4321 Public Sub Push( elem )
\r
4322 ReDim Preserve m_Array( UBound(m_Array) + 1 )
\r
4323 If IsObject( elem ) Then
\r
4324 Set m_Array( UBound(m_Array) ) = elem
\r
4326 m_Array( UBound(m_Array) ) = elem
\r
4330 Public Function Pop()
\r
4331 If IsObject( m_Array( UBound(m_Array) ) ) Then
\r
4332 Set Pop = m_Array( UBound(m_Array) )
\r
4334 Pop = m_Array( UBound(m_Array) )
\r
4336 ReDim Preserve m_Array( UBound(m_Array) - 1 )
\r
4339 Public Property Get Count()
\r
4340 Count = UBound(m_Array) + 1
\r
4343 Public Property Get UBound_()
\r
4344 UBound_ = UBound(m_Array)
\r
4348 WScript.Echo Value
\r
4351 Public Property Get Value()
\r
4354 s = "count = " & Count
\r
4355 For Each i In m_Array
\r
4356 If IsObject( i ) Then
\r
4357 s = s + vbCRLF + "Class " & TypeName( i )
\r
4358 On Error Resume Next
\r
4359 s = s + vbCRLF + i.Value
\r
4362 If e <> 0 And e <> 438 Then Err.Raise e
\r
4364 s = s + vbCRLF + "each = " & i
\r
4370 Public Sub Copy( SrcArr )
\r
4371 If IsArray( SrcArr ) Then
\r
4373 ElseIf TypeName( SrcArr ) = "ArrayClass" Then
\r
4374 m_Array = SrcArr.m_Array
\r
4380 Public Sub AddElems( SrcArr )
\r
4381 If IsArray( SrcArr ) Then
\r
4382 AddArrElem m_Array, SrcArr
\r
4383 ElseIf TypeName( SrcArr ) = "ArrayClass" Then
\r
4384 AddArrElem m_Array, SrcArr.m_Array
\r
4393 '-------------------------------------------------------------------------
\r
4394 ' ### <<<< [ArrayDictionary] Class >>>>
\r
4395 '-------------------------------------------------------------------------
\r
4397 Class ArrayDictionary
\r
4401 Private Sub Class_Initialize
\r
4402 Set m_Dic = CreateObject("Scripting.Dictionary")
\r
4405 Public Sub ToEmpty
\r
4409 Public Sub Add( key, item )
\r
4412 If m_Dic.Exists( key ) Then
\r
4413 m_Dic.Item( key ).Add item
\r
4415 Set dic_item = New ArrayClass : ErrCheck
\r
4417 m_Dic.Add key, dic_item
\r
4421 Public Function Count
\r
4424 For Each i in m_Dic.Items()
\r
4425 Count = Count + i.Count
\r
4432 WScript.Echo "--- ArrayDictionary ------------------------------"
\r
4433 WScript.Echo "key count = " & m_Dic.Count
\r
4435 WScript.Echo "item count = " & Count
\r
4437 For Each i in m_Dic.Keys()
\r
4438 WScript.Echo "key=""" & i & """"
\r
4439 m_Dic.Item(i).Echo
\r
4448 '-------------------------------------------------------------------------
\r
4449 ' ### <<<< [StringStream] Class >>>>
\r
4450 '-------------------------------------------------------------------------
\r
4452 Class StringStream
\r
4455 Public m_INextLine
\r
4456 Private m_RaedLine, m_WriteLine, m_bPrevIsWrite
\r
4457 Public Property Get Line()
\r
4458 If m_bPrevIsWrite Then Line = m_WriteLine Else Line = m_ReadLine
\r
4461 Public Sub SetString( Str )
\r
4468 Public Function ReadLine()
\r
4471 i = InStr( m_INextLine, m_Str, vbCRLF )
\r
4473 ReadLine = Mid( m_Str, m_INextLine, i - m_INextLine )
\r
4474 m_INextLine = i + 2
\r
4476 ReadLine = Mid( m_Str, m_INextLine )
\r
4478 m_INextLine = Empty
\r
4480 m_RaedLine = m_RaedLine + 1
\r
4483 Public Function ReadAll()
\r
4488 Public Property Get AtEndOfStream : AtEndOfStream = IsEmpty( m_Str ) : End Property
\r
4489 Public Sub Write( Str ) : m_Str = m_Str + Str : End Sub
\r
4490 Public Sub WriteLine( LineStr ) : m_Str = m_Str + LineStr + vbCRLF : m_WriteLine = m_WriteLine + 1 : End Sub
\r
4495 '-------------------------------------------------------------------------
\r
4496 ' ### <<<< [StrMatchKey] Class >>>>
\r
4497 '-------------------------------------------------------------------------
\r
4500 Public Property Let Keyword( s )
\r
4502 m_LeftCount = InStr( s, "*" ) - 1
\r
4503 m_LeftStr = Left( s, m_LeftCount )
\r
4504 m_RightCount = Len( s ) - m_LeftCount - 1
\r
4505 m_RightStr = Right( s, m_RightCount )
\r
4507 If InStr( m_LeftCount + 2, s, "*" ) > 0 Then _
\r
4508 Raise 1,"*
\82ð
\95¡
\90\94\8ew
\92è
\82·
\82é
\82±
\82Æ
\82Í
\82Å
\82«
\82Ü
\82¹
\82ñ"
\r
4511 Public Property Get Keyword()
\r
4512 Keyword = m_Keyword
\r
4516 Public Function IsMatch( TestStr )
\r
4517 '// m_Keyword must be low case
\r
4519 If LCase( Right( TestStr, m_RightCount ) ) = m_RightStr Then
\r
4520 If m_LeftCount = 0 Then IsMatch = True : Exit Function
\r
4521 If LCase( Left( TestStr, m_LeftCount ) ) = m_LeftStr Then
\r
4527 Public Function IsMatchULCase( TestStr )
\r
4528 If Right( TestStr, m_RightCount ) = m_RightStr Then
\r
4529 If m_LeftCount = 0 Then IsMatchULCase = True : Exit Function
\r
4530 If Left( TestStr, m_LeftCount ) = m_LeftStr Then
\r
4531 IsMatchULCase = True
\r
4538 Public m_LeftCount
\r
4539 Public m_RightCount
\r
4546 '********************************************************************************
\r
4548 '********************************************************************************
\r
4549 Function LenK( Str )
\r
4550 Dim c, a, i, n_zen
\r
4554 c = Mid( Str, i, 1 )
\r
4555 If c = "" Then LenK = i - 1 + n_zen : Exit Function
\r
4557 If a >= 256 or a < 0 Then n_zen = n_zen + 1
\r
4564 '********************************************************************************
\r
4565 ' <<< [DateAddStr] >>>
\r
4566 '********************************************************************************
\r
4567 Function DateAddStr( BaseDate, Plus )
\r
4568 Dim i, i2, c, flag, num, unit, i_over
\r
4570 DateAddStr = BaseDate
\r
4572 i_over = Len( Plus ) + 1
\r
4574 '//=== Skip spaces
\r
4575 While Mid( Plus, i, 1 ) = " " : i=i+1 : WEnd
\r
4579 c = Mid( Plus, i, 1 )
\r
4582 ElseIf c = "-" Then
\r
4588 '//=== Skip spaces
\r
4589 While Mid( Plus, i, 1 ) = " " : i=i+1 : WEnd
\r
4591 If i = i_over Then Exit Do
\r
4594 c = Mid( Plus, i, 1 )
\r
4596 While (c >= "0" and c <= "9") or c="-" or c="+" : i2=i2+1 : c = Mid( Plus, i2, 1 ) : WEnd
\r
4597 num = CInt( Mid( Plus, i, i2 - i ) )
\r
4600 '//=== Skip spaces
\r
4601 While Mid( Plus, i, 1 ) = " " : i=i+1 : WEnd
\r
4604 c = Mid( Plus, i, 1 )
\r
4606 While (c >= "a" and c <= "z") or (c >= "A" and c <= "Z") : i2=i2+1 : c = Mid( Plus, i2, 1 ) : WEnd
\r
4607 Select Case LCase( Mid( Plus, i, i2 - i ) )
\r
4608 Case "year", "years" : unit = "yyyy"
\r
4609 Case "month", "months" : unit = "m"
\r
4610 Case "day", "days" : unit = "d"
\r
4611 Case "hour", "hours" : unit = "h"
\r
4612 Case "minute","minutes","min": unit = "n"
\r
4613 Case "second","seconds","sec": unit = "s"
\r
4614 Case Else Err.Raise 1,,"
\92P
\88Ê
\82ª
\82¨
\82©
\82µ
\82¢"
\r
4619 DateAddStr = DateAdd( unit, flag * num, DateAddStr )
\r
4625 '*-------------------------------------------------------------------------*
\r
4626 '* ### <<<< System (safe part) >>>>
\r
4627 '*-------------------------------------------------------------------------*
\r
4631 '********************************************************************************
\r
4632 ' <<< [RegRead] >>>
\r
4633 '********************************************************************************
\r
4634 Function RegRead( Path )
\r
4636 If TryStart(e) Then On Error Resume Next
\r
4637 RegRead = g_sh.RegRead( Path )
\r
4638 If TryEnd Then On Error GoTo 0
\r
4639 If e.num = E_PathNotFound or e.num = E_WIN32_FILE_NOT_FOUND Then
\r
4642 If e.num <> 0 Then e.Raise
\r
4648 '********************************************************************************
\r
4649 ' <<< [RegEnumKey] >>>
\r
4650 '********************************************************************************
\r
4651 Sub RegEnumKey( ByVal Path, out_Keys, Opt )
\r
4653 Dim keys, key, i, u
\r
4655 If IsEmpty( Opt ) Then RegEnumKey_sub Path, out_Keys : Exit Sub
\r
4658 out_Keys(0) = Path
\r
4661 RegEnumKey_sub out_Keys(i), keys '// get keys
\r
4663 If not IsNull( keys ) Then
\r
4664 For Each key In keys
\r
4666 ReDim Preserve out_Keys( u + 1 )
\r
4667 out_Keys(u) = out_Keys(i) + "\" + key
\r
4671 If i > u Then Exit Do
\r
4676 Sub RegEnumKey_sub( ByVal Path, out_Keys )
\r
4677 Dim reg, i, root_key
\r
4679 i = InStr( Path, "\" )
\r
4680 Select Case Left( Path, i - 1 )
\r
4681 Case "HKEY_CLASSES_ROOT" : root_key = &h80000000
\r
4682 Case "HKEY_CURRENT_USER" : root_key = &h80000001
\r
4683 Case "HKEY_LOCAL_MACHINE" : root_key = &h80000002
\r
4684 Case "HKEY_USERS" : root_key = &h80000003
\r
4685 Case "HKEY_PERFORMANCE_DATA":root_key= &h80000004
\r
4686 Case "HKEY_CURRENT_CONFIG": root_key = &h80000005
\r
4687 Case "HKEY_DYN_DATA" : root_key = &h80000006
\r
4688 Case Else : Err.Raise &h80070002
\r
4691 Path = Mid( Path, i + 1 )
\r
4693 If IsEmpty( g_reg ) Then _
\r
4694 Set g_reg = GetObject("winmgmts:{impersonationLevel=impersonate}!root/default:StdRegProv")
\r
4695 g_reg.EnumKey root_key, Path, out_Keys
\r
4697 If IsNull( out_Keys ) Then ReDim out_Keys(-1)
\r
4702 '********************************************************************************
\r
4703 ' <<< [RegEnumValues] >>>
\r
4704 '********************************************************************************
\r
4705 Class RegValueName
\r
4711 Sub RegEnumValues( ByVal Path, out_Values )
\r
4712 Dim reg, i, root_key, names, types
\r
4714 i = InStr( Path, "\" )
\r
4715 Select Case Left( Path, i - 1 )
\r
4716 Case "HKEY_CLASSES_ROOT" : root_key = &h80000000
\r
4717 Case "HKEY_CURRENT_USER" : root_key = &h80000001
\r
4718 Case "HKEY_LOCAL_MACHINE" : root_key = &h80000002
\r
4719 Case "HKEY_USERS" : root_key = &h80000003
\r
4720 Case "HKEY_PERFORMANCE_DATA":root_key= &h80000004
\r
4721 Case "HKEY_CURRENT_CONFIG": root_key = &h80000005
\r
4722 Case "HKEY_DYN_DATA" : root_key = &h80000006
\r
4723 Case Else : Err.Raise &h80070002
\r
4726 Path = Mid( Path, i + 1 )
\r
4728 If IsEmpty( g_reg ) Then _
\r
4729 Set g_reg = GetObject("winmgmts:{impersonationLevel=impersonate}!root/default:StdRegProv")
\r
4730 g_reg.EnumValues root_key, Path, names, types
\r
4732 ReDim out_Values( UBound( names ) )
\r
4733 For i=0 To UBound( names )
\r
4735 Set out_Values(i) = new RegValueName : ErrCheck
\r
4737 out_Values(i).Name = names(i)
\r
4739 Select Case types(i)
\r
4740 Case 1 : out_Values(i).Type_ = "REG_SZ"
\r
4741 Case 2 : out_Values(i).Type_ = "REG_EXPAND_SZ"
\r
4742 Case 3 : out_Values(i).Type_ = "REG_BINARY"
\r
4743 Case 4 : out_Values(i).Type_ = "REG_DWORD"
\r
4744 Case 7 : out_Values(i).Type_ = "REG_MULTI_SZ"
\r
4750 '********************************************************************************
\r
4751 ' <<< [RegExists] >>>
\r
4752 '********************************************************************************
\r
4753 Function RegExists( Path )
\r
4755 Const E_PathNotFound = &h80070002
\r
4757 On Error Resume Next
\r
4759 en = Err.Number : ed = Err.Description : On Error GoTo 0
\r
4760 If en = E_PathNotFound Then RegExists = False : Exit Function
\r
4761 If en <> 0 Then Err.Raise en,,ed
\r
4766 '*-------------------------------------------------------------------------*
\r
4767 '* ### <<<< Error, Err2 >>>>
\r
4768 '*-------------------------------------------------------------------------*
\r
4772 '********************************************************************************
\r
4773 ' <<< [Finish] >>>
\r
4774 '********************************************************************************
\r
4781 '********************************************************************************
\r
4782 ' <<< [Error] >>>
\r
4783 '********************************************************************************
\r
4790 '********************************************************************************
\r
4792 '********************************************************************************
\r
4795 Public Number ' Err.Number
\r
4796 Public num ' Err.Number
\r
4797 Public Description ' Err.Description (Error Message)
\r
4798 Public desc ' Err.Description (Error Message)
\r
4799 Public Source ' Err.Source
\r
4800 Public ErrID ' count of (num <> 0) in each first Copy after Clear
\r
4801 Public RaiseID ' count of (num <> 0) in Copy
\r
4802 Public BreakErrID ' as integer
\r
4803 Public BreakRaiseID ' as integer
\r
4805 Private Sub Class_Initialize
\r
4806 num = 0 : Description = "" : ErrID = 0 : RaiseID = 0
\r
4809 Public Sub OnSuccessFinish
\r
4810 If Err.Number = 0 and Me.num <> 0 Then
\r
4811 echo "<ERROR msg='Script finished before Err2.Clear or Raise the error'"+vbCRLF+_
\r
4812 "jp='
\83G
\83\89\81[
\82ª Err2.Clear
\82Ü
\82½
\82Í Raise
\82³
\82ê
\82È
\82¢
\82Å
\8fI
\97¹
\82µ
\82Ü
\82µ
\82½'"+vbCRLF+_
\r
4813 "err_symbol='E_NotClear' />"
\r
4815 Dim b_dbg : b_dbg = not IsDefined( "Setting_getCanExceptionDebugger" )
\r
4816 If not b_dbg Then b_dbg = Setting_getCanExceptionDebugger()
\r
4818 If Me.ErrID >= 2 or b_dbg Then
\r
4819 echo "Run debugger with writing following code in main function." + vbCRLF + _
\r
4820 "g_Err2.BreakErrID = " & Me.ErrID & " [or] " & Me.ErrID & ".5"
\r
4822 On Error Resume Next
\r
4823 Err.Raise Me.num, Me.Source, Me.desc
\r
4827 Public Sub OnErrorFinish
\r
4828 If Me.num <> 0 Then
\r
4829 echo "Run debugger with writing following code in main function." + vbCRLF + _
\r
4830 "g_Err2.BreakErrID = " & Me.ErrID & " [or] " & Me.ErrID & ".5"
\r
4834 Public Sub Copy( err )
\r
4835 Me.Number = err.Number
\r
4836 Me.num = err.Number
\r
4837 Me.Description = err.Description
\r
4838 Me.desc = err.Description
\r
4839 Me.Source = err.Source
\r
4840 If Me.num <> 0 Then Me.RaiseID = Me.RaiseID + 1 : If Me.RaiseID = 1 Then Me.ErrID = Me.ErrID + 1
\r
4843 Public Function Value
\r
4844 Value = GetErrStr( num, Description )
\r
4847 Public Sub OverRaise( e_num, e_desc )
\r
4849 Description = e_desc
\r
4855 Err.Raise 1 '// Look at caller function using watch window of debugger.
\r
4857 Err.Raise num, Source, Description '// Re-raise previous Error again.
\r
4858 '// Write g_Err2.BreakErrID = (ErrID) or (ErrID)+0.5 at the first of main function.
\r
4859 '// [sample] g_Err2.BreakErrID = 1
\r
4864 num = 0 : Description = "" : RaiseID = 0
\r
4870 '********************************************************************************
\r
4871 ' <<< [Raise] >>>
\r
4872 '********************************************************************************
\r
4873 Sub Raise( ErrNum, Description )
\r
4874 g_Err2.num = ErrNum
\r
4875 g_Err2.Source = "ERROR"
\r
4876 g_Err2.Description = Description
\r
4877 g_Err2.RaiseID = g_Err2.RaiseID + 1 : If g_Err2.RaiseID = 1 Then g_Err2.ErrID = g_Err2.ErrID + 1
\r
4879 echo "Run debugger with writing following code in main function."
\r
4880 echo "g_Err2.BreakErrID = " & g_Err2.ErrID & " [or] " & g_Err2.ErrID & ".5"
\r
4882 Err.raise g_Err2.num, g_Err2.Source, g_Err2.Description
\r
4887 '********************************************************************************
\r
4888 ' <<< [SetErrBreak] >>>
\r
4889 '********************************************************************************
\r
4890 Sub SetErrBreak( ErrID, RaiseID )
\r
4891 g_Err2.BreakErrID = ErrID
\r
4892 g_Err2.BreakRaiseID = RaiseID
\r
4897 '********************************************************************************
\r
4898 ' <<< [NestPos] >>>
\r
4899 '********************************************************************************
\r
4901 Public m_HereArr()
\r
4903 Private Sub Class_Initialize '
\83R
\83\93\83X
\83g
\83\89\83N
\83^
\r
4904 Redim m_HereArr(0)
\r
4908 Public Function GetPos( arr )
\r
4910 u = UBound( m_HereArr )
\r
4912 Redim Preserve arr(u-1)
\r
4915 arr(i) = m_HereArr(i)
\r
4919 Public Sub OnBlockStart
\r
4921 u = UBound( m_HereArr )
\r
4922 m_HereArr(u) = m_HereArr(u) + 1
\r
4923 Redim Preserve m_HereArr(u+1)
\r
4924 m_HereArr(u+1) = 0
\r
4927 Public Sub OnBlockEnd
\r
4928 Redim Preserve m_HereArr( UBound( m_HereArr ) - 1 )
\r
4934 '********************************************************************************
\r
4935 ' <<< [NotCallFinish] >>>
\r
4936 '********************************************************************************
\r
4937 Sub NotCallFinish()
\r
4938 echo "[ERROR] not call Finish"
\r
4940 If g_b_cscript_exe Then pause
\r
4946 '********************************************************************************
\r
4947 ' <<< [ErrorCheckInTerminate] >>>
\r
4948 '********************************************************************************
\r
4949 Sub ErrorCheckInTerminate()
\r
4950 If Err.Number <> 0 Then
\r
4951 echo GetErrStr( Err.Number, Err.Description + " in Class_Terminate" )
\r
4953 If g_b_cscript_exe Then pause
\r
4959 '********************************************************************************
\r
4960 ' <<< [TryStart] >>>
\r
4961 '********************************************************************************
\r
4962 Function TryStart( e )
\r
4964 If e.num <> 0 Then Stop '// g_Err2.Clear
\82³
\82ê
\82Ä
\82¢
\82Ü
\82¹
\82ñ
\r
4965 If IsEmpty( e.BreakErrID ) Then
\r
4968 If e.ErrID = e.BreakErrID - 1 Then
\r
4978 '********************************************************************************
\r
4979 ' <<< [Trying] >>>
\r
4980 '********************************************************************************
\r
4982 Trying = (Err.Number=0)
\r
4983 If not Trying Then If g_Err2.ErrID = g_Err2.BreakErrID - 1.5 Then g_Err2.BreakErrID = Empty :_
\r
4984 Stop '// Look at caller function by call stack window
\r
4989 '********************************************************************************
\r
4990 ' <<< [TryEnd] >>>
\r
4991 '********************************************************************************
\r
4993 ' Do not have parameters.
\r
4994 ' Because "If TryEnd(e) Then On Error Goto 0" cannot get error, if e is not Dim.
\r
4996 If Err.Number <> 0 Then
\r
4999 If g_Err2.ErrID = g_Err2.BreakErrID Then
\r
5005 If g_Err2.ErrID = g_Err2.BreakErrID - 0.5 Then g_Err2.BreakErrID = Empty :_
\r
5006 Stop '// Look at caller function by call stack window
\r
5014 '********************************************************************************
\r
5015 ' <<< [ErrCheck] >>>
\r
5016 '********************************************************************************
\r
5018 If Err.Number <> 0 Then g_Err2.Copy Err : g_Err2.Raise
\r
5022 '********************************************************************************
\r
5023 ' <<< [chk_exist_in_lib] >>>
\r
5025 ' - If there is not path in vbslib folder, raise error of E_FileNotExist.
\r
5026 '********************************************************************************
\r
5027 Sub chk_exist_in_lib( ByVal path )
\r
5028 If not exist( g_vbslib_ver_folder + path ) Then Err.Raise E_FileNotExist,, _
\r
5029 "Not found """ + g_vbslib_ver_folder + path + """"
\r
5034 '-------------------------------------------------------------------------
\r
5035 ' ### <<<< [SkipSection] Class >>>>
\r
5036 '-------------------------------------------------------------------------
\r
5038 Public m_CurrentSecNum
\r
5039 Public m_SkipToSecNum
\r
5043 Dim g_bSkipSectionSupport
\r
5045 Sub SkipToSection( Num )
\r
5046 If IsEmpty( Num ) Then
\r
5047 g_SkipSection = Empty
\r
5049 Set g_SkipSection = new SkipSection
\r
5050 g_SkipSection.m_SkipToSecNum = Num
\r
5054 Function NotSkipSection()
\r
5055 g_bSkipSectionSupport = True
\r
5056 If IsEmpty( g_SkipSection ) Then NotSkipSection = True : Exit Function
\r
5057 Dim m : Set m = g_SkipSection
\r
5058 m.m_CurrentSecNum = m.m_CurrentSecNum + 1
\r
5059 If m.m_CurrentSecNum < m.m_SkipToSecNum Then NotSkipSection = False : Exit Function
\r
5060 echo "<Section num='" & m.m_CurrentSecNum & "'/>"
\r
5061 NotSkipSection = True
\r
5066 '-------------------------------------------------------------------------
\r
5067 ' ### <<<< [FinObj] Class >>>>
\r
5068 '-------------------------------------------------------------------------
\r
5070 Public m_Vars ' as Dictionay
\r
5071 Public m_FinallyFunc
\r
5073 Private Sub Class_Initialize
\r
5074 Set m_Vars = CreateObject("Scripting.Dictionary")
\r
5077 Public Sub SetFunc( FuncName )
\r
5078 Set m_FinallyFunc = GetRef( FuncName )
\r
5081 Public Sub SetVar( Name, Var )
\r
5082 If IsObject( Var ) Then Set m_Vars.Item( Name ) = Var _
\r
5083 Else m_Vars.Item( Name ) = Var
\r
5086 Private Sub Class_Terminate()
\r
5087 If not IsEmpty( m_FinallyFunc ) Then
\r
5088 Dim en, ed : en = Err.Number : ed = Err.Description
\r
5089 m_FinallyFunc m_Vars
\r