Decompiled source of RuTranslationMerger v1.0.0

Mods/RuTranslationMerger.dll

Decompiled 4 hours ago
using System;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Text.RegularExpressions;
using MelonLoader;
using MelonLoader.Utils;
using Microsoft.CodeAnalysis;
using RuTranslationMerger;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: MelonInfo(typeof(TranslationMergerLoader), "Ru Translation merger", "1.0.0", "gSpidy", null)]
[assembly: MelonGame("TVGS", "Schedule I")]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("RuTranslationMerger")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+67a4e7ce9e2d7b4aeec92ff9da03d0f29311d761")]
[assembly: AssemblyProduct("RuTranslationMerger")]
[assembly: AssemblyTitle("RuTranslationMerger")]
[assembly: AssemblyVersion("1.0.0.0")]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace RuTranslationMerger
{
	public class TranslationMergerLoader : MelonMod
	{
		private const string RTLC_FOLDER_NAME = "RTLC-RTLC_Russian_Translation/AutoTranslator/Translation/ru/Text";

		private const string SWEET_FOLDER_NAME = "Sweet_Russian_ScheduleI";

		private static readonly Regex fixerSearch = new Regex("(<[^>]+[^\\\\>])=\\\\?([^>]+>)", RegexOptions.Compiled);

		private static readonly Regex spacerSearch = new Regex("(?<!\\\\)=", RegexOptions.Compiled);

		public override void OnInitializeMelon()
		{
			((MelonBase)this).OnInitializeMelon();
			string path = Path.Combine(MelonEnvironment.ModsDirectory, "RTLC-RTLC_Russian_Translation/AutoTranslator/Translation/ru/Text");
			string path2 = Path.Combine(MelonEnvironment.UserDataDirectory, "Sweet_Russian_ScheduleI");
			foreach (string item in from x in Directory.EnumerateFiles(path)
				where x.EndsWith(".txt", ignoreCase: true, CultureInfo.InvariantCulture)
				select x)
			{
				string fileNameWithoutExtension = Path.GetFileNameWithoutExtension(item);
				string outputPath = Path.Combine(MelonEnvironment.UserDataDirectory, path2, fileNameWithoutExtension + ".tsv");
				ConvertFile(item, outputPath);
			}
		}

		private void ConvertFile(string inputPath, string outputPath)
		{
			string fileName = Path.GetFileName(inputPath);
			MelonLogger.Msg(ConsoleColor.Cyan, "Converting " + fileName + "...");
			string[] source = File.ReadAllLines(inputPath);
			source = (from x in source
				where !string.IsNullOrWhiteSpace(x)
				select fixerSearch.Replace(x, "$1\\=$2") into x
				select spacerSearch.Replace(x, "\t", 1) into x
				select x.Replace("\\=", "=")).ToArray();
			if (source.Length < 1)
			{
				MelonLogger.Msg(ConsoleColor.Yellow, "File is empty, skipping...");
				return;
			}
			string directoryName = Path.GetDirectoryName(outputPath);
			if (!string.IsNullOrWhiteSpace(directoryName) && !Directory.Exists(directoryName))
			{
				Directory.CreateDirectory(directoryName);
			}
			File.WriteAllLines(outputPath, source);
			MelonLogger.Msg(ConsoleColor.Green, "successful write to " + outputPath);
		}
	}
}