public void Restore(World world) { if (world.BackupPath == null) throw new ArgumentNullException("world.BackupPath"); // aaaEAP7Z4wQ= // EA0AAIogCQA= // KvMEAEZT4wQ= string[] alphaNum = { "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9"}; var n = DateTime.Now; string compactDate = alphaNum[n.Year - 2015] + alphaNum[n.Month] + alphaNum[n.Day] + alphaNum[n.Hour] + alphaNum[n.Minute] + alphaNum[n.Second]; string restorePath = Path.Combine(this.WorldFolder, "MCBR" + compactDate + "1="); if(Directory.Exists(restorePath)) restorePath = Path.Combine(this.WorldFolder, "MCBR" + compactDate + "2="); Directory.CreateDirectory(restorePath); ZipFile.ExtractToDirectory(world.BackupPath, restorePath); }
public void Backup(World world) { if (world.Name == null) throw new ArgumentNullException("world.Name"); var zipFileName = string.Format("{0}_{1:yyyy-MM-dd_HHmmss}{2}", world.Name, DateTime.Now, settings.BackupExtension); var zipPath = Path.Combine(BackupFolder, zipFileName); ZipFile.CreateFromDirectory(world.Folder, zipPath); using (FileStream zipToOpen = new FileStream(zipPath, FileMode.OpenOrCreate)) { using (ZipArchive archive = new ZipArchive(zipToOpen, ZipArchiveMode.Update)) { ZipArchiveEntry readmeEntry = archive.CreateEntry(settings.BackupDataFile); using (StreamWriter writer = new StreamWriter(readmeEntry.Open())) { writer.WriteLine(world.SerializeXML()); } } } }