public void CreateAndLoadDFDocWithTwoFilesTest() { var dfDoc = CreateDocWithTwoFiles(); using var ms = new MemoryStream(); dfDoc.Save(ms); Assert.True(ms.Length > 0); ms.Seek(0, SeekOrigin.Begin); var loadedDoc = DFDoc.Load(ms); Assert.True(loadedDoc.Count == 2); Assert.Equal(dfDoc.Count, loadedDoc.Count); CheckDoc(0); CheckDoc(1); void CheckDoc(int index) { var oldDoc = dfDoc[index]; var newDoc = loadedDoc[index]; var oldDocInfo = oldDoc.Document; var newDocInfo = newDoc.Document; var oldContent = oldDoc.Content; var newContent = newDoc.Content; Assert.Equal(oldDocInfo.Filename, newDocInfo.Filename); Assert.Equal(oldDocInfo.Target, newDocInfo.Target); Assert.Equal(oldContent.Length, newContent.Length); Assert.Equal((IEnumerable <byte>)oldContent, (IEnumerable <byte>)newContent); } }
static void Main(string[] args) { if (args.Length < 2) { Console.WriteLine("DATAflor.DfDoc.Tool.exe (filename) (directory)"); Console.WriteLine("(filename) is the path to a DFDoc-File"); Console.WriteLine("(directory) is the path to a directory where the data is extracted to"); return; } string filePath = args[0]; if (!System.IO.File.Exists(filePath)) { Console.WriteLine($"File {filePath} not found."); return; } string directory = args[1]; if (!System.IO.Directory.Exists(directory)) { Console.WriteLine($"Directory {directory} not found."); return; } try { using var stream = new System.IO.FileStream(filePath, System.IO.FileMode.Open, System.IO.FileAccess.Read); var dfDoc = DFDoc.Load(stream); foreach ((DocumentType Document, byte[] Content)entry in dfDoc.Entries()) { string targetName = System.IO.Path.Combine(directory, entry.Document.Filename); Console.WriteLine($"Extracting {entry.Document.Filename} to {targetName}"); if (System.IO.File.Exists(targetName)) { System.IO.File.SetAttributes(targetName, System.IO.FileAttributes.Normal); System.IO.File.Delete(targetName); } System.IO.File.WriteAllBytes(targetName, entry.Content); } } catch (InvalidFileformatException e) { Console.WriteLine("Error reading file\n" + e); } catch (Exception e) { Console.WriteLine(e); } }