static void Main(string[] args) { if (args.Length != 2) { Console.WriteLine("Need two arguments"); return; } string inputFileName = args[0]; string outputFileName = args[1]; try { FoundRecord[] found = MstRecover64 .FindRecords(inputFileName) .Where(record => (record.Flags & (int)RecordStatus.LogicallyDeleted) == 0) .ToArray(); Console.WriteLine("Records found: {0}", found.Length); using (StreamWriter output = File.CreateText(outputFileName)) using (MstFile64 input = new MstFile64(inputFileName, DirectAccessMode.ReadOnly)) { foreach (FoundRecord info in found) { Console.WriteLine ( "MFN {0}: ver {1} status {2}", info.Mfn, info.Version, info.Flags ); MstRecord64 mstRecord = input.ReadRecord(info.Position); MarcRecord marcRecord = mstRecord.DecodeRecord(); PlainText.WriteRecord(output, marcRecord); } } } catch (Exception exception) { Console.WriteLine(exception); } }
static void Main(string[] args) { if (args.Length != 2) { Console.WriteLine("Need two arguments"); return; } string inputFileName = args[0] .ThrowIfNull("inputFileName"); string outputFileName = args[1] .ThrowIfNull("outputFileName"); string mstFileName = Path.ChangeExtension(outputFileName, ".mst") .ThrowIfNull("mstFileName"); string xrfFileName = Path.ChangeExtension(outputFileName, ".xrf") .ThrowIfNull("xrfFileName"); Stopwatch stopwatch = new Stopwatch(); stopwatch.Start(); try { DirectUtility.CreateMasterFile64(outputFileName); int mfn = 0; using (Stream mstFile = new FileStream(mstFileName, FileMode.Open, FileAccess.ReadWrite, FileShare.None)) using (Stream xrfFile = File.OpenWrite(xrfFileName)) using (StreamReader reader = File.OpenText(inputFileName)) { MstControlRecord64 control = new MstControlRecord64 { NextPosition = MstControlRecord64.RecordSize }; control.Write(mstFile); MarcRecord marcRecord; while ((marcRecord = PlainText.ReadRecord(reader)) != null) { if (mfn % 100 == 0) { Console.Write(" {0} ", mfn); } marcRecord.Mfn = ++mfn; marcRecord.Version = 1; marcRecord.Status = RecordStatus.Last; long position = mstFile.Position; MstRecord64 mstRecord = MstRecord64.EncodeRecord(marcRecord); mstRecord.Prepare(); mstRecord.Write(mstFile); xrfFile.WriteInt64Network(position); xrfFile.WriteInt32Network((int)RecordStatus.NonActualized); } if (mfn != 0) { // Update the control record long nextPosition = mstFile.Length; mstFile.Seek(0, SeekOrigin.Begin); control = MstControlRecord64.Read(mstFile); control.Blocked = 0; control.NextMfn = mfn; control.NextPosition = nextPosition; mstFile.Seek(0, SeekOrigin.Begin); control.Write(mstFile); } } Console.WriteLine(" Total: {0}", mfn); } catch (Exception exception) { Console.WriteLine(exception); } stopwatch.Stop(); TimeSpan elapsed = stopwatch.Elapsed; Console.WriteLine("Elapsed: {0}", elapsed.ToAutoString()); }