Esempio n. 1
0
        /// <summary>
        /// 读取数据库中本地文件信息
        /// </summary>
        /// <returns></returns>
        public CommonData.FileData GetFileDataFromDB()
        {
            CommonData.FileData filedata = new CommonData.FileData();

            string    strSql = string.Format(@"SELECT FilePath,FileMD5,FileURL FROM LocalFileList");
            DataTable table  = GetDataTable(strSql);

            if (table == null || table.Rows.Count == 0)
            {
                return(null);
            }
            for (int i = 0; i < table.Rows.Count; i++)
            {
                DataRow         dr   = table.Rows[i];
                CommonData.Data data = new CommonData.Data();
                data.FilePath = DecryptString(GetString(dr["FilePath"]), Skey);
                data.FileMD5  = DecryptString(GetString(dr["FileMD5"]), Skey);
                data.FileURL  = DecryptString(GetString(dr["FileURL"]), Skey);
                filedata.DataList.Add(data);
            }
            return(filedata);
        }
Esempio n. 2
0
        /// <summary>
        /// 从本地文件中读取文件信息,放进locallist列表
        /// </summary>
        /// <param name="path"></param>
        public void SetLocalFileList(string path)
        {
            try
            {
                string[] FilePath = Directory.GetDirectories(path);
                string   filename = string.Empty;
                for (int i = 0; i < FilePath.Length; i++)
                {
                    SetLocalFileList(FilePath[i]);
                }
                string[] Newfilepath = Directory.GetFiles(path);
                for (int i = 0; i < Newfilepath.Length; i++)
                {
                    filename = Path.GetFullPath(Newfilepath[i]);
                    string fileRealName = Path.GetDirectoryName(Newfilepath[i]) + "\\" + Path.GetFileNameWithoutExtension(Newfilepath[i]);
                    string fileExName   = Path.GetExtension(Newfilepath[i]);
                    if (string.Compare(fileExName, ".xxx") == 0)
                    {
                        string fileTempName = fileRealName + ".temp";

                        DESFileClass.DecryptFile(filename, fileTempName, Global.FileEnKey);
                        CommonData.Data data = new CommonData.Data
                        {
                            FilePath = fileRealName,
                            FileMD5  = GetMD5Content(fileTempName),
                            FileURL  = ""
                        };
                        fileListLocal.DataList.Add(data);
                    }
                }
                string sysPath = System.Windows.Forms.Application.StartupPath;
            }
            catch (Exception ex)
            {
                Log.Error("[" + System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "][" + System.Reflection.MethodBase.GetCurrentMethod().Name + "] err" + ex);
                throw;
            }
        }
Esempio n. 3
0
        public int DoUpdateFileList(BeingUpdateFile beingupdateform)
        {
            int  res      = -1;
            bool stepIsOk = true;

            try
            {
                //fileListLocal.DataList=fileListUpdate.DataList+fileListAdd.DataList;
                if (fileListUpdate.DataList.Count != 0 && fileListDelete.DataList.Count != 0 && fileListAdd.DataList.Count != 0)
                {
                    return(res);
                }
                int totalCount = fileListUpdate.DataList.Count * 2 + fileListDelete.DataList.Count + fileListAdd.DataList.Count;
                beingupdateform.SetMaxValue(10000 * (totalCount - 1) / totalCount);
                int index = 0;
                if (fileListUpdate.DataList.Count != 0)
                {
                    foreach (CommonData.Data d in fileListUpdate.DataList)
                    {
                        CommonData.Data delData = FindDataByPath(fileListLocal, d.FilePath);
                        if (delData != null)
                        {
                            //int index = fileListLocal.DataList.IndexOf();
                            if (File.Exists(delData.FilePath + ".xxx"))
                            {
                                File.Delete(delData.FilePath + ".xxx");
                                fileListLocal.DataList.Remove(delData);
                                fileListAdd.DataList.Add(d);
                                if (File.Exists(delData.FilePath + ".temp"))
                                {
                                    File.Delete(delData.FilePath + ".temp");
                                }
                                beingupdateform.SetTextMessage(10000 * index++ / totalCount);
                            }
                            else
                            {
                                stepIsOk = false;
                                break;
                            }
                        }
                    }
                    if (stepIsOk)
                    {
                        fileListUpdate.DataList.Clear();
                    }
                }

                if (fileListDelete.DataList.Count != 0)
                {
                    foreach (CommonData.Data d in fileListDelete.DataList)
                    {
                        CommonData.Data data = FindDataByPath(fileListLocal, d.FilePath);
                        if (data != null)
                        {
                            //int index = fileListLocal.DataList.IndexOf();
                            if (File.Exists(data.FilePath + ".xxx"))
                            {
                                File.Delete(data.FilePath + ".xxx");
                                fileListLocal.DataList.Remove(data);
                                if (File.Exists(data.FilePath + ".temp"))
                                {
                                    File.Delete(data.FilePath + ".temp");
                                }
                                beingupdateform.SetTextMessage(10000 * index++ / totalCount);
                            }
                            else
                            {
                                stepIsOk = false;
                                break;
                            }
                        }
                    }
                    if (stepIsOk)
                    {
                        fileListDelete.DataList.Clear();
                    }
                }

                if (fileListAdd.DataList.Count != 0)
                {
                    foreach (CommonData.Data d in fileListAdd.DataList)
                    {
                        //Log.Info("Application.StartupPath + \"//\" + d.FilePath + \".temp\" = " + Application.StartupPath + "//" + d.FilePath + ".temp");
                        if (HttpDownload(d.FileURL, Application.StartupPath + "//" + d.FilePath + ".temp"))
                        {
                            DESFileClass.EncryptFile(Application.StartupPath + "//" + d.FilePath + ".temp", Application.StartupPath + "//" + d.FilePath + ".xxx", Global.FileEnKey);
                            fileListLocal.DataList.Add(d);
                            beingupdateform.SetTextMessage(10000 * index++ / totalCount);
                        }
                        else
                        {
                            stepIsOk = false;
                            break;
                        }
                    }
                    if (stepIsOk)
                    {
                        fileListAdd.DataList.Clear();
                    }
                }
                if (fileListUpdate.DataList.Count == 0 && fileListDelete.DataList.Count == 0 && fileListAdd.DataList.Count == 0)
                {
                    res = 0;
                }
            }
            catch (Exception ex)
            {
                Log.Error("[" + System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "][" + System.Reflection.MethodBase.GetCurrentMethod().Name + "] err" + ex);
                res = -1;
                throw;
            }
            return(res);
        }