Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

117 lines
3.3 KiB

  1. Option Explicit
  2. Const ForReading= 1
  3. Const TextualCompare= 1
  4. Function ManDskSpc( ByVal SrcFileName, ByVal DstFileName, ByVal Factor )
  5. Dim fs, SrcFile, DstFile, LineRead, NewLine
  6. Set fs= CreateObject( "Scripting.FileSystemObject" )
  7. If Not fs.FileExists( SrcFileName )Then ' Fail if source file not present
  8. ManDskSpace= False
  9. Exit Function
  10. End If
  11. Set SrcFile= fs.OpenTextFile( SrcFileName, ForReading ) ' open source
  12. Set DstFile= fs.CreateTextFile( DstFileName, True ) ' overwrite destination
  13. Do While Not SrcFile.AtEndOfStream ' till the source file ends
  14. LineRead= LTrim( SrcFile.ReadLine() ) ' Read line removing leading spaces
  15. NewLine = ProcessLine(LineRead)
  16. DstFile.WriteLine NewLine ' write the untouched or modified line
  17. Loop
  18. ManDskSpc= True ' everything is okay, NO ERRORS
  19. End Function
  20. Function ProcessLine(ByVal LineRead)
  21. Dim Pos, Pos2, Pos3
  22. Dim TempStr, Val1, Val2, NewLine
  23. ProcessLine = LineRead
  24. Pos= InStr( 1, LineRead, ":TempDirSpace", TextualCompare )
  25. If Pos = 0 Then ' doesn't have TempDirSpace, but may have WinDirSpace
  26. Pos= InStr( 1, LineRead, ":WinDirSpace", TextualCompare )
  27. End If
  28. If Pos <> 0 Then ' If there is a "TempDirSpace" or "WinDirSpace" in line it MAY be interesting
  29. ' Pos2= InStr( Pos + Len( "TempDirSpace" ), LineRead, "=", TextualCompare )
  30. Pos2 = InStr( Pos, LineRead, "=", TextualCompare )
  31. If Pos2 <> 0 Then ' the line is interesting if it also has an equal
  32. Pos3= InStr( Pos2, LineRead, ",", TextualCompare )
  33. TempStr= Right( LineRead, Len( LineRead ) - Pos2 ) ' the first value is right after the '=' sign
  34. If Pos3 <> 0 Then ' If this is a double entry trim the next value for now
  35. TempStr= Left( TempStr, Len( TempStr) - ( Len( LineRead ) - Pos3 + 1 ) )
  36. End If
  37. Val1= Round(CDbl(TempStr)*Factor) ' get value multiply by factor
  38. If Pos3 <> 0 Then ' if this is a double entry get the next value as well
  39. TempStr= Right( LineRead, Len( LineRead ) - Pos3 )
  40. Val2= Round(CDbl(TempStr)*Factor) ' multiply by the factor
  41. End If
  42. NewLine= Left( LineRead, Pos2 ) & " " & Val1 ' reconstruct first part of entry
  43. If Pos3 <> 0 Then ' if this is a dual entry, append the second part
  44. NewLine= NewLine & "," & Val2
  45. End If
  46. ProcessLine = NewLine ' the new line is the line to write back
  47. End If
  48. End If
  49. End Function
  50. Function Launch ' extracts args and calls ManDskSpc()
  51. Dim SrcFileName, DstFileName
  52. If WScript.Arguments.Count() <> 3 Or Not IsNumeric( WScript.Arguments(2) ) Then ' bad args
  53. Wscript.Echo "Bad args"
  54. Wscript.Echo "ManDskSpc <src file> <dst file> <factor>"
  55. Launch = 1
  56. Exit Function
  57. End If
  58. SrcFileName= WScript.Arguments(0)
  59. DstFileName= WScript.Arguments(1)
  60. Factor= CDbl( WScript.Arguments(2) )
  61. Wscript.Echo SrcFileName & " * " & Factor & " ==> " & DstFileName ' show file names
  62. If Not ManDskSpc( SrcFileName , DstFileName, Factor ) Then ' call function and check return
  63. WScript.Echo "Failed to ManDskSpace!"
  64. Launch = 1
  65. Exit Function
  66. End If
  67. WScript.Echo "Done"
  68. Launch = 0
  69. End Function
  70. ' MAIN
  71. ' global vars
  72. Dim iRet, Factor
  73. iRet = Launch
  74. WScript.Quit(iRet)