Microsoft KB Archive/295409

= Unpacking and repacking files in themes in FrontPage =

Article ID: 295409

Article Last Modified on 1/31/2007

-

APPLIES TO


 * Microsoft FrontPage 2000 Standard Edition
 * Microsoft FrontPage 2002 Standard Edition
 * Microsoft Office FrontPage 2003

-



This article was previously published under Q295409



SUMMARY
This article provides sample Windows Script Host (WSH) scripts that can be used to unpack and repack files used in FrontPage themes.



MORE INFORMATION
Microsoft provides programming examples for illustration only, without warranty either expressed or implied. This includes, but is not limited to, the implied warranties of merchantability or fitness for a particular purpose. This article assumes that you are familiar with the programming language that is being demonstrated and with the tools that are used to create and to debug procedures. Microsoft support engineers can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific requirements.

FrontPage Themes
FrontPage installs themes to the following folder by default:

C:\Program Files\Common Files\Microsoft Shared\Themes

All themes created by you are saved in the following folder:

%USERPROFILE%\Application Data\Microsoft\Themes

Individual themes are saved in a folder named after the theme. For example, the Artsy theme is saved in the Artsy folder. In each theme folder is a file with a .inf file extension and a file with a .elm file extension. The file names match the name of the folder. For example, the Artsy folder contains the Artsy.inf and the Artsy.elm files.

The .inf file contains descriptive information about the theme. The .elm file is a self-defining file list for the theme. It contains an uncompressed concatenation of all the files that compose the theme. The following list shows the basic file format of a .elm file:
 * Line 1: VVV (where VVV is the version number of the .elm file format)
 * Line 2: NNN (where NNN is the number of individual files packed in the .elm file)
 * Line 3 to Line (NNN + 2): filename,filelength
 * Line (NNN + 2) to EOF: &quot;<==MS-Theme==>&quot; & filedata

FrontPage 2000 integrates theme editing functionality so that you can create or modify FrontPage themes. It does not allow you to easily manipulate all of the files in the theme. The WSH code samples provided in this article either unpack all the files in a .elm file or repack the individual files back into a .elm file.

IMPORTANT NOTES
 * If you incorrectly modify a theme, the theme may become unusable and you may need to reinstall it to use it again. Therefore, if you modify a theme, save the theme under a different file name by clicking Save As in the FrontPage 2000 Themes dialog box.
 * Save the WSH code samples as Unpack_elm.vbs and Repack_elm.vbs. If you don't they will not work correctly.
 * Run the scripts listed in this article from a theme's folder; if you run them from a different folder, you may receive errors.
 * The WSH code sample for repacking the .elm file builds the .elm file from all files that are in the folder excluding the .elm file, the inf file, the Unpack_elm.vbs file, and the Repack_elm.vbs file. Because it packs all other files found in the theme's folder into the .elm file, some unused files may be stored in the .elm file.

Unpacking a .elm File
The following WSH script sample unpacks a .elm file into the individual files used in the theme.   Save the following WSH code as Unpack_elm.vbs on your desktop: Option Explicit

' Declare all variables. Dim objFSO,objFolder Dim objInputFile Dim objOutputFile Dim strELM Dim lngFileCount Dim strFileName Dim strFileLength Dim strFileVersion Dim strFileArray Dim X

' Create constants for the .elm version and Theme string. Const strELMVersion = &quot;4.0.2.4022&quot; Const strThemeString = &quot;<==MS-Theme==>&quot;

' Create object for file I/O. Set objFSO = WScript.CreateObject(&quot;Scripting.FileSystemObject&quot;)

' Get object for current folder. Set objFolder = objFSO.GetFolder(&quot;.&quot;)

' Create variable for .elm file. strELM = LCase(objFolder.Name & &quot;.elm&quot;)

' Open the .elm file. Set objInputFile = objFSO.OpenTextFile(strELM)

' Get the .elm file's version. strFileVersion = objInputFile.ReadLine

' Get the file count. lngFileCount = CLng(objInputFile.ReadLine)

' Create an array for file information. ReDim strFileArray(lngFileCount)

