Skip to content

Commit 0638998

Browse files
committed
Use auto-fields where possible
1 parent ad31139 commit 0638998

File tree

8 files changed

+218
-345
lines changed

8 files changed

+218
-345
lines changed

SabreTools.Serialization/Wrappers/CFB.cs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ public byte[] MiniStreamData
3737
get
3838
{
3939
// Use the cached value, if it exists
40-
if (_miniStreamData != null)
41-
return _miniStreamData;
40+
if (field != null)
41+
return field;
4242

4343
// If there are no directory entries
4444
if (DirectoryEntries == null || DirectoryEntries.Length == 0)
@@ -48,11 +48,10 @@ public byte[] MiniStreamData
4848
var startingSector = (SectorNumber)DirectoryEntries[0].StartingSectorLocation;
4949

5050
// Get the mini stream data
51-
_miniStreamData = GetFATSectorChainData(startingSector);
52-
return _miniStreamData ?? [];
51+
field = GetFATSectorChainData(startingSector);
52+
return field ?? [];
5353
}
54-
}
55-
private byte[]? _miniStreamData;
54+
} = null;
5655

5756
/// <summary>
5857
/// Normal sector size in bytes

SabreTools.Serialization/Wrappers/GCF.cs

Lines changed: 33 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,33 @@ public partial class GCF : WrapperBase<Data.Models.GCF.File>
1414

1515
#region Extension Properties
1616

17+
/// <inheritdoc cref="Models.GCF.DataBlockHeader.BlockSize"/>
18+
public uint BlockSize => Model.DataBlockHeader.BlockSize;
19+
20+
/// <summary>
21+
/// Set of all data block offsets
22+
/// </summary>
23+
public long[]? DataBlockOffsets
24+
{
25+
get
26+
{
27+
// Use the cached value if we have it
28+
if (field != null)
29+
return field;
30+
31+
// Otherwise, build the data block set
32+
field = new long[Model.DataBlockHeader.BlockCount];
33+
for (int i = 0; i < Model.DataBlockHeader.BlockCount; i++)
34+
{
35+
long dataBlockOffset = Model.DataBlockHeader.FirstBlockOffset + (i * Model.DataBlockHeader.BlockSize);
36+
field[i] = dataBlockOffset;
37+
}
38+
39+
// Return the set of data blocks
40+
return field;
41+
}
42+
} = null;
43+
1744
/// <summary>
1845
/// Set of all files and their information
1946
/// </summary>
@@ -22,8 +49,8 @@ public FileInfo[]? Files
2249
get
2350
{
2451
// Use the cached value if we have it
25-
if (_files != null)
26-
return _files;
52+
if (field != null)
53+
return field;
2754

2855
// If we don't have a required property
2956
if (Model.DirectoryEntries == null || Model.DirectoryMapEntries == null)
@@ -69,7 +96,7 @@ public FileInfo[]? Files
6996

7097
// Traverse the block entries
7198
index = directoryMapEntry.FirstBlockIndex;
72-
while (index != Model.DataBlockHeader?.BlockCount)
99+
while (index != Model.DataBlockHeader.BlockCount)
73100
{
74101
var nextBlock = Model.BlockEntries[index];
75102
blockEntries.Add(nextBlock);
@@ -109,55 +136,10 @@ public FileInfo[]? Files
109136
}
110137

111138
// Set and return the file infos
112-
_files = [.. files];
113-
return _files;
139+
field = [.. files];
140+
return field;
114141
}
115-
}
116-
117-
/// <summary>
118-
/// Set of all data block offsets
119-
/// </summary>
120-
public long[]? DataBlockOffsets
121-
{
122-
get
123-
{
124-
// Use the cached value if we have it
125-
if (_dataBlockOffsets != null)
126-
return _dataBlockOffsets;
127-
128-
// If we don't have a block count, offset, or size
129-
if (Model.DataBlockHeader?.BlockCount == null || Model.DataBlockHeader?.FirstBlockOffset == null || Model.DataBlockHeader?.BlockSize == null)
130-
return null;
131-
132-
// Otherwise, build the data block set
133-
_dataBlockOffsets = new long[Model.DataBlockHeader.BlockCount];
134-
for (int i = 0; i < Model.DataBlockHeader.BlockCount; i++)
135-
{
136-
long dataBlockOffset = Model.DataBlockHeader.FirstBlockOffset + (i * Model.DataBlockHeader.BlockSize);
137-
_dataBlockOffsets[i] = dataBlockOffset;
138-
}
139-
140-
// Return the set of data blocks
141-
return _dataBlockOffsets;
142-
}
143-
}
144-
145-
/// <inheritdoc cref="Models.GCF.DataBlockHeader.BlockSize"/>
146-
public uint BlockSize => Model.DataBlockHeader?.BlockSize ?? 0;
147-
148-
#endregion
149-
150-
#region Instance Variables
151-
152-
/// <summary>
153-
/// Set of all files and their information
154-
/// </summary>
155-
private FileInfo[]? _files = null;
156-
157-
/// <summary>
158-
/// Set of all data block offsets
159-
/// </summary>
160-
private long[]? _dataBlockOffsets = null;
142+
} = null;
161143

162144
#endregion
163145

SabreTools.Serialization/Wrappers/GZip.cs

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,8 @@ public long DataOffset
7777
{
7878
get
7979
{
80-
if (_dataOffset > -1)
81-
return _dataOffset;
80+
if (field > -1)
81+
return field;
8282

8383
// Minimum offset is 10 bytes:
8484
// - ID1 (1)
@@ -88,20 +88,20 @@ public long DataOffset
8888
// - LastModifiedTime (4)
8989
// - ExtraFlags (1)
9090
// - OperatingSystem (1)
91-
_dataOffset = 10;
91+
field = 10;
9292

9393
// Add extra lengths
94-
_dataOffset += Header.ExtraLength;
94+
field += Header.ExtraLength;
9595
if (Header.OriginalFileName != null)
96-
_dataOffset += Header.OriginalFileName.Length + 1;
96+
field += Header.OriginalFileName.Length + 1;
9797
if (Header.FileComment != null)
98-
_dataOffset += Header.FileComment.Length + 1;
98+
field += Header.FileComment.Length + 1;
9999
if (Header.CRC16 != null)
100-
_dataOffset += 2;
100+
field += 2;
101101

102-
return _dataOffset;
102+
return field;
103103
}
104-
}
104+
} = -1;
105105

106106
/// <inheritdoc cref="Archive.Header"/>
107107
public Header Header => Model.Header;
@@ -152,15 +152,6 @@ public bool IsTorrentGZip
152152

153153
#endregion
154154

155-
#region Instance Variables
156-
157-
/// <summary>
158-
/// Offset to the compressed data
159-
/// </summary>
160-
private long _dataOffset = -1;
161-
162-
#endregion
163-
164155
#region Constructors
165156

166157
/// <inheritdoc/>

SabreTools.Serialization/Wrappers/InstallShieldArchiveV3.cs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -39,26 +39,25 @@ public Dictionary<int, int> FileDirMap
3939
get
4040
{
4141
// Return the prebuilt map
42-
if (_fileDirMap != null)
43-
return _fileDirMap;
42+
if (field != null)
43+
return field;
4444

4545
// Build the file map
46-
_fileDirMap = [];
46+
field = [];
4747

4848
int fileId = 0;
4949
for (int i = 0; i < Directories.Length; i++)
5050
{
5151
var dir = Directories[i];
5252
for (int j = 0; j < dir.FileCount; j++)
5353
{
54-
_fileDirMap[fileId++] = i;
54+
field[fileId++] = i;
5555
}
5656
}
5757

58-
return _fileDirMap;
58+
return field;
5959
}
60-
}
61-
private Dictionary<int, int>? _fileDirMap = null;
60+
} = null;
6261

6362
/// <summary>
6463
/// Map of all files found in the archive
@@ -68,11 +67,11 @@ public Dictionary<int, int> FileDirMap
6867
get
6968
{
7069
// Return the prebuilt map
71-
if (_fileNameMap != null)
72-
return _fileNameMap;
70+
if (field != null)
71+
return field;
7372

7473
// Build the file map
75-
_fileNameMap = [];
74+
field = [];
7675
for (int fileIndex = 0; fileIndex < Files.Length; fileIndex++)
7776
{
7877
// Get the current file
@@ -90,13 +89,14 @@ public Dictionary<int, int> FileDirMap
9089
);
9190

9291
// Add to the map
93-
_fileNameMap[filename] = file;
92+
field[filename] = file;
9493
}
9594

96-
return _fileNameMap;
95+
return field;
9796
}
98-
}
99-
private Dictionary<string, Data.Models.InstallShieldArchiveV3.File>? _fileNameMap = null;
97+
98+
private set;
99+
} = null;
100100

101101
/// <summary>
102102
/// Data offset for all archives

SabreTools.Serialization/Wrappers/N3DS.cs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,7 @@ public partial class N3DS : WrapperBase<Cart>
3030
/// Media unit size in bytes
3131
/// </summary>
3232
public uint MediaUnitSize
33-
{
34-
get
35-
{
36-
return (uint)(0x200 * Math.Pow(2, Model.Header.PartitionFlags[(int)NCSDFlags.MediaUnitSize]));
37-
}
38-
}
33+
=> (uint)(0x200 * Math.Pow(2, Model.Header.PartitionFlags[(int)NCSDFlags.MediaUnitSize]));
3934

4035
/// <summary>
4136
/// Partitions data table

0 commit comments

Comments
 (0)