Ejemplo n.º 1
0
        /// <summary>
        /// 将所有文件加密成xxx文件
        /// </summary>
        /// <param name="path"></param>
        public void AllFile2xxx(string path)
        {
            string[] FilePath = Directory.GetDirectories(path);
            string   filename = string.Empty;

            for (int i = 0; i < FilePath.Length; i++)
            {
                AllFile2xxx(FilePath[i]);
            }
            string[] Newfilepath = Directory.GetFiles(path);
            for (int i = 0; i < Newfilepath.Length; i++)
            {
                string filepath     = Path.GetFullPath(Newfilepath[i]);
                string filerealpath = Path.GetDirectoryName(Newfilepath[i]) + "\\" + Path.GetFileNameWithoutExtension(Newfilepath[i]);
                DESFileClass.EncryptFile(filepath, filerealpath + ".xxx", Global.FileEnKey);
            }
        }
Ejemplo n.º 2
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);
        }