public void fileSearch(TreeNode parentNode, DirectoryInfo directory) { try { ArrayList excludedFiles = Serialization.deserializeXML("files.xml"); foreach (FileInfo f in directory.GetFiles()) { if ((f.Attributes & FileAttributes.System) != FileAttributes.System) { TreeNode childNode = new TreeNode(f.Name); childNode.Checked = parentNode.Checked; childNode.ImageIndex = 1; parentNode.Nodes.Add(childNode); if (excludedFiles.Count > 0) { foreach (string str in excludedFiles) { if (childNode.Text == str) { childNode.Checked = false; } } } } } } catch (Exception e) { parentNode.Nodes.Add(new TreeNode("erreur")); Log.write("erreur lors de la récupération du chemin du fichier:" + e.Message); } }
public int calculNbFichierACopier() { ArrayList listRepertoires = Serialization.deserializeXML("folders.xml"); int nbfichiers = 0; foreach (string rep in listRepertoires) { try { nbfichiers += Directory.GetFiles(@"C:\" + rep, ".", SearchOption.AllDirectories).Length; } catch { } } return(nbfichiers); }
public void copyFiles(string s, BackgroundWorker bgw) { try { ArrayList excludedFiles = (ArrayList)Serialization.deserializeXML("files.xml"); string[] files = Directory.GetFiles(@"C:\" + s); foreach (string filePath in files) { this.fichierCopie = new DirectoryInfo(filePath).Name; string fileName; FileInfo fi = new FileInfo(filePath); fileName = fi.Name; if (!File.Exists(this.saveRoot + @".tmp\" + this.toSavedFilePathFormat(s) + @"\" + fileName)) { if (!this.estUnRaccourci(filePath)) { bool ok = true; foreach (string str in excludedFiles) { if (str == fileName) { ok = false; } } if (ok) { File.Copy(filePath, this.saveRoot + @".tmp\" + this.toSavedFilePathFormat(s) + @"\" + fileName, true); this.nbfichierscopie++; this.volumeFichiers += fi.Length; bgw.ReportProgress(nbfichierscopie); } } } } } catch (Exception e) { Log.write("erreur: "); Log.write(e.Message); Log.write("\n"); } }
private List <FolderSaveItem> CreateFolderSaveItems(List <string> foldersList) { var list = new List <FolderSaveItem>(); foldersList.ForEach(S => list.Add(new FolderSaveItem(S))); var fileList = Serialization.deserializeXML("files.xml"); list.ForEach(F => { F.Folder.GetFiles().ToList().ForEach(FI => { if (fileList.Count(X => X == FI.FullName) == 0) { F.AddItem(new FileSaveItem(FI.FullName)); } }); }); return(list); }
private void btnActualiser_Click(object sender, EventArgs e) { ArrayList pathesList = new ArrayList(); this.recursiveNodeSearch(this.treeview.Nodes[0], pathesList); try { Serialization.serializeToXML(pathesList, "folders.xml"); Serialization.serializeToXML(this.files, "files.xml"); } catch (Exception ex) { MessageBox.Show(ex.Message); } Thread th = new Thread(new ThreadStart(this.initWaitForm)); th.Start(); this.folders = Serialization.deserializeXML("folders.xml"); this.populatetreeView(); th.Abort(); }
public ConfigForm(MainForm f) { InitializeComponent(); //chargement des paramètres this.folders = Serialization.deserializeXML("folders.xml"); this.files = new ArrayList(); ImageList imgList = new ImageList(); this.treeview.ImageList = imgList; this.treeViewFichiers.ImageList = imgList; imgList.Images.Add(System.Drawing.Image.FromFile(Environment.CurrentDirectory + @"/images/dossier_windows.png")); imgList.Images.Add(System.Drawing.Image.FromFile(Environment.CurrentDirectory + @"/images/fichier.jpg")); this.NUDInterval.Value = Convert.ToDecimal(ConfigurationManager.AppSettings["period"]); this.tbHour.Text = ConfigurationManager.AppSettings["heure"]; this.tbMinutes.Text = ConfigurationManager.AppSettings["minute"]; this.tbPath.Text = ConfigurationManager.AppSettings["path"]; this.tbMDP.Text = ConfigurationManager.AppSettings["password"]; Security sec = new Security(); this.tbMDPAdmin.Text = sec.caesarToString(ConfigurationManager.AppSettings["passwordAdmin"], 15); this.numericUpDown1.Value = Convert.ToDecimal(ConfigurationManager.AppSettings["nbSaves"]); this.tbFrom.Text = ConfigurationManager.AppSettings["from"]; this.tbMDPFrom.Text = ConfigurationManager.AppSettings["MDPfrom"]; this.tbSMTP.Text = ConfigurationManager.AppSettings["SMTP"]; this.tbPort.Text = ConfigurationManager.AppSettings["port"]; this.tbTo.Text = ConfigurationManager.AppSettings["to"]; if (ConfigurationManager.AppSettings["SSL"] == "1") { this.cbSSL.Checked = true; } this.ancienInterval = this.NUDInterval.Value.ToString(); this.toolTip1.ToolTipIcon = ToolTipIcon.Warning; this.form = f; this.populatetreeView(); this.form.configFormThread.Abort(); }
private void LoadFolders() { listSaveItems = CreateFolderSaveItems(Serialization.deserializeXML("folders.xml")); }
public void execute(BackgroundWorker bgw) { //Envoi de mail en début de sauvegarde try { Mailer m = new Mailer(this); m.sendNotificationDebut(); Log.notifieDebutSauvegarde(); } catch (Exception e) { Log.write("- " + DateTime.Now.ToShortDateString() + DateTime.Now.ToShortTimeString() + ": " + e.Message + "/n"); } //Mise à de la date de dernière sauvegarde Serialization.serializeLastSaveDate(DateTime.Now); //chargement de la liste des fichiers à sauvegarder ArrayList pathesList = (ArrayList)Serialization.deserializeXML("folders.xml"); string path = this.saveRoot + @".tmp"; //création du dossier de sauvegarde de l'utilisateur try { if (Directory.Exists(path)) { Directory.Delete(path, true); } if (Directory.Exists(this.saveRoot)) { Directory.Delete(this.saveRoot, true); } Directory.CreateDirectory(path); } catch (UnauthorizedAccessException uae) { MessageBox.Show(uae.Message + Environment.NewLine + "veuillez le supprimer manuellement"); } //construction du chemin de sauvegarde des fichiers et copie des fichiers foreach (string s in pathesList) { try { if (!this.bgwk.CancellationPending) { string savedDirPath = ""; savedDirPath += path + @"\" + this.toSavedFilePathFormat(s); if (!Directory.Exists(savedDirPath)) { Directory.CreateDirectory(savedDirPath); } this.copyFiles(s, this.bgwk); } else { break; } } catch (Exception ex) { MessageBox.Show(ex.Message); } } try { Log.notifieFinSauvegarde(); Directory.Move(this.saveRoot + @".tmp", this.saveRoot); } catch (Exception e) { MessageBox.Show(e.Message); Log.write(e.Message); } }