public void BackupGame(SteamdumpGameMetadata input, FileInfo outputFile) { if (outputFile.Exists) { throw new FileAlreadyExistsException(outputFile.FullName); } XmlCommentary xc = new XmlCommentary(); xc.magic = "Azusa Steam Dumper"; xc.acfName = input.acfFile.Name; xc.acfContent = File.ReadAllText(input.acfFile.FullName); XmlSerializer xs = new XmlSerializer(xc.GetType()); StringWriter sw = new StringWriter(); xs.Serialize(sw, xc); TextWriterLogAdapter twla = new TextWriterLogAdapter(); ZipFile zip = new ZipFile(outputFile.FullName, twla, Encoding.UTF8); DirectoryInfo gameRoot = input.rootDirectory; FileInfo[] gameFiles = gameRoot.GetFiles("*", SearchOption.AllDirectories); string cutoff = gameRoot.FullName; zip.SaveProgress += (sender, e) => { TextWriterLogAdapter.LogCallback.SetProgress(e); }; zip.AddDirectory(gameRoot.FullName); zip.Comment = sw.ToString(); zip.Save(); }
public void RestoreGame(FileInfo inputFile) { TextWriterLogAdapter twla = new TextWriterLogAdapter(); ZipFile zipFile = new ZipFile(inputFile.FullName, twla, Encoding.UTF8); zipFile.ExtractProgress += (sender, e) => { TextWriterLogAdapter.LogCallback.SetProgress(e); }; StringReader sr = new StringReader(zipFile.Comment); XmlSerializer xs = new XmlSerializer(typeof(XmlCommentary)); XmlCommentary xml = (XmlCommentary)xs.Deserialize(sr); if (!xml.magic.StartsWith("Azusa Steam")) { throw new ArgumentException(nameof(inputFile)); } string name = null; string installdir = null; StringReader acfReader = new StringReader(xml.acfContent); do { string acfLine = acfReader.ReadLine(); if (string.IsNullOrEmpty(acfLine)) { break; } if (acfLine.Contains("\"name\"")) { name = acfLine.Split(new char[] { '\t' }, StringSplitOptions.RemoveEmptyEntries)[1].Replace("\"", ""); } if (acfLine.Contains("\"installdir\"")) { installdir = acfLine.Split(new char[] { '\t' }, StringSplitOptions.RemoveEmptyEntries)[1].Replace("\"", ""); } if (name != null && installdir != null) { break; } } while (true); DirectoryInfo libPath = GetLibraryPath(); DirectoryInfo zipExtractOutputDir = new DirectoryInfo(Path.Combine(libPath.FullName, installdir)); zipFile.ExtractAll(zipExtractOutputDir.FullName, ExtractExistingFileAction.DoNotOverwrite); DirectoryInfo acfOutputDir = libPath.Parent; FileInfo acfFile = new FileInfo(Path.Combine(acfOutputDir.FullName, xml.acfName)); File.WriteAllText(acfFile.FullName, xml.acfContent); }