pjblog 自动安装包原理
作者:leleou 日期:2010-02-14
install.asp和install.dat。本来以为是一个gz或者zip的压缩文件,将install.dat改变了后缀依然不能解压,于是引起了我的兴趣。
1、先看install.asp文件,发现install.asp文件中对install.dat文件操作方式是objXmlFile。原来install.dat是一个XML文件?
2、用UltraEdit打开install.dat文件,发现果真是XML文件。格式为:
\atom.css 这里是编码
在中保存的是路径
在中保存的是数据的内容
就是将asp css gif jpg等文件以bin.base64 类型的节点内容存放,现在新版本的word文档都用这种格式了。
3、可以参考一个技术文档
因为最近要做的项目中,我要通过XML动态生成窗体,看了UI图样,我有些叫苦:我通过XML动态生成窗体,可是主窗体中UI要用图标来确定要使用的窗体,怎么才能使主窗体的图标也是动态加载而且图标和要生成的窗体还有关联呢?我又想到用XML,查MSDN,看到只有XmlTextWriter 和XmlTextReader里分别有XmlTextWriter.WriteBase64和XmlTextReader.ReadBase64可以操作图片这种二进制字节的数据。但是XmlTextWriter和XmlTextReader远不如XmlDocument操作方便,如果用这两者我就得写太多的代码。困扰了我一天,记得以前看到过一篇文章介绍怎样将图片数据存储到Xml文件,可是怎么也找不到,后来终于在一个英文网站上找到了相关内容,而且还是2003年贴出来的,汗。好了,不废话了,我把我的实现代码贴给大家吧。private XmlDocument document;private string FilePath = Application.StartupPath + "\\..\\..\\FormStyle.xml"; // FormStyle.xml 文件地址private void frmMain_Load(object sender, System.EventArgs e){ if(document == null) { document = new XmlDocument(); document.Load(FilePath); } // 只挑选含有Form的节点 XmlNodeList FormNodes = document.GetElementsByTagName("Form"); lbIcons.BeginUpdate(); lbIcons.Items.Clear(); foreach(XmlNode node in FormNodes) { // 把节点的名称放到下拉列表里 lbIcons.Items.Add(node.Attributes["Name"].Value); } lbIcons.EndUpdate();}private void lbIcons_SelectedValueChanged(object sender, System.EventArgs e){ // 查找下拉框所选的窗体下是否有Image元素,若无则退出 XmlNode node = document.DocumentElement.SelectSingleNode(string.Format("descendant::Form[@Name='{0}']/Image", lbIcons.SelectedItem.ToString())); if(node == null) return; // 如果含有Image元素,就将元素值转换为Base64String,然后放到内存流 using (MemoryStream mem = new MemoryStream(Convert.FromBase64String(node.InnerText))) { // 加载内存流数据为位图 Bitmap bmp = Bitmap.FromStream(mem) as Bitmap; pictureBox1.Image = bmp; }}private void btnAdd_Click(object sender, System.EventArgs e){ // 如果不存在txtFilePath.Text所指文件,就退出 if(!File.Exists(txtFilePath.Text) || lbIcons.Items.Count == 0) return; if(lbIcons.SelectedIndex == -1) lbIcons.SelectedIndex = 0; if(document == null) { document = new XmlDocument(); document.Load(FilePath); } //Read the bitmap. string data = null; Bitmap bmp = new Bitmap(txtFilePath.Text); using (MemoryStream mem = new MemoryStream()) { bmp.Save(mem, System.Drawing.Imaging.ImageFormat.Bmp); // 将位图数据转换为Base64String放入字符串中 data = Convert.ToBase64String(mem.ToArray()); } // 查找当前所选的窗体是否含有Image节点,若就新建一个 XmlNode node = document.DocumentElement.SelectSingleNode(string.Format("descendant::Form[@Name='{0}']", lbIcons.SelectedItem.ToString())); XmlNode ImageNode = document.DocumentElement.SelectSingleNode(string.Format("descendant::Form[@Name='{0}']/Image", lbIcons.SelectedItem.ToString())); if(ImageNode == null) { ImageNode = document.CreateElement("Image"); node.AppendChild(ImageNode); } // 将位图数据保存到XML文档 ImageNode.InnerText = data; document.Save(FilePath);}
4、这种方式制作安装包是做第一次见到的,有两个好处:一是可以网络安装,不需要上传几十个文件,只需要上传一个安装文件和一个安装包即可;二是可以使ASP程序变得更加专业业和商业化,安装文件构造和修改都很简单,如果有一个很好的制作数据文件的工具,或许还能制作出来一个像样的安装工具来。
1、先看install.asp文件,发现install.asp文件中对install.dat文件操作方式是objXmlFile。原来install.dat是一个XML文件?
2、用UltraEdit打开install.dat文件,发现果真是XML文件。格式为:
在
在
就是将asp css gif jpg等文件以bin.base64 类型的节点内容存放,现在新版本的word文档都用这种格式了。
3、可以参考一个技术文档
因为最近要做的项目中,我要通过XML动态生成窗体,看了UI图样,我有些叫苦:我通过XML动态生成窗体,可是主窗体中UI要用图标来确定要使用的窗体,怎么才能使主窗体的图标也是动态加载而且图标和要生成的窗体还有关联呢?我又想到用XML,查MSDN,看到只有XmlTextWriter 和XmlTextReader里分别有XmlTextWriter.WriteBase64和XmlTextReader.ReadBase64可以操作图片这种二进制字节的数据。但是XmlTextWriter和XmlTextReader远不如XmlDocument操作方便,如果用这两者我就得写太多的代码。困扰了我一天,记得以前看到过一篇文章介绍怎样将图片数据存储到Xml文件,可是怎么也找不到,后来终于在一个英文网站上找到了相关内容,而且还是2003年贴出来的,汗。好了,不废话了,我把我的实现代码贴给大家吧。private XmlDocument document;private string FilePath = Application.StartupPath + "\\..\\..\\FormStyle.xml"; // FormStyle.xml 文件地址private void frmMain_Load(object sender, System.EventArgs e){ if(document == null) { document = new XmlDocument(); document.Load(FilePath); } // 只挑选含有Form的节点 XmlNodeList FormNodes = document.GetElementsByTagName("Form"); lbIcons.BeginUpdate(); lbIcons.Items.Clear(); foreach(XmlNode node in FormNodes) { // 把节点的名称放到下拉列表里 lbIcons.Items.Add(node.Attributes["Name"].Value); } lbIcons.EndUpdate();}private void lbIcons_SelectedValueChanged(object sender, System.EventArgs e){ // 查找下拉框所选的窗体下是否有Image元素,若无则退出 XmlNode node = document.DocumentElement.SelectSingleNode(string.Format("descendant::Form[@Name='{0}']/Image", lbIcons.SelectedItem.ToString())); if(node == null) return; // 如果含有Image元素,就将元素值转换为Base64String,然后放到内存流 using (MemoryStream mem = new MemoryStream(Convert.FromBase64String(node.InnerText))) { // 加载内存流数据为位图 Bitmap bmp = Bitmap.FromStream(mem) as Bitmap; pictureBox1.Image = bmp; }}private void btnAdd_Click(object sender, System.EventArgs e){ // 如果不存在txtFilePath.Text所指文件,就退出 if(!File.Exists(txtFilePath.Text) || lbIcons.Items.Count == 0) return; if(lbIcons.SelectedIndex == -1) lbIcons.SelectedIndex = 0; if(document == null) { document = new XmlDocument(); document.Load(FilePath); } //Read the bitmap. string data = null; Bitmap bmp = new Bitmap(txtFilePath.Text); using (MemoryStream mem = new MemoryStream()) { bmp.Save(mem, System.Drawing.Imaging.ImageFormat.Bmp); // 将位图数据转换为Base64String放入字符串中 data = Convert.ToBase64String(mem.ToArray()); } // 查找当前所选的窗体是否含有Image节点,若就新建一个 XmlNode node = document.DocumentElement.SelectSingleNode(string.Format("descendant::Form[@Name='{0}']", lbIcons.SelectedItem.ToString())); XmlNode ImageNode = document.DocumentElement.SelectSingleNode(string.Format("descendant::Form[@Name='{0}']/Image", lbIcons.SelectedItem.ToString())); if(ImageNode == null) { ImageNode = document.CreateElement("Image"); node.AppendChild(ImageNode); } // 将位图数据保存到XML文档 ImageNode.InnerText = data; document.Save(FilePath);}
4、这种方式制作安装包是做第一次见到的,有两个好处:一是可以网络安装,不需要上传几十个文件,只需要上传一个安装文件和一个安装包即可;二是可以使ASP程序变得更加专业业和商业化,安装文件构造和修改都很简单,如果有一个很好的制作数据文件的工具,或许还能制作出来一个像样的安装工具来。
评论: 0 | 引用: 0 | 查看次数: 1607
发表评论
上一篇:
下一篇: 


文章来自:
Tags:
相关日志:
