wakawaka

Publication Updater (HTA)

Aug 2nd, 2011
172
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  2.  
  3. <html>
  4.     <head>
  5.     <title>Publication Updater</title>
  6.       <hta:application id="oPU"
  7.         applicationname="Publication Updater"
  8.         border="thick"
  9.         caption="yes"
  10.         contextmenu="no"
  11.         icon=""
  12.         maximizebutton="no"
  13.         minimizebutton="no"
  14.         navigable="no"
  15.         scroll="no"
  16.         showintaskbar="yes"
  17.         singleinstance="yes"
  18.         sysmenu="yes"
  19.         version="1.0.1"
  20.         windowstate="normal"
  21.         >
  22.  
  23.         <style type="text/css">
  24.             body{
  25.                 text-align: center;
  26.             }
  27.             .vAlign{
  28.                 vertical-align: top;
  29.             }
  30.             #driveSelect{
  31.                 text-align: left;
  32.             }
  33.         </style>
  34.        
  35.         <script language="VBScript">
  36.             Const SOURCE_PATH = "Your folder path"
  37.             Dim aImageCollection : aImageCollection = Array("images\loading.gif", "images\go.jpg", "images\warning.jpg", "images\error.jpg")
  38.             Dim aMessageStatus : aMessageStatus = Array("Please wait while we check for updates...", "Version up-to-date", "Version needs to be updated", "Operation failed; Contact Administrator")
  39.        
  40.             '''<summary>Executes when the HTA is opened</summary>
  41.             Sub Window_OnLoad
  42.                 Call SetupWindow(500, 250, True)
  43.                 Call SetInitalView()
  44.                 Call CheckVersion(0)
  45.             End Sub
  46.            
  47.            
  48.             '''<summary>Allows the window to be resized and centered</summary>
  49.             '''<param name="iWidth">New width of the window</param>
  50.             '''<param name="iHeight">New height of the window</param>
  51.             '''<param name="bCenter">Determines if the window should be centered</param>
  52.             '''<remarks>You can specify a width and height of 0,0 to use defaults</remarks>
  53.             Sub SetupWindow(iWidth, iHeight, bCenter)
  54.                 If iWidth <> 0 And iHeight <> 0 Then
  55.                     Me.ResizeTo iWidth, iHeight
  56.                 End If
  57.                
  58.                 If bCenter Then
  59.                     With Document.Body
  60.                         Me.MoveTo ((Screen.Width - .OffsetWidth) / 2), ((Screen.Height - .OffsetHeight) / 2)
  61.                     End With
  62.                 End If
  63.             End Sub
  64.            
  65.            
  66.             '''<summary>Sets up the inital view of the HTA</summary>
  67.             '''<remarks>This is used to keep the Window_OnLoad methods from being cluttered</remarks>
  68.             Sub SetInitalView()
  69.                 Call ToggleElementVisibility(driveSelect)
  70.                 Call ToggleElementVisibility(copy)
  71.                 Call UpdateDriveSelection(2)
  72.                 Call UpdateImageAndCaption(aImageCollection(0), aMessageStatus(0))
  73.             End Sub
  74.            
  75.            
  76.             '''<summary>Gets all the drives for a specific drive type</summary>
  77.             '''<param name="iDriveType">An integer defining the type of drive to retreive</param>
  78.             '''<returns>A array with the drive letter and volume name in x & x+1 format</returns
  79.             '''<remarks>If element 0 is "C:\" then element 1 is the name for the volume</remarks>
  80.             Function GetLocalDrives(iDriveType)
  81.                 Dim aDrives()
  82.                 Dim iCurrentIndex : iCurrentIndex = 0
  83.                 Dim oDriveCollection : Set oDriveCollection = _
  84.                                         GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2") _
  85.                                         .ExecQuery("SELECT Name, VolumeName FROM Win32_LogicalDisk WHERE DriveType='" & iDriveType & "'")
  86.                
  87.                 ReDim aDrives(oDriveCollection.Count * 2)
  88.  
  89.                 For Each drive In oDriveCollection
  90.                     aDrives(iCurrentIndex) = drive.Name & "\"
  91.                     aDrives(iCurrentIndex + 1) = drive.VolumeName
  92.                        
  93.                     iCurrentIndex = iCurrentIndex + 2
  94.                 Next
  95.                
  96.                 GetLocalDrives = aDrives
  97.             End Function
  98.            
  99.            
  100.             '''<summary>Copys a folder to the specified destination</summary>
  101.             '''<param name="sDestination">The path where the folder should be copied to</summary>
  102.             Sub CopyFolder(sDestination)
  103.                 On Error Resume Next
  104.                 Err.Clear()
  105.                
  106.                 Call CreateObject("Scripting.FileSystemObject").CopyFolder(SOURCE_PATH, sDestination, True)
  107.                
  108.                 If Err.Number <> 0 Then
  109.                     Call UpdateImageAndCaption(aImageCollection(3), aMessageStatus(3))
  110.                 Else
  111.                     Call UpdateImageAndCaption(aImageCollection(1), aMessageStatus(1))
  112.                 End If
  113.                
  114.                 'Err.Clear()
  115.             End Sub
  116.            
  117.            
  118.             '''<summary>Updates the HTA's selectable drives</summary>
  119.             '''<remarks>This method is hard-coded with the HTML select element's id</remarks>
  120.             Sub UpdateDriveSelection(iDriveType)
  121.                 Dim aDrives : aDrives = GetLocalDrives(iDriveType)
  122.                
  123.                 For i=0 To UBound(aDrives) - 1 Step 2
  124.                     Set driveOption = Document.CreateElement("option")
  125.                     driveOption.Value = aDrives(i)
  126.                     driveOption.Text = "(" & aDrives(i) & ") " & aDrives(i+1)
  127.                     drives.Options.Add(driveOption)
  128.                 Next
  129.             End Sub
  130.            
  131.            
  132.             '''<summary>Updates the HTA's status image & the caption for the image</summary>
  133.             '''<remarks>This method is hard-coded with the HTML image & span element's id</remarks>
  134.             Sub UpdateImageAndCaption(sImagePath, sCaptionText)
  135.                 If sImagePath <> "" Then
  136.                     displayImage.src = sImagePath
  137.                 End If
  138.  
  139.                 imageCaption.InnerText = sCaptionText
  140.             End Sub
  141.            
  142.            
  143.             '''<summary>Updates the HTA's version date</summary>
  144.             '''<remarks>This method is hard-coded with the HTML span element's id</remarks>
  145.             Sub UpdateVersionDate(sDate)
  146.                 versionDate.InnerText = "Version: " & sDate
  147.             End Sub
  148.            
  149.            
  150.             '''<summary>Toggles the "Display" property of an HTML element reference passed to it</summary>
  151.             '''<param name="oHtmlElement">The HTML element you want to hide</param>
  152.             '''<remarks>This method will automatically suppress any errors that occur while attempting to hide the element</remarks>
  153.             Sub ToggleElementVisibility(oHtmlElement)
  154.                 On Error Resume Next
  155.                
  156.                 If LCase(oHtmlElement.Style.Display) = "none" Then
  157.                     oHtmlElement.Style.Display = "block"
  158.                 Else
  159.                     oHtmlElement.Style.Display = "none"
  160.                 End If
  161.                
  162.                 Err.Clear()
  163.             End Sub
  164.            
  165.            
  166.             'Up to user to implement
  167.             'This is only showing an example
  168.             Sub CheckVersion(iTest)
  169.                 'If the version is correct do the following:
  170.                 '-Keep "Update" options hidden
  171.                 '-change image and its' caption
  172.                 '-Update the version date and status
  173.            
  174.                 'If the version is incorrect do the following:
  175.                 '-Expand the window to show the "Update" options
  176.                 '-change the image and its' caption
  177.                 '-Update the version date and status
  178.                 Select Case iTest
  179.                 Case 1
  180.                     'Version up-to-date
  181.                     Call SetupWindow(500, 275, True)
  182.                     Call UpdateImageAndCaption(aImageCollection(1), aMessageStatus(1))
  183.                     Call UpdateVersionDate(Now)
  184.                 Case 2
  185.                     'Version not up-to-date
  186.                     Call SetupWindow(500, 350, True)
  187.                     Call UpdateImageAndCaption(aImageCollection(2), aMessageStatus(2))
  188.                     Call ToggleElementVisibility(driveSelect)
  189.                     Call ToggleElementVisibility(copy)
  190.                     Call UpdateVersionDate(Now)
  191.                 Case 3
  192.                     'Error
  193.                     Call UpdateImageAndCaption(aImageCollection(3), aMessageStatus(3))
  194.                     Call UpdateVersionDate(Now)
  195.                 Case Else
  196.                     'Don't change anything, just display the load screen
  197.                 End Select
  198.             End Sub
  199.         </script>
  200.     </head>
  201.    
  202.     <body>
  203.         <div id="wrapper" class="contentWrapper">
  204.             <div id="imageContainer">
  205.                 <img id="displayImage" />
  206.                 <br />
  207.                 <span id="imageCaption"></span>
  208.             </div>
  209.            
  210.             <br />
  211.            
  212.             <div id="information">
  213.                 <span id="versionDate"></span>
  214.             </div>
  215.            
  216.             <hr />
  217.             <br />
  218.            
  219.             <div id="driveSelect">
  220.                 <span class="vAlign">Select the drive you would like to copy the files to:</span>
  221.                 <select id="drives"></select>
  222.             </div>
  223.            
  224.             <br />
  225.             <button id="copy" onClick="CopyFolder(drives.options(drives.SelectedIndex).Value)">Update</button>
  226.         </div>
  227.     </body>
  228. </html>
Advertisement
Add Comment
Please, Sign In to add comment