' Create array from the file name/size list in the .elm file. For X = 1 to lngFileCount strFileArray(X) = objInputFile.ReadLine Next

' Loop through the array of files. For X = 1 to lngFileCount ' Get the file name. strFileName = Left(strFileArray(X),InStrRev(strFileArray(X),&quot;,&quot;)-1) ' Get the file size. strFileLength = Mid(strFileArray(X),Len(strFileName) + 2) ' Create a file object for the output file. Set objOutputFile = objFSO.CreateTextFile(strFileName) ' Skip past the MS Theme text. objInputFile.Read Len(strThemeString) ' Extract the packed file data from the .elm file. objOutputFile.Write objInputFile.Read(strFileLength) ' Close the output file. objOutputFile.Close Next

Set objFolder = Nothing Set objFSO = Nothing  Copy the Unpack_elm.vbs file to the folder containing a packed theme. For example, if you want to unpack the Artsy theme files, copy the Unpack_elm.vbs file to the Artsy folder:

C:\Program Files\Common Files\Microsoft Shared\Themes\artsy

 Double-click the Unpack_elm.vbs script to run it. When the script is finished, the graphics and text files that make up the theme will be unpacked in the folder.

Repacking a .elm File
The following sample WSH script sample repacks the individual files used in the theme into a .elm file.   Save the following WSH code as Repack_elm.vbs on your desktop: Option Explicit

' Declare all variables. Dim objFSO,objFile,objFolder Dim objInputFile Dim objOutputFile Dim strELM,strINF Dim strPACK,strUNPACK Dim strName,strFileNames Dim strFileArray,lngFileCount Dim X

' Create constants for the .elm version and the theme string. Const strELMVersion = &quot;4.0.2.4022&quot; Const strThemeString = &quot;<==MS-Theme==>&quot;

' Create object for file I/O. Set objFSO = WScript.CreateObject(&quot;Scripting.FileSystemObject&quot;) ' get object for current folder Set objFolder = objFSO.GetFolder(&quot;.&quot;)

' Create variables for ignored file names. strELM   = LCase(objFolder.Name & &quot;.elm&quot;) strINF   = LCase(objFolder.Name & &quot;.inf&quot;) strPACK  = &quot;repack_elm.vbs&quot; strUNPACK = &quot;unpack_elm.vbs&quot;

' Loop through the files collection. For Each objFile in objFolder.Files ' Get a file name. strName = objFile.Name ' Is the file name an ignored file name? If (LCase(strName) <> strELM) And _ (LCase(strName) <> strINF) And _ (LCase(strName) <> strPACK) And _ (LCase(strName) <> strUNPACK) Then strFileNames = strFileNames & &quot;:&quot; & strName End If Next

' Create an array of file names. strFileArray = Split(strFileNames,&quot;:&quot;) lngFileCount = UBound(strFileArray)

If lngFileCount > 0 Then ' Open the .elm file. Set objOutputFile = objFSO.CreateTextFile(strELM,-1,0)

' Output the .elm version and file count. objOutputFile.Write strELMVersion & vbLf objOutputFile.Write lngFileCount & vbLf

' Loop through the files. For X = 1 To lngFileCount Set objFile = objFSO.GetFile(strFileArray(X)) objOutputFile.Write objFile.Name & &quot;,&quot; & objFile.Size & vbLf Next

' Loop through the files. For X = 1 To lngFileCount Set objFile = objFSO.GetFile(strFileArray(X)) objOutputFile.Write strThemeString Set objInputFile = objFSO.OpenTextFile(objFile.Name,1) objOutputFile.Write objInputFile.Read(objFile.Size) objInputFile.Close Next

objOutputFile.Close End If

Set objFolder = Nothing Set objFSO = Nothing  Copy the Repack_elm.vbs file to the folder containing an unpacked theme. For example, if you unpacked the Artsy theme, copy the Repack_elm.vbs file to the following folder:

C:\Program Files\Common Files\Microsoft Shared\Themes\artsy

</li> Double-click the Repack_elm.vbs script to run it.</li> When the script is finished, the graphics and text files will be repacked in the .elm file for the theme.</li></ol>

<div class="references_section">