|
9 | 9 |
|
10 | 10 | namespace PartInfoInPAW |
11 | 11 | { |
12 | | - public delegate void PartPatchesHistoryCallback(List<MMPatchInfo> patchesList); |
| 12 | + internal delegate void PartPatchesHistoryCallback(List<MMPatchInfo> patchesList); |
13 | 13 |
|
14 | | - public static class MMLogParser |
| 14 | + internal static class MMLogParser |
15 | 15 | { |
16 | 16 | public enum ParserStatus |
17 | 17 | { |
@@ -112,8 +112,10 @@ public static async Task<List<MMPatchInfo>> ParseLogFile(string partName) |
112 | 112 | if (LogFileLines.Length > 0) |
113 | 113 | { |
114 | 114 | string searchStr = "/PART[" + @partName + "]"; |
115 | | - foreach (string line in LogFileLines) |
| 115 | + int linesCount = LogFileLines.Length; |
| 116 | + for (int i = 0; i < linesCount; i++) |
116 | 117 | { |
| 118 | + string line = LogFileLines[i]; |
117 | 119 | if (line.IndexOf(searchStr) != -1) |
118 | 120 | { |
119 | 121 | Match m = Regex.Match(line.Trim(), RegexPattern(partName)); |
@@ -156,9 +158,11 @@ public static async Task<List<MMPatchInfo>> ParseLogFile(string partName) |
156 | 158 | int occurence = 0; |
157 | 159 | int level = -1; |
158 | 160 | bool found = false; |
159 | | - foreach (string cfgLine in patchCFGFileLines) |
| 161 | + int cfgLinesCount = patchCFGFileLines.Length; |
| 162 | + string[] commentStart = { "//" }; |
| 163 | + for (int j = 0; j < cfgLinesCount; j++) |
160 | 164 | { |
161 | | - string[] code = cfgLine.Split(new string[] { "//" }, 2, StringSplitOptions.None); |
| 165 | + string[] code = patchCFGFileLines[j].Split(commentStart, 2, StringSplitOptions.None); |
162 | 166 | if (code[0].IndexOf(patchSelector) != -1) |
163 | 167 | { |
164 | 168 | if (patchNum == occurence) |
@@ -207,109 +211,9 @@ public static async Task<List<MMPatchInfo>> ParseLogFile(string partName) |
207 | 211 | return patches; |
208 | 212 | } |
209 | 213 |
|
210 | | - public static string GetPatchesHistoryAsStr(string partName) |
211 | | - { |
212 | | - if (PatchesHistoryDict.ContainsKey(partName)) |
213 | | - { |
214 | | - List<MMPatchInfo> patches = PatchesHistoryDict[partName]; |
215 | | - string result = $"// Patches for part {partName}: {patches.Count}" + Environment.NewLine + Environment.NewLine; |
216 | | - foreach (MMPatchInfo m in patches) |
217 | | - { |
218 | | - result += m; |
219 | | - } |
220 | | - return result; |
221 | | - } |
222 | | - else |
223 | | - { |
224 | | - return $"// Patches count for part {partName}: 0" + Environment.NewLine; |
225 | | - } |
226 | | - } |
227 | | - |
228 | 214 | private static string RegexPattern(string partName) |
229 | 215 | { |
230 | | - return @"^\[LOG \d{2}:\d{2}:\d{2}\.\d{3}\] Applying update (.+)/(@PART\[.+) to .+/PART\[" + Regex.Escape(partName) + @"\]$"; |
231 | | - } |
232 | | - } |
233 | | - |
234 | | - public class MMPatchInfo |
235 | | - { |
236 | | - public string PatchFilePath { get; protected set; } |
237 | | - public string Patch { get; protected set; } |
238 | | - public string PatchBody { get; protected set; } |
239 | | - public bool PatchFullCollapsed { get; protected set; } |
240 | | - |
241 | | - public MMPatchInfo(string patchFilePath, string patch, string patchBody) |
242 | | - { |
243 | | - PatchFilePath = patchFilePath; |
244 | | - Patch = patch; |
245 | | - PatchBody = patchBody; |
246 | | - PatchFullCollapsed = true; |
247 | | - } |
248 | | - |
249 | | - public static string AddExtension(string patch) |
250 | | - { |
251 | | - string result = patch; |
252 | | - if (result[0] == '/') |
253 | | - { |
254 | | - result = result.Substring(1); |
255 | | - } |
256 | | - result += "." + UrlDir.configExtension; |
257 | | - return result; |
258 | | - } |
259 | | - |
260 | | - public void ToggleCollapsed() |
261 | | - { |
262 | | - PatchFullCollapsed = !PatchFullCollapsed; |
263 | | - } |
264 | | - |
265 | | - public void Collapse() |
266 | | - { |
267 | | - PatchFullCollapsed = true; |
268 | | - } |
269 | | - |
270 | | - public void Expand() |
271 | | - { |
272 | | - PatchFullCollapsed = false; |
273 | | - } |
274 | | - |
275 | | - public bool IsCollapsed() |
276 | | - { |
277 | | - return PatchFullCollapsed; |
278 | | - } |
279 | | - |
280 | | - public string GetPatchStr() |
281 | | - { |
282 | | - if (PatchBody == null) |
283 | | - { |
284 | | - return "// " + PatchFilePath + Environment.NewLine + |
285 | | - Patch + Environment.NewLine + |
286 | | - "{} // Could not parse patch CFG from " + PatchFilePath + Environment.NewLine + Environment.NewLine; |
287 | | - } |
288 | | - return "// " + PatchFilePath + Environment.NewLine + |
289 | | - Patch + Environment.NewLine + |
290 | | - PatchBody + Environment.NewLine + Environment.NewLine; |
291 | | - } |
292 | | - |
293 | | - public override string ToString() |
294 | | - { |
295 | | - if (PatchFullCollapsed) |
296 | | - { |
297 | | - return Localizer.Format("#LOC_PartInfoInPAW_PartMMPatchesHistory_PatchFileName", PatchFilePath); |
298 | | - } |
299 | | - else |
300 | | - { |
301 | | - if (PatchBody == null) |
302 | | - { |
303 | | - return Localizer.Format("#LOC_PartInfoInPAW_PartMMPatchesHistory_PatchFileName", PatchFilePath) + |
304 | | - Environment.NewLine + Environment.NewLine + |
305 | | - Patch + Environment.NewLine + |
306 | | - Localizer.Format("#LOC_PartInfoInPAW_CantParsePatchCFG_ErrorMsg"); |
307 | | - } |
308 | | - return Localizer.Format("#LOC_PartInfoInPAW_PartMMPatchesHistory_PatchFileName", PatchFilePath) + |
309 | | - Environment.NewLine + Environment.NewLine + |
310 | | - Patch + Environment.NewLine + |
311 | | - PatchBody; |
312 | | - } |
| 216 | + return @"^\[LOG \d{2}:\d{2}:\d{2}\.\d{3}\] Applying update (.+)/(@PART.+) to .+/PART\[" + Regex.Escape(partName) + @"\]$"; |
313 | 217 | } |
314 | 218 | } |
315 | 219 | } |
0 commit comments