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




index 3a918d3..f4a74dc 100644 (file)
@@ -71,6 +71,53 @@ AboutPage = Path + "sfmpq.dll"
 If Not FileExists(AboutPage) Then AboutPage = "sfmpq.dll"
 ShellExecute 0, vbNullString, "res://" + AboutPage + "/about", vbNullString, vbNullString, 1
 End Sub
+Sub GetCompressFlags(File As String, ByRef cType As Integer, ByRef dwFlags As Long)
+Dim bNum As Long, fExt As String
+dwFlags = MAFA_REPLACE_EXISTING
+If GlobalEncrypt Then dwFlags = dwFlags Or MAFA_ENCRYPT
+For bNum = 1 To Len(File)
+    If InStr(bNum, File, ".") > 0 Then
+        bNum = InStr(bNum, File, ".")
+    Else
+        Exit For
+    End If
+Next bNum
+If bNum > 1 Then
+    fExt = Mid(File, bNum - 1)
+Else
+    fExt = File
+End If
+If LCase(fExt) = ".bik" Then
+    cType = CInt(GetReg(AppKey + "Compression\.bik", "-2"))
+    dwFlags = dwFlags And (-1& Xor MAFA_ENCRYPT)
+ElseIf LCase(fExt) = ".smk" Then
+    cType = CInt(GetReg(AppKey + "Compression\.smk", "-2"))
+    dwFlags = dwFlags And (-1& Xor MAFA_ENCRYPT)
+ElseIf LCase(fExt) = ".mp3" Then
+    cType = CInt(GetReg(AppKey + "Compression\.mp3", "-2"))
+    dwFlags = dwFlags And (-1& Xor MAFA_ENCRYPT)
+ElseIf LCase(fExt) = ".mpq" Then
+    cType = CInt(GetReg(AppKey + "Compression\.mpq", "-2"))
+    dwFlags = dwFlags And (-1& Xor MAFA_ENCRYPT)
+ElseIf LCase(fExt) = ".scm" Then
+    cType = CInt(GetReg(AppKey + "Compression\.scm", "-2"))
+    dwFlags = dwFlags And (-1& Xor MAFA_ENCRYPT)
+ElseIf LCase(fExt) = ".scx" Then
+    cType = CInt(GetReg(AppKey + "Compression\.scx", "-2"))
+    dwFlags = dwFlags And (-1& Xor MAFA_ENCRYPT)
+ElseIf LCase(fExt) = ".w3m" Then
+    cType = CInt(GetReg(AppKey + "Compression\.w3m", "-2"))
+    dwFlags = dwFlags And (-1& Xor MAFA_ENCRYPT)
+ElseIf LCase(fExt) = ".w3x" Then
+    cType = CInt(GetReg(AppKey + "Compression\.w3x", "-2"))
+    dwFlags = dwFlags And (-1& Xor MAFA_ENCRYPT)
+ElseIf LCase(fExt) = ".wav" Then
+    cType = CInt(GetReg(AppKey + "Compression\.wav", "0"))
+Else
+    cType = CInt(GetReg(AppKey + "Compression\" + fExt, CStr(DefaultCompressID)))
+End If
+End Sub
+
 Function mOpenMpq(FileName As String) As Long
 Dim hMPQ As Long
 mOpenMpq = 0
@@ -264,46 +311,15 @@ StartSearch:
     If Right(NewFileLists, 2) = vbCrLf Then NewFileLists = Left(NewFileLists, Len(NewFileLists) - 2)
 End If
 nHashEntries = SFileGetFileInfo(hMPQ, SFILE_INFO_HASH_TABLE_SIZE)
-If nHashEntries - 1 < 1 Then Exit Function
+If nHashEntries - 1 < 0 Then Exit Function
 ReDim ListedFiles(nHashEntries - 1)
 sListFiles = SFileListFiles(hMPQ, NewFileLists, ListedFiles(0), 0)
 End Function
 Sub mAddAutoFile(hMPQ As Long, File As String, MpqPath As String)
-Dim cType As Integer, bNum As Long, fExt As String, dwFlags As Long
-dwFlags = MAFA_REPLACE_EXISTING
-If GlobalEncrypt Then dwFlags = dwFlags Or MAFA_ENCRYPT
-For bNum = 1 To Len(File)
-    If InStr(bNum, File, ".") > 0 Then
-        bNum = InStr(bNum, File, ".")
-    Else
-        Exit For
-    End If
-Next bNum
-If bNum > 1 Then
-    fExt = Mid(File, bNum - 1)
-Else
-    fExt = File
-End If
-If LCase(fExt) = ".bik" Then
-    cType = CInt(GetReg(AppKey + "Compression\.bik", "-2"))
-    dwFlags = dwFlags And (-1& Xor MAFA_ENCRYPT)
-ElseIf LCase(fExt) = ".smk" Then
-    cType = CInt(GetReg(AppKey + "Compression\.smk", "-2"))
-    dwFlags = dwFlags And (-1& Xor MAFA_ENCRYPT)
-ElseIf LCase(fExt) = ".mp3" Then
-    cType = CInt(GetReg(AppKey + "Compression\.mp3", "-2"))
-    dwFlags = dwFlags And (-1& Xor MAFA_ENCRYPT)
-ElseIf LCase(fExt) = ".mpq" Then
-    cType = CInt(GetReg(AppKey + "Compression\.mpq", "-2"))
-    dwFlags = dwFlags And (-1& Xor MAFA_ENCRYPT)
-ElseIf LCase(fExt) = ".w3m" Then
-    cType = CInt(GetReg(AppKey + "Compression\.w3m", "-2"))
-    dwFlags = dwFlags And (-1& Xor MAFA_ENCRYPT)
-ElseIf LCase(fExt) = ".wav" Then
-    cType = CInt(GetReg(AppKey + "Compression\.wav", "0"))
-Else
-    cType = CInt(GetReg(AppKey + "Compression\" + fExt, CStr(DefaultCompressID)))
-End If
+Dim cType As Integer, dwFlags As Long
+
+GetCompressFlags File, cType, dwFlags
+
 Select Case cType
 Case -2
 MpqAddFileToArchiveEx hMPQ, File, MpqPath, dwFlags, 0, 0
@@ -311,12 +327,43 @@ Case -1
 MpqAddFileToArchiveEx hMPQ, File, MpqPath, dwFlags Or MAFA_COMPRESS, MAFA_COMPRESS_STANDARD, 0
 Case -3
 MpqAddFileToArchiveEx hMPQ, File, MpqPath, dwFlags Or MAFA_COMPRESS, MAFA_COMPRESS_DEFLATE, DefaultCompressLevel
+Case -4
+MpqAddFileToArchiveEx hMPQ, File, MpqPath, dwFlags Or MAFA_COMPRESS, MAFA_COMPRESS_BZIP2, 0
 Case 0, 1, 2
 MpqAddWaveToArchive hMPQ, File, MpqPath, dwFlags Or MAFA_COMPRESS, cType
 Case Else
-MpqAddFileToArchiveEx hMPQ, File, MpqPath, dwFlags Or MAFA_COMPRESS, DefaultCompress, DefaultCompressLevel
+If DefaultCompress = MAFA_COMPRESS_DEFLATE Then
+    MpqAddFileToArchiveEx hMPQ, File, MpqPath, dwFlags Or MAFA_COMPRESS, DefaultCompress, DefaultCompressLevel
+Else
+    MpqAddFileToArchiveEx hMPQ, File, MpqPath, dwFlags Or MAFA_COMPRESS, DefaultCompress, 0
+End If
 End Select
 End Sub
+Sub mAddAutoFromBuffer(hMPQ As Long, ByRef buffer As Byte, BufSize As Long, MpqPath As String)
+Dim cType As Integer, dwFlags As Long
+
+GetCompressFlags MpqPath, cType, dwFlags
+
+Select Case cType
+Case -2
+MpqAddFileFromBufferEx hMPQ, buffer, BufSize, MpqPath, dwFlags, 0, 0
+Case -1
+MpqAddFileFromBufferEx hMPQ, buffer, BufSize, MpqPath, dwFlags Or MAFA_COMPRESS, MAFA_COMPRESS_STANDARD, 0
+Case -3
+MpqAddFileFromBufferEx hMPQ, buffer, BufSize, MpqPath, dwFlags Or MAFA_COMPRESS, MAFA_COMPRESS_DEFLATE, DefaultCompressLevel
+Case -4
+MpqAddFileFromBufferEx hMPQ, buffer, BufSize, MpqPath, dwFlags Or MAFA_COMPRESS, MAFA_COMPRESS_BZIP2, 0
+Case 0, 1, 2
+MpqAddWaveFromBuffer hMPQ, buffer, BufSize, MpqPath, dwFlags Or MAFA_COMPRESS, cType
+Case Else
+If DefaultCompress = MAFA_COMPRESS_DEFLATE Then
+    MpqAddFileFromBufferEx hMPQ, buffer, BufSize, MpqPath, dwFlags Or MAFA_COMPRESS, DefaultCompress, DefaultCompressLevel
+Else
+    MpqAddFileFromBufferEx hMPQ, buffer, BufSize, MpqPath, dwFlags Or MAFA_COMPRESS, DefaultCompress, 0
+End If
+End Select
+End Sub
+
 Function DirEx(ByVal Path As String, Filter As String, Attributes, Recurse As Boolean) As String
 Dim Files() As String, lNum As Long, Folders() As String
 If Right(Path, 1) <> "\" And Path <> "" Then Path = Path + "\"
@@ -762,7 +809,11 @@ For bNum = 1 To Len(Script)
                             ElseIf cType = -1 Then
                                 mAddAutoFile hMPQ, FullPath(CurPath, fLine), Param(3) + fLine
                             ElseIf cType = 1 Then
-                                MpqAddFileToArchiveEx hMPQ, FullPath(CurPath, fLine), Param(3) + fLine, dwFlags, DefaultCompress, DefaultCompressLevel
+                                If DefaultCompress = MAFA_COMPRESS_DEFLATE Then
+                                    MpqAddFileToArchiveEx hMPQ, FullPath(CurPath, fLine), Param(3) + fLine, dwFlags, DefaultCompress, DefaultCompressLevel
+                                Else
+                                    MpqAddFileToArchiveEx hMPQ, FullPath(CurPath, fLine), Param(3) + fLine, dwFlags, DefaultCompress, 0
+                                End If
                             Else
                                 MpqAddFileToArchiveEx hMPQ, FullPath(CurPath, fLine), Param(3) + fLine, dwFlags, 0, 0
                             End If
@@ -772,7 +823,11 @@ For bNum = 1 To Len(Script)
                             ElseIf cType = -1 Then
                                 mAddAutoFile hMPQ, FullPath(CurPath, fLine), Param(3)
                             ElseIf cType = 1 Then
-                                MpqAddFileToArchiveEx hMPQ, FullPath(CurPath, fLine), Param(3), dwFlags, DefaultCompress, DefaultCompressLevel
+                                If DefaultCompress = MAFA_COMPRESS_DEFLATE Then
+                                    MpqAddFileToArchiveEx hMPQ, FullPath(CurPath, fLine), Param(3), dwFlags, DefaultCompress, DefaultCompressLevel
+                                Else
+                                    MpqAddFileToArchiveEx hMPQ, FullPath(CurPath, fLine), Param(3), dwFlags, DefaultCompress, 0
+                                End If
                             Else
                                 MpqAddFileToArchiveEx hMPQ, FullPath(CurPath, fLine), Param(3), dwFlags, 0, 0
                             End If