致友 (1千字)
今天粗略翻了翻此前写的APP结构的简单分析,明显的BUG就有两处了,实为
误人子弟。
1、分离单个文件时,不能分离序号为
0 的文件,应改为:
Private Sub cmdSplit_Click()
Dim tDir As String
tDir
= BrowFolder
If tDir <> "" And Val(txtID.Text) <> 0 And Trim(txtID.Text)
<> "0" Then
SplitFile mApp, Val(txtID.Text), tDir
MsgBox "成功分离第 " & Val(txtID.Text) & " 个文件!", vbInformation + vbSystemModal,
"信息提示"
End If
End Sub
2、分离单个文件的算法设计有错误,分离文件会少一字节,应改为:
'------------------------------------------------------------------------
'- aBuffer 是所取得的FOX结构类型,ID是编号,dPath 是要分离到的目录
'- 算法设计:定义一个数组,大小=从当前编号的文件的大小,从当前编号的文件
'- 开始的地方读取大小相当的数据,赋予数组
'------------------------------------------------------------------------
Public Sub SplitFile(aBuffer As VfpStructure, ID As Long, dPath As String)
Dim tData() As Byte
ReDim tData(0 To aBuffer.aFilesSize(ID)) As Byte
Open aBuffer.aAppFileName For Binary As #4
Seek #4, aBuffer.aFilesStartPos(ID)
+ 1
Get #4, aBuffer.aFilesStartPos(ID) + 1, tData()
Close #4
Open dPath & aBuffer.aFilesName(ID) For Binary As #5
Put #5, , tData()
Close #5
End Sub
另外,整个过程多没有对错误陷阱进行判断,实为不该。
