コード例 #1
0
        public UpdateFileList GetUpdateList()
        {
            string         sql      = "SELECT name, D, Version, LastWriteTime, ReleasePath, RevPath, UpdateLevel, Signa, Description, IsReboot FROM FileUpdateList";
            SqlCommand     cm       = new SqlCommand(sql, _cnn);
            SqlDataReader  reader   = cm.ExecuteReader();
            UpdateFileList fileList = new UpdateFileList();

            while (reader.Read())
            {
                UpdateFileContent f = new UpdateFileContent();
                f.Name          = reader.GetString(0);
                f.D             = Core.General.FromString(reader.GetString(1));
                f.FileVersion   = reader.GetString(2);
                f.LastWriteTime = Core.General.FromString(reader.GetString(3));
                f.ReleasePath   = (FileSpecialFolder)Enum.Parse(typeof(FileSpecialFolder), reader.GetString(4));
                f.RevPath       = reader.GetString(5);
                f.Level         = reader.GetInt16(6);
                f.Signa         = reader.GetString(7);
                f.Description   = reader.GetString(8);
                f.IsReboot      = reader.GetValue(9).ToString() == "1" ? true : false;
                fileList.Add(f.Name, f);
            }
            reader.Close();
            return(fileList);
        }
コード例 #2
0
        void Build()
        {
            SaveFileDialog sf = new SaveFileDialog();

            sf.AddExtension = true;
            sf.DefaultExt   = "Unv.Package";
            if (sf.ShowDialog(this) != DialogResult.OK)
            {
                return;
            }
            this.Cursor = Cursors.WaitCursor;
            string filename = sf.FileName;

            UpdateFileContent[] fcs = new UpdateFileContent[dataGridView1.RowCount];
            int i = 0;

            foreach (DataGridViewRow row in dataGridView1.Rows)
            {
                fcs[i]             = FileUpdater.GetUpdateFileContent(row.Cells[2].EditedFormattedValue.ToString() + row.Cells[1].EditedFormattedValue.ToString());
                fcs[i].ReleasePath = (FileSpecialFolder)Enum.Parse(typeof(FileSpecialFolder), row.Cells[5].EditedFormattedValue.ToString());
                fcs[i].RevPath     = row.Cells[6].EditedFormattedValue.ToString();
                fcs[i].IsReboot    = (bool)row.Cells[7].EditedFormattedValue;
                i++;
            }
            string debug = "";

            FileUpdater.BuildPackage(fcs, filename, ref debug);
#if (DEBUG)
            {
                System.IO.File.WriteAllText("c:\\debug.xml", debug);
            }
#endif
            this.Cursor = Cursors.Default;
        }
コード例 #3
0
        /// <summary>
        /// 获得UpdateFileContent的基本信息和Content和签名
        /// </summary>
        /// <param name="filename"></param>
        /// <returns></returns>
        public static UpdateFileContent GetUpdateFileContent(string filename)
        {
            UpdateFileContent f = FileUpdater.GetUpdateFile(filename) as UpdateFileContent;

            f.Content = System.IO.File.ReadAllBytes(filename);
            string k = System.Windows.Forms.Application.ProductName + System.Windows.Forms.Application.CompanyName;

            f.Signa = Core.ShaEnCoder.HashToString(Core.ShaEnCoder.GetHash(f.Content, Encoding.ASCII.GetBytes(k)));
            return(f);
        }
コード例 #4
0
        /// <summary>
        /// 不锁定文件获得版本等信息
        /// </summary>
        /// <param name="filename"></param>
        /// <returns></returns>
        public static UpdateFile GetUpdateFile(string filename)
        {
            UpdateFileContent f = new UpdateFileContent();

            System.IO.FileInfo fileInfo = new System.IO.FileInfo(filename);
            f.Name          = fileInfo.Name;
            f.LastWriteTime = fileInfo.LastWriteTime;
            f.FileVersion   = General.GetVersionInfo(filename).FileVersion;
            f.D             = DateTime.Today;
            f.SourcePath    = fileInfo.FullName.Replace(f.Name, "");
            return(f);
        }
