private void BtnUpdateFile_Click(object sender, EventArgs e) { try { ClearAllControl(); CheckFileUpdate(); if (IsNeedUpdateFile) { BeingUpdateFile updateForm = new BeingUpdateFile(fileSys); DialogResult dr = updateForm.ShowDialog(); //int res = fileSys.DoUpdateFileList(); if (dr != DialogResult.Yes) { throw new Exception("文件未更新完成,请再次操作"); } while (tv.Nodes.Count > 1) { tv.Nodes[tv.Nodes.Count - 1].Remove(); } LocalFileList.Clear(); GetNodeValue(Global.SysFilePath, tv.Nodes); MessageBox.Show("更新完成"); } else { MessageBox.Show("当前文件无需更新!"); } } catch (Exception ex) { Log.Error("[" + System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "][" + System.Reflection.MethodBase.GetCurrentMethod().Name + "] err" + ex); MessageBox.Show(ex.Message); } }
private void InitFileSys() { try { fileSys.InitFileList(); fileSys.fileListLocal.DataList.Clear(); fileSys.fileListAccept.DataList.Clear(); fileSys.SetLocalFileList(Global.SysFilePath); fileSys.GetServerFileList(Global.userMsgData.Account); if (fileSys.fileListAccept.DataList.Count != 0) { IsNeedUpdateFile = fileSys.MatchFilePath(); } if (IsNeedUpdateFile) { if (MessageBox.Show("文件需要更新!点击确定更新文件。") == DialogResult.OK) { //更新文件 //Thread t_UpdateFile = new Thread(new ThreadStart(DoUpdateFile)); BeingUpdateFile updateForm = new BeingUpdateFile(fileSys); DialogResult dr = updateForm.ShowDialog(); fileSys.DelAllTempFile(Global.SysFilePath); fileSys.fileListLocal.DataList.Clear(); fileSys.SetLocalFileList(Global.SysFilePath); if (dr != DialogResult.Yes) { MessageBox.Show("文件未更新完成,请再次操作"); } else { MessageBox.Show("文件更新完成,欢迎使用!"); } } } //else // MessageBox.Show("文件初始化完毕,欢迎使用!"); } catch (Exception ex) { Log.Error("[" + System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "][" + System.Reflection.MethodBase.GetCurrentMethod().Name + "] err" + ex); MessageBox.Show(ex.Message); } }
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); }