-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Btrieve v6 support #1
base: main
Are you sure you want to change the base?
Conversation
Added support for tolerating corrupted records during reading. Updated to dotnet8
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a lot of var
-ing that's needed and some smaller stuff.
Looking good!
@@ -4,6 +4,8 @@ | |||
using MBBSEmu.Btrieve.Enums; | |||
using Microsoft.Extensions.Logging; | |||
using System.Text; | |||
using System.ComponentModel; | |||
using System.Net.Mail; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think these new imports are needed
@@ -143,6 +147,16 @@ public ushort KeyCount | |||
} | |||
} | |||
|
|||
public ushort DupOffset | |||
{ | |||
get => BitConverter.ToUInt16(_fcr, 0x72); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can make these expression-bodied members:
public ushort DupOffset => BitConverter.ToUInt16(_fcr, 0x72);
var usageCount2 = Data[PageLength + 4] | Data[PageLength + 5] << 8 | Data[PageLength + 6] << 16 | Data[PageLength + 7] << 24; | ||
// get the FCR | ||
if (usageCount1 > usageCount2) | ||
Data.AsSpan().Slice(0, PageLength).CopyTo(_fcr.AsSpan()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Dealers choice on this one, but you can use a range indexer on these now vs. slice if it starts from 0
Data.AsSpan()[..PageLength].CopyTo(_fcr.AsSpan());
LogKeyPresent = (btrieveFileContentSpan[0x10C] == 1); | ||
LogKeyPresent = (_fcr[0x10C] == 1); | ||
|
||
int[] keyOffsets = new int[KeyCount]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
var
all the things
// ACS page immediately follows FCR (the first) | ||
var offset = PageLength; | ||
var data = Data.AsSpan().Slice(offset); | ||
Span<Byte> pat1 = Data.AsSpan().Slice(PageLength * 2, PageLength); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
var
all the things
} | ||
} | ||
|
||
private bool LoadACS(ILogger logger, bool v6, int pageNumber) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This could be made void
as the return type looks like it's never evaluated
catch (ArgumentException ex) | ||
{ | ||
if (!allowCorruptedRecords) | ||
throw ex; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should just be throw
if you want to throw the exception that was caught
/// <summary> | ||
/// Gets the complete variable length data from the specified <paramref name="recordOffset"/>, | ||
/// walking through all data pages and returning the concatenated data. | ||
/// </summary> | ||
/// <param name="first">Fixed record pointer offset of the record from a data page</param> | ||
/// <param name="stream">MemoryStream containing the fixed record data already read.</param> | ||
private byte[] GetVariableLengthData(uint recordOffset, MemoryStream stream) { | ||
private byte[] GetVariableLengthData(uint recordOffset, MemoryStream stream, bool v6) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit Update the XML documentation to match the new signature
@@ -554,8 +736,12 @@ private bool IsUnusedRecord(ReadOnlySpan<byte> fixedRecordData) | |||
var offsetPointer = (uint)PageLength - 2u * (fragment + 1u); | |||
var (offset, nextPointerExists) = GetPageOffsetFromFragmentArray(page.Slice((int)offsetPointer, 2)); | |||
|
|||
// check offset for corruption now? | |||
if (offset < 0xC) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because of this, we can remove the check on 763
Not sure if variable data length reading is 100% correct, but it can handle simple fixed length v6 databases.
Give it a run through and tell me how bad my C# is