kbmmw 中虚拟文件操作入门
kbmmw 中一直有一个功能,但是基本上都没有提过,但是在实际应用中,却非常有用,这个功能就是
虚拟文件包功能,他可以把一大堆文件保存到一个文件里面,方便后台管理。
kbmmw 的虚拟文件在单元kbmMWStreamStore 中实现,这个是非控件形式的,因此需要手工添加这个
单元。另外虚拟文件操作的类为TkbmMWLookupStorage,所有的操作都由这个类实现,具体可以参加源码。
因为这个很简单,直接就上界面

具体实现代码如下
procedure TForm2.Button1Click(Sender: TObject);// 打包
var
sr:TSearchRec;
i:integer;
fs:TFileStream;
fsfile:TFileStream;
st:TkbmMWLookupStorage;
begin
fs:=TFileStream.Create(edit2.Text,fmCreate or fmOpenReadWrite);
try
st:=TkbmMWLookupStorage.Create(fs);
try chdir(edit1.Text);
i:=FindFirst('*.*',faNormal,sr);
while i= do
begin
try
fsfile:=TFileStream.Create(sr.Name,fmOpenRead or fmShareCompat);
try
st.Add(sr.Name,fsfile);
finally
fsfile.Free;
end;
except
end;
i:=FindNext(sr);
end;
finally
st.Free;
end;
finally
fs.Free;
end; showmessage('打包成功'); end; procedure TForm2.Button2Click(Sender: TObject); //列目录
var
fs:TFileStream;
st:TkbmMWLookupStorage;
begin
fs:=TFileStream.Create(edit2.text,fmOpenReadWrite);
try
st:=TkbmMWLookupStorage.Create(fs);
try
Label1.Caption:=inttostr(st.Count);
st.GetIdentifiers(ListBox1.Items);
finally
st.Free;
end;
finally
fs.Free;
end; end; procedure TForm2.Button3Click(Sender: TObject);//解压文件
var
i:integer;
fs:TFileStream;
fsfile:TFileStream;
st:TkbmMWLookupStorage;
sl:TStringList;
s:string;
begin
fs:=TFileStream.Create(edit2.Text,fmOpenReadWrite);
try
st:=TkbmMWLookupStorage.Create(fs);
try
sl:=TStringList.Create;
try
st.GetIdentifiers(sl);
for i:= to sl.Count- do
begin
s:=sl.Strings[i];
fsfile:=TFileStream.Create(edit3.Text+s,fmCreate or fmOpenWrite);
try
st.Get(s,fsfile);
finally
fsfile.Free;
end;
end; finally
sl.Free;
end;
finally
st.Free;
end;
finally
fs.Free;
end; showmessage('解包成功!'); end;
运行效果

可以看见一共319 个文件
同时在d:\temp 生成了一个so 文件

打包成功
列表可以显示包里面的文件

解压结果

解压正确。
有的时候我们为了保密和减小文件大小,可以采用加密和压缩。
下面再演示一下加密的方式。
加入一个kbmmwcrypt和两个按钮。

