FilesModul.xba 27 KB

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