Current News
Archived News
Search News
Discussion Forum


Old Forum
Install Programs More Downloads...
Troubleshooting
Source Code
Format Specs.
Misc. Information
Non-SF Stuff
Links




CommitLineData
62046253 1VERSION 4.00
2Begin VB.Form frmMpq
3 BorderStyle = 1 'Fixed Single
4 Caption = "MPQ Embedder"
5 ClientHeight = 1695
6 ClientLeft = 3045
7 ClientTop = 2730
8 ClientWidth = 2775
9 Height = 2385
10 Icon = "frmMpq.frx":0000
11 Left = 2985
12 LinkTopic = "Form1"
13 MaxButton = 0 'False
14 ScaleHeight = 1695
15 ScaleWidth = 2775
16 Top = 2100
17 Width = 2895
18 Begin VB.CommandButton cmdSaveEXE
19 Caption = "Save &EXE"
20 Enabled = 0 'False
21 Height = 375
22 Left = 1440
23 TabIndex = 3
24 Top = 1200
25 Width = 1215
26 End
27 Begin VB.CommandButton cmdRemove
28 Caption = "&Remove"
29 Enabled = 0 'False
30 Height = 375
31 Left = 120
32 TabIndex = 2
33 Top = 1200
34 Width = 1215
35 End
36 Begin VB.CommandButton cmdSaveMPQ
37 Caption = "Save &MPQ"
38 Enabled = 0 'False
39 Height = 375
40 Left = 1440
41 TabIndex = 1
42 Top = 720
43 Width = 1215
44 End
45 Begin VB.CommandButton cmdAdd
46 Caption = "&Add"
47 Enabled = 0 'False
48 Height = 375
49 Left = 120
50 TabIndex = 0
51 Top = 720
52 Width = 1215
53 End
54 Begin VB.Label Label1
55 Height = 615
56 Left = 120
57 TabIndex = 4
58 Top = 120
59 Width = 2565
60 WordWrap = -1 'True
61 End
62 Begin VB.Menu mnuFile
63 Caption = "&File"
64 Begin VB.Menu mnuFOpen
65 Caption = "&Open..."
66 End
67 Begin VB.Menu mnuFSep
68 Caption = "-"
69 End
70 Begin VB.Menu mnuFExit
71 Caption = "E&xit"
72 End
73 End
74 Begin VB.Menu mnuRun
75 Caption = "&Run EXE"
76 Enabled = 0 'False
77 End
78 Begin VB.Menu mnuHelp
79 Caption = "&Help"
80 Begin VB.Menu mnuHReadme
81 Caption = "View &Readme..."
82 End
83 Begin VB.Menu mnuHSep
84 Caption = "-"
85 End
86 Begin VB.Menu mnuHAbout
87 Caption = "&About..."
88 End
89 End
90End
91Attribute VB_Name = "frmMpq"
92Attribute VB_Creatable = False
93Attribute VB_Exposed = False
94Option Explicit
95
96Dim MpqHeader As Long, IsEXE As Boolean, FileDialog As OPENFILENAME
97Private Sub cmdAdd_Click()
98Dim OldFileName As String, NewMpqHeader As Long, fNum As Long, Text As String, fNum2 As Long, Text2 As String, bNum As Long
99FileDialog.Flags = &H1000 Or &H4 Or &H2
0e6c0d4d 100FileDialog.Filter = "Mpq Archives (*.mpq;*.exe;*.snp;*.scm;*.scx;*.w3m;*.w3x)|*.mpq;*.exe;*.snp;*.scm;*.scx;*.w3m;*.w3x|All Files (*.*)|*.*"
62046253 101OldFileName = FileDialog.FileName
102FileDialog.hwndOwner = hWnd
103If ShowOpen(FileDialog) = False Then GoTo Cancel
104NewMpqHeader = FindMpqHeader(FileDialog.FileName)
105If NewMpqHeader = -1 Then
106 MsgBox "This file does not contain an MPQ archive.", , "MPQ Embedder"
107 GoTo Cancel
108End If
109fNum = FreeFile
110Open FileDialog.FileName For Binary As #fNum
111fNum2 = FreeFile
112Open OldFileName For Binary As #fNum2
113If MpqHeader / 512 <> Int(MpqHeader / 512) Then
114 bNum = MsgBox("The file you are adding the MPQ archive to" + vbCrLf + "is not the proper size; therefore, most MPQ" + vbCrLf + "archive readers will not be able to read it." + vbCrLf + "Do you want to increase the size of the file," + vbCrLf + "so other programs can read it?", vbQuestion Or vbYesNo Or vbDefaultButton1, "MPQ Embedder")
115 If bNum = vbYes Then
116 Text = String(512 - (MpqHeader - Int(MpqHeader / 512) * 512), Chr(0))
117 Put #fNum2, MpqHeader + 1, Text
118 MpqHeader = MpqHeader + Len(Text)
119 End If
120End If
121For bNum = NewMpqHeader + 1 To LOF(fNum) Step 2 ^ 20
122 Text = String(2 ^ 20, Chr(0))
123 If LOF(fNum) - bNum + 1 >= 2 ^ 20 Then
124 Get #fNum, bNum, Text
125 Put #fNum2, MpqHeader + bNum - NewMpqHeader, Text
126 Else
127 Text = String(LOF(fNum) - bNum + 1, Chr(0))
128 Get #fNum, bNum, Text
129 Put #fNum2, MpqHeader + bNum - NewMpqHeader, Text
130 End If
131Next bNum
132Close #fNum2
133Close #fNum
134cmdAdd.Enabled = False
135cmdRemove.Enabled = True
136cmdSaveMPQ.Enabled = True
137cmdSaveEXE.Enabled = True
138If MpqHeader / 512 = Int(MpqHeader / 512) Then
139 Label1.Caption = "This file contains an MPQ archive."
140Else
141 Label1.Caption = "This file contains an MPQ archive, but other programs may not be able to read it."
142End If
143Cancel:
144FileDialog.FileName = OldFileName
145End Sub
146Private Sub cmdRemove_Click()
147Dim fNum As Long, Text As String, fNum2 As Long, Text2 As String, bNum As Long
148bNum = MsgBox("Are you sure you want to permanently" + vbCrLf + "remove the MPQ archive from this file?", vbQuestion Or vbYesNo Or vbDefaultButton2, "MPQ Embedder")
149If bNum = vbNo Then Exit Sub
150fNum = FreeFile
151Open FileDialog.FileName For Binary As #fNum
152fNum2 = FreeFile
153If Dir(FileDialog.FileName + ".remove") <> "" Then Kill FileDialog.FileName + ".remove"
154Open FileDialog.FileName + ".remove" For Binary As #fNum2
155For bNum = 1 To MpqHeader Step 2 ^ 20
156 Text = String(2 ^ 20, Chr(0))
157 If MpqHeader - bNum + 1 >= 2 ^ 20 Then
158 Get #fNum, bNum, Text
159 Put #fNum2, bNum, Text
160 Else
161 Text = String(MpqHeader - bNum + 1, Chr(0))
162 Get #fNum, bNum, Text
163 Put #fNum2, bNum, Text
164 End If
165Next bNum
166Close #fNum2
167Close #fNum
168Kill FileDialog.FileName
169Name FileDialog.FileName + ".remove" As FileDialog.FileName
170cmdAdd.Enabled = True
171cmdRemove.Enabled = False
172cmdSaveMPQ.Enabled = False
173cmdSaveEXE.Enabled = True
174Label1.Caption = "This file does not contain an MPQ archive."
175End Sub
176Private Sub cmdSaveEXE_Click()
177Dim OldFileName As String, fNum As Long, Text As String, fNum2 As Long, Text2 As String, bNum As Long
178FileDialog.Flags = &H1000 Or &H4 Or &H2
179FileDialog.Filter = "File (*.*)|*.*"
180FileDialog.DefaultExt = ""
181OldFileName = FileDialog.FileName
182FileDialog.FileName = FileDialog.FileName
183FileDialog.hwndOwner = hWnd
184If ShowSave(FileDialog) = False Then GoTo Cancel
185fNum = FreeFile
186Open OldFileName For Binary As #fNum
187fNum2 = FreeFile
188If Dir(FileDialog.FileName) <> "" Then Kill FileDialog.FileName
189Open FileDialog.FileName For Binary As #fNum2
190For bNum = 1 To MpqHeader Step 2 ^ 20
191 Text = String(2 ^ 20, Chr(0))
192 If MpqHeader - bNum + 1 >= 2 ^ 20 Then
193 Get #fNum, bNum, Text
194 Put #fNum2, bNum, Text
195 Else
196 Text = String(MpqHeader - bNum + 1, Chr(0))
197 Get #fNum, bNum, Text
198 Put #fNum2, bNum, Text
199 End If
200Next bNum
201Close #fNum2
202Close #fNum
203Cancel:
204FileDialog.FileName = OldFileName
205End Sub
206Private Sub cmdSaveMPQ_Click()
207Dim OldFileName As String, fNum As Long, Text As String, fNum2 As Long, Text2 As String, bNum As Long
208FileDialog.Flags = &H1000 Or &H4 Or &H2
209FileDialog.Filter = "MPQ Archive (*.mpq)|*.mpq"
210FileDialog.DefaultExt = "mpq"
211OldFileName = FileDialog.FileName
212FileDialog.FileName = FileDialog.FileName + ".mpq"
213FileDialog.hwndOwner = hWnd
214If ShowSave(FileDialog) = False Then GoTo Cancel
215fNum = FreeFile
216Open OldFileName For Binary As #fNum
217fNum2 = FreeFile
218If Dir(FileDialog.FileName) <> "" Then Kill FileDialog.FileName
219Open FileDialog.FileName For Binary As #fNum2
220For bNum = MpqHeader + 1 To LOF(fNum) Step 2 ^ 20
221 Text = String(2 ^ 20, Chr(0))
222 If LOF(fNum) - bNum + 1 >= 2 ^ 20 Then
223 Get #fNum, bNum, Text
224 Put #fNum2, bNum - MpqHeader, Text
225 Else
226 Text = String(LOF(fNum) - bNum + 1, Chr(0))
227 Get #fNum, bNum, Text
228 Put #fNum2, bNum - MpqHeader, Text
229 End If
230Next bNum
231Close #fNum2
232Close #fNum
233Cancel:
234FileDialog.FileName = OldFileName
235End Sub
236
237Private Sub Form_Load()
238FileDialog = CD
239End Sub
240Private Sub mnuFExit_Click()
241Unload Me
242End Sub
243Private Sub mnuFOpen_Click()
244Dim OldFileName As String, OldMpqHeader As Long, fNum As Long, Text As String
245FileDialog.Flags = &H1000 Or &H4 Or &H2
246FileDialog.Filter = "All Files (*.*)|*.*"
247OldFileName = FileDialog.FileName
248OldMpqHeader = MpqHeader
249FileDialog.hwndOwner = hWnd
250If ShowOpen(FileDialog) = False Then GoTo Cancel
251If FileLen(FileDialog.FileName) = 0 Then
252 MsgBox "This is an empty file.", vbExclamation, "MPQ Embedder"
253 GoTo Cancel
254End If
255fNum = FreeFile
256Open FileDialog.FileName For Binary As #fNum
257Text = String(2, Chr(0))
258If LOF(fNum) >= 2 Then Get #fNum, 1, Text
259Close #fNum
260If Text = "MZ" Then IsEXE = True Else IsEXE = False
261If IsEXE Then mnuRun.Enabled = True Else mnuRun.Enabled = False
262MpqHeader = FindMpqHeader(FileDialog.FileName)
263If MpqHeader <= -1 Then
264 cmdAdd.Enabled = True
265 cmdRemove.Enabled = False
266 cmdSaveMPQ.Enabled = False
267 cmdSaveEXE.Enabled = True
268 MpqHeader = FileLen(FileDialog.FileName)
269 Label1.Caption = "This file does not contain an MPQ archive."
270ElseIf MpqHeader = 0 Then
271 cmdAdd.Enabled = False
272 cmdRemove.Enabled = False
273 cmdSaveMPQ.Enabled = True
274 cmdSaveEXE.Enabled = False
275 Label1.Caption = "This file is an MPQ archive."
276ElseIf MpqHeader > 0 Then
277 cmdAdd.Enabled = False
278 cmdRemove.Enabled = True
279 cmdSaveMPQ.Enabled = True
280 cmdSaveEXE.Enabled = True
281 If MpqHeader / 512 = Int(MpqHeader / 512) Then
282 Label1.Caption = "This file contains an MPQ archive."
283 Else
284 Label1.Caption = "This file contains an MPQ archive, but other programs may be unable to read it."
285 End If
286End If
287Exit Sub
288Cancel:
289FileDialog.FileName = OldFileName
290MpqHeader = OldMpqHeader
291End Sub
292Private Sub mnuHAbout_Click()
293About.Show 1
294End Sub
295Private Sub mnuHReadme_Click()
296Dim Path As String
297Path = App.Path
298If Right(Path, 1) <> "\" Then Path = Path + "\"
299If Dir(Path + "WMpqEmbed.rtf") = "" Then MsgBox "Could not find WMpqEmbed.rtf!", vbCritical, "MPQ Embedder"
300ShellExecute hWnd, vbNullString, Path + "WMpqEmbed.rtf", vbNullString, vbNullString, 1
301End Sub
302Private Sub mnuRun_Click()
303On Error GoTo NotExecutable
304Shell FileDialog.FileName, 1
305Exit Sub
306NotExecutable:
307MsgBox "This file is not a .exe file.", vbInformation, "MPQ Embedder"
308End Sub