public void RecoverInfosTest() { RecoverInfos ris = new RecoverInfos(); ris.addRawRecord("C:\\ciao.txt\r\n0000000000000000abcdefghabcdefghabcdefghabcdefgh\r\n", 1); var res = ris.getRecoverUniqueList(); RecoverRecord rr = res[0]; Assert.AreEqual("C:\\ciao.txt", rr.rf.nameAndPath); Assert.AreEqual("abcdefghabcdefghabcdefghabcdefgh", rr.rf.hash); Assert.AreEqual(-1, rr.rf.size); Assert.AreEqual(new DateTime(1970, 1, 1, 1, 0, 0), rr.rf.lastModified); }
public void askForSingleFile(RecoverRecord rr) { FileStream fout; string localFileName; MyLogger.print("Ripristino file in corso..."); sendToServer(commRecoverFile); waitForAck(commCmdAckFromServer); try { if (File.Exists(rr.rf.nameAndPath)) { //chiede se sovrascrivere string message = "file già esistente. si desidera sovrascriverlo?"; string caption = "Attenzione!"; bool wantOverwrite = (bool)mainWindow.recoverW.Dispatcher.Invoke(mainWindow.recoverW.DelYesNoQuestion, message, caption); if (!wantOverwrite) { //salvare con nome throw new IOException("need to save with name"); } } else { Directory.CreateDirectory(System.IO.Path.GetDirectoryName(rr.rf.nameAndPath)); } localFileName = rr.rf.nameAndPath; fout = File.Open(localFileName, FileMode.OpenOrCreate); } catch (Exception e) when (e is IOException || e is UnauthorizedAccessException) { //file omonimo esiste già o altri errori nell'aprire il file. apro una dialog di salvataggio Microsoft.Win32.SaveFileDialog sfd = new Microsoft.Win32.SaveFileDialog(); sfd.InitialDirectory = mainWindow.settings.getRootFolder(); sfd.FileName = rr.rf.getJustName(); Nullable<bool> result = sfd.ShowDialog(); localFileName = sfd.FileName; if (result == true) { try { fout = File.Open(localFileName, FileMode.Create); } catch (Exception) { //mainWindow.Dispatcher.Invoke(mainWindow.DelShowOkMsg, "Impossibile aprire il file", MessageBoxImage.Error); MyLogger.popup("Impossibile aprire il file. Operazione Annullata\n", MessageBoxImage.Error); MyLogger.print("Impossibile aprire il file. Operazione Annullata\n"); //annullo richiesta recupero di questo file return; } } else { MyLogger.print("Operazione Annullata\n"); //annullo richiesta recupero di questo file return; } } //invio nome singolo file sendToServer(rr.rf.nameAndPath + "\r\n" + rr.backupVersion.ToString() + "\r\n"); System.DateTime LastModifyDate; try { //ricevi contenuto file LastModifyDate = RecFileContent(localFileName, fout); } catch (CancelFileRequestException) { MyLogger.print("Operazione Annullata\n"); fout.Close(); deleteFile(localFileName); return; } catch (IOException) { MyLogger.popup("Impossibile accedere al file. Operazione annullata.", MessageBoxImage.Error); fout.Close(); deleteFile(localFileName); return; } fout.Close(); FileInfo fi = new FileInfo(localFileName); fi.LastWriteTime = LastModifyDate; MyLogger.print("completato.\n"); }
public recoverListEntry(RecoverRecord rRec) { this.rr = rRec; this.Name = rRec.rf.nameAndPath; this.lastMod = rRec.rf.lastModified.ToString(); }