1. I'd like to hear about anybody's data validation tools that seem to be working.
Well I did some vbscript hacking tonight and was able to use xMedia custom fields for verification purposes. What I did was to create a custom field to store the MD5 hash of a file. If you select a file in the catalog, and then run the script, it calls fciv.exe to generate the MD5 value, captures the output, and then writes it into the catalog. (For now the script just does a single file, but this was just a proof of concept anyway.)
I then wrote another script to call fciv.exe to generate an MD5 hash, and then display whether the re-generated value matches what's in the catalog.
So that would be one way to verify the integrity of your files. I checked that it's working by going into bridge and changing the rating; the verification then fails because the file has been changed.
I mentioned in a previous post that fciv.exe will store the MD5 values for the files in a directory in an XML file. My next plan is to extract that MD5 value for a file from that XML database, and use that as the catalog value, or to compare to the MD5 value already in the catalog. I'll post when I get that working. The scripts are listed below.
Cheers,
Matt
'MJH_Set_MD5_From_File.vbs
Option Explicit
Const kTitle = "MJH: Set MD5 From File (via FCIV.EXE)"
Main
Sub Main()
Dim app, cat, sel, item, ff, f, re, mm, m
Dim WshShell, execObj, line, name, StdOut
Set app = CreateObject("ExpressionMedia.Application")
If app.Catalogs.count <= 0 Then
MsgBox "No catalog; please start Expression Media.", vbCritical, kTitle
Exit Sub
End If
Set cat = app.ActiveCatalog
Set sel = cat.Selection
If sel.Count <= 0 Then
MsgBox "No items selected.", vbCritical, kTitle
Exit Sub
End If
If sel.Count > 1 Then
MsgBox "Only 1 item may be selected", vbCritical, kTitle
Exit Sub
End If
Set item = sel.Item(1) 'yes, this is a 1-based index
Set ff = item.CustomFields
If ff.Count <= 0 Then
MsgBox "No custom fields defined", vbOKOnly, kTitle
Exit Sub
End If
'2008/04/02
'Here is where we should check the name, but xMedia 1.0 SP1 has a
'bug such that custom field names are changed (it appends a junk character
'to the name) when the catalog is saved and then re-opened. A work-around
'is to use the index of the custom field instead of the name.
'MD5 custom field
'TODO when xMedia 2.0 is released 2008 Q2
'f = ff.Item("MD5")
'workaround:
Set f = ff.Item(CInt(1)) 'CustomFieldIndexOrName
Set WshShell = CreateObject("WScript.Shell")
'TODO: the shell for this app is briefly visible while the command
'executes. See if there are some vbs hacks to prevent the window from
'being visible. (I think WshShell.Run allows you to do that, but we need
'to use Exec because only that function allows you to capture stdout.)
Set execObj = WshShell.Exec("fciv -wp """ & item.path & """")
Set StdOut = execObj.StdOut
'This is written with a certain amount of paranoia, but that's appropriate
'here, since we're generating a hash value that will be used to verify
'the integrity of this file, now and forever.
line = StdOut.ReadLine()
If StrComp(line, "//", vbTextCompare) Then
MsgBox "bad FCIV result (1st line)", vbCritical, kTitle
Exit Sub
End If
line = StdOut.ReadLine()
If StrComp(line, "// File Checksum Integrity Verifier version 2.05.", vbTextCompare) Then
MsgBox "bad FCIV result (2nd line)", vbCritical, kTitle
Exit Sub
End If
line = StdOut.ReadLine()
If StrComp(line, "//", vbTextCompare) Then
MsgBox "bad FCIV result (3rd line)", vbCritical, kTitle
Exit Sub
End If
line = StdOut.ReadLine()
If not StdOut.AtEndOfStream Then
MsgBox "bad FCIV result (end-of-stream)", vbCritical, kTitle
Exit Sub
End If
'2008/04/02
'xMedia 1.0 SP1 also has a bug (I think caused by QuickTime) such
'that Item.Name returns the DOS 8.3 name, so as a work-around we
'use the full path and strip off the leading path-part
name = NamePart(item.path)
Set re = New RegExp
re.Pattern = "^(\S+) (\S+)$" 'parens turn on SubMatches
Set mm = re.Execute(line)
Set m = mm(0)
'TODO: can we say mm.Item(1) instead?
If StrComp(LCase(m.SubMatches(1)), LCase(name), vbTextCompare) Then
MsgBox "bad FCIV result (4th line - no submatch)", vbCritical, kTitle
Exit Sub
End If
f.Value = m.SubMatches(0)
End Sub
function NamePart(Path)
Dim intFileNamePos
intFileNamePos = InStrRev(Path, "\", -1, vbTextCompare)
NamePart = mid(Path, intFileNamePos + 1)
End function
'MJH_Check_MD5.vbs
Option Explicit
Const kTitle = "MJH: Check MD5 Of File (via FCIV.EXE)"
Main
Sub Main()
Dim app, cat, sel, item, ff, f, re, mm, m
Dim WshShell, execObj, line, name, StdOut
Set app = CreateObject("ExpressionMedia.Application")
If app.Catalogs.count <= 0 Then
MsgBox "No catalog; please start Expression Media.", vbCritical, kTitle
Exit Sub
End If
Set cat = app.ActiveCatalog
Set sel = cat.Selection
If sel.Count <= 0 Then
MsgBox "No items selected.", vbCritical, kTitle
Exit Sub
End If
If sel.Count > 1 Then
MsgBox "Only 1 item may be selected", vbCritical, kTitle
Exit Sub
End If
Set item = sel.Item(1) 'yes, this is a 1-based index
Set ff = item.CustomFields
If ff.Count <= 0 Then
MsgBox "No custom fields defined", vbOKOnly, kTitle
Exit Sub
End If
'2008/04/02
'Here is where we should check the name, but xMedia 1.0 SP1 has a
'bug such that custom field names are changed (it appends a junk character
'to the name) when the catalog is saved and then re-opened. A work-around
'is to use the index of the custom field instead of the name.
'MD5 custom field
'TODO when xMedia 2.0 is released 2008 Q2
'f = ff.Item("MD5")
'workaround:
Set f = ff.Item(CInt(1)) 'MD5
Set WshShell = CreateObject("WScript.Shell")
Set execObj = WshShell.Exec("fciv -wp """ & item.path & """")
Set StdOut = execObj.StdOut
line = StdOut.ReadLine()
If StrComp(line, "//", vbTextCompare) Then
MsgBox "bad FCIV result (1st line)", vbCritical, kTitle
Exit Sub
End If
line = StdOut.ReadLine()
If StrComp(line, "// File Checksum Integrity Verifier version 2.05.", vbTextCompare) Then
MsgBox "bad FCIV result (2nd line)", vbCritical, kTitle
Exit Sub
End If
line = StdOut.ReadLine()
If StrComp(line, "//", vbTextCompare) Then
MsgBox "bad FCIV result (3rd line)", vbCritical, kTitle
Exit Sub
End If
line = StdOut.ReadLine()
If not StdOut.AtEndOfStream Then
MsgBox "bad FCIV result (end-of-stream)", vbCritical, kTitle
Exit Sub
End If
'2008/04/02
'xMedia 1.0 SP1 also has a bug (I think caused by QuickTime) such
'that Item.Name returns the DOS 8.3 name, so as a work-around we
'use the full path and strip off the leading path-part
name = NamePart(item.path)
Set re = New RegExp
re.Pattern = "^(\S+) (\S+)$" 'parens turn on SubMatches
're.IgnoreCase = True
're.Global = False
Set mm = re.Execute(line)
Set m = mm(0)
'TODO: can we say mm.Item(1) instead?
If StrComp(LCase(m.SubMatches(1)), LCase(name), vbTextCompare) Then
MsgBox "bad FCIV result (4th line - no submatch)", vbCritical, kTitle
Exit Sub
End If
If f.Value = m.SubMatches(0) Then
MsgBox "MD5 of file matches catalog", vbOKOnly, kTitle
Else
MsgBox "MD5 of file does not match catalog", vbCritical, kTitle
End If
End Sub
function NamePart(Path)
Dim intFileNamePos
intFileNamePos = InStrRev(Path, "\", -1, vbTextCompare)
NamePart = mid(Path, intFileNamePos + 1)
End function