Fix typos
[TortoiseGit.git] / contrib / diff-scripts / merge-ods.vbs
blobddaa89c94d5e28eaf1c99af01b729962e0f5a20d
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
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
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 '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"
48 End If
51 Set objScript = Nothing
53 On Error Resume Next
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."
59 Wscript.Quit 1
60 End If
62 On Error Goto 0
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
80 Dim oPropertyValue(0)
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)
86 'Set the frame
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