Results 1 to 4 of 4

Thread: wbfs verify script

  1. #1
    New Member
    Join Date
    Feb 2013
    Posts
    20
    Thanks
    0
    Thanked 0 Times in 0 Posts

    wbfs verify script

    This program will perform a wit verify on all wbfs game files and send output results to file
    Features:
    - ability to limit game folder verify based on game folder name pattern
    - ability to verify files created within specific # of days
    - prints summary at end that includes list of identified bad/corrupt game backups

    Requires an install of Wit ISO Tool

    This does add some useful functionality beyond just using wit tool itself from command line.
    Hope everyone finds it useful.

    To execute silent, then type from windows command line:
    cscript verify_wbfs.vbs

    Script: verify_wbfs.vbs:

    Code:
    'Script: verify_wbfs.vbs
    'Author: matrixman1013
    'Date: 2/8/2013
    
    Option Explicit
    Dim argCount, strFolderToSearch, objFSO, objRootFolder, objFolder, colSubfolders, strOutput, strStdOut, witcmd
    Dim WshShell, objScriptExec, gamelist, gameLine, gameItem, witvercmd, gamefolder, gamesize
    Dim outputFileStream, outputFile, gamefolder_fq, bad_count, bad_filelist, start_time, x, outputFilename
    Dim scan_days, folder_pattern, foundMatchFolder, foundMatchDate, scandaysprint, folderDateDiff
    
    '**************************************************************
    ' Comments Section
    '
    'save this file as something like this - verify_wbfs.vbs and run with cscript from windows command prompt
    'Example - cscript verify_wbfs.vbs
    '
    'This program will perform a wit verify on all wbfs game files and send output results to file
    'Features: 
    '           - ability to limit game folder verify to select game folder name pattern
    '           - ability to verify files created within specific # of days  
    '           - prints summary at end that includes list of identified bad/corrupt game backups
    '
    'Credits to Dirk Clemens creators of Wiimms ISO Tool and to stackoverflow.com for programming info
    '
    'TODO-FIX
    ' check if folder arg exists
    ' force cscript execution
    '**************************************************************
    
    'record start time
    start_time = Now
    
    'test for command line usage prompt
    argCount = WScript.Arguments.Count
    If (argCount < 1) then
      displayUsagePrompt
      WScript.Quit
    End If
    If (argCount = 1) then
      If (WScript.Arguments.Item(0) = "help") Or (WScript.Arguments.Item(0) = "?") then
        displayUsagePrompt
        WScript.Quit
      End If
    End If
    
    'grab cmdline args and set output filename
    strFolderToSearch = WScript.Arguments.Item(0) & "\"
    outputFilename = FilenameTimestamped("witVerify-output")
    outputFile = strFolderToSearch & outputFilename
    
    'determine if days option arg is provided, if not scan all files
    'I think a default of more than 100 years should cover shelf life of Wii for scan all files
    scan_days = 99999
    If (argCount > 1) then
      If IsNumeric(WScript.Arguments.Item(1)) then scan_days = WScript.Arguments.Item(1)
    End If
    
    'determine if file pattern is provided, if not use default
    folder_pattern = "*"
    If argCount = 3 then
      folder_pattern = WScript.Arguments.Item(2)
    End If
    If (argCount = 2) then
      If Not IsNumeric(WScript.Arguments.Item(1)) then
        folder_pattern = WScript.Arguments.Item(1)
      End If
    End If
    
    
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    Set objRootFolder = objFSO.GetFolder(strFolderToSearch)
    Set colSubfolders = objRootFolder.SubFolders
    
    Set outputFileStream = objFSO.CreateTextFile(outputFile,True)
    
    Set WshShell = CreateObject("WScript.Shell")
    x = 0
    For Each objFolder in colSubfolders
        foundMatchDate = 0
        foundMatchFolder = 0
        folderDateDiff = CLng(DateDiff("d", objFolder.DateCreated, Now))
        gamefolder = objFolder.name
        If CLng(scan_days) >= folderDateDiff then
           foundMatchDate = 1
        End If
        If folder_pattern = "*" then 
           foundMatchFolder = 1
        End If
        If Not (folder_pattern = "*") then 
           If Instr(1, gamefolder, folder_pattern, 1) > 0 then 
              foundMatchFolder = 1
           End If
        End If
        If (foundMatchFolder=1) And (foundMatchDate=1) then
           x = x + 1
           gamesize = FormatSize(objFolder.size)
            outputFileStream.Write(vbCrLf & "*********************************************************" & vbCrLf)
            outputFileStream.Write(gamefolder & " (" & gamesize  & " " & objFolder.DateCreated & ")" & " - begin verify"  & vbCrLf)
            gamefolder_fq = strFolderToSearch & gamefolder
            runWitVerify gamefolder_fq
        End If
    Next
    
    'write summary to output file
    scandaysprint = scan_days
    If scan_days = 99999 then scandaysprint = "ALL"
    outputFileStream.Write(vbCrLf & vbCrLf & "*********************************************************" & vbCrLf)
    outputFileStream.Write("VERIFY SUMMARY:" & vbCrLf)
    outputFileStream.Write(vbCrLf & "Criteria: " & "folder_pattern="  & folder_pattern & ", scan_days=" & scandaysprint)
    outputFileStream.Write(vbCrLf & "Start Time: " & start_time)
    outputFileStream.Write(vbCrLf & "End Time: " & Now)
    outputFileStream.Write(vbCrLf & "Games Verified: " & x)
    outputFileStream.Write(vbCrLf & vbCrLf & "Bad Files Identified: " & vbCrLf)
    If Len(bad_filelist) > 0 then
      outputFileStream.Write(vbCrLf & bad_filelist)
    Else
      outputFileStream.Write(vbCrLf & "No bad found, all games verified good.")
    End If
    
    'cleanup and close
    Set WshShell = Nothing
    outputFileStream.Close
    
    Sub runWitVerify(strParm)
       'clear stdout in prep for wit results only
       Set strStdOut = Nothing
       witvercmd = "wit verify " & chr(34) & strParm & chr(34) & " -vvv"
       'Msgbox witvercmd
       runCommand witvercmd
       Set witvercmd = Nothing
    End Sub
    
    
    Sub runCommand(strCommand)
            'redirect StdErr to StdOut using the POSIX standard 2>&1
            Set objScriptExec = WshShell.Exec("cmd /c " &  strCommand  & " 2>&1")
            'TODO - ReadAll could block and hang if cmd process writes more then 4K to stdout
            'Should not be issue since output from wit verify on wbfs file is small and we clear buffer after each
            strStdOut = objScriptExec.StdOut.ReadAll
            'check for corrupted game backup
            bad_count = Instr(strStdOut, "H1-ERR")
            If bad_count > 0 then
               bad_filelist = bad_filelist & gamefolder & " (" & gamesize & ")" & vbCrLf
            End If
            'capture stdOut to output file
            outputFileStream.Write(strStdOut)
            'Msgbox strStdOut
            Set objScriptExec = Nothing
    End Sub
    
    
    Sub runCommandNoOutput(strCommand)
            'redirect StdErr to StdOut using the POSIX standard 2>&1
            Set objScriptExec = WshShell.Exec("cmd /c " &  strCommand  & " 2>&1")
            'TODO - ReadAll could block and hang if cmd process writes more then 4K to stdout
            'Should not be issue since output from wit verify on wbfs file is small and we clear buffer after each
            strStdOut = objScriptExec.StdOut.ReadAll
            'Msgbox strStdOut
            Set objScriptExec = Nothing
    End Sub
    
    Sub displayUsagePrompt
      WScript.Echo "usage: "
      WScript.Echo "  verify_wbfs.vbs [path] [optional: # of days in past, 0 for today] [optional: folder pattern]"
      WScript.Echo " "
      WScript.Echo "Examples:"
      WScript.Echo "verify_wbfs.vbs w:\wbfs (verify all files)"
      WScript.Echo "verify_wbfs.vbs w:\wbfs 10 (verify files created in last 10 days)"
      WScript.Echo "verify_wbfs.vbs w:\wbfs 0 (verify files created only today)"
      WScript.Echo "verify_wbfs.vbs w:\wbfs 0 sonic (verify files created only today and game folder name contains sonic)"
      WScript.Echo "verify_wbfs.vbs w:\wbfs sonic (verify all files where game folder name contains sonic)"
    End Sub
    
    Public Function FormatSize(ByVal Bytes)
       Dim currval, countdiv, buildstr 
       Dim lookupprefix()
        
       ReDim LookupPrefix(8)
       LookupPrefix(0) = " Bytes"
       LookupPrefix(1) = "KB"
       LookupPrefix(2) = "MB"
       LookupPrefix(3) = "GB"
       LookupPrefix(4) = "TB"
       LookupPrefix(5) = "PB"
       LookupPrefix(6) = "EB"
       LookupPrefix(7) = "ZB"
       LookupPrefix(8) = "YB"
    
       currval = Bytes
       Do Until currval < 1024
           currval = currval / 1024
           countdiv = countdiv + 1
       Loop
    
       buildstr = Trim(FormatNumber(Round(currval, 2)))
       buildstr = buildstr + " " + Lookupprefix(countdiv)
       FormatSize = buildstr
    End Function
    
    
    Public Function FilenameTimestamped(filename)
       Dim strSafeDate, strSafeTime, strDateTime
      
       strSafeDate = DatePart("yyyy",Date) & Right("0" & DatePart("m",Date), 2) & Right("0" & DatePart("d",Date), 2)
    
       strSafeTime = Right("0" & Hour(Now), 2) & Right("0" & Minute(Now), 2) & Right("0" & Second(Now), 2)
    
       'Set strDateTime equal to a string representation of the current date and time, for use as part of a valid Windows filename
       strDateTime = strSafeDate & "-" & strSafeTime
    
       'Assemble the path and filename
       FilenameTimestamped = filename & "_" & strDateTime & ".txt"
    End Function
    Example Output Sample:
    Code:
    *********************************************************
    Pirates vs Ninjas Dodgeball [R5JES5] (278.00 MB 2/6/2013 8:31:26 PM) - begin verify
    
    wit: Wiimms ISO Tool v2.10a r4118 cygwin - Dirk Clemens - 2012-10-10
    
    1 object scanned, 1 directory found ... 
    2 objects scanned, 1 directory and 1 supported file found.   
    >scan   .0  DATA    R5JES5 /cygdrive/y/wbfs2/Pirates vs Ninjas Dodgeball [R5JES5]/R5JES5.wbfs/#0
    >info               TICKET & TMD are well signed. Partition is encrypted and scrubbed.
    +OK     .0  DATA    R5JES5 /cygdrive/y/wbfs2/Pirates vs Ninjas Dodgeball [R5JES5]/R5JES5.wbfs/#0
    
    *********************************************************
    Super Fruit Fall [RF4E36] (66.00 MB 2/6/2013 8:30:36 PM) - begin verify
    
    wit: Wiimms ISO Tool v2.10a r4118 cygwin - Dirk Clemens - 2012-10-10
    
    1 object scanned, 1 directory found ... 
    2 objects scanned, 1 directory and 1 supported file found.   
    >scan   .0  DATA    RF4E36 /cygdrive/y/wbfs2/Super Fruit Fall [RF4E36]/RF4E36.wbfs/#0
    >info               TICKET & TMD are well signed. Partition is encrypted and scrubbed.
    +OK     .0  DATA    RF4E36 /cygdrive/y/wbfs2/Super Fruit Fall [RF4E36]/RF4E36.wbfs/#0
    
    *********************************************************
    SUPER PAPER MARIO [R8PE01] (408.00 MB 2/6/2013 8:31:02 PM) - begin verify
    
    wit: Wiimms ISO Tool v2.10a r4118 cygwin - Dirk Clemens - 2012-10-10
    
    1 object scanned, 1 directory found ... 
    2 objects scanned, 1 directory and 1 supported file found.   
    >scan   .0  DATA    R8PE01 /cygdrive/y/wbfs2/SUPER PAPER MARIO [R8PE01]/R8PE01.wbfs/#0
    >info               TICKET & TMD are well signed. Partition is encrypted and scrubbed.
    +OK     .0  DATA    R8PE01 /cygdrive/y/wbfs2/SUPER PAPER MARIO [R8PE01]/R8PE01.wbfs/#0
    
    *********************************************************
    Thrillville2 [RTVE64] (4.11 GB 1/29/2013 12:18:32 AM) - begin verify
    
    wit: Wiimms ISO Tool v2.10a r4118 cygwin - Dirk Clemens - 2012-10-10
    
    1 object scanned, 1 directory found ... 
    3 objects scanned, 1 directory and 1 supported file found.   
    >scan   .0  DATA    RTVE64 /cygdrive/y/wbfs2/Thrillville2 [RTVE64]/RTVE64.wbfs/#0
    >info               TICKET & TMD are well signed. Partition is encrypted.
    !H1-ERR .0  DATA    RTVE64 /cygdrive/y/wbfs2/Thrillville2 [RTVE64]/RTVE64.wbfs/#0
    !H1-ERR .0  DATA    RTVE64 /cygdrive/y/wbfs2/Thrillville2 [RTVE64]/RTVE64.wbfs/#0
    !H1-ERR .0  DATA    RTVE64 /cygdrive/y/wbfs2/Thrillville2 [RTVE64]/RTVE64.wbfs/#0
    !H1-ERR .0  DATA    RTVE64 /cygdrive/y/wbfs2/Thrillville2 [RTVE64]/RTVE64.wbfs/#0
    wit: Command 'VERIFY' returns with status #1 [FILES DIFFER]
    
    
    *********************************************************
    VERIFY SUMMARY:
    
    Criteria: folder_pattern=*, scan_days=ALL
    Start Time: 2/8/2013 2:50:06 PM
    End Time: 2/8/2013 2:51:05 PM
    Games Verified: 4
    
    Bad Files Identified: 
    
    Thrillville2 [RTVE64] (4.11 GB)
    Last edited by matrixman1013; 02-08-2013 at 10:03 PM.

  2. #2
    New Member
    Join Date
    Feb 2013
    Posts
    20
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I am new to Wii Homebrew, but would it be possible to execute something similar like this on the Wii itself?

    Looks like wit tools comes as a linux executable as well. But I do not know what can be run on a Wii, that is, is Wii OS based on Linux kernal?

    If so I might be willing to write a dol if more people are interested in such a thing.

  3. #3
    Junior Member dniMretsaM's Avatar
    Join Date
    May 2010
    Location
    NE Ohio
    Posts
    1,142
    Thanks
    76
    Thanked 331 Times in 269 Posts
    Quote Originally Posted by matrixman1013 View Post
    I am new to Wii Homebrew, but would it be possible to execute something similar like this on the Wii itself?

    Looks like wit tools comes as a linux executable as well. But I do not know what can be run on a Wii, that is, is Wii OS based on Linux kernal?

    If so I might be willing to write a dol if more people are interested in such a thing.
    You'd have to rewrite WIT to run on the Wii. More trouble than it's worth since the Wii's processor is pretty slow and WIT would take forever.
    Last edited by dniMretsaM; 02-08-2013 at 12:22 PM.
    Quote Originally Posted by sven
    [16:26:34] i'm never sarcastic.
    [16:26:41] feel free to quote me on that.

  4. #4
    New Member
    Join Date
    Feb 2013
    Posts
    20
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by dniMretsaM View Post
    You'd have to rewrite WIT to run on the Wii. More trouble than it's worth since the Wii's processor is pretty slow and WIT would take forever.
    Good to know thanks.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •