update dev300-m58
[ooovba.git] / migrationanalysis / src / wizard / RunServer.bas
blob310098345c734173440bf05ae004be25a80c32b8
1 Attribute VB_Name = "RunServer"
2 '/*************************************************************************
3 ' *
4 ' * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 ' *
6 ' * Copyright 2008 by Sun Microsystems, Inc.
7 ' *
8 ' * OpenOffice.org - a multi-platform office productivity suite
9 ' *
10 ' * $RCSfile: RunServer.bas,v $
11 ' * $Revision: 1.2.66.2 $
12 ' *
13 ' * This file is part of OpenOffice.org.
14 ' *
15 ' * OpenOffice.org is free software: you can redistribute it and/or modify
16 ' * it under the terms of the GNU Lesser General Public License version 3
17 ' * only, as published by the Free Software Foundation.
18 ' *
19 ' * OpenOffice.org is distributed in the hope that it will be useful,
20 ' * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 ' * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 ' * GNU Lesser General Public License version 3 for more details
23 ' * (a copy is included in the LICENSE file that accompanied this code).
24 ' *
25 ' * You should have received a copy of the GNU Lesser General Public License
26 ' * version 3 along with OpenOffice.org. If not, see
27 ' * <http://www.openoffice.org/license.html>
28 ' * for a copy of the LGPLv3 License.
29 ' *
30 ' ************************************************************************/
32 Option Explicit
34 Private Declare Function WritePrivateProfileString Lib "kernel32" _
35 Alias "WritePrivateProfileStringA" _
36 (ByVal lpSectionName As String, _
37 ByVal lpKeyName As Any, _
38 ByVal lpString As Any, _
39 ByVal lpFileName As String) As Long
41 Const CWORD_DRIVER = "_OOoDocAnalysisWordDriver.doc"
42 Const CEXCEL_DRIVER = "_OOoDocAnalysisExcelDriver.xls"
43 Const CPP_DRIVER = "_OOoDocAnalysisPPTDriver.ppt"
45 Const CWORD_APP = "word"
46 Const CEXCEL_APP = "excel"
47 Const CPP_APP = "pp"
49 Const CSTART_FILE = "PAW_Start_Analysis"
50 Const CSTOP_FILE = "PAW_Stop_Analysis"
52 Sub Main()
54 Dim serverType As String
55 serverType = LCase(Command$)
56 If (serverType <> CWORD_APP) And (serverType <> CEXCEL_APP) And (serverType <> CPP_APP) Then
57 MsgBox "Unknown server type: " & serverType
58 GoTo FinalExit
59 End If
61 Dim fso As New FileSystemObject
62 Dim driverName As String
64 If (serverType = CWORD_APP) Then
65 driverName = fso.GetAbsolutePathName(".\" & CWORD_DRIVER)
66 ElseIf (serverType = CEXCEL_APP) Then
67 driverName = fso.GetAbsolutePathName(".\" & CEXCEL_DRIVER)
68 ElseIf (serverType = CPP_APP) Then
69 driverName = fso.GetAbsolutePathName(".\" & CPP_DRIVER)
70 End If
72 If Not fso.FileExists(driverName) Then
73 If (serverType = CWORD_APP) Then
74 driverName = fso.GetAbsolutePathName(".\Resources\" & CWORD_DRIVER)
75 ElseIf (serverType = CEXCEL_APP) Then
76 driverName = fso.GetAbsolutePathName(".\Resources\" & CEXCEL_DRIVER)
77 ElseIf (serverType = CPP_APP) Then
78 driverName = fso.GetAbsolutePathName(".\Resources\" & CPP_DRIVER)
79 End If
80 End If
82 If Not fso.FileExists(driverName) Then
83 WriteToLog fso, "ALL", "LaunchDrivers: Could not find: " & driverName
84 GoTo FinalExit
85 End If
87 If (serverType = CWORD_APP) Then
88 OpenWordDriverDoc fso, driverName
89 ElseIf (serverType = CEXCEL_APP) Then
90 OpenExcelDriverDoc fso, driverName
91 ElseIf (serverType = CPP_APP) Then
92 OpenPPDriverDoc fso, driverName
93 End If
95 FinalExit:
97 Set fso = Nothing
98 End Sub
100 Sub OpenWordDriverDoc(fso As FileSystemObject, driverName As String)
102 Dim wrdApp As Word.Application
103 Dim wrdDriverDoc As Word.Document
105 On Error GoTo HandleErrors
107 Set wrdApp = New Word.Application
108 Set wrdDriverDoc = wrdApp.Documents.Open(driverName)
110 wrdApp.Run ("AnalysisTool.AnalysisDriver.AnalyseDirectory")
111 If Err.Number <> 0 Then
112 WriteToLog fso, CWORD_APP, "OpenWordDriverDoc: " & Err.Number & " " & Err.Description & " " & Err.Source
113 End If
115 wrdDriverDoc.Close wdDoNotSaveChanges
116 wrdApp.Quit False
118 FinalExit:
119 Set wrdDriverDoc = Nothing
120 Set wrdApp = Nothing
121 Exit Sub
123 HandleErrors:
124 WriteToLog fso, CWORD_APP, "OpenWordDriverDoc: " & Err.Number & " " & Err.Description & " " & Err.Source
125 Resume FinalExit
126 End Sub
128 Sub OpenExcelDriverDoc(fso As FileSystemObject, driverName As String)
130 Dim excelApp As Excel.Application
131 Dim excelDriverDoc As Excel.Workbook
133 On Error GoTo HandleErrors
135 Set excelApp = New Excel.Application
136 Set excelDriverDoc = Excel.Workbooks.Open(driverName)
137 excelApp.Run ("AnalysisTool.AnalysisDriver.AnalyseDirectory")
139 If Err.Number <> 0 Then
140 WriteToLog fso, CEXCEL_APP, "OpenExcelDriverDoc: " & Err.Number & " " & Err.Description & " " & Err.Source
141 End If
143 excelDriverDoc.Close False
144 excelApp.Quit
146 FinalExit:
147 Set excelDriverDoc = Nothing
148 Set excelApp = Nothing
149 Exit Sub
151 HandleErrors:
152 WriteToLog fso, CEXCEL_APP, "OpenExcelDriverDoc: " & Err.Number & " " & Err.Description & " " & Err.Source
153 Resume FinalExit
154 End Sub
156 Sub OpenPPDriverDoc(fso As FileSystemObject, driverName As String)
158 Dim ppApp As PowerPoint.Application
159 Dim ppDriverDoc As PowerPoint.Presentation
160 Dim ppDummy(0) As Variant
162 On Error GoTo HandleErrors
164 Set ppApp = New PowerPoint.Application
165 ppApp.Visible = msoTrue
166 Set ppDriverDoc = ppApp.Presentations.Open(driverName) ', msoTrue, msoFalse, msoFalse)
167 ppApp.Run ("AnalysisDriver.AnalyseDirectory")
169 If Err.Number <> 0 Then
170 WriteToLog fso, CPP_APP, "OpenPPDriverDoc: " & Err.Number & " " & Err.Description & " " & Err.Source
171 End If
173 ppDriverDoc.Close
174 ppApp.Quit
176 FinalExit:
177 Set ppDriverDoc = Nothing
178 Set ppApp = Nothing
179 Exit Sub
181 HandleErrors:
182 WriteToLog fso, CPP_APP, "OpenPPDriverDoc: " & Err.Number & " " & Err.Description & " " & Err.Source
183 Resume FinalExit
184 End Sub
186 Sub WriteToLog(fso As FileSystemObject, currApp As String, errMsg As String)
188 On Error Resume Next
190 Static ErrCount As Long
191 Dim logFileName As String
192 Dim tempPath As String
194 tempPath = fso.GetSpecialFolder(TemporaryFolder).Path
195 If (tempPath = "") Then tempPath = "."
196 logFileName = fso.GetAbsolutePathName(tempPath & "\LauchDrivers.log")
197 ErrCount = ErrCount + 1
199 Call WritePrivateProfileString("ERRORS", currApp & "_log" & ErrCount, _
200 errMsg, logFileName)
201 End Sub