private void btnLoadAll_Click(object sender, EventArgs e) { if (ofdZip.ShowDialog() == DialogResult.OK) { List <string> projectList = new List <string>(); if (File.Exists(Path.Combine(DataDir, "projectList.lst"))) { projectList.AddRange(File.ReadAllLines(Path.Combine(DataDir, "projectList.lst"))); } foreach (string s in ofdZip.FileNames) { //生成本地目录 FileInfo fi = new FileInfo(s); string destDir = Path.Combine(DataDir, fi.Name.Replace(".zip", string.Empty) + "_" + DateTime.Now.Ticks); //解压需要导入的包 FileZipOpr fzo = new FileZipOpr(); fzo.UnZipFile(s, destDir, string.Empty, true); projectList.Add(destDir); File.WriteAllLines(Path.Combine(DataDir, "projectList.lst"), projectList.ToArray()); UpdateProjectList(); } } }
private void btn_upload_Click(object sender, EventArgs e) { int count = 0; string filelist = string.Empty; if (cb_zip.Checked) { if (filepathlist.Count() == 0) { return; } string path = filepathlist[0].FilePath; string rootpath = Path.GetDirectoryName(path); string verdir = rootpath + "\\" + txb_ver.Text; if (Directory.Exists(verdir)) { Directory.Delete(verdir, true); } Directory.CreateDirectory(verdir); foreach (var filepath in filepathlist) { File.Copy(filepath.FilePath, verdir + "\\" + filepath.FileName); } FileZipOpr zipOpr = new FileZipOpr(); string deszip = verdir + ".zip"; zipOpr.ZipFileDirectory(verdir, deszip); Directory.Delete(verdir, true); count = RequestUpload(deszip); UpdateSysVer(count, Path.GetFileName(deszip), true); File.Delete(deszip); } else { foreach (var file in filepathlist) { filelist += file.FileName + ","; count = RequestUpload(file.FilePath); if (count == 0) { break; } } filelist = UpdateSysVer(count, filelist, false); } }
private void btn_upgrade_Click(object sender, EventArgs e) { string amb = Application.StartupPath + "\\" + program; FileVersionInfo fvi = FileVersionInfo.GetVersionInfo(amb); string verstring = fvi.FileVersion; if (verstring == sysVer.sysver) { MetroMessageBox.Show(this, "该版本为最新版本,无需升级!"); return; } string filepath = Application.StartupPath + "\\"; string ver = sysVer.sysver + "/"; bool zip = false; foreach (var str in filstr) { probar.Value = 0; int d = fileLoadPresent.DownLoadFile(ver + str, filepath + str, probar); if (d == 0) { MetroMessageBox.Show(this, "升级文件出错,请联系管理员"); return; } zip = str.EndsWith(".zip"); } if (zip) { FileZipOpr zipOpr = new FileZipOpr(); zipOpr.UnZipFile(filepath + filstr[0], filepath, "", true); File.Delete(filepath + filstr[0]); } progressTool.RunProcess(program); this.Close(); }
private void bwWorkers_DoWork(object sender, DoWorkEventArgs e) { try { printHint("正在准备数据,请稍等......"); #region 初始化目录 //InitProjectDir("P" + Process.GetCurrentProcess().Id + "-Project"); Program.TryInitProjectDir("Current"); if (StartupParams.Length >= 1) { //需要导入文件 FileZipOpr fzo = new FileZipOpr(); if (StartupParams[0] != null) { if (StartupParams[0].StartsWith("Export:")) { printHint("正在导出数据,请稍等......"); //导出 string toZipFile = StartupParams[0].Replace("Export:", string.Empty); string toZipDir = new FileInfo(toZipFile).DirectoryName; //string docFile = Path.Combine(toZipDir, "申报书.doc"); //if (File.Exists(docFile)) //{ // File.Copy(docFile, Path.Combine(MainForm.ProjectDir, "申报书.doc"), true); //} //打包文件 fzo.ZipFileDirectory(MainForm.ProjectDir, toZipFile); //删除临时Doc文件 //File.Delete(Path.Combine(MainForm.ProjectDir, "申报书.doc")); } else if (StartupParams[0].StartsWith("Clear:")) { printHint("正在清理数据,请稍等......"); Directory.Delete(MainForm.ProjectDir, true); Program.TryInitProjectDir("Current"); //复制摘要模板 //File.Copy(Path.Combine(Application.StartupPath, Path.Combine("Helper", "xiangmuzhaiyaomoban.rtf")), Path.Combine(MainForm.ProjectFilesDir, "rtpinput_0.rtf"), true); } else { //导入 printHint("正在导入数据,请稍等......"); //检查是否需要备份 if (StartupParams != null && StartupParams.Length >= 2 && StartupParams[1] != null && StartupParams[1].Length >= 2) { //备份当前的数据库 if (Directory.Exists(Path.Combine(MainForm.BaseDir, StartupParams[1]))) { Directory.Delete(Path.Combine(MainForm.BaseDir, StartupParams[1]), true); } Directory.Move(MainForm.ProjectDir, Path.Combine(MainForm.BaseDir, StartupParams[1])); } else { //删除当前目录 if (Directory.Exists(MainForm.ProjectDir)) { Directory.Delete(MainForm.ProjectDir, true); } } //创建新目录 Directory.CreateDirectory(MainForm.ProjectDir); //解压需要导入的包 fzo.UnZipFile(StartupParams[0], MainForm.ProjectDir, string.Empty, true); } } //打开DB文件连接 Program.TryOpenProjectDirDB(); } else { //打开DB文件连接 Program.TryOpenProjectDirDB(); //复制摘要模板 if (!File.Exists(Path.Combine(MainForm.ProjectFilesDir, "rtpinput_0.rtf"))) { File.Copy(Path.Combine(Application.StartupPath, Path.Combine("Helper", "xiangmuzhaiyaomoban.rtf")), Path.Combine(MainForm.ProjectFilesDir, "rtpinput_0.rtf")); } } #endregion printHint("正在启动中,请稍等......"); #region 启动窗体 if (IsHandleCreated) { Invoke(new MethodInvoker(delegate() { try { //显示主窗体 MainForm logicform = new MainForm(); Program.context.MainForm = logicform; logicform.InitAll(); logicform.Show(); //关闭欢迎窗体 WelcomeForm startform = (WelcomeForm)Program.context.Tag; startform.Close(); } catch (Exception exxx) { MessageBox.Show("启动失败!Ex:" + exxx.ToString(), "错误", MessageBoxButtons.OK); } })); } else { throw new Exception("数据没有准备好!"); } #endregion } catch (Exception exxx) { MessageBox.Show("启动失败!Ex:" + exxx.ToString(), "错误", MessageBoxButtons.OK); //重新启动 System.Diagnostics.Process.Start(Application.ExecutablePath); //退出当前程序 Application.Exit(); } }