对应的代码如下:
procedure TForm2.Button4Click(Sender: TObject); //加密打包
var
sr:TSearchRec;
i:integer;
ms:Tbytesstream;
fs:TFileStream;
fsfile:TFileStream;
st:TkbmMWLookupStorage;
begin
fs:=TFileStream.Create(edit2.Text,fmCreate or fmOpenReadWrite); ms:=TbytesStream.Create; try
st:=TkbmMWLookupStorage.Create(ms);
try chdir(edit1.Text);
i:=FindFirst('*.*',faNormal,sr);
while i= do
begin
try
fsfile:=TFileStream.Create(sr.Name,fmOpenRead or fmShareCompat);
try
st.Add(sr.Name,fsfile);
finally
fsfile.Free;
end;
except
end;
i:=FindNext(sr);
end; kbmMWCrypt1.PassPhrase:='xalion123456';
ms.Position:=;
kbmMWCrypt1.Encrypt(nil,ms,fs); finally
st.Free;
end; finally
fs.Free;
ms.Free;
end; showmessage('打包成功'); end; procedure TForm2.Button5Click(Sender: TObject); // 解密展开
var
i:integer;
fs:TFileStream;
fsfile:TFileStream;
ms:Tbytesstream;
st:TkbmMWLookupStorage;
sl:TStringList;
s:string;
begin
fs:=TFileStream.Create(edit2.Text,fmOpenReadWrite);
ms:=TbytesStream.Create;
kbmMWCrypt1.PassPhrase:='xalion123456';
kbmMWCrypt1.decrypt(nil,fs,ms); try
st:=TkbmMWLookupStorage.Create(ms);
try
sl:=TStringList.Create;
try
st.GetIdentifiers(sl);
for i:= to sl.Count- do
begin
s:=sl.Strings[i];
fsfile:=TFileStream.Create(edit3.Text+s,fmCreate or fmOpenWrite);
try
st.Get(s,fsfile);
finally
fsfile.Free;
end;
end; finally
sl.Free;
end;
finally
st.Free;
end;
finally
fs.Free;
end; showmessage('解包成功!'); end;
运行程序,与没有加密的运行效果一致,但是生成的文件已经被加密。
别人即使偷走文件,也不用担心信息泄露了。
kbmmw 中虚拟文件操作入门的更多相关文章
- 第32课 Qt中的文件操作
1. Qt的中IO操作 (1)Qt中IO操作的处理方式 ①Qt通过统一的接口简化了文件和外部设备的操作方式 ②Qt中的文件被看作一种特殊的外部设备 ③Qt中的文件操作与外部设备的操作相同 (2)IO操 ...
- 003-Tuple、Array、Map与文件操作入门实战
003-Tuple.Array.Map与文件操作入门实战 Tuple 各个元素可以类型不同 注意索引的方式 下标从1开始 灵活 Array 注意for循环的until用法 数组的索引方式 上面的for ...
- 重新想象 Windows 8 Store Apps (24) - 文件系统: Application Data 中的文件操作, Package 中的文件操作, 可移动存储中的文件操作
原文:重新想象 Windows 8 Store Apps (24) - 文件系统: Application Data 中的文件操作, Package 中的文件操作, 可移动存储中的文件操作 [源码下载 ...
- 背水一战 Windows 10 (91) - 文件系统: Application Data 中的文件操作, Application Data 中的“设置”操作, 通过 uri 引用 Application Data 中的媒体
[源码下载] 背水一战 Windows 10 (91) - 文件系统: Application Data 中的文件操作, Application Data 中的“设置”操作, 通过 uri 引用 Ap ...
- 背水一战 Windows 10 (90) - 文件系统: 获取 Package 中的文件, 可移动存储中的文件操作, “库”管理
[源码下载] 背水一战 Windows 10 (90) - 文件系统: 获取 Package 中的文件, 可移动存储中的文件操作, “库”管理 作者:webabcd 介绍背水一战 Windows 10 ...
- Java中的文件操作(一)RandomAccessFile
今天,学到的是java中的文件操作. Java.IO.File Java中操作文件用到RandomAccessFile类,既可以读取文件内容,也可以向文件输出数据,但不同与普通输入/输出流的是Rand ...
- Win 32平台SDK中的文件操作
读取文件: HANDLE hFile ; // 声明文件操作内核对象句柄 hFile = CreateFile(, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL ...
- 关于文件的INode与Java中的文件操作接口
本文由作者周梁伟授权网易云社区发布. 近日做的项目中涉及到多进程共同读写多个文件的问题,文件名和最后修改时间都是可能会被频繁修改的,因而识别文件的唯一性会产生相当的麻烦,于是专门再学习了一下文件系统对 ...
- ASP.NET中的文件操作(文件信息,新建,移动,复制,重命名,上传,遍历)(亲测详细)
做了几天的文件操作,现在来总结一下,错误之处,还望指点!以文件为例,如果对文件夹操作,基本上将File换为Directory即可(例:FileInfo file = new FileInfo(Path ...
随机推荐
- Win7 访问win2008 远程桌面提示:您的凭证不工作
背景: win7 远程桌面连接 服务器 windows 2008 报错,“您的凭证不工作”,但是 xp 系统却可以正常连接. 解决方法: 1.在“运行” 中执行 secpol.msc-->进入本 ...
- Vue之组件
Vue之全局组件 全局组件可以被任何局部组件调用 <div id="app"> <!--这里是组件的使用--> <global-component&g ...
- PAT1066(AVL树)
An AVL tree is a self-balancing binary search tree. In an AVL tree, the heights of the two child sub ...
- POJ-3278.CatchThatCow(数字BFS最短路输出)
本题大意:一个农夫和一头牛在一个数轴上,牛不动,农夫每次可使自己的坐标 +1 , -1, *2 ,问最小需要多少次农夫与牛坐标相等. 本题思路:最短路,BFS. 本题代码: #include < ...
- Shell教程 之第一个shell脚本
1.第一个shell脚本 打开文本编辑器(可以使用 vi/vim 命令来创建文件),新建一个文件 test.sh,扩展名为 sh(sh代表shell),扩展名并不影响脚本执行 输入一些代码 #!/bi ...
- FortiGate基本信息
1.介绍 FortiGate是全新的下一代防火墙,在整个硬件架构和系统上面都有新的设计,在性能和功能上面都有了很大提升,具有性能高.接口丰富.功能齐全.安全路由交换一体化.性价比高等优势. Forti ...
- 再遇ibatisNet
11年在Mr刘的带领下第一次接触ibatisnet ,当时Mr刘很详细的很讲了xml里的写法还有配置文件之类的,但是随着时间越来越久远.很多东西都开始淡忘了. 如今,再次和它相遇,依然觉得很亲切,虽然 ...
- Spring <context:annotation-config> 和 <context:component-scan> 区别
一篇很不错的文章,看到就是赚到Get.... https://www.cnblogs.com/leiOOlei/p/3713989.html 说白了 :<context:component-sc ...
- localstorage和vue结合使用
父组件 <template> <div class="hello"> <p>Original message:"{{message}} ...
- Oracle性能优化5-索引的不足
索引的不足 1.索引开销 a.访问开销 反问集中导致热块的竞争(对最新数据的查询) 回表性能取决聚合因子 索引的访问开销,返回几条数据快,但是返回大量的数据很慢 全表扫描与全扫描 ...