private void cmd_BackUp_Click(object sender, EventArgs e) { string strVer = GetVer(); try { if (!string.IsNullOrEmpty(txt_BuildNo.Text)) { panel1.Enabled = false; progressBar1.Value = 0; progressBar1.Enabled = true; progressBar1.Maximum = 10000; progressBar1.Visible = true; string SourcePatch = ""; string strTime = Classes.Modfunction.datetime_today.ToString("yyyyMMdd") + "_" + DateTime.Now.ToString("HHmm"); if (!string.IsNullOrEmpty(strUpdateZipTime)) { strTime = strUpdateZipTime; } if (!string.IsNullOrEmpty(cbo_SpecialName.Text)) { string strSpecialName = "Special-" + cbo_SpecialName.Text.Replace(" ", ""); strTime += "(" + strSpecialName + ")"; } if (!string.IsNullOrEmpty(txtFolder.Text)) { SourcePatch = txtFolder.Text; string NewP = Classes.Modfunction.baseDPath + @"New SysFreight Source_" + strVer.Replace(".", "_") + "_" + txt_BuildNo.Text.Trim().ToString() + "_" + strTime; if (Directory.Exists(NewP)) { AWF.Classes.Modfunction.DeleteFilesAndFolders(NewP); } DirectoryInfo DInfo = new DirectoryInfo(SourcePatch); try { DInfo.MoveTo(NewP); SourcePatch = NewP; } catch (Exception ex) { SourcePatch = ""; MessageBox.Show(ex.Message.ToString()); } } else { SourcePatch = Classes.Modfunction.baseDPath + "New SysFreight Source " + strVer.Replace(".", ""); } string ZipName = Classes.Modfunction.baseDPath + "New SysFreight Source_" + strVer.Replace(".", "_") + "_" + txt_BuildNo.Text.Trim().ToString() + "_" + strTime + ".zip"; Classes.ZipThread thZip = new Classes.ZipThread(SourcePatch, ZipName); thZip.start(); while (thZip.threadState() == System.Threading.ThreadState.Running) { Application.DoEvents(); if (progressBar1.Value == progressBar1.Maximum) { progressBar1.Value = 0; } progressBar1.Value += 1; } thZip.abort(); progressBar1.Visible = false; panel1.Enabled = true; progressBar1.Enabled = false; if (File.Exists(ZipName)) { StartKiller(); MessageBox.Show("BackUp Successful!", "Message"); Environment.Exit(0); } else { MessageBox.Show("BackUp Faild!"); } } else { MessageBox.Show("请输入版本修订号! and make sure of right directory of SourceCode."); } } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { GC.Collect(); } }
private void cmd_Published2Zip_Click(object sender, EventArgs e) { panel1.Enabled = false; progressBar1.Value = 0; progressBar1.Maximum = 1000; progressBar1.Enabled = true; progressBar1.Visible = true; string strVer = GetVer(); string update_publish_path = AWF.Classes.Modfunction.baseDPath + @"PublishFolder\sysfreightupdate\publish"; string filepath = Classes.Modfunction.baseDPath + @"PublishFolder\sysfreight"; try { AWF.Classes.Modfunction.DeleteFilesAndFolders(update_publish_path); if (!Directory.Exists(update_publish_path)) { Directory.CreateDirectory(update_publish_path); } AWF.Classes.Modfunction.copyFilesAndFolders(update_publish_path, filepath); if (!string.IsNullOrEmpty(txt_BuildNo.Text)) { string verName = "sysfreightupdate_" + strVer.Replace(".", "_") + "_"; string strTime = Classes.Modfunction.datetime_today.ToString("yyyyMMdd") + "_" + DateTime.Now.ToString("HHmm"); strUpdateZipTime = strTime; if (!string.IsNullOrEmpty(cbo_SpecialName.Text)) { string strSpecialName = "Special-" + cbo_SpecialName.Text.Replace(" ", ""); strTime += "(" + strSpecialName + ")"; } string ogFileName = verName + txt_BuildNo.Text.Trim().ToString() + "_" + strTime; string ZipName = Classes.Modfunction.baseDPath + @"PublishFolder\" + ogFileName + ".zip"; string SourcePatch = Classes.Modfunction.baseDPath + @"PublishFolder\sysfreightupdate"; string tempFolder_Master = ZipName.Substring(0, ZipName.Length - 4); string tempFolder_Sub = tempFolder_Master + "\\" + ogFileName; Directory.CreateDirectory(tempFolder_Master); DirectoryInfo DInfo = new DirectoryInfo(SourcePatch); DInfo.MoveTo(tempFolder_Sub); Classes.ZipThread thPub2Zip = new Classes.ZipThread(tempFolder_Master, ZipName); //Thread thPub2Zip = new Thread(delegate() { }); thPub2Zip.start(); while (thPub2Zip.threadState() == System.Threading.ThreadState.Running) { Application.DoEvents(); if (progressBar1.Value == progressBar1.Maximum) { progressBar1.Value = 0; } progressBar1.Value += 1; } thPub2Zip.abort(); progressBar1.Visible = false; panel1.Enabled = true; progressBar1.Enabled = false; if (File.Exists(ZipName)) { string xlsFolder = Classes.Modfunction.datetime_today.ToString("yyMMdd") + " Update(" + "Version " + strVer + "." + txt_BuildNo.Text.Trim().ToString() + ")"; if (!string.IsNullOrEmpty(cbo_SpecialName.Text)) { string strSpecialName = "Special-" + cbo_SpecialName.Text.Replace(" ", ""); xlsFolder = Classes.Modfunction.datetime_today.ToString("yyMMdd") + " Update(" + "Version " + strVer + "." + txt_BuildNo.Text.Trim().ToString() + ")(" + strSpecialName + ")"; } string xls = Classes.Modfunction.baseDPath + @"SysFreight Update\EXCEL\" + xlsFolder; if (Directory.Exists(xls)) { File.Move(ZipName, xls + @"\" + verName + txt_BuildNo.Text.Trim().ToString() + "_" + strTime + ".zip"); } MessageBox.Show("Published to Zip Successful!"); } else { MessageBox.Show("Published to Zip Faild!"); string path = @"D:\PublishFolder\sysfreightupdate\publish"; System.Diagnostics.Process.Start("explorer.exe", path); } DirectoryInfo DInfoNew = new DirectoryInfo(tempFolder_Sub); DInfoNew.MoveTo(SourcePatch); if (Directory.Exists(tempFolder_Master)) { Directory.Delete(tempFolder_Master); } } else { MessageBox.Show("请输入版本修订号!"); } } catch (Exception ex) { Log.Debug(ex.Message, ex); } finally { GC.Collect(); } }