summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/scripts/bitmap2eps/bitmap2eps.vbs
blob: fbfc850e851d2b65868fcecc852c61ec008ffe44 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
option explicit
On Error Resume next

dim oWsh, oArgs, oFS, oDia, oTS, infile, outfile, f, c, result

set oWsh = createobject( "wscript.Shell" )
Set oFS = CreateObject("Scripting.FileSystemObject")
Set oArgs = wscript.arguments

' assume sam2p and bmeps on searchpath
If oArgs.count = 0 Then
  ' This appears to fail on win7: 'No file to convert' messagebox
  Set oDia = CreateObject("UserAccounts.CommonDialog")
  'oDia.InitialDir = oWsh.SpecialFolders("MyDocuments")
  oDia.filter = _
    "Bitmaps|*.bmp;*.png;*.gif;*.bmp;*.jpg;*.jpeg;*.tif;*.tiff|All files|*.*"
  oDia.filterindex = 1
  oDia.flags = 1
  If oDia.ShowOpen = False then
    msgBox "No file to convert"
    wscript.quit
  End If
  infile = oDia.filename
  ' MsgBox "infile: " & infile
Else
  ' may have to flip slashes if the file was on a network drive !!!
  infile = replace(oArgs(0), "/", "\")
  infile = ofs.getabsolutepathname(infile)
End If

' name of output file
outfile = ofs.buildpath(ofs.getparentfoldername(infile), _
  ofs.getbasename(infile) & ".eps")

If ofs.fileexists(outfile) Then
  result = MsgBox(outfile & vbcrlf & "exists; overwrite?", _
    vbyesno+vbquestion)
  If result <> vbyes Then
    wscript.quit
  Else
    oFS.deletefile(outfile)
    Err.clear
    If ofs.fileexists(outfile) Then
      MsgBox "Unable to remove old " & outfile, vbcritical
      wscript.quit
    End If
  End If
End If

' MsgBox "trying sam2p"
owsh.run "sam2p """ & infile & """ EPS: """ & outfile & """", 0
If Err Then
  ' This is a failure of this script to start sam2p,
  ' not just a failure of sam2p to do its job
  MsgBox "Unspecified failure", vbcritical
  wscript.quit
End If
wscript.sleep(1000)

If ofs.fileexists(outfile) Then
  MsgBox ofs.getbasename(infile) & "." & ofs.getextensionname(infile) & _
  " successfully converted", vbInformation
Else
 Err.clear
  ' clear sam2p temp files
  For Each f in ofs.getfolder(ofs.getparentfoldername(infile)).files
    If InStr(f.Name, "tmp__sam2p") = 1 Then
      f.delete
      Err.clear
    End If
  Next
  ' MsgBox "trying bmeps"
  owsh.run "bmeps -c """ & infile & """ """ & outfile & """", 0
  If Err Then
    MsgBox "Unspecified failure", vbcritical
    wscript.quit
  End If
  wscript.sleep(1000)
  If ofs.fileexists(outfile) Then
    result = True
    ' check the eps file; it may contain just an error mesage from bmeps
    Set oTS = ofs.opentextfile (outfile, 1)
    If Err Then
      result = False
      Err.clear
    Else
      c = oTS.read(2)
      If Err Then
        result = false
        Err.clear
      Else
        If c <> "%!" Then
          result = False
        End If
      End If
      oTS.close
    End If
    If result then
      MsgBox ofs.getbasename(infile) & "." & ofs.getextensionname(infile) & _
      " successfully converted with bmeps", vbInformation
    Else
      'ofs.deletefile(outfile)
      MsgBox "Conversion failed", vbCritical
    End If
  Else
   MsgBox "Conversion failed", vbCritical
  End If
End If