/// <summary> /// Esegue il ripristino di un backup. /// </summary> /// <param name="backupFilePath">Percorso del file zip di backup</param> public void RestoreFromFile(string backupFilePath) { ICrossPlatformSpecialFolder specialFolder = DependencyService.Get <ICrossPlatformSpecialFolder>(); string tempFolder = specialFolder.GetTemporaryFolder(); string tempExport = Path.Combine(tempFolder, "zip_restore_" + DateTime.Now.ToString("ddMMyyyy_HHmmss")); Directory.CreateDirectory(tempExport); try { ArchiveUtility.UnzipArchive(backupFilePath, tempExport); DoRestore(tempExport); } finally { if (Directory.Exists(tempExport)) { Directory.Delete(tempExport, true); } } }
/// <summary> /// Effettua il backup dei file e delle cartelle specificate, in formato ZIP. /// </summary> /// <param name="fileStream">Stream del file ZIP con il backup dei file e delle cartelle</param> /// <returns>Dimensione in byte del file di backup</returns> public async Task <long> BackupToFile(Stream fileStream) { ICrossPlatformSpecialFolder specialFolder = DependencyService.Get <ICrossPlatformSpecialFolder>(); string tempFolder = specialFolder.GetTemporaryFolder(); string tempExport = Path.Combine(tempFolder, DateTime.Now.ToString("ddMMyyyy_HHmmss")); string tempZIPFolder = Path.Combine(tempExport, "zip"); Directory.CreateDirectory(tempZIPFolder); try { foreach (string filePath in Files.Keys) { string newPath = Path.Combine(tempZIPFolder, Path.GetFileName(filePath)); File.Copy(filePath, newPath, true); } foreach (string folderPath in Folders.Keys) { string newFolder = Path.Combine(tempZIPFolder, Path.GetFileName(folderPath)); Directory.CreateDirectory(newFolder); string[] files = Directory.GetFiles(folderPath); foreach (string filePath in files) { string newPath = Path.Combine(newFolder, Path.GetFileName(filePath)); File.Copy(filePath, newPath, true); } } await ArchiveUtility.ZipArchive(fileStream, tempZIPFolder); } finally { if (Directory.Exists(tempExport)) { Directory.Delete(tempExport, true); } } return(fileStream.Length); }