Fixed issue #4132: Error "Could not get next commit. libgit returns: -4" in Log Messa...
[TortoiseGit.git] / contrib / diff-scripts / diff-odt.vbs
blob8e94095b95f4757e7086c761795b6c67cc383b97
1 ' extensions: odt;ods
3 ' TortoiseSVN Diff script for Open Office Text files
5 ' Copyright (C) 2004-2009, 2012-2014 the TortoiseSVN team
6 ' This file is distributed under the same license as TortoiseSVN
8 ' Last commit by:
9 ' $Author$
10 ' $Date$
11 ' $Rev$
13 ' Authors:
14 ' Jonathan Ashley, 2007
15 ' Stefan Küng, 2006, 2009
17 dim objArgs, num, sBaseDoc, sNewDoc, objScript
19 Set objArgs = WScript.Arguments
20 num = objArgs.Count
21 if num < 2 then
22 MsgBox "Usage: [CScript | WScript] diff-odt.vbs base.odt new.odt", vbExclamation, "Invalid arguments"
23 WScript.Quit 1
24 end if
26 sBaseDoc = objArgs(0)
27 sNewDoc = objArgs(1)
29 Set objScript = CreateObject("Scripting.FileSystemObject")
30 If objScript.FileExists(sBaseDoc) = False Then
31 MsgBox "File " + sBaseDoc + " does not exist. Cannot compare the documents.", vbExclamation, "File not found"
32 Wscript.Quit 1
33 End If
34 If objScript.FileExists(sNewDoc) = False Then
35 MsgBox "File " + sNewDoc + " does not exist. Cannot compare the documents.", vbExclamation, "File not found"
36 Wscript.Quit 1
37 End If
38 'remove the file write protection
39 objScript.GetFile(sBaseDoc).Attributes = objScript.GetFile(sBaseDoc).Attributes And Not 1
40 objScript.GetFile(sNewDoc).Attributes = objScript.GetFile(sNewDoc).Attributes And Not 1
42 Set objScript = Nothing
44 On Error Resume Next
45 'The service manager is always the starting point
46 'If there is no office running then an office is started
47 Set objServiceManager = Wscript.CreateObject("com.sun.star.ServiceManager")
48 If Err.Number <> 0 Then
49 Wscript.Echo "You must have OpenOffice installed to perform this operation."
50 Wscript.Quit 1
51 End If
53 On Error Goto 0
55 'Because this is a diff, TortoiseSVN marks the files as read-only.
56 'However, OpenOffice will not compare any file with that flag set.
57 'Make sure we un-set that flag.
58 Set objFSO = CreateObject("Scripting.FileSystemObject")
59 Set objFile = objFSO.GetFile(sNewDoc)
60 If (objFile.Attributes AND 1) = 1 Then
61 objFile.Attributes = objFile.Attributes XOR 1
62 End If
64 'Create the DesktopSet
65 Set objDesktop = objServiceManager.createInstance("com.sun.star.frame.Desktop")
66 Set objUriTranslator = objServiceManager.createInstance("com.sun.star.uri.ExternalUriReferenceTranslator")
67 'Adjust the paths for OO
68 sBaseDoc = Replace(sBaseDoc, "\", "/")
69 sBaseDoc = Replace(sBaseDoc, ":", "|")
70 sBaseDoc = Replace(sBaseDoc, "%", "%25")
71 sBaseDoc = Replace(sBaseDoc, " ", "%20")
72 sBaseDoc = Replace(sBaseDoc, "#", "%23")
73 sBaseDoc = "file:///"&sBaseDoc
74 sBaseDoc = objUriTranslator.translateToInternal(sBaseDoc)
75 sNewDoc = Replace(sNewDoc, "\", "/")
76 sNewDoc = Replace(sNewDoc, ":", "|")
77 sNewDoc = Replace(sNewDoc, "%", "%25")
78 sNewDoc = Replace(sNewDoc, " ", "%20")
79 sNewDoc = Replace(sNewDoc, "#", "%23")
80 sNewDoc = "file:///"&sNewDoc
81 sNewDoc = objUriTranslator.translateToInternal(sNewDoc)
83 'Open the %base document
84 Dim oPropertyValue(0)
85 Set oPropertyValue(0) = objServiceManager.Bridge_GetStruct("com.sun.star.beans.PropertyValue")
86 oPropertyValue(0).Name = "ShowTrackedChanges"
87 oPropertyValue(0).Value = true
88 Set objDocument = objDesktop.loadComponentFromURL(sNewDoc, "_blank", 0, oPropertyValue)
90 'Set the frame
91 Set Frame = objDesktop.getCurrentFrame
93 Set dispatcher = objServiceManager.CreateInstance("com.sun.star.frame.DispatchHelper")
95 'Execute the comparison
96 dispatcher.executeDispatch Frame, ".uno:ShowTrackedChanges", "", 0, oPropertyValue
97 oPropertyValue(0).Name = "URL"
98 oPropertyValue(0).Value = sBaseDoc
99 dispatcher.executeDispatch Frame, ".uno:CompareDocuments", "", 0, oPropertyValue