--- /dev/null
+//\r
+// TortoiseSVN Diff script for Word Doc files\r
+//\r
+// Copyright (C) 2004-2008 the TortoiseSVN team\r
+// This file is distributed under the same license as TortoiseSVN\r
+//\r
+// Last commit by:\r
+// $Author: steveking $\r
+// $Date: 2008-07-17 23:29:51 +0800 (Thu, 17 Jul 2008) $\r
+// $Rev: 13493 $\r
+//\r
+// Authors:\r
+// Jared Silva, 2008\r
+// Davide Orlandi and Hans-Emil Skogh, 2005\r
+//\r
+\r
+var objArgs,num,sBaseDoc,sNewDoc,sTempDoc,objScript,word,destination;\r
+// Microsoft Office versions for Microsoft Windows OS\r
+var vOffice2000 = 9;\r
+var vOffice2002 = 10;\r
+var vOffice2003 = 11;\r
+var vOffice2007 = 12;\r
+// WdCompareTarget\r
+var wdCompareTargetSelected = 0;\r
+var wdCompareTargetCurrent = 1;\r
+var wdCompareTargetNew = 2;\r
+// WdViewType\r
+var wdMasterView = 5;\r
+var wdNormalView = 1;\r
+var wdOutlineView = 2;\r
+// WdSaveOptions\r
+var wdDoNotSaveChanges = 0;\r
+var wdPromptToSaveChanges = -2;\r
+var wdSaveChanges = -1;\r
+\r
+objArgs = WScript.Arguments;\r
+num = objArgs.length;\r
+if (num < 2)\r
+{\r
+ WScript.Echo("Usage: [CScript | WScript] diff-doc.js base.doc new.doc");\r
+ WScript.Quit(1);\r
+}\r
+\r
+sBaseDoc = objArgs(0);\r
+sNewDoc = objArgs(1);\r
+\r
+objScript = new ActiveXObject("Scripting.FileSystemObject");\r
+if ( ! objScript.FileExists(sBaseDoc))\r
+{\r
+ WScript.Echo("File " + sBaseDoc + " does not exist. Cannot compare the documents.");\r
+ WScript.Quit(1);\r
+}\r
+if ( ! objScript.FileExists(sNewDoc))\r
+{\r
+ WScript.Echo("File " + sNewDoc + " does not exist. Cannot compare the documents.");\r
+ WScript.Quit(1);\r
+}\r
+\r
+try\r
+{\r
+ word = WScript.CreateObject("Word.Application");\r
+}\r
+catch(e)\r
+{\r
+ // before giving up, try with OpenOffice\r
+ try\r
+ {\r
+ var OO;\r
+ OO = WScript.CreateObject("com.sun.star.ServiceManager");\r
+ }\r
+ catch(e)\r
+ {\r
+ WScript.Echo("You must have Microsoft Word or OpenOffice installed to perform this operation.");\r
+ WScript.Quit(1);\r
+ }\r
+ // yes, OO is installed - do the diff with that one instead\r
+ var objFile = objScript.GetFile(sNewDoc);\r
+ if ((objFile.Attributes & 1)==1)\r
+ {\r
+ // reset the readonly attribute\r
+ objFile.Attributes = objFile.Attributes & (~1);\r
+ }\r
+ //Create the DesktopSet \r
+ var objDesktop = OO.createInstance("com.sun.star.frame.Desktop");\r
+ var objUriTranslator = OO.createInstance("com.sun.star.uri.ExternalUriReferenceTranslator");\r
+ //Adjust the paths for OO\r
+ sBaseDoc = sBaseDoc.replace(/\\/g, "/");\r
+ sBaseDoc = sBaseDoc.replace(/:/g, "|");\r
+ sBaseDoc = sBaseDoc.replace(/ /g, "%20");\r
+ sBaseDoc="file:///" + sBaseDoc;\r
+ sBaseDoc=objUriTranslator.translateToInternal(sBaseDoc);\r
+ sNewDoc = sNewDoc.replace(/\\/g, "/");\r
+ sNewDoc = sNewDoc.replace(/:/g, "|");\r
+ sNewDoc = sNewDoc.replace(/ /g, "%20");\r
+ sNewDoc="file:///" + sNewDoc;\r
+ sNewDoc=objUriTranslator.translateToInternal(sNewDoc);\r
+\r
+ //Open the %base document\r
+ var oPropertyValue = new Array();\r
+ oPropertyValue[0] = OO.Bridge_GetStruct("com.sun.star.beans.PropertyValue");\r
+ oPropertyValue[0].Name = "ShowTrackedChanges";\r
+ oPropertyValue[0].Value = true;\r
+ var objDocument=objDesktop.loadComponentFromURL(sNewDoc,"_blank", 0, oPropertyValue);\r
+ \r
+ //Set the frame\r
+ var Frame = objDesktop.getCurrentFrame();\r
+ \r
+ var dispatcher=OO.CreateInstance("com.sun.star.frame.DispatchHelper");\r
+ \r
+ //Execute the comparison\r
+ dispatcher.executeDispatch(Frame, ".uno:ShowTrackedChanges", "", 0, oPropertyValue);\r
+ oPropertyValue[0].Name = "URL";\r
+ oPropertyValue[0].Value = sBaseDoc;\r
+ dispatcher.executeDispatch(Frame, ".uno:CompareDocuments", "", 0, oPropertyValue);\r
+ WScript.Quit(0);\r
+}\r
+\r
+if (Number(word.Version) >= vOffice2007)\r
+{\r
+ sTempDoc = sNewDoc;\r
+ sNewDoc = sBaseDoc;\r
+ sBaseDoc = sTempDoc;\r
+}\r
+\r
+objScript = null;\r
+\r
+word.visible = true;\r
+\r
+// Open the new document\r
+try\r
+{\r
+ destination = word.Documents.Open(sNewDoc, true, true);\r
+}\r
+catch(e)\r
+{\r
+ WScript.Echo("Error opening " + sNewDoc);\r
+ // Quit\r
+ WScript.Quit(1);\r
+}\r
+\r
+// If the Type property returns either wdOutlineView or wdMasterView and the Count property returns zero, the current document is an outline.\r
+if (((destination.ActiveWindow.View.Type == wdOutlineView) || (destination.ActiveWindow.View.Type == wdMasterView)) && (destination.Subdocuments.Count == 0))\r
+{\r
+ // Change the Type property of the current document to normal\r
+ destination.ActiveWindow.View.Type = wdNormalView;\r
+}\r
+\r
+// Compare to the base document\r
+if (Number(word.Version) <= vOffice2000)\r
+{\r
+ // Compare for Office 2000 and earlier\r
+ try\r
+ {\r
+ destination.Compare(sBaseDoc);\r
+ }\r
+ catch(e)\r
+ {\r
+ WScript.Echo("Error comparing " + sBaseDoc + " and " + sNewDoc);\r
+ // Quit\r
+ WScript.Quit(1);\r
+ }\r
+}\r
+else\r
+{\r
+ // Compare for Office XP (2002) and later\r
+ try\r
+ {\r
+ destination.Compare(sBaseDoc, "Comparison", wdCompareTargetNew, true, true);\r
+ }\r
+ catch(e)\r
+ {\r
+ WScript.Echo("Error comparing " + sBaseDoc + " and " + sNewDoc);\r
+ // Close the first document and quit\r
+ destination.Close(wdDoNotSaveChanges);\r
+ WScript.Quit(1);\r
+ }\r
+}\r
+ \r
+// Show the comparison result\r
+if (Number(word.Version) < vOffice2007)\r
+{\r
+ word.ActiveDocument.Windows(1).Visible = 1;\r
+}\r
+ \r
+// Mark the comparison document as saved to prevent the annoying\r
+// "Save as" dialog from appearing.\r
+word.ActiveDocument.Saved = 1;\r
+ \r
+// Close the first document\r
+if (Number(word.Version) >= vOffice2002)\r
+{\r
+ destination.Close(wdDoNotSaveChanges);\r
+}\r