2 // TortoiseSVN Merge script for Word Doc files
\r
4 // Copyright (C) 2004-2008 the TortoiseSVN team
\r
5 // This file is distributed under the same license as TortoiseSVN
\r
9 // $Date: 2008-06-13 21:52:53 +0800 (Fri, 13 Jun 2008) $
\r
13 // Dan Sheridan, 2008
\r
14 // Davide Orlandi and Hans-Emil Skogh, 2005
\r
17 var objArgs,num,sTheirDoc,sMyDoc,sBaseDoc,sMergedDoc,objScript,word,baseDoc,WSHShell;
\r
19 // Microsoft Office versions for Microsoft Windows OS
\r
20 var vOffice2000 = 9;
\r
21 var vOffice2002 = 10;
\r
22 var vOffice2003 = 11;
\r
23 var vOffice2007 = 12;
\r
25 var wdCompareTargetSelected = 0;
\r
26 var wdCompareTargetCurrent = 1;
\r
27 var wdCompareTargetNew = 2;
\r
29 objArgs = WScript.Arguments;
\r
30 num = objArgs.length;
\r
33 WScript.Echo("Usage: [CScript | WScript] merge-doc.js merged.doc theirs.doc mine.doc base.doc");
\r
37 sMergedDoc=objArgs(0);
\r
38 sTheirDoc=objArgs(1);
\r
40 sBaseDoc=objArgs(3);
\r
42 objScript = new ActiveXObject("Scripting.FileSystemObject")
\r
43 if ( ! objScript.FileExists(sTheirDoc))
\r
45 WScript.Echo("File " + sTheirDoc +" does not exist. Cannot compare the documents.", vbExclamation, "File not found");
\r
48 if ( ! objScript.FileExists(sMergedDoc))
\r
50 WScript.Echo("File " + sMergedDoc +" does not exist. Cannot compare the documents.", vbExclamation, "File not found");
\r
58 word = WScript.CreateObject("Word.Application");
\r
62 WScript.Echo("You must have Microsoft Word installed to perform this operation.");
\r
68 // Open the base document
\r
69 baseDoc = word.Documents.Open(sTheirDoc);
\r
71 // Merge into the "My" document
\r
72 if (Number(word.Version) < vOffice2000)
\r
74 baseDoc.Compare(sMergedDoc);
\r
76 else if (Number(word.Version) < vOffice2007)
\r
78 baseDoc.Compare(sMergedDoc, "Comparison", wdCompareTargetNew, true, true);
\r
80 baseDoc.Merge(sMergedDoc);
\r
83 // Show the merge result
\r
84 if (Number(word.Version) < 12)
\r
86 word.ActiveDocument.Windows(1).Visible = 1;
\r
89 // Close the first document
\r
90 if (Number(word.Version) >= 10)
\r
95 // Show usage hint message
\r
96 WSHShell = WScript.CreateObject("WScript.Shell");
\r
97 if(WSHShell.Popup("You have to accept or reject the changes before\nsaving the document to prevent future problems.\n\nWould you like to see a help page on how to do this?", 0, "TSVN Word Merge", 4 + 64) == 6)
\r
99 WSHShell.Run("http://office.microsoft.com/en-us/assistance/HP030823691033.aspx");
\r