Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
FileMetadata.cs
Go to the documentation of this file.
1using System;
2using System.IO;
3
4namespace Terraria.IO;
5
6public class FileMetadata
7{
8 public const ulong MAGIC_NUMBER = 27981915666277746uL;
9
10 public const int SIZE = 20;
11
12 public FileType Type;
13
14 public uint Revision;
15
16 public bool IsFavorite;
17
18 private FileMetadata()
19 {
20 }
21
23 {
24 writer.Write(0x6369676F6C6572uL | ((ulong)Type << 56));
25 writer.Write(Revision);
26 writer.Write((ulong)(int)(((uint)IsFavorite.ToInt() & 1u) | 0u));
27 }
28
30 {
31 Revision++;
33 }
34
36 {
37 return new FileMetadata
38 {
39 Type = type,
40 Revision = 0u,
41 IsFavorite = false
42 };
43 }
44
45 public static FileMetadata Read(BinaryReader reader, FileType expectedType)
46 {
47 FileMetadata fileMetadata = new FileMetadata();
48 fileMetadata.Read(reader);
49 if (fileMetadata.Type != expectedType)
50 {
51 throw new FormatException("Expected type \"" + Enum.GetName(typeof(FileType), expectedType) + "\" but found \"" + Enum.GetName(typeof(FileType), fileMetadata.Type) + "\".");
52 }
53 return fileMetadata;
54 }
55
56 private void Read(BinaryReader reader)
57 {
58 ulong num = reader.ReadUInt64();
59 if ((num & 0xFFFFFFFFFFFFFFL) != 27981915666277746L)
60 {
61 throw new FormatException("Expected Re-Logic file format.");
62 }
63 byte b = (byte)((num >> 56) & 0xFF);
64 FileType fileType = FileType.None;
66 for (int i = 0; i < array.Length; i++)
67 {
68 if ((uint)array[i] == b)
69 {
70 fileType = array[i];
71 break;
72 }
73 }
74 if (fileType == FileType.None)
75 {
76 throw new FormatException("Found invalid file type.");
77 }
78 Type = fileType;
79 Revision = reader.ReadUInt32();
80 ulong num2 = reader.ReadUInt64();
81 IsFavorite = (num2 & 1) == 1;
82 }
83}
static Array GetValues(Type enumType)
Definition Enum.cs:323
static ? string GetName(Type enumType, object value)
Definition Enum.cs:281
virtual ulong ReadUInt64()
virtual uint ReadUInt32()
void Read(BinaryReader reader)
void Write(BinaryWriter writer)
static FileMetadata Read(BinaryReader reader, FileType expectedType)
void IncrementAndWrite(BinaryWriter writer)
static FileMetadata FromCurrentSettings(FileType type)