FilesModul.xba 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!DOCTYPE script:module PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "module.dtd">
  3. <!--***********************************************************
  4. *
  5. * Licensed to the Apache Software Foundation (ASF) under one
  6. * or more contributor license agreements. See the NOTICE file
  7. * distributed with this work for additional information
  8. * regarding copyright ownership. The ASF licenses this file
  9. * to you under the Apache License, Version 2.0 (the
  10. * "License"); you may not use this file except in compliance
  11. * with the License. You may obtain a copy of the License at
  12. *
  13. * http://www.apache.org/licenses/LICENSE-2.0
  14. *
  15. * Unless required by applicable law or agreed to in writing,
  16. * software distributed under the License is distributed on an
  17. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  18. * KIND, either express or implied. See the License for the
  19. * specific language governing permissions and limitations
  20. * under the License.
  21. *
  22. ***********************************************************-->
  23. <script:module xmlns:script="http://openoffice.org/2000/script" script:name="FilesModul" script:language="StarBasic">Option Explicit
  24. Public AbsTemplateFound as Integer
  25. Public AbsDocuFound as Integer
  26. Public oLogDocument as Object
  27. Public oLogTable as Object
  28. Public bLogExists as Boolean
  29. Public sComment as String
  30. Public MaxCollectIndex as Integer
  31. Public bInsertRow as Boolean
  32. Public sLogUrl as String
  33. Public sCurPassWord as String
  34. Public FileCount as Integer
  35. Public XMLTemplateCount as Integer
  36. Public PathCollection(7,3) as String
  37. Public bIsFirstLogTable as Boolean
  38. Public bFilterTracerIsinsideTable as Boolean
  39. Function ReadCollectionPaths(FilesList() as String, sFilterName() as String)
  40. Dim FilterIndex as Integer
  41. Dim bRecursive as Boolean
  42. Dim SearchDir as String
  43. Dim i as Integer
  44. Dim n as Integer
  45. Dim a as Integer
  46. Dim s as Integer
  47. Dim t as Integer
  48. Dim sFileContent() as String
  49. Dim NewList(0,1) as String
  50. Dim Index as Integer
  51. Dim CurFileName as String
  52. Dim CurExtension as String
  53. Dim CurFileContent as String
  54. Dim XMLTemplateContentList() as String
  55. Dim bIsTemplatePath as Boolean
  56. Dim MaxIndex as Integer
  57. Dim NewContentList() as String
  58. Dim XMLTemplateContentString as String
  59. Dim ApplIndex as Integer
  60. Dim bAssignFileName as Boolean
  61. bInterruptSearch = False
  62. For i = 0 To MaxCollectIndex
  63. SearchDir = PathCollection(i,0)
  64. bRecursive = PathCollection(i,1)
  65. sFileContent() = ArrayoutofString(PathCollection(i,2), &quot;|&quot;)
  66. NewList() = ReadDirectories(SearchDir, bRecursive, False, False, sFileContent(), &quot;&quot;)
  67. If InterruptProcess Then
  68. ReadCollectionPaths() = False
  69. Exit Function
  70. End If
  71. If Ubound(NewList()) &gt; -1 Then
  72. bIsTemplatePath = FieldInList(&quot;vor&quot;, sFileContent)
  73. If bIsTemplatePath Then
  74. XMLTemplateContentString = PathCollection(i,3)
  75. XMLTemplateContentList() = ArrayoutofString(XMLTemplateContentString, &quot;|&quot;)
  76. If Ubound(XMLTemplateContentList()) &gt; -1 Then
  77. MaxIndex = Ubound(NewList())
  78. ReDim Preserve NewList(MaxIndex, 1) as String
  79. ReDim Preserve NewContentList(MaxIndex) as String
  80. a = -1
  81. For n = 0 To MaxIndex
  82. bAssignFileName = True
  83. If InterruptProcess() Then
  84. ReadCollectionPaths() = False
  85. Exit Function
  86. End If
  87. CurFileContent = &quot;&quot;
  88. CurFileName = NewList(n,0)
  89. If (FieldInList(NewList(n,1), XMLTemplateList())) Then
  90. CurFileContent = GetRealFileContent(CurFileName)
  91. t = SearchArrayforPartString(CurFileContent, XMLTemplateContentList())
  92. bAssignFileName = (t &gt; -1)
  93. If bAssignFileName Then
  94. CurFileContent = XMLTemplateContentList(t)
  95. End If
  96. NewList(n,1) = CurFileContent
  97. End If
  98. CurExtension = NewList(n,1)
  99. If bAssignFileName Then
  100. If a &lt; n Then
  101. a = a + 1
  102. NewList(a,0) = CurFileName
  103. NewList(a,1) = CurExtension
  104. If CurFileContent = &quot;&quot; Then
  105. CurFileContent = CurExtension
  106. End If
  107. ApplIndex = GetApplicationIndex(CurFileContent, sFiltername())
  108. NewContentList(a) = ApplIndex
  109. End If
  110. End If
  111. Next n
  112. If a &lt; MaxIndex And a &gt; -1 Then
  113. ReDim Preserve NewList(a, 1) as String
  114. End If
  115. If a &gt; -1 Then
  116. AddListtoFilesList(FilesList(), NewList(), NewContentList())
  117. End If
  118. End If
  119. Else
  120. MaxIndex = Ubound(NewList())
  121. ReDim Preserve NewContentList(MaxIndex) as String
  122. For s = 0 To MaxIndex
  123. CurExtension = NewList(s,1)
  124. NewContentList(s) = GetApplicationIndex(CurExtension, sFiltername())
  125. Next s
  126. AddListtoFilesList(FilesList(), NewList(), NewContentList())
  127. End If
  128. End If
  129. Next i
  130. ReadCollectionPaths() = Ubound(FilesList()) &gt; -1
  131. End Function
  132. Function GetApplicationIndex(CurFileContent as String, sFilterName() as String) as Integer
  133. Dim Index as Integer
  134. Dim i as Integer
  135. Index = GetIndexForPartStringinMultiArray(sFilterName(), CurFileContent, 0)
  136. If Index &gt;= MaxApplCount Then
  137. Index = Index - MaxApplCount
  138. End If
  139. For i = 0 To MaxApplCount - 1
  140. If Applications(i, SBAPPLKEY) = Index Then
  141. GetApplicationIndex() = i
  142. Exit Function
  143. End If
  144. Next i
  145. GetApplicationIndex() = - 1
  146. End Function
  147. Function InterruptProcess() as Boolean
  148. If bCancelTask Or RetValue = 0 Then
  149. bConversionIsRunning = False
  150. InterruptProcess() = True
  151. Exit Function
  152. End if
  153. InterruptProcess() = False
  154. End Function
  155. Sub AddCollectionPath(ApplIndex as Integer, DocIndex as Integer, RecursiveIndex as Integer, sFiltername() as String, DistIndex as Integer)
  156. MaxCollectIndex = MaxCollectIndex + 1
  157. PathCollection(MaxCollectIndex, 0) = Applications(ApplIndex, DocIndex)
  158. PathCollection(MaxCollectIndex, 1) = Applications(ApplIndex, RecursiveIndex)
  159. AddFilterNameToPathItem(ApplIndex, MaxCollectIndex, sFiltername(), DistIndex)
  160. End Sub
  161. Function SetExtension(LocExtension) as String
  162. if (Instr(LocExtension, &quot;vnd.sun.xml.impress&quot;)) &gt; 0 then
  163. SetExtension() = &quot;vor|sti|std&quot;
  164. elseif (Instr(LocExtension, &quot;vnd.sun.xml.writer&quot;)) &gt; 0 then
  165. SetExtension() = &quot;vor|stw&quot;
  166. elseif (Instr(LocExtension, &quot;vnd.sun.xml.calc&quot;)) &gt; 0 then
  167. SetExtension() = &quot;vor|stc&quot;
  168. elseif (Instr(LocExtension, &quot;vnd.sun.xml.draw&quot;)) &gt; 0 then
  169. SetExtension() = &quot;vor|std|sti&quot;
  170. endif
  171. End Function
  172. Sub AddFilterNameToPathItem(ApplIndex as Integer, CollectIndex as Integer, sFiltername() as String, DistIndex as Integer)
  173. Dim iKey as Integer
  174. Dim CurListString as String
  175. Dim LocExtension as String
  176. Dim LocContentString as String
  177. Dim LocXMLTemplateContent as String
  178. iKey = Applications(ApplIndex, SBAPPLKEY)
  179. CurListString = PathCollection(CollectIndex, 2)
  180. LocExtension = sFilterName(iKey +DistIndex, 0)
  181. If Len(LocExtension) &gt; SBMAXEXTENSIONLENGTH Then &apos; 7 == Length of two extensions like &apos;sda|sdd
  182. LocExtension = SetExtension(LocExtension)
  183. LocContentString = sFilterName(iKey +DistIndex, 0)
  184. LocContentString = ReplaceString(LocContentString, &quot;|&quot;, &quot;;&quot;)
  185. LocXMLTemplateContent = PathCollection(CollectIndex, 3)
  186. If LocXMLTemplateContent = &quot;&quot; Then
  187. LocXMLTemplateContent = LocContentString
  188. Else
  189. LocXMLTemplateContent = LocXMLTemplateContent &amp; &quot;|&quot; &amp; LocContentString
  190. End If
  191. PathCollection(CollectIndex, 3) = LocXMLTemplateContent
  192. End If
  193. If CurListString = &quot;&quot; Then
  194. PathCollection(CollectIndex, 2) = LocExtension
  195. Else
  196. If Instr(CurListString, LocExtension) = 0 Then
  197. PathCollection(CollectIndex, 2) = CurListString &amp; &quot;|&quot; &amp; LocExtension
  198. End If
  199. End If
  200. End Sub
  201. Sub CheckIfToAddPathToCollection(ApplIndex as Integer, bDoConvertIndex as Integer, DocIndex as Integer, RecursiveIndex as Integer, sFiltername() as String, DistIndex as Integer)
  202. Dim CollectIndex as Integer
  203. Dim bCheckDocuType as Boolean
  204. bCheckDocuType = Applications(ApplIndex, bDoConvertIndex)
  205. If bCheckDocuType Then
  206. CollectIndex = GetIndexInMultiArray(PathCollection(), Applications(ApplIndex,DocIndex), 0)
  207. If (CollectIndex &gt;-1) Then
  208. If Applications(ApplIndex, RecursiveIndex) &lt;&gt; PathCollection(CollectIndex, 1) Then
  209. AddCollectionPath(ApplIndex, DocIndex, RecursiveIndex, sFilterName(), DistIndex)
  210. Else
  211. AddFilterNameToPathItem(ApplIndex, CollectIndex, sFilterName(), DistIndex)
  212. End If
  213. Else
  214. AddCollectionPath(ApplIndex, DocIndex, RecursiveIndex, sFilterName(), DistIndex)
  215. End If
  216. End If
  217. End Sub
  218. Sub CollectPaths(sFiltername() as String)
  219. Dim i as Integer
  220. Dim XMLTemplateContentString as String
  221. MaxCollectIndex = -1
  222. For i = 0 To ApplCount-1
  223. CheckIfToAddPathToCollection(i, SBDOCCONVERT, SBDOCSOURCE, SBDOCRECURSIVE, sFilterName(), 0)
  224. Next i
  225. XMLTemplateCount = 0
  226. XMLTemplateContentString = &quot;&quot;
  227. For i = 0 To ApplCount-1
  228. If WizardMode = SBXMLMODE Then
  229. XMLTemplateCount = XMLTemplateCount + 1
  230. End If
  231. CheckIfToAddPathToCollection(i, SBTEMPLCONVERT, SBTEMPLSOURCE, SBTEMPLRECURSIVE, sFilterName(), MaxApplCount)
  232. Next i
  233. End Sub
  234. Sub ConvertAllDocuments(sFilterName() as String)
  235. Dim FileProperties(1) as new com.sun.star.beans.PropertyValue
  236. Dim PWFileProperties(2) as New com.sun.star.beans.PropertyValue
  237. Dim WriterWebProperties(0) as new com.sun.star.beans.PropertyValue
  238. Dim OpenProperties(4) as new com.sun.star.beans.PropertyValue
  239. Dim oInteractionHandler as Object
  240. Dim InteractionTypes(0) as Long
  241. Dim FilesList(0,2) as String
  242. Dim sViewPath as String
  243. Dim i as Integer
  244. Dim FilterIndex as Integer
  245. Dim sSourceUrl as String
  246. Dim CurFilename as String
  247. Dim oDocument as Object
  248. Dim sExtension as String
  249. Dim OldExtension as String
  250. Dim CurFound as Integer
  251. Dim TotFound as Integer
  252. Dim TargetStemDir as String
  253. Dim SourceStemDir as String
  254. Dim TargetDir as String
  255. Dim sTargetUrl as String
  256. Dim CurFilterName as String
  257. Dim ApplIndex as Integer
  258. Dim Index as Integer
  259. Dim bIsDocument as Boolean
  260. Dim bDoSave as Boolean
  261. Dim sCurFileExists as String
  262. Dim MaxFileIndex as Integer
  263. Dim bContainsBasicMacro as Boolean
  264. Dim bIsPassWordProtected as Boolean
  265. Dim iOverwrite as Integer
  266. Dim sMimeTypeorExtension as String
  267. Dim sPrevMimeTypeorExtension as String
  268. bConversionisrunning = True
  269. InteractionTypes(0) = com.sun.star.task.PasswordRequestMode.PASSWORD_REENTER
  270. oInteractionHandler = createUnoService(&quot;com.sun.star.task.InteractionHandler&quot;)
  271. oInteractionHandler.initialize(InteractionTypes())
  272. iGeneralOverwrite = SBOVERWRITEUNDEFINED
  273. bConversionIsRunning = True
  274. bLogExists = false
  275. AbsTemplateFound = 0
  276. AbsDocuFound = 0
  277. CollectPaths(sFiltername())
  278. If Not ReadCollectionPaths(FilesList(), sFilterName()) Then
  279. TotFound = 0
  280. SetProgressDisplay(0)
  281. bConversionisrunning = false
  282. FinalizeDialogButtons()
  283. Exit Sub
  284. End If
  285. TotFound = Ubound(FilesList()) + 1
  286. If FilesList(0,0) = &quot;&quot; Then &apos; Querying the number of fields in a multidimensionl Array is unsecure
  287. TotFound = 0 &apos; because it will return the value 0 (and not -1) even when the Array is empty
  288. SetProgressDisplay(0)
  289. End If
  290. BubbleSortList(FilesList(), true)
  291. If TotFound &gt; 0 Then
  292. CreateLogDocument(OpenProperties())
  293. InitializeProgressPage(ImportDialog)
  294. OpenProperties(0).Name = &quot;Hidden&quot;
  295. OpenProperties(0).Value = True
  296. OpenProperties(1).Name = &quot;AsTemplate&quot;
  297. OpenProperties(1).Value = False
  298. OpenProperties(2).Name = &quot;MacroExecutionMode&quot;
  299. OpenProperties(2).Value = com.sun.star.document.MacroExecMode.NEVER_EXECUTE
  300. OpenProperties(3).Name = &quot;UpdateDocMode&quot;
  301. OpenProperties(3).Value = com.sun.star.document.UpdateDocMode.NO_UPDATE
  302. OpenProperties(4).Name = &quot;InteractionHandler&quot;
  303. OpenProperties(4).Value = oInteractionHandler
  304. MaxFileIndex = Ubound(FilesList(),1)
  305. FileCount = 0
  306. For i = 0 To MaxFileIndex
  307. sComment = &quot;&quot;
  308. If InterruptProcess() Then
  309. Exit For
  310. End If
  311. bDoSave = True
  312. sSourceUrl = FilesList(i,0)
  313. sPrevMimeTypeorExtension = sMimeTypeorExtension
  314. sMimeTypeorExtension = FilesList(i,1)
  315. CurFiltername = GetFilterName(sMimeTypeorExtension, sFilterName(), sExtension, FilterIndex)
  316. ApplIndex = FilesList(i,2)
  317. If sMimeTypeorExtension &lt;&gt; sPrevMimeTypeorExtension Then
  318. CreateLogTable(ApplIndex, sMimeTypeOrExtension, sFiltername()
  319. End If
  320. If ApplIndex &gt; Ubound(Applications) or (ApplIndex &lt; 0) Then
  321. Msgbox &quot;Applicationindex out of bounds:&quot; &amp; sSourcUrl
  322. End If
  323. sViewPath = ConvertFromUrl(sSourceUrl) &apos; CutPathView(sSourceUrl, 70)
  324. ImportDialog.LabelCurDocument.Label = Str(i+1) &amp; &quot;/&quot; &amp; MaxFileIndex + 1 &amp; &quot; (&quot; &amp; sViewPath &amp; &quot;)&quot;
  325. Select Case lcase(sExtension)
  326. Case &quot;odt&quot;, &quot;ods&quot;, &quot;odp&quot;, &quot;odg&quot;, &quot;odm&quot;, &quot;odf&quot;
  327. SourceStemDir = RTrimStr(Applications(ApplIndex,SBDOCSOURCE), &quot;/&quot;)
  328. TargetStemDir = RTrimStr(Applications(ApplIndex,SBDOCTARGET), &quot;/&quot;)
  329. Case Else &apos; Templates and Helper-Applications remain
  330. SourceStemDir = RTrimStr(Applications(ApplIndex,SBTEMPLSOURCE), &quot;/&quot;)
  331. TargetStemDir = RTrimStr(Applications(ApplIndex,SBTEMPLTARGET), &quot;/&quot;)
  332. End Select
  333. sTargetUrl = ReplaceString(sSourceUrl, TargetStemDir, SourceStemDir)
  334. CurFilename = GetFileNameWithoutExtension(sTargetUrl, &quot;/&quot;)
  335. OldExtension = GetFileNameExtension(sTargetUrl)
  336. sTargetUrl = RTrimStr(sTargetUrl, OldExtension)
  337. sTargetUrl = sTargetUrl &amp; sExtension
  338. TargetDir = RTrimStr(sTargetUrl, CurFilename &amp; &quot;.&quot; &amp; sExtension)
  339. If (oUcb.Exists(sTargetUrl)) Then
  340. If (iGeneralOverwrite &lt;&gt; SBOVERWRITEALWAYS) Then
  341. If (iGeneralOverwrite = SBOVERWRITEUNDEFINED) Then
  342. ShowOverwriteAllDialog(sTargetUrl, sTitle)
  343. bDoSave = (iGeneralOverwrite = SBOVERWRITEQUERY) Or (iGeneralOverwrite = SBOVERWRITEALWAYS)
  344. Elseif iGeneralOverwrite = SBOVERWRITENEVER Then
  345. bDoSave = False
  346. ElseIf ((iGeneralOverWrite = SBOVERWRITEQUERY) OR (iGeneralOverwrite = SBOVERWRITECANCEL)) Then
  347. &apos; Todo: According to AS there might come a new feature that storeasUrl could possibly rise a UI dialog.
  348. &apos; In this case my own UI becomes obsolete
  349. sCurFileExists = ReplaceString(sFileExists, ConvertFromUrl(sTargetUrl), &quot;&lt;1&gt;&quot;)
  350. sCurFileExists = ReplaceString(sCurFileExists, chr(13), &quot;&lt;CR&gt;&quot;)
  351. iOverWrite = Msgbox (sCurFileExists, 32 + 3, sTitle)
  352. Select Case iOverWrite
  353. Case 1 &apos; OK
  354. &apos; In the FileProperty-Bean this is already default
  355. bDoSave = True
  356. Case 2 &apos; Abort
  357. CancelTask(False)
  358. bDoSave = False
  359. Case 7 &apos; No
  360. bDoSave = False
  361. End Select
  362. End If
  363. End If
  364. End If
  365. If bDoSave Then
  366. If Not oUcb.Exists(TargetDir) Then
  367. bDoSave = CreateFolder(TargetDir)
  368. End If
  369. If bDoSave Then
  370. oDocument = StarDesktop.LoadComponentFromURL(sSourceUrl, &quot;_default&quot;, 0, OpenProperties())
  371. If Not IsNull(oDocument) Then
  372. InsertSourceUrlToLogDocument(sSourceUrl, &quot;&quot;)
  373. bIsPassWordProtected = CheckPassWordProtection(oDocument)
  374. CheckIfMacroExists(oDocument.BasicLibraries, sComment)
  375. On Local Error Goto NOSAVING
  376. If bIsPassWordProtected Then
  377. PWFileProperties(0).Name = &quot;FilterName&quot;
  378. PWFileProperties(0).Value = CurFilterName
  379. PWFileProperties(1).Name = &quot;Overwrite&quot;
  380. PWFileProperties(1).Value = True
  381. PWFileProperties(2).Name = &quot;Password&quot;
  382. PWFileProperties(2).Value = sCurPassWord
  383. oDocument.StoreAsUrl(sTargetUrl, PWFileProperties())
  384. Else
  385. FileProperties(0).Name = &quot;FilterName&quot;
  386. FileProperties(0).Value = CurFilterName
  387. FileProperties(1).Name = &quot;Overwrite&quot;
  388. FileProperties(1).Value = True
  389. oDocument.StoreAsUrl(sTargetUrl,FileProperties())
  390. End If
  391. &apos; Todo: Make sure that an errorbox pops up when saving fails
  392. NOSAVING:
  393. If Err &lt;&gt; 0 Then
  394. sCurcouldnotsaveDocument = ReplaceString(scouldnotsaveDocument, ConvertFromUrl(sTargetUrl), &quot;&lt;1&gt;&quot;)
  395. sComment = ConcatComment(sComment, sCurCouldnotsaveDocument)
  396. Resume LETSGO
  397. LETSGO:
  398. Else
  399. FileCount = FileCount + 1
  400. End If
  401. oDocument.Dispose()
  402. InsertTargetUrlToLogDocument(sTargetUrl, sComment, ApplIndex)
  403. Else
  404. sCurcouldnotopenDocument = ReplaceString(scouldnotopenDocument, ConvertFromUrl(sSourceUrl), &quot;&lt;1&gt;&quot;)
  405. sComment = ConcatComment(sComment, sCurCouldnotopenDocument)
  406. InsertSourceUrlToLogDocument(sSourceUrl, sComment)
  407. End If
  408. End If
  409. End If
  410. Next i
  411. End If
  412. AddLogStatistics()
  413. FinalizeDialogButtons()
  414. bConversionIsRunning = False
  415. Exit Sub
  416. RTError:
  417. Msgbox sRTErrorDesc, 16, sRTErrorHeader
  418. End Sub
  419. Sub AddListtoFilesList(FirstList(), SecList(), NewContentList() as String)
  420. Dim sLocExtension as String
  421. Dim FirstStart as Integer
  422. Dim FirstEnd as Integer
  423. Dim i as Integer
  424. Dim s as Integer
  425. If FirstList(0,0) = &quot;&quot; Then
  426. FirstStart = Ubound(FirstList(),1)
  427. Else
  428. FirstStart = Ubound(FirstList(),1) + 1
  429. End If
  430. FirstEnd = FirstStart + Ubound(SecList(),1)
  431. ReDim Preserve FirstList(FirstEnd,2)
  432. s = 0
  433. For i = FirstStart To FirstEnd
  434. FirstList(i,0) = SecList(s,0)
  435. FirstList(i,1) = SecList(s,1)
  436. sLocExtension = lcase(FirstList(i,1))
  437. Select Case sLocExtension
  438. Case &quot;sdw&quot;, &quot;sdc&quot;, &quot;sda&quot;, &quot;sdd&quot;, &quot;smf&quot;, &quot;sgl&quot;, &quot;doc&quot;, &quot;xls&quot;, &quot;ppt&quot;, &quot;sxi&quot; , &quot;sxw&quot; , &quot;sxd&quot; , &quot;sxg&quot; , &quot;sxm&quot; , &quot;sxc&quot; , &quot;pps&quot; , &quot;docx&quot; , &quot;docm&quot; , &quot;xlsx&quot; , &quot;xlsm&quot; , &quot;xlsb&quot; , &quot;pptx&quot; , &quot;pptm&quot;
  439. AbsDocuFound = AbsDocuFound + 1
  440. Case else
  441. AbsTemplateFound = AbsTemplateFound + 1
  442. End Select
  443. FirstList(i,2) = CStr(NewContentList(s))
  444. s = s + 1
  445. Next i
  446. SetProgressDisplay(Ubound(FirstList()) + 1)
  447. End Sub
  448. Function GetTargetTemplatePath(Index as Integer)
  449. Select Case WizardMode
  450. Case SBMICROSOFTMODE
  451. GetTargetTemplatePath() = SOTemplatePath &amp; &quot;/&quot; &amp; sTemplateGroupName
  452. Case SBXMLMODE
  453. If Index = 3 Then
  454. &apos; Helper Application
  455. GetTargetTemplatePath = SOWorkPath
  456. Else
  457. GetTargetTemplatePath = SOTemplatePath
  458. End If
  459. End Select
  460. End Function
  461. &apos; Retrieves the second value for a next to &apos;SearchString&apos; in
  462. &apos; a two-dimensional string-Array
  463. Function GetFilterName(sMimetypeorExtension as String, sFilterName(), sExtension as string, FilterIndex as Integer) as String
  464. Dim i as Integer
  465. Dim MaxIndex as Integer
  466. Dim sLocFilterlist() as String
  467. For i = 0 To Ubound(sFiltername(),1)
  468. If Instr(1,sFilterName(i,0),sMimeTypeOrExtension) &lt;&gt; 0 Then
  469. sLocFilterList() = ArrayoutofString(sFiltername(i,0),&quot;|&quot;, MaxIndex)
  470. If MaxIndex = 0 Then
  471. sExtension = sFiltername(i,2)
  472. GetFilterName = sFilterName(i,1)
  473. Else
  474. Dim b as Integer
  475. Dim sLocExtensionList() as String
  476. b = SearchArrayForPartString(sMimetypeOrExtension, sLocFilterList())
  477. sLocFilterList() = ArrayoutofString(sFiltername(i,1),&quot;|&quot;, MaxIndex)
  478. GetFilterName = sLocFilterList(b)
  479. sLocExtensionList() = ArrayoutofString(sFilterName(i,2), &quot;|&quot;, MaxIndex)
  480. sExtension = sLocExtensionList(b)
  481. End If
  482. Exit For
  483. End If
  484. Next
  485. FilterIndex = i
  486. End Function
  487. Function SearchArrayforPartString(SearchString as String, LocList()) as Integer
  488. Dim i as Integer
  489. Dim a as Integer
  490. Dim StringList() as String
  491. For i = Lbound(LocList(),1) to Ubound(LocList(),1)
  492. StringList() = ArrayoutofString(LocList(i), &quot;|&quot;)
  493. For a = 0 To Ubound(StringList())
  494. If (Instr(1, SearchString, StringList(a)) &lt;&gt; 0) Then
  495. SearchArrayForPartString() = i
  496. Exit Function
  497. End If
  498. Next a
  499. Next i
  500. SearchArrayForPartString() = -1
  501. End Function
  502. Sub CreateLogTable(ApplIndex as Integer, CurFileContent as String, sFilterName() as String)
  503. Dim oLogCursor as Object
  504. Dim oLogRows as Object
  505. Dim FilterIndex as Integer
  506. Dim sDocumentType as String
  507. Dim oTextCursor
  508. Dim oCell
  509. If Not bLogExists Then
  510. Exit Sub
  511. End If
  512. bFilterTracerIsinsideTable = False
  513. FilterIndex = GetIndexForPartStringinMultiArray(sFilterName(), CurFileContent, 0)
  514. sDocumentType = sFiltername(FilterIndex,3)
  515. oLogCursor = oLogDocument.Text.createTextCursor()
  516. oLogCursor.GotoEnd(False)
  517. If Not bIsFirstLogTable Then
  518. oLogDocument.Text.insertControlCharacter(oLogCursor, com.sun.star.text.ControlCharacter.PARAGRAPH_BREAK, False)
  519. Else
  520. bisFirstLogTable = False
  521. End If
  522. oLogCursor.HyperLinkURL = &quot;&quot;
  523. oLogCursor.HyperLinkName = &quot;&quot;
  524. oLogCursor.HyperLinkTarget = &quot;&quot;
  525. oLogCursor.ParaStyleName = &quot;Heading 1&quot;
  526. oLogCursor.setString(sDocumentType)
  527. If WizardMode = SBMICROSOFTMODE Then
  528. If bFilterTracingAvailable Then
  529. If bMSApplFilterTracingAvailable(ApplIndex) Then
  530. Dim CurFilterTracingPath as String
  531. CurFilterTracingPath = FilterTracingLogPath(ApplIndex)
  532. bFilterTracerIsinsideTable = (bTakeOverTargetName(ApplIndex) Or bTakeOverPathName(ApplIndex))
  533. If Not bFilterTracerIsinsideTable Then
  534. oLogCursor.CollapseToEnd()
  535. oLogDocument.Text.insertControlCharacter(oLogCursor, com.sun.star.text.ControlCharacter.PARAGRAPH_BREAK, False)
  536. InsertCommandButtonatViewCursor(oLogDocument, oLogCursor, CurFilterTracingPath)
  537. End If
  538. End If
  539. End If
  540. End If
  541. oLogCursor.CollapsetoEnd()
  542. oLogDocument.Text.insertControlCharacter(oLogCursor, com.sun.star.text.ControlCharacter.PARAGRAPH_BREAK, False)
  543. oLogTable = oLogDocument.CreateInstance(&quot;com.sun.star.text.TextTable&quot;)
  544. oLogTable.RepeatHeadline = true
  545. If bFilterTracerIsinsideTable Then
  546. oLogTable.initialize(2,3)
  547. End If
  548. oLogCursor.Text.InsertTextContent(oLogCursor, oLogTable, True)
  549. oTextCursor = oLogTable.GetCellbyPosition(0,0).createTextCursor()
  550. oTextCursor.SetString(sSourceDocuments)
  551. oTextCursor = oLogTable.GetCellbyPosition(1,0).createTextCursor()
  552. oTextCursor.SetString(sTargetDocuments)
  553. If bFilterTracerIsinsideTable Then
  554. oTextCursor = oLogTable.GetCellbyPosition(2,0).createTextCursor()
  555. oTextCursor.SetString(&quot;FilterTracer&quot;)
  556. End If
  557. bInsertRow = False
  558. End Sub
  559. Function GetSize(iWidth, iHeight) As New com.sun.star.awt.Size
  560. Dim aSize As New com.sun.star.awt.Size
  561. aSize.Width = iWidth
  562. aSize.Height = iHeight
  563. GetSize() = aSize
  564. End Function
  565. Sub InsertCommandButtonatViewCursor(oLocDocument, oLocCursor, TargetUrl as String, Optional aSize)
  566. Dim oDocument
  567. Dim oController
  568. Dim oCommandButton
  569. Dim oShape
  570. Dim oDrawPage
  571. Dim oCommandControl
  572. Dim oEvent
  573. Dim oCell
  574. oCommandButton = oLocDocument.createInstance(&quot;com.sun.star.form.component.CommandButton&quot;)
  575. oShape = oLocDocument.CreateInstance (&quot;com.sun.star.drawing.ControlShape&quot;)
  576. If IsMissing(aSize) Then
  577. oShape.Size = GetSize(4000, 600)
  578. End If
  579. oCommandButton.Label = FileNameoutofPath(Targeturl)
  580. oCommandButton.TargetFrame = &quot;_default&quot;
  581. oCommandButton.ButtonType = com.sun.star.form.FormButtonType.URL
  582. oCommandbutton.DispatchUrlInternal = True
  583. oCommandButton.TargetURL = ConverttoUrl(TargetUrl)
  584. oShape.Control = oCommandbutton
  585. oLocCursor.Text.InsertTextContent(oLocCursor, oShape, True)
  586. End Sub
  587. Sub CreateLogDocument(HiddenProperties())
  588. Dim OpenProperties(0) as new com.sun.star.beans.PropertyValue
  589. Dim NoArgs()
  590. Dim i as Integer
  591. Dim bLogIsThere as Boolean
  592. If ImportDialog.chkLogfile.State = 1 Then
  593. i = 2
  594. OpenProperties(0).Name = &quot;Hidden&quot;
  595. OpenProperties(0).Value = True
  596. oLogDocument = StarDesktop.LoadComponentFromURL(&quot;private:factory/swriter&quot;, &quot;_default&quot;, 4, OpenProperties())
  597. SOWorkPath = RTrimStr(SOWorkPath,&quot;/&quot;)
  598. sLogUrl = SOWorkPath &amp; &quot;/Logfile.odt&quot;
  599. Do
  600. bLogIsThere = oUcb.Exists(sLogUrl)
  601. If bLogIsThere Then
  602. If i = 2 Then
  603. sLogUrl = ReplaceString(sLogUrl, &quot;/Logfile_2.odt&quot;, &quot;/Logfile.odt&quot;)
  604. Else
  605. sLogUrl = ReplaceString(sLogUrl, &quot;/Logfile_&quot; &amp; cStr(i) &amp; &quot;.odt&quot;, &quot;/Logfile_&quot; &amp; cStr(i-1) &amp; &quot;.odt&quot;)
  606. End If
  607. i = i + 1
  608. End If
  609. Loop Until Not bLogIsThere
  610. bLogExists = True
  611. oLogDocument.StoreAsUrl(sLogUrl, NoArgs())
  612. End If
  613. End Sub
  614. Function GetFilterTracingLogPath(sTargetUrl as String, ApplIndex) as String
  615. Dim TargetFileName as String
  616. Dim sTargetFolder as String
  617. Dim CurFilterTracingPath as String
  618. Dim CurFilterTracingname as String
  619. Dim CurFilterFolder as String
  620. CurFilterTracingPath = FilterTracingLogPath(ApplIndex)
  621. If bTakeOverTargetName(ApplIndex) Then
  622. TargetFilename = GetFileNameWithoutextension(sTargetUrl, &quot;/&quot;)
  623. CurFilterFolder = DirectoryNameoutofPath(FilterTracingLogPath(ApplIndex), &quot;/&quot;)
  624. CurFilterTracingpath = CurFilterFolder &amp; &quot;/&quot; &amp; TargetFilename &amp; &quot;.log&quot;
  625. End If
  626. If bTakeOverPathName(ApplIndex) Then &apos;Replace the Folder in the FilterTracerpath by the Folder of the targetUrl
  627. sTargetFolder = DirectoryNameoutofPath(sTargetUrl,&quot;/&quot;)
  628. CurFilterTracingPath = sTargetFolder &amp; &quot;/&quot; &amp; FileNameoutofPath(CurFilterTracingPath, &quot;/&quot;)
  629. End If
  630. GetFilterTracingLogPath() = CurFilterTracingPath
  631. End Function
  632. Sub InsertTargetUrlToLogDocument(sTargetUrl as String, sComment as String, ApplIndex as Integer)
  633. Dim oCell
  634. Dim oTextCursor
  635. Dim CurFilterTracingpath as String
  636. If (bLogExists) And (sTargetUrl &lt;&gt; &quot;&quot;) Then
  637. If sTargetUrl &lt;&gt; &quot;&quot; Then
  638. oCell = oLogTable.GetCellbyPosition(1,oLogTable.Rows.Count-1)
  639. InsertCommentToLogCell(sComment, oCell)
  640. InsertHyperLinkToLogCell(sTargetUrl, oCell)
  641. If bFilterTracerIsinsideTable Then
  642. oCell = oLogTable.getCellByPosition(2, oLogTable.Rows.Count-1)
  643. oTextCursor = oCell.Text.CreateTextCursor()
  644. CurFilterTracingpath = GetFilterTracingLogPath(sTargetUrl, ApplIndex)
  645. InsertCommandButtonatViewCursor(oLogDocument, oTextCursor, CurFilterTracingPath)
  646. End If
  647. oLogDocument.Store()
  648. End If
  649. End If
  650. End Sub
  651. Sub InsertSourceUrlToLogDocument(SourceUrl as String, sComment) &apos;
  652. Dim oCell as Object
  653. If bLogExists Then
  654. If bInsertRow Then
  655. oLogTable.Rows.InsertByIndex(oLogTable.Rows.Count,1)
  656. Else
  657. bInsertRow = True
  658. End If
  659. oCell = oLogTable.GetCellbyPosition(0,oLogTable.Rows.Count-1)
  660. InsertCommentToLogCell(sComment, oCell)
  661. InsertHyperLinkToLogCell(SourceUrl, oCell)
  662. oLogDocument.Store()
  663. End If
  664. End Sub
  665. Sub InsertHyperLinkToLogCell(sUrl as String, oCell as Object)
  666. Dim oLogCursor as Object
  667. Dim LocFileName as String
  668. oLogCursor = oCell.createTextCursor()
  669. oLogCursor.CollapseToStart()
  670. oLogCursor.HyperLinkURL = sUrl
  671. oLogCursor.HyperLinkName = sUrl
  672. oLogCursor.HyperLinkTarget = sUrl
  673. LocFileName = FileNameOutOfPath(sUrl)
  674. oCell.InsertString(oLogCursor, LocFileName,False)
  675. End Sub
  676. Sub InsertCommentToLogCell(sComment as string, oCell as Object)
  677. Dim oCommentCursor as Object
  678. If sComment &lt;&gt; &quot;&quot; Then
  679. oCommentCursor = oCell.createTextCursor()
  680. oCell.insertControlCharacter(oCommentCursor, com.sun.star.text.ControlCharacter.PARAGRAPH_BREAK, False)
  681. oCell.insertString(oCommentCursor, sComment, false)
  682. End If
  683. End Sub
  684. Sub AddLogStatistics()
  685. Dim oCell as Object
  686. Dim oLogCursor as Object
  687. Dim MaxRowIndex as Integer
  688. If bLogExists Then
  689. MaxRowIndex = oLogTable.Rows.Count
  690. sLogSummary = ReplaceString(sLogSummary, FileCount, &quot;&lt;COUNT&gt;&quot;)
  691. &apos; oLogTable.Rows.InsertByIndex(MaxRowIndex, 1)
  692. &apos; oCell = oLogTable.GetCellbyPosition(0, MaxRowIndex)
  693. &apos; oLogCursor = oCell.createTextCursor()
  694. &apos; oCell.InsertString(oLogCursor, sLogSummary,False)
  695. &apos; MergeRange(oLogTable, oCell, 1)
  696. oLogCursor = oLogDocument.Text.CreateTextCursor
  697. oLogCursor.gotoEnd(False)
  698. oLogCursor.HyperLinkURL = &quot;&quot;
  699. oLogCursor.HyperLinkName = &quot;&quot;
  700. oLogCursor.HyperLinkTarget = &quot;&quot;
  701. oLogCursor.SetString(sLogSummary)
  702. oLogDocument.Store()
  703. oLogDocument.Dispose()
  704. bLogExists = False
  705. End If
  706. End Sub
  707. Function CheckIfMacroExists(oBasicLibraries as Object, sComment as String) as Boolean
  708. Dim ModuleNames() as String
  709. Dim ModuleName as String
  710. Dim MaxLibIndex as Integer
  711. Dim MaxModuleIndex as Integer
  712. Dim bMacroExists as Boolean
  713. Dim n as Integer
  714. Dim m as Integer
  715. Dim LibName as String
  716. Dim sBasicCode as String
  717. Dim oLibrary as Object
  718. bMacroExists = False
  719. bMacroExists = oBasicLibraries.hasElements
  720. If bMacroExists Then
  721. MaxLibIndex = Ubound(oBasicLibraries.ElementNames())
  722. For n = 0 To MaxLibIndex
  723. LibName = oBasicLibraries.ElementNames(n)
  724. If oBasicLibraries.isLibraryLoaded(LibName) Then
  725. oLibrary = oBasicLibraries.getbyName(LibName)
  726. If oLibrary.hasElements() Then
  727. MaxModuleIndex = Ubound(oLibrary.ElementNames())
  728. For m = 0 To MaxModuleIndex
  729. ModuleName = oLibrary.ElementNames(m)
  730. sBasicCode = oLibrary.getbyName(ModuleName)
  731. If sBasicCode &lt;&gt; &quot;&quot; Then
  732. ConcatComment(sComment, sReeditMacro)
  733. CheckIfMacroExists() = True
  734. Exit Function
  735. End If
  736. Next m
  737. End If
  738. End If
  739. Next n
  740. End If
  741. CheckIfMacroExists() = False
  742. End Function
  743. Function CheckPassWordProtection(oDocument as Object)
  744. Dim bIsPassWordProtected as Boolean
  745. Dim i as Integer
  746. Dim oArgs()
  747. Dim MaxIndex as Integer
  748. Dim sblabla as String
  749. bIsPassWordProtected = false
  750. oArgs() = oDocument.getArgs()
  751. MaxIndex = Ubound(oArgs())
  752. For i = 0 To MaxIndex
  753. sblabla = oArgs(i).Name
  754. If oArgs(i).Name = &quot;Password&quot; Then
  755. bIsPassWordProtected = True
  756. sCurPassWord = oArgs(i).Value
  757. Exit For
  758. End If
  759. Next i
  760. CheckPassWordProtection() = bIsPassWordProtected
  761. End Function
  762. Sub OpenLogDocument()
  763. bShowLogFile = True
  764. ImportDialogArea.endexecute()
  765. End Sub
  766. Sub MergeRange(oTable as Object, oCell as Object, MergeCount as Integer)
  767. Dim oTableCursor as Object
  768. oTableCursor = oTable.createCursorByCellName(oCell.CellName)
  769. oTableCursor.goRight(MergeCount, True)
  770. oTableCursor.mergeRange()
  771. End Sub
  772. Function ConcatComment(sComment as String, AdditionalComment as String)
  773. If sComment = &quot;&quot; Then
  774. sComment = AdditionalComment
  775. Else
  776. sComment = sComment &amp; chr(13) + AdditionalComment
  777. End If
  778. ConcatComment = sComment
  779. End Function
  780. </script:module>