1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132
|
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Diagnostics;
using System.Collections;
using System.Net.NetworkInformation;
using Microsoft.Win32;
namespace OutilMigration
{
public partial class Form_Main : Form
{
// ----- VARIABLES GLOBALES ----- //
private int compteurmc = 0;
private string TempPath = Environment.GetEnvironmentVariable("tmp");
private string CurrentPath = Directory.GetCurrentDirectory();
ArrayList lmc = new ArrayList();
//Fonction copie des dossiers
private static void DirectoryCopy(string sourceDirName, string destDirName, bool copySubDirs)
{
try
{
//Get the subdirectories for the specified directory.
DirectoryInfo dir = new DirectoryInfo(sourceDirName);
DirectoryInfo[] dirs = dir.GetDirectories();
if (!Directory.Exists(sourceDirName))
{
MessageBox.Show("chemin non trouvé");
}
// If the destination directory doesn't exist, create it.
if (!Directory.Exists(destDirName))
{
Directory.CreateDirectory(destDirName);
}
// Get the files in the directory and copy them to the new location.
FileInfo[] files = dir.GetFiles();
foreach (FileInfo file in files)
{
string temppath = Path.Combine(destDirName, file.Name);
//Attribut lecture seule mise à false pour tout les fichiers copiés
file.IsReadOnly = false;
file.CopyTo(temppath, false);
}
// If copying subdirectories, copy them and their contents to new location.
if (copySubDirs)
{
foreach (DirectoryInfo subdir in dirs)
{
string temppath = Path.Combine(destDirName, subdir.Name);
DirectoryCopy(subdir.FullName, temppath, copySubDirs);
}
}
}
catch (DirectoryNotFoundException dnfe)
{
MessageBox.Show(dnfe.Message.ToString(), "Erreur", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
catch ( FileNotFoundException fnfe)
{
MessageBox.Show(fnfe.Message.ToString());
}
}
//*******************************************************************************************************//
//Gestion de la récupération du des fichiers et des registres avec BackgroundWorker
//*******************************************************************************************************//
//Création d'un backgroundworker pour récuperation fichiers et registres
private void StartProcessCopie(int nbmachinesel)
{
BackgroundWorker worker = new BackgroundWorker();
worker.WorkerReportsProgress = false;
worker.DoWork += ProcessAsyncCopie;
worker.RunWorkerCompleted += ResultProcessCopie;
worker.RunWorkerAsync(nbmachinesel);
}
//Fonction de recupération des fichiers et registres
void ProcessAsyncCopie(object sender, DoWorkEventArgs e)
{
for (int i = 0; i <= (int)e.Argument; i++)
{
switch (lmc[i].ToString().Substring(4))
{
case "BC":
if (Directory.Exists(TempPath + "\\SYSTEME\\" + lmc[i].ToString()))
{
Directory.Delete(TempPath + "\\SYSTEME\\" + lmc[i].ToString(), true);
}
DirectoryCopy("\\\\" + lmc[i].ToString() + "\\SYSTEME\\bdd", TempPath + "\\SYSTEME\\" + lmc[i].ToString() + "\\bdd", true);
DirectoryCopy("\\\\" + lmc[i].ToString() + "\\SYSTEME\\son", TempPath + "\\SYSTEME\\" + lmc[i].ToString() + "\\son", true);
DirectoryCopy("\\\\" + lmc[i].ToString() + "\\SYSTEME\\symbole", TempPath + "\\SYSTEME\\" + lmc[i].ToString() + "\\symbole", true);
break;
case "BC2":
if (Directory.Exists(TempPath + "\\SYSTEME\\" + lmc[i].ToString()))
{
Directory.Delete(TempPath + "\\SYSTEME\\" + lmc[i].ToString(), true);
}
DirectoryCopy("\\\\" + lmc[i].ToString() + "\\SYSTEME\\son", TempPath + "\\SYSTEME\\" + lmc[i].ToString() + "\\son", true);
DirectoryCopy("\\\\" + lmc[i].ToString() + "\\SYSTEME\\symbole", TempPath + "\\SYSTEME\\" + lmc[i].ToString() + "\\symbole", true);
break;
default:
MessageBox.Show("Pas de récupération");
break;
}
}
}
void ResultProcessCopie(object sender, RunWorkerCompletedEventArgs e)
{
MessageBox.Show("Récupération terminée", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
private void btn_migration_Click(object sender, EventArgs e)
{
StartProcessCopie(compteurmc);
} |
Partager