Очистка скриптов
This commit is contained in:
@@ -1,10 +0,0 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net10.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
</Project>
|
||||
@@ -1,80 +0,0 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
|
||||
namespace FormatFixer
|
||||
{
|
||||
class Program
|
||||
{
|
||||
static void Main(string[] args)
|
||||
{
|
||||
var srcPath = @"e:\GIT\forkmessager\apps\server-net\src";
|
||||
var files = Directory.GetFiles(srcPath, "*.cs", SearchOption.AllDirectories);
|
||||
foreach (var file in files)
|
||||
{
|
||||
var lines = File.ReadAllLines(file);
|
||||
bool changed = false;
|
||||
for (int i = 0; i < lines.Length; i++)
|
||||
{
|
||||
var line = lines[i];
|
||||
var stripped = line.TrimStart();
|
||||
if ((stripped.StartsWith("if (") || stripped.StartsWith("if(") ||
|
||||
stripped.StartsWith("foreach (") || stripped.StartsWith("foreach("))
|
||||
&& stripped.EndsWith(";"))
|
||||
{
|
||||
// Check if it's already a block
|
||||
if (stripped.Contains("{")) continue;
|
||||
|
||||
int parenCount = 0;
|
||||
bool inString = false;
|
||||
int firstParenIdx = line.IndexOf('(');
|
||||
int condEndIdx = -1;
|
||||
|
||||
for (int j = firstParenIdx; j < line.Length; j++)
|
||||
{
|
||||
char c = line[j];
|
||||
if (c == '"' && line[j - 1] != '\\')
|
||||
{
|
||||
inString = !inString;
|
||||
}
|
||||
else if (!inString)
|
||||
{
|
||||
if (c == '(') parenCount++;
|
||||
else if (c == ')')
|
||||
{
|
||||
parenCount--;
|
||||
if (parenCount == 0)
|
||||
{
|
||||
condEndIdx = j;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (condEndIdx != -1)
|
||||
{
|
||||
var statement = line.Substring(condEndIdx + 1).Trim();
|
||||
if (!string.IsNullOrEmpty(statement) && !statement.StartsWith("{") && statement.EndsWith(";"))
|
||||
{
|
||||
var indent = line.Substring(0, line.Length - line.TrimStart().Length);
|
||||
var newLine1 = line.Substring(0, condEndIdx + 1);
|
||||
var newLine2 = indent + "{";
|
||||
var newLine3 = indent + " " + statement;
|
||||
var newLine4 = indent + "}";
|
||||
|
||||
lines[i] = newLine1 + Environment.NewLine + newLine2 + Environment.NewLine + newLine3 + Environment.NewLine + newLine4;
|
||||
changed = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (changed)
|
||||
{
|
||||
File.WriteAllText(file, string.Join(Environment.NewLine, lines));
|
||||
Console.WriteLine("Fixed: " + file);
|
||||
}
|
||||
}
|
||||
Console.WriteLine("Formatting complete.");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user