Changeset 28354

Show
Ignore:
Timestamp:
04.10.2013 19:18:48 (6 years ago)
Author:
ak19
Message:

This VBScript file is now replacing the old VB files (exe, frm form file and vbp project file). Otherwise this script was already working and writing out the item file and slide files, which were generated from converting ppt slides to txt, as UTF-8. This is where this script is preferable to the older VB executable, which had all the code that wrote out UTF-8 commented out. By default, file write methods in VB and VBScript write out UTF16 LE, which is not what Greenstone wants. Greenstone wants UTF-8. The differences from the last revision: 1. Added subroutine to run this script as CScript, which uses the console, in case this .vbs file (VBScript) is launched with WScript. 2. Better comments.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • main/trunk/binaries/windows/bin/pptextract.vbs

    r28353 r28354  
     1' This file is a port to VBScript from VB of the pptextract.exe, pptextract.frm (and pptextract.vbp) files. 
     2 
     3' It was hard to upgrade the VB pptextract.frm form script in Visual Studio 
     4' to the current Visual Basic, and some packages it needed wouldn't install, 
     5' making it hard to compile up. 
     6 
     7' As this VBScript doesn't need to be compiled up, it may be easier to maintain. 
     8 
     9' For differences between VBScript and VB, see  
     10' http://msdn.microsoft.com/en-us/library/ms970436.aspx 
     11' http://www.htmlgoodies.com/beyond/asp/vbs-ref/article.php/3458611/Key-Differences-Between-VB-and-VB-Script.htm 
     12' (Note that VBScript does support reading and writing to files) 
     13 
     14 
     15 
    116'Option Explicit 
    217'Imports PowerPoint = Microsoft.Office.Interop.PowerPoint 
     
    823' If you want the code to work, you have to use cscript.exe to run it. 
    924 
    10  
     25' This is a CScript (console-only). If launched in WScript mode, run as CScript anyway 
     26' From: http://stackoverflow.com/questions/4692542/force-a-vbs-to-run-using-cscript-instead-of-wscript 
     27Sub forceCScriptExecution 
     28    Dim Arg, Str 
     29    If Not LCase( Right( WScript.FullName, 12 ) ) = "\cscript.exe" Then 
     30        For Each Arg In WScript.Arguments 
     31            If InStr( Arg, " " ) Then Arg = """" & Arg & """" 
     32            Str = Str & " " & Arg 
     33        Next 
     34        CreateObject( "WScript.Shell" ).Run _ 
     35            "cscript //nologo """ & _ 
     36            WScript.ScriptFullName & _ 
     37            """ " & Str 
     38        WScript.Quit 
     39    End If 
     40End Sub 
     41forceCScriptExecution 
     42 
     43' Where this script actually starts 
    1144Dim args 
    1245args = WScript.Arguments.Count 
     
    92125Sub PPTslidesToImgs(outputType, inFileName, outFileStem) 
    93126    ' switch statement, http://msdn.microsoft.com/en-us/library/6ef9w614%28v=vs.84%29.aspx 
    94     WScript.StdErr.Write ("Output stem: " & outFileStem & vbCrLf) 
     127    'WScript.StdErr.Write ("Output stem: " & outFileStem & vbCrLf) 
    95128     
    96129    Dim fso 
     
    102135    itemFile = Mid(outFileStem, InStrRev(outFileStem, "\")+1) 
    103136     
    104     WScript.StdErr.Write ("outputDir: " & outFileStem & vbCrLf)  
     137    'WScript.StdErr.Write ("outputDir: " & outFileStem & vbCrLf)     
    105138     
    106139    If Not fso.FolderExists(outputDir) Then 
     
    130163    itemFile = outFileStem + "\" + itemFile + ".item" 
    131164     
    132     'Set item = fso.CreateTextFile(itemFile, 2, True) ' ForWriting = 2, Unicode = -1, see http://msdn.microsoft.com/en-us/library/314cz14s%28v=vs.84%29.aspx 
    133      
    134     ' Writing out to a file in UTF-8 http://stackoverflow.com/questions/10450156/write-text-file-in-appending-utf-8-encoded-in-vb6 
     165    'Set item = fso.CreateTextFile(itemFile, 2, True) ' ForWriting = 2, default is Unicode = -1, see http://msdn.microsoft.com/en-us/library/314cz14s%28v=vs.84%29.aspx 
     166    ' The default file-write methods in VBScript all create UTF16 Little Endian (USC-2LE) files like Notepad's default, rather than the UTF-8 we want 
     167    ' Writing out to a file in UTF-8 is achieved as at: http://stackoverflow.com/questions/10450156/write-text-file-in-appending-utf-8-encoded-in-vb6    
    135168    Dim item 
    136169    Set item = CreateObject("ADODB.Stream")