-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
74 lines (63 loc) · 3.72 KB
/
Program.cs
File metadata and controls
74 lines (63 loc) · 3.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
using System;
using System.Collections.Generic;
using System.IO;
using System.Text.RegularExpressions;
namespace FuncomDBFixGenerator
{
internal class Program
{
static void Main(string[] args)
{
// Specify the file name (assuming it is in the same directory as the executable)
string fileName = "ConanSandbox.log";
string outputFileName = "GeneratedSql.sql";
// Define the regex pattern to match to log entries in ConanSandbox.log
string pattern = @"\[\d+.\d+.\d+-\d+.\d+.\d+.\d+\].* NameToLoad: (.*)\n.*\n\[\d+.\d+.\d+-\d+.\d+.\d+.\d+\].* String asset reference \""None\"".*slow.";
try
{
// Check if the file exists in the same directory as the executable
string filePath = Path.Combine(Directory.GetCurrentDirectory(), fileName);
if (!File.Exists(filePath))
{
Console.WriteLine($"File '{fileName}' not found in the current directory.");
return;
}
// Read entire content of the file
string content = File.ReadAllText(filePath);
Console.WriteLine($"Searching for pattern '{pattern}' in '{fileName}'...");
// Execute Regex pattern matching on the read contnet
MatchCollection matches = Regex.Matches(content, pattern);
// Write matches to the output file
string outputFilePath = Path.Combine(Directory.GetCurrentDirectory(), outputFileName);
if (File.Exists(outputFilePath))
{
Console.WriteLine($"File '{outputFileName}' already exists and will be deleted.");
File.Delete(outputFilePath);
}
using (StreamWriter writer = new StreamWriter(outputFilePath))
{
foreach (Match match in matches)
{
string target = match.Groups[1].ToString().Replace("\r", "");
writer.WriteLine($"DELETE FROM buildable_health WHERE object_id IN(SELECT DISTINCT object_id FROM buildings WHERE object_id IN (SELECT DISTINCT object_id FROM properties WHERE object_id IN (SELECT id FROM (SELECT id, trim(substr(class, INSTR(class, '/BP'), length(class)), '/') AS name FROM actor_position WHERE class LIKE '{target}%'))));");
writer.WriteLine($"DELETE FROM buildings WHERE object_id IN(SELECT DISTINCT object_id FROM properties WHERE object_id IN (SELECT id FROM (SELECT id, trim(substr(class, INSTR(class, '/BP'), length(class)), '/') AS name FROM actor_position WHERE class LIKE '{target}%')));");
writer.WriteLine($"DELETE FROM properties WHERE object_id IN(SELECT id FROM (SELECT id, trim(substr(class, INSTR(class, '/BP'), length(class)), '/') AS name FROM actor_position WHERE class LIKE '{target}%'));");
writer.WriteLine($"DELETE FROM actor_position WHERE class LIKE '{target}%';");
writer.WriteLine("--"); // Separator between matches
}
writer.WriteLine("VACUUM;");
writer.WriteLine("REINDEX;");
writer.WriteLine("ANALYZE;");
writer.WriteLine("PRAGMA integrity_check;");
}
Console.WriteLine($"Matches used to generate script in file: '{outputFileName}' with '--' as a separator.");
Console.WriteLine($"Hit Any Key to Close.");
Console.ReadLine();
}
catch (Exception ex)
{
Console.WriteLine("An error occurred: " + ex.Message);
}
}
}
}