コード例 #5
0
        public UpdateFileContent[] AnalyPackage(string filename)
        {
            UpdateFileContent[] fcs = new UpdateFileContent[0];
            byte[] bt     = System.IO.File.ReadAllBytes(filename);
            int    length = 1024 * 100;

            /// 前100K为XML头
            byte[] btOfXml = new byte[length];
            Array.Copy(bt, 0, btOfXml, 0, length);
            string      xmlString = Encoding.UTF8.GetString(btOfXml);
            XmlDocument xml       = new XmlDocument();

            try
            {
                xml.LoadXml(xmlString);
                XmlNodeList list = xml.GetElementsByTagName("files");
                foreach (XmlNode node in list)
                {
                    Array.Resize <UpdateFileContent>(ref fcs, fcs.Length + 1);
                    int i = fcs.Length - 1;
                    fcs[i]               = new UpdateFileContent();
                    fcs[i].Name          = node.FirstChild.InnerText;
                    fcs[i].LastWriteTime = Core.General.FromString(node.Attributes["LastWriteTime"].Value);
                    fcs[i].D             = Core.General.FromString(node.Attributes["D"].Value);
                    fcs[i].FileVersion   = node.Attributes["FileVersion"].Value;
                    fcs[i].ReleasePath   = (FileSpecialFolder)Enum.Parse(typeof(FileSpecialFolder), node.Attributes["ReleasePath"].Value);
                    fcs[i].RevPath       = node.Attributes["RevPath"].Value;
                    fcs[i].IsReboot      = (node.Attributes["IsReboot"].Value) == "1"?true :false;
                    fcs[i].Level         = Int16.Parse(node.Attributes["Level"].Value);
                    fcs[i].Description   = node.Attributes["Description"].Value;
                    int ln = int.Parse(node.Attributes["Length"].Value);
                    fcs[i].Content = new byte[ln];
                    Array.Copy(bt, length, fcs[i].Content, 0, ln);
                    fcs[i].Signa = node.LastChild.InnerText;
                    length      += ln;
                    i++;
                }
                return(fcs);
            }
            catch (Exception ex)
            {
                System.Windows.Forms.MessageBox.Show(ex.Message, "分析更新包");

                return(fcs);
            }
        }
コード例 #6
0
        /// <summary>
        /// 根据UpdateFileContent的基本信息,获取其Content和签名
        /// </summary>
        /// <param name="f"></param>
        public void GetUpdateFile(UpdateFileContent f)
        {
            string        sql    = "select signa,content from FileUpdateList where name='" + f.Name + "'";
            SqlCommand    cm     = new SqlCommand(sql, _cnn);
            SqlDataReader reader = cm.ExecuteReader(CommandBehavior.SequentialAccess);

            if (reader.Read())
            {
                f.Signa = reader.GetString(0);
                if (!reader.IsDBNull(1))
                {
                    long i = reader.GetBytes(1, 0, null, 0, 1);;
                    if (i > 0)
                    {
                        byte[] buff = new byte[i];
                        reader.GetBytes(1, 0, buff, 0, buff.Length);
                        f.Content = buff;
                    }
                }
            }
            reader.Close();
        }
コード例 #7
0
        /// <summary>
        /// 上传文件
        /// </summary>
        /// <returns></returns>
        public bool UpLoad(UpdateFileContent f, SqlTransaction trans)
        {
            try
            {
                string     sql = "delete from FileUpdateList where name='" + f.Name + "'";
                SqlCommand cm  = new SqlCommand(sql, _cnn, trans);
                cm.ExecuteNonQuery();

                sql = "Select name, D, Version, LastWriteTime, ReleasePath, RevPath, UpdateLevel, Description, IsReboot,signa,content from FileUpdateList where name='" + f.Name + "'";
                cm  = new SqlCommand(sql, _cnn, trans);
                SqlDataAdapter sda = new SqlDataAdapter(cm);
                sda.Fill(MyDataSet, "FileUpdateList");

                DataRow dr = MyDataSet.Tables["FileUpdateList"].NewRow();
                dr["Name"]          = f.Name;
                dr["D"]             = f.D.ToString("yyyyMMdd");
                dr["Version"]       = f.FileVersion;
                dr["ReleasePath"]   = Enum.GetName(typeof(FileSpecialFolder), f.ReleasePath);
                dr["RevPath"]       = f.RevPath;
                dr["LastWriteTime"] = f.LastWriteTime.ToString("yyyyMMddHHmmss");
                dr["Description"]   = f.Description;
                dr["UpdateLevel"]   = f.Level;
                dr["signa"]         = f.Signa;
                dr["IsReboot"]      = f.IsReboot;
                dr["content"]       = f.Content;
                MyDataSet.Tables["FileUpdateList"].Rows.Add(dr);

                SqlCommandBuilder sb = new SqlCommandBuilder(sda);
                sda.Update(MyDataSet, "FileUpdateList");
                sda.Dispose();
                return(true);
            }
            catch (Exception ex)
            {
                System.Windows.Forms.MessageBox.Show(ex.Message, "上传内容");
                return(false);
            }
        }