Skip to content

Commit

Permalink
Added file flags to Manifest.FileEntry
Browse files Browse the repository at this point in the history
  • Loading branch information
Nuclearistt committed Jan 24, 2024
1 parent 5ec2f61 commit a1537ac
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 6 deletions.
2 changes: 1 addition & 1 deletion TEKSteamClient.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<BaseVersion>1.1.1</BaseVersion>
<BaseVersion>1.2.0</BaseVersion>
<Version>$(BaseVersion)</Version>
<Version Condition="'$(GITHUB_RUN_NUMBER)' != ''">$(BaseVersion)-alpha.$(GITHUB_RUN_NUMBER)</Version>
<Authors>Nuclearist</Authors>
Expand Down
3 changes: 3 additions & 0 deletions protos/manifest/payload.proto
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ message Payload
enum FileFlag
{
NONE = 0;
READONLY = 8;
HIDDEN = 16;
EXECUTABLE = 32;
DIRECTORY = 64;
}
message Chunk
Expand Down
13 changes: 10 additions & 3 deletions src/Manifest/DepotManifest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -128,10 +128,17 @@ void loadDirectory(int index, int payloadEntryIndex)
Checksum = chunk.Checksum
};
new Span<ChunkEntry>(ChunkBuffer, chunkStartOffset, numChunks).Sort();
FileEntry.Flag flags = 0;
if ((file.Flags & FileFlag.Readonly) is not FileFlag.None)
flags = FileEntry.Flag.ReadOnly;
if ((file.Flags & FileFlag.Hidden) is not FileFlag.None)
flags |= FileEntry.Flag.Hidden;
if ((file.Flags & FileFlag.Executable) is not FileFlag.None)
flags |= FileEntry.Flag.Executable;
FileBuffer[fileOffset++] = new()
{
Name = numSepChars > 0 ? Path.GetFileName(file.Name) : file.Name,
Size = file.Size,
SizeAndFlags = file.Size | ((long)flags << 56),
Chunks = new(ChunkBuffer, chunkStartOffset, numChunks)
};
}
Expand Down Expand Up @@ -209,7 +216,7 @@ public DepotManifest(string filePath, ItemIdentifier item, ulong id)
FileBuffer[i] = new()
{
Name = Encoding.UTF8.GetString(buffer.Slice(nameOffset, nameLength)),
Size = Unsafe.As<int, long>(ref Unsafe.Add(ref spanRef, offset)),
SizeAndFlags = Unsafe.As<int, long>(ref Unsafe.Add(ref spanRef, offset)),
Chunks = new(ChunkBuffer, chunkOffset, numChunks)
};
offset += 4;
Expand Down Expand Up @@ -289,7 +296,7 @@ public void WriteToFile(string filePath)
{
int nameLength = Encoding.UTF8.GetBytes(file.Name, buffer[nameOffset..]);
nameOffset += nameLength;
Unsafe.As<int, long>(ref Unsafe.Add(ref spanRef, offset)) = file.Size;
Unsafe.As<int, long>(ref Unsafe.Add(ref spanRef, offset)) = file.SizeAndFlags;
offset += 2;
entriesSpan[offset++] = nameLength;
entriesSpan[offset++] = file.Chunks.Count;
Expand Down
20 changes: 18 additions & 2 deletions src/Manifest/FileEntry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,34 @@ public readonly struct FileEntry
{
/// <summary>Name of the file.</summary>
public required string Name { get; init; }
/// <summary>Total size of the file OR'ed with its flags. Used only during initialization.</summary>
public required long SizeAndFlags { get; init; }
/// <summary>Total size of the file.</summary>
public required long Size { get; init; }
public long Size => SizeAndFlags & 0x00FFFFFFFFFFFFFF;
/// <summary>Extra flags of the file.</summary>
public Flag Flags => (Flag)((SizeAndFlags & 0x7F00000000000000) >> 56);
/// <summary>Chunks that compose the file.</summary>
public required ArraySegment<ChunkEntry> Chunks { get; init; }
/// <summary>Extra flags describing file's attributes or permissions.</summary>
[Flags]
public enum Flag
{
/// <summary>The file has <see cref="FileAttributes.ReadOnly"/> attribute.</summary>
ReadOnly = 1 << 0,
/// <summary>The file has <see cref="FileAttributes.Hidden"/> attribute.</summary>
Hidden = 1 << 1,
/// <summary>The file has <see cref="UnixFileMode.UserExecute"/>, <see cref="UnixFileMode.GroupExecute"/> and <see cref="UnixFileMode.OtherExecute"/> permissions.</summary>
Executable = 1 << 2
}
/// <summary>Structure used in <see cref="DepotDelta"/> to store indexes of files and chunks that must be acquired.</summary>
internal readonly struct AcquisitionEntry
{
/// <summary>Index of the file entry in its parent directory.</summary>
public required int Index { get; init; }
/// <summary>File's chunks that must be acquired. If empty, the whole file is acquired.</summary>
public required ArraySegment<ChunkEntry> Chunks { get; init; }
//struct int long
/// <summary>Structure storing chunk's index along with its optional offset in chunk buffer file.</summary>
/// <param name="index">Index of the chunk in its file.</param>
public readonly struct ChunkEntry(int index)
{
/// <summary>Index of the chunk entry in its file.</summary>
Expand Down

0 comments on commit a1537ac

Please sign in to comment.