1 ' extensions: ods;odt;sxw
3 ' TortoiseSVN Merge script for Open Office Calc files
5 ' Copyright (C) 2004-2009, 2012-2014 the TortoiseSVN team
6 ' This file is distributed under the same license as TortoiseSVN
14 ' Jonathan Ashley, 2007
15 ' Stefan Küng, 2006, 2009
17 dim objArgs
, num
, sBaseDoc
, sMergedDoc
, sTheirDoc
, sMyDoc
, objScript
19 Set objArgs
= WScript
.Arguments
22 MsgBox
"Usage: [CScript | WScript] merge-ods.vbs %merged %theirs %mine %base", vbExclamation
, "Invalid arguments"
26 sMergedDoc
= objArgs(0)
27 sTheirDoc
= objArgs(1)
31 Set objScript
= CreateObject("Scripting.FileSystemObject")
32 If objScript
.FileExists(sMyDoc
) = False Then
33 MsgBox
"File " + sMyDoc
+ " does not exist. Cannot compare the documents.", vbExclamation
, "File not found"
36 If objScript
.FileExists(sTheirDoc
) = False Then
37 MsgBox
"File " + sTheirDoc
+ " does not exist. Cannot compare the documents.", vbExclamation
, "File not found"
40 'remove the file write protection
41 objScript
.GetFile(sMyDoc
).Attributes
= objScript
.GetFile(sMyDoc
).Attributes
And Not 1
42 objScript
.GetFile(sTheirDoc
).Attributes
= objScript
.GetFile(sTheirDoc
).Attributes
And Not 1
44 'since i haven't found a way to tell OO a new "save" path after a document is opened,
45 'the %mine and %merged paths need to be identical since it always saves to the %mine path
46 if (sMergedDoc
<> sMyDoc
) Then
47 MsgBox
"You need to safe the merged file as """ + sMergedDoc
+ """ after merging otherwise you might lose your changes.", vbInformation
, "TortoiseGit OpenOffice merge helper"
51 Set objScript
= Nothing
54 'The service manager is always the starting point
55 'If there is no office running then an office is started
56 Set objServiceManager
= Wscript
.CreateObject("com.sun.star.ServiceManager")
57 If Err
.Number
<> 0 Then
58 Wscript
.Echo
"You must have OpenOffice installed to perform this operation."
63 'Create the DesktopSet
64 Set objDesktop
= objServiceManager
.createInstance("com.sun.star.frame.Desktop")
65 'Adjust the paths for OO
66 sMyDoc
= Replace(sMyDoc
, "\", "/")
67 sMyDoc
= Replace(sMyDoc
, ":", "|")
68 sMyDoc
= Replace(sMyDoc
, "%", "%25")
69 sMyDoc
= Replace(sMyDoc
, " ", "%20")
70 sMyDoc
= Replace(sMyDoc
, "#", "%23")
71 sMyDoc
= "file:///"&sMyDoc
72 sTheirDoc
= Replace(sTheirDoc
, "\", "/")
73 sTheirDoc
= Replace(sTheirDoc
, ":", "|")
74 sTheirDoc
= Replace(sTheirDoc
, "%", "%25")
75 sTheirDoc
= Replace(sTheirDoc
, " ", "%20")
76 sTheirDoc
= Replace(sTheirDoc
, "#", "%23")
77 sTheirDoc
= "file:///"&sTheirDoc
79 'Open the %mine document
81 Set oPropertyValue(0) = objServiceManager
.Bridge_GetStruct("com.sun.star.beans.PropertyValue")
82 oPropertyValue(0).Name
= "ShowTrackedChanges"
83 oPropertyValue(0).Value
= true
84 Set objDocument
= objDesktop
.loadComponentFromURL(sMyDoc
, "_blank", 0, oPropertyValue
)
87 Set Frame
= objDesktop
.getCurrentFrame
89 Set dispatcher
= objServiceManager
.CreateInstance("com.sun.star.frame.DispatchHelper")
91 'Execute the comparison
92 Dispatcher
.executeDispatch Frame
, ".uno:ShowTrackedChanges", "", 0, oPropertyValue
93 oPropertyValue(0).Name
= "URL"
94 oPropertyValue(0).Value
= sTheirDoc
95 Dispatcher
.executeDispatch Frame
, ".uno:CompareDocuments", "", 0, oPropertyValue