TModLoader v1.4.4.9
TModLoader source code documentation
Loading...
Searching...
No Matches

◆ Archive()

static void Terraria.ModLoader.Engine.LogArchiver.Archive ( )
inlinestaticprivate

Definition at line 97 of file LogArchiver.cs.

98 {
99 //IL_012b: Unknown result type (might be due to invalid IL or missing references)
100 //IL_0132: Expected O, but got Unknown
101 List<string> logFiles = GetOldLogs().ToList();
102 if (!logFiles.Any())
103 {
104 return;
105 }
106 DateTime time;
107 try
108 {
109 time = logFiles.Select(File.GetCreationTime).Min();
110 }
111 catch (Exception e3)
112 {
113 Logging.tML.Error((object)e3);
114 return;
115 }
116 int i = 1;
117 Regex pattern = new Regex($"{time:yyyy-MM-dd}-(\\d+)\\.zip");
118 string[] existingLogArchives = new string[0];
119 try
120 {
121 existingLogArchives = (from s in Directory.GetFiles(Logging.LogArchiveDir)
122 where pattern.IsMatch(Path.GetFileName(s))
123 select s).ToArray();
124 }
125 catch (Exception e2)
126 {
127 Logging.tML.Error((object)e2);
128 return;
129 }
130 if (existingLogArchives.Length != 0)
131 {
132 i = existingLogArchives.Select((string s) => int.Parse(pattern.Match(Path.GetFileName(s)).Groups[1].Value)).Max() + 1;
133 }
134 try
135 {
136 ZipFile zip = new ZipFile(Path.Combine(Logging.LogArchiveDir, $"{time:yyyy-MM-dd}-{i}.zip"), Encoding.UTF8);
137 try
138 {
139 foreach (string logFile in logFiles)
140 {
141 string entryName = Path.GetFileNameWithoutExtension(logFile);
142 using (FileStream stream = File.OpenRead(logFile))
143 {
144 if (stream.Length > 10000000)
145 {
146 Logging.tML.Warn((object)(logFile + " exceeds 10MB, it will be truncated for the logs archive."));
147 zip.AddEntry(entryName, stream.ReadBytes(10000000));
148 }
149 else
150 {
151 zip.AddEntry(entryName, (Stream)stream);
152 }
153 zip.Save();
154 }
155 File.Delete(logFile);
156 }
157 }
158 finally
159 {
160 ((IDisposable)zip)?.Dispose();
161 }
162 }
163 catch (Exception e)
164 {
165 Logging.tML.Error((object)e);
166 }
167 }
static IEnumerable< string > GetOldLogs()

References Terraria.ModLoader.Engine.LogArchiver.GetOldLogs(), Terraria.ModLoader.Logging.LogArchiveDir, and Terraria.ModLoader.Logging.tML.

Referenced by Terraria.ModLoader.Engine.LogArchiver.ArchiveLogs().

+ Here is the call graph for this function:
+ Here is the caller graph for this function: