Hi,

I've got a usecase where I'm committing ZIP files to the repository. It is 
usefull for me to compare the contents of the ZIP file (filenames, date and 
time suffice, not contents of the individual files).

I've created a diff script, below, inspired by the existing diff scripts. 
Does the code make sense? Can we include it in the standard setup? If the 
response is positive, I'll commit it and do the necessary changes to the 
installation and default settings.

[[[
'
' TortoiseSVN Diff script for ZIP files
'
' Last commit by:
' $Author: $
' $Date: $
' $Rev: $
'
' Authors:
' Daniel Sahlberg, 2024
'

Set Arguments = WScript.Arguments
If Arguments.Count < 2 Then
MsgBox "Usage: [CScript | WScript] diff-zip.vbs base.zip new.zip", 
vbCritical, "Invalid arguments"
WScript.Quit 1
End If

Set ShellApplication = CreateObject("Shell.Application")
Set WScriptShell = CreateObject("WScript.Shell")
Set FileSystemObject = CreateObject("Scripting.FileSystemObject")

Function ReadZip(pathToZipFile)
Set Folder = ShellApplication.NameSpace(pathToZipFile)
If Folder Is Nothing Then
MsgBox "Can't read " & pathToZipFile, vbCritical, "Invalid zip file"
Else
Set Items = Folder.Items
FileName = FileSystemObject.GetSpecialFolder(2) & "\" & 
FileSystemObject.GetTempName()
' 2 = ForWriting
' -1 = Opens the file as Unicode
Set File = FileSystemObject.OpenTextFile(FileName, 2, True, -1)
If File Is Nothing Then
MsgBox("Can't open " & File & " for writing")
Else
File.WriteLine(pathToZipFile)
File.WriteLine("")
MaxLength = 0
For i = 0 To Items.Count-1
If Len(Items.Item(i).Name) > MaxLength Then MaxLength = 
Len(Items.Item(i).Name)
Next
MaxLength = MaxLength+1
For i = 0 To Items.Count-1
Set Item = Items.Item(i)
File.WriteLine(Item.Name & String(MaxLength-Len(Item.Name), " ") & 
Item.ModifyDate & String(10-Len(Item.Size), " ") & Item.Size)
Next
File.WriteLine("")
File.WriteLine(Items.Count & " items")
File.Close()
ReadZip = FileName
End if
End if
End Function

BaseFile = ReadZip(Arguments(0))
NewFile = ReadZip(Arguments(1))

If BaseFile = "" Or NewFile = "" Then
WScript.Quit 1
End If

WScriptShell.Run """TortoiseMerge.exe"" /readonly /base:""" & BaseFile & 
""" /basename:""" & Arguments(0) & """ /mine:""" & NewFile & """ 
/minename:""" & Arguments(1) & """", 0, True

FileSystemObject.DeleteFile BaseFile
FileSystemObject.DeleteFile NewFile

WScript.Quit 0
]]]

Another option would be to have TortoiseMerge learn to read ZIP files and 
generating the directory listing internally, but it seems to be more work 
and I don't know if we have a library already that can read ZIP files or if 
we'd have to include additional dependencies.

Kind regards,
Daniel

-- 
You received this message because you are subscribed to the Google Groups 
"TortoiseSVN-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/tortoisesvn-dev/52fb40fe-89ce-466a-81a8-6aa161a4d88bn%40googlegroups.com.

Reply via email to