Skip to content

Commit

Permalink
Handle zz_machineTranslation.txt files
Browse files Browse the repository at this point in the history
  • Loading branch information
ManlyMarco committed Sep 30, 2021
1 parent f97b7ef commit 172eaae
Showing 1 changed file with 20 additions and 10 deletions.
30 changes: 20 additions & 10 deletions tools/ReleaseTool/ReleaseTool/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ void AddToZip(string filePath, string entryName)
_originalOut = Console.Out;
Console.SetOut(new StreamWriter(detailsPath));
// Clean up the copied files
var result = CleanTranslations(copyDir);
var result = CleanTranslations(copyDir, copyDir);
Console.Out.Flush();
Console.SetOut(_originalOut);

Expand Down Expand Up @@ -258,7 +258,7 @@ private static void ShowInvalidArgsError()
Console.WriteLine("Drag the repository folder (it must contain a translation folder) on to this tool's exe to generate a release. Detailed results will be saved to results.txt in the program directory.");
}

private static Results CleanTranslations(DirectoryInfo dir)
private static Results CleanTranslations(DirectoryInfo dir, DirectoryInfo rootDir)
{
var files = dir.GetFiles("*.txt", SearchOption.TopDirectoryOnly);
var folders = dir.GetDirectories();
Expand All @@ -267,15 +267,21 @@ private static Results CleanTranslations(DirectoryInfo dir)

foreach (var file in files)
{
if (file.Name == "_AutoGeneratedTranslations.txt")
{
file.Delete();
continue;
}

var lines = File.ReadAllLines(file.FullName).Where(x => !string.IsNullOrWhiteSpace(x)).ToArray();
var translatedLines = lines.Where(x => !x.StartsWith("//")).ToArray();
var notComments = lines.Where(x => !x.StartsWith("//")).ToArray();

try
{
file.Delete();

if (translatedLines.Length != 0)
File.WriteAllLines(file.FullName, translatedLines);
if (notComments.Length != 0)
File.WriteAllLines(file.FullName, notComments);
}
catch (Exception e)
{
Expand All @@ -287,20 +293,24 @@ private static Results CleanTranslations(DirectoryInfo dir)
//Console.ForegroundColor = ConsoleColor.DarkGray;
//Console.WriteLine($"{file.FullName} - {translatedLines.Length}/{lines.Length} lines - {100 * percentage:F0}%");

folderPercentage.Total += lines.Length;
folderPercentage.Translated += translatedLines.Length;
// Don't count MTL
if (file.Name != "zz_machineTranslation.txt")
{
folderPercentage.Total += lines.Count(x => x.Contains('='));
folderPercentage.Translated += lines.Count(x => x.Contains('=') && !x.StartsWith("//"));
}
}

foreach (var folder in folders)
{
var r = CleanTranslations(folder);
var r = CleanTranslations(folder, rootDir);
folderPercentage.Add(r);
}

Console.ForegroundColor = ConsoleColor.White;
Console.WriteLine($"{dir.FullName} - {folderPercentage.Translated}/{folderPercentage.Total} lines - {100 * folderPercentage.GetPercent():F1}%");
Console.WriteLine($"{dir.FullName.Remove(0, rootDir.FullName.Length)} - {folderPercentage.Translated}/{folderPercentage.Total} lines - {100 * folderPercentage.GetPercent():F1}%");

if (folderPercentage.GetPercent() == 0f)
if (dir.GetFiles("*", SearchOption.AllDirectories).Length == 0)
{
try
{
Expand Down

0 comments on commit 172eaae

Please sign in to comment.