Synced diff-scripts with TortoiseSVN
[TortoiseGit.git] / contrib / diff-scripts / merge-ods.vbs
blob8878055166e97d7a85a5e2d9f02a97f061a28b39
1 ' extensions: ods;odt;sxw
3 ' TortoiseSVN Merge script for Open Office Calc files
5 ' Copyright (C) 2004-2009 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,sMergedDoc,sTheirDoc,sMyDoc,objScript,word,destination
19 Set objArgs = WScript.Arguments
20 num = objArgs.Count
21 if num < 4 then
22 MsgBox "Usage: [CScript | WScript] merge-ods.vbs %merged %theirs %mine %base", vbExclamation, "Invalid arguments"
23 WScript.Quit 1
24 end if
26 sMergedDoc=objArgs(0)
27 sTheirDoc=objArgs(1)
28 sMyDoc=objArgs(2)
29 sBaseDoc=objArgs(3)
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"
34 Wscript.Quit 1
35 End If
36 If objScript.FileExists(sTheirDoc) = False Then
37 MsgBox "File " + sTheirDoc +" does not exist. Cannot compare the documents.", vbExclamation, "File not found"
38 Wscript.Quit 1
39 End If
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 Set objScript = Nothing
46 On Error Resume Next
47 'The service manager is always the starting point
48 'If there is no office running then an office is started
49 Set objServiceManager= Wscript.CreateObject("com.sun.star.ServiceManager")
50 If Err.Number <> 0 Then
51 Wscript.Echo "You must have OpenOffice installed to perform this operation."
52 Wscript.Quit 1
53 End If
55 On Error Goto 0
56 'Create the DesktopSet
57 Set objDesktop = objServiceManager.createInstance("com.sun.star.frame.Desktop")
58 'Adjust the paths for OO
59 sMyDoc=Replace(sMyDoc, "\", "/")
60 sMyDoc=Replace(sMyDoc, ":", "|")
61 sMyDoc=Replace(sMyDoc, "%", "%25")
62 sMyDoc=Replace(sMyDoc, " ", "%20")
63 sMyDoc=Replace(sMyDoc, "#", "%23")
64 sMyDoc="file:///"&sMyDoc
65 sTheirDoc=Replace(sTheirDoc, "\", "/")
66 sTheirDoc=Replace(sTheirDoc, ":", "|")
67 sTheirDoc=Replace(sTheirDoc, "%", "%25")
68 sTheirDoc=Replace(sTheirDoc, " ", "%20")
69 sTheirDoc=Replace(sTheirDoc, "#", "%23")
70 sTheirDoc="file:///"&sTheirDoc
72 'Open the %mine document
73 Dim oPropertyValue(0)
74 Set oPropertyValue(0) = objServiceManager.Bridge_GetStruct("com.sun.star.beans.PropertyValue")
75 oPropertyValue(0).Name = "ShowTrackedChanges"
76 oPropertyValue(0).Value = true
77 Set objDocument=objDesktop.loadComponentFromURL(sMyDoc,"_blank", 0, oPropertyValue)
79 'Set the frame
80 Set Frame = objDesktop.getCurrentFrame
82 Set dispatcher=objServiceManager.CreateInstance("com.sun.star.frame.DispatchHelper")
84 'Execute the comparison
85 Dispatcher.executeDispatch Frame, ".uno:ShowTrackedChanges", "", 0, oPropertyValue
86 oPropertyValue(0).Name = "URL"
87 oPropertyValue(0).Value = sTheirDoc
88 Dispatcher.executeDispatch Frame, ".uno:CompareDocuments", "", 0, oPropertyValue