private void button1_Click(object sender, EventArgs e) { try { this.Enabled = false; var N = dataGridView1.SelectedRows.Count; progressBar1.Visible = true; Exception err = null; for (int i = N - 1; i >= 0; i--) { try { var r = dataGridView1.SelectedRows[i]; var saved_file = r.Cells[1].Value + ""; var f_local = r.Cells[0].Value + ""; if (File.Exists(saved_file)) { continue; } File.Copy(f_local, saved_file); if (File.Exists(saved_file)) { var f1 = new FileInfo(f_local); var f2 = new FileInfo(saved_file); bi.AddedFilesCount++; bi.TotalSizeAdded += f1.Length; bi.SaveAgain(); f2.CreationTimeUtc = f1.CreationTimeUtc; f2.LastWriteTimeUtc = f1.LastWriteTimeUtc; f2.LastWriteTime = f1.LastWriteTime; f2.CreationTime = f1.CreationTime; } progressBar1.Value = 1 + (int)(98 - 98.0 * i / N); progressBar1.Refresh(); Application.DoEvents(); r.Selected = false; } catch (Exception ex) { err = ex; } } if (err != null) { throw err; } Close(); } catch { } finally { this.Enabled = true; } }
private void backgroundWorker_backup_DoWork(object sender, DoWorkEventArgs e) { var empty_dir = false; try { if (textBox_local.Text.Trim() == "-") { var dir = Path.GetTempPath() + "\\temp_proj_dir\\"; if (!Directory.Exists(dir)) { Directory.CreateDirectory(dir); } try { File.WriteAllText(dir + "empty.txt", ""); } catch { } git.local_dirs = new List <string> { dir }; empty_dir = true; } var sw = new System.Diagnostics.Stopwatch(); sw.Start(); warning_files = new List <string[]>(); git.progress = (p, state) => { if (p == -100) { warning_files.Add((string[])state); } else { UpdateProgress(p, state + ""); } return(null); }; git.settings.ignor_obj = ObjToolStripMenuItem.Checked; git.settings.ignor_rst = rstToolStripMenuItem.Checked; git.settings.ignor_baktmpasv = baktmpasvToolStripMenuItem.Checked; git.settings.warnin_larg_files = largfilesToolStripMenuItem.Checked; last_backup_info = git.BackUp(); if (last_backup_info.InfoSection == null) { last_backup_info.InfoSection = last_backup_info.InfoFile.AddSection("info"); } last_backup_info.InfoSection["server"] = git.server_dir; last_backup_info.InfoSection["local"] = project.LocalPath.Replace("\r", "").Replace("\n", " ; "); last_backup_info.InfoSection["BackUpSkipPattern"] = project.BackUpSkipPattern.Replace("\r", "").Replace("\n", " ; "); last_backup_info.InfoSection["machine"] = Environment.UserName + "@" + Environment.MachineName; last_backup_info.InfoSection["user"] = textBox_user.Text;; last_backup_info.InfoSection["backup-duration"] = new TSpan((int)sw.Elapsed.TotalSeconds).ToString(true); last_backup_info.ProjectSection["name"] = project.Name; last_backup_info.ProjectSection["backup_by"] = db.user.ID; last_backup_info.ProjectSection["code"] = project.code; last_backup_info.ProjectSection["manager"] = project.Manager; last_backup_info.ProjectSection["total-time"] = project.SumTimes().ToString(false); if (project.Times.Count > 0) { last_backup_info.ProjectSection["first-date"] = Utils.DateString(project.Times[0].Start); last_backup_info.ProjectSection["last-date"] = Utils.DateString(project.LastTime.End); } last_backup_info.SaveAgain(); project.LastBackup = DateTime.Now; { var proj_name = new IniFile(); var file = git.server_dir + "\\..\\نام پروژه ها.ini"; if (File.Exists(file)) { proj_name.Load(file); } var sec = proj_name.AddSection(db.user.name.Replace(" ", "_")); sec.AddKey(project.code.Replace(" ", "_"), project.Name); if (proj_name.changed) { proj_name.Save(file); } } } catch (Exception ex) { e.Result = ex; } finally { if (empty_dir) { textBox_local.Text = "-"; } } }