using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace UpdateVersion
{
public partial class Form1 : Form
{
List<string> listFiles = new List<string>();
double countFiles = 0.0;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
backgroundWorker1.RunWorkerAsync();
}
private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
{
listFiles = CopyFolder("D:\\Datas", "D:\\Backup");
countFiles = 100.0 / listFiles.Count;
for(int i=1;i<=listFiles.Count;i++)
{
backgroundWorker1.ReportProgress(i);
if (i == listFiles.Count)
Thread.Sleep(500);
Thread.Sleep(50);
}
}
private void backgroundWorker1_ProgressChanged(object sender, ProgressChangedEventArgs e)
{
progressBarValue.Value = (int)(countFiles * e.ProgressPercentage);
this.label1.Text = "Update to "+ listFiles[e.ProgressPercentage-1].ToString();
}
private void backgroundWorker1_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
{
this.label1.Text = "Update completed!!!!";
Thread.Sleep(1000);
// Process.Start("D:\\Backup\\UpdateVersion.exe");
Application.Exit();
}
static public List<string> CopyFolder(string sourceFolder, string destFolder)
{
List<string> listfile = new List<string>();
if (!Directory.Exists(destFolder))
Directory.CreateDirectory(destFolder);
string[] files = Directory.GetFiles(sourceFolder);
foreach (string file in files)
{
string name = Path.GetFileName(file);
string dest = Path.Combine(destFolder, name);
File.Copy(file, dest,true);
listfile.Add(dest);
}
string[] folders = Directory.GetDirectories(sourceFolder);
foreach (string folder in folders)
{
string name = Path.GetFileName(folder);
string dest = Path.Combine(destFolder, name);
CopyFolder(folder, dest);
listfile.Add(dest);
}
return listfile;
}
}
}