using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Runtime.InteropServices;
using System.Text;
using Big5UaoFileHandler;

internal class a
{
	private static extern bool CreateSymbolicLink(string A_0, string A_1, global::a.a A_2);

	private static void a(object A_0, ConsoleCancelEventArgs A_1)
	{
		Console.WriteLine();
		global::a.a("Ctrl-C is pressed!");
		global::a.b();
	}

	private static void b()
	{
		if (global::a.k)
		{
			try
			{
				Directory.Delete(global::a.j, true);
			}
			catch (Exception ex)
			{
				global::a.a("Cannot delete temp directory \"" + global::a.j + "\"! " + ex.Message);
			}
		}
		Console.OutputEncoding = global::a.d;
		Environment.SetEnvironmentVariable("Path", global::a.c);
		Environment.Exit(0);
	}

	private static string h(string A_0)
	{
		if (!Path.GetExtension(A_0).Equals(".lnk", StringComparison.OrdinalIgnoreCase))
		{
			return A_0;
		}
		string text4;
		try
		{
			FileStream fileStream = File.Open(A_0, FileMode.Open, FileAccess.Read);
			using (BinaryReader binaryReader = new BinaryReader(fileStream))
			{
				fileStream.Seek(20L, SeekOrigin.Begin);
				if ((binaryReader.ReadUInt32() & 1U) == 1U)
				{
					fileStream.Seek(76L, SeekOrigin.Begin);
					uint num = (uint)binaryReader.ReadUInt16();
					fileStream.Seek((long)((ulong)num), SeekOrigin.Current);
				}
				long position = fileStream.Position;
				ulong num2 = (ulong)binaryReader.ReadUInt32();
				fileStream.Seek(12L, SeekOrigin.Current);
				uint num3 = binaryReader.ReadUInt32();
				fileStream.Seek(position + (long)((ulong)num3), SeekOrigin.Begin);
				long num4 = (long)(num2 + (ulong)position - (ulong)fileStream.Position - 2UL);
				string text = (global::a.e ? UAO.GetStringFromBig5Bytes(binaryReader.ReadBytes((int)num4)) : Encoding.Default.GetString(binaryReader.ReadBytes((int)num4)));
				int num5 = text.IndexOf("\0\0");
				if (num5 > -1)
				{
					int num6 = text.IndexOf("\\\\", num5 + 2) + 2;
					num6 = text.IndexOf('\0', num6) + 1;
					string text2 = text.Substring(0, num5);
					string text3 = text.Substring(num6);
					text4 = text2 + text3;
				}
				else
				{
					text4 = text;
				}
			}
		}
		catch
		{
			text4 = A_0;
		}
		return text4;
	}

	private static void a(string[] A_0)
	{
		Console.Title = "SushiHelper v250629 test";
		Console.CancelKeyPress += global::a.a;
		Console.OutputEncoding = Encoding.UTF8;
		Environment.SetEnvironmentVariable("Path", global::a.b + ";" + global::a.c);
		Console.WriteLine();
		global::a.a();
		if (global::a.n != "" && !Directory.Exists(global::a.n))
		{
			try
			{
				Directory.CreateDirectory(global::a.n);
			}
			catch
			{
				global::a.n = "";
			}
		}
		if (global::a.o != "" && !Directory.Exists(global::a.o))
		{
			try
			{
				Directory.CreateDirectory(global::a.o);
			}
			catch
			{
				global::a.o = "";
			}
		}
		if (global::a.p == "")
		{
			global::a.p = global::a.b + "\\ffmpeg.exe";
		}
		if (!File.Exists(global::a.p))
		{
			try
			{
				Process process = Process.Start(new ProcessStartInfo
				{
					FileName = "ffmpeg.exe",
					UseShellExecute = false,
					RedirectStandardError = true,
					StandardErrorEncoding = Encoding.Default
				});
				process.StandardError.ReadToEnd();
				process.WaitForExit();
				global::a.p = "ffmpeg.exe";
			}
			catch
			{
				global::a.a("\"ffmpeg.exe\" is not found!");
				global::a.b();
			}
		}
		if (global::a.q == "")
		{
			global::a.q = global::a.b + "\\ffprobe.exe";
		}
		if (!File.Exists(global::a.q))
		{
			try
			{
				Process process2 = Process.Start(new ProcessStartInfo
				{
					FileName = "ffprobe.exe",
					UseShellExecute = false,
					RedirectStandardError = true,
					StandardErrorEncoding = Encoding.Default
				});
				process2.StandardError.ReadToEnd();
				process2.WaitForExit();
				global::a.q = "ffprobe.exe";
			}
			catch
			{
				global::a.b("\"ffprobe.exe\" is not found!");
				global::a.q = "";
			}
		}
		if (global::a.r == "")
		{
			global::a.r = global::a.b + "\\sushi.exe";
		}
		if (!File.Exists(global::a.r))
		{
			try
			{
				Process process3 = Process.Start(new ProcessStartInfo
				{
					FileName = "sushi.exe",
					UseShellExecute = false,
					RedirectStandardError = true,
					StandardErrorEncoding = Encoding.Default
				});
				process3.StandardError.ReadToEnd();
				process3.WaitForExit();
				global::a.r = "sushi.exe";
			}
			catch
			{
				global::a.a("\"sushi.exe\" is not found!");
				global::a.b();
			}
		}
		List<string> list = new List<string>();
		for (int i = 0; i < A_0.Length; i++)
		{
			if (A_0[i].Equals("-mw", StringComparison.OrdinalIgnoreCase))
			{
				int num;
				if (i + 1 < A_0.Length && int.TryParse(A_0[i + 1], out num))
				{
					i++;
					if (num >= 30)
					{
						global::a.h = A_0[i];
					}
				}
			}
			else if (A_0[i].Equals("-sr", StringComparison.OrdinalIgnoreCase))
			{
				int num2;
				if (i + 1 < A_0.Length && int.TryParse(A_0[i + 1], out num2))
				{
					i++;
					if (num2 >= 12000)
					{
						global::a.i = A_0[i];
					}
				}
			}
			else if (A_0[i].Equals("-td", StringComparison.OrdinalIgnoreCase))
			{
				if (i + 1 < A_0.Length)
				{
					i++;
					if (!Directory.Exists(A_0[i]))
					{
						try
						{
							Directory.CreateDirectory(A_0[i]);
						}
						catch (Exception ex)
						{
							global::a.a("Cannot create temp directory \"" + A_0[i] + "\"! " + ex.Message);
							global::a.b();
						}
						global::a.k = true;
					}
					global::a.j = A_0[i];
				}
			}
			else
			{
				list.Add(global::a.h(A_0[i]));
			}
		}
		try
		{
			switch (list.Count)
			{
			case 0:
			{
				if (!Directory.Exists(global::a.l) || !Directory.Exists(global::a.m))
				{
					goto IL_0610;
				}
				global::a.a(global::a.l, global::a.m, false);
				if (!Directory.Exists(global::a.o) || Directory.GetFiles(global::a.m, "*.sushi.*").Length == 0)
				{
					goto IL_0610;
				}
				foreach (string text in Directory.EnumerateFiles(global::a.l))
				{
					string text2 = global::a.o + text.Substring(global::a.l.Length);
					if (File.Exists(text2))
					{
						File.Delete(text2);
					}
					File.Move(text, text2);
				}
				using (IEnumerator<string> enumerator = Directory.EnumerateFiles(global::a.m).GetEnumerator())
				{
					while (enumerator.MoveNext())
					{
						string text3 = enumerator.Current;
						string text2 = global::a.o + text3.Substring(global::a.m.Length);
						if (File.Exists(text2))
						{
							File.Delete(text2);
						}
						File.Move(text3, text2);
					}
					goto IL_0610;
				}
				break;
			}
			case 1:
				break;
			case 2:
				if (Directory.Exists(list[0]) && Directory.Exists(list[1]))
				{
					global::a.a(Path.GetFullPath(list[0]), Path.GetFullPath(list[1]), true);
					goto IL_0610;
				}
				goto IL_0610;
			case 3:
				if (File.Exists(list[0]))
				{
					if (File.Exists(list[1]) && File.Exists(list[2]))
					{
						decimal num3;
						decimal num4;
						global::a.a(Path.GetFullPath(list[0]), Path.GetFullPath(list[1]), Path.GetFullPath(list[2]), out num3, out num4, true);
						goto IL_0610;
					}
					goto IL_0610;
				}
				else
				{
					if (Directory.Exists(list[0]) && Directory.Exists(list[1]) && Directory.Exists(list[2]))
					{
						global::a.a(Path.GetFullPath(list[0]), Path.GetFullPath(list[1]), Path.GetFullPath(list[2]), true);
						goto IL_0610;
					}
					goto IL_0610;
				}
				break;
			default:
				goto IL_0610;
			}
			if (File.Exists(list[0]))
			{
				global::a.g(list[0]);
			}
			else if (Directory.Exists(list[0]))
			{
				global::a.f(Path.GetFullPath(list[0]));
			}
			IL_0610:;
		}
		catch (Exception innerException)
		{
			while (innerException != null)
			{
				global::a.a(innerException.ToString());
				innerException = innerException.InnerException;
			}
		}
		finally
		{
			global::a.b();
		}
	}

	private static void g(string A_0)
	{
		global::a.b("Processing text file \"" + A_0 + "\"");
		using (StringReader stringReader = new StringReader(global::a.e ? UAO.ReadFile(A_0) : File.ReadAllText(A_0, Encoding.Default)))
		{
			List<string> list = new List<string>();
			List<string> list2 = new List<string>();
			List<string> list3 = new List<string>();
			string text;
			while ((text = stringReader.ReadLine()) != null)
			{
				text = text.Trim();
				while (text.Length >= 2 && text[0] == '"' && text[text.Length - 1] == '"')
				{
					text = text.Substring(1, text.Length - 2);
				}
				if (text.Length != 0 && text[0] != ';' && !text.StartsWith("rem", StringComparison.OrdinalIgnoreCase))
				{
					if (File.Exists(text))
					{
						list.Add(text);
					}
					else if (Directory.Exists(text))
					{
						list2.Add(text);
					}
					else
					{
						list3.Add(text);
					}
				}
			}
			if (list.Count >= 1 && (list2.Count == 1 || list2.Count == 2))
			{
				bool flag = false;
				int i;
				for (i = 0; i < list[0].Length; i++)
				{
					char c = list[0][i];
					for (int j = 1; j < list.Count; j++)
					{
						if (i >= list[j].Length || c != list[j][i])
						{
							flag = true;
							break;
						}
					}
					if (flag)
					{
						break;
					}
				}
				if (i > 0)
				{
					i = list[0].LastIndexOf('\\', i - 1) + 1;
				}
				string text2 = list[0].Substring(0, 3) + "[SH]";
				Directory.CreateDirectory(text2);
				List<string> list4 = new List<string>();
				for (int k = 0; k < list.Count; k++)
				{
					list4.Add(text2 + "\\" + list[k].Substring(i).Replace(':', '_').Replace('\\', '$'));
					if (!global::a.CreateSymbolicLink(list4[k], list[k], global::a.a.a))
					{
						break;
					}
				}
				if (File.Exists(list4[0]))
				{
					int count = list2.Count;
					if (count != 1)
					{
						if (count == 2)
						{
							global::a.a(list2[0], text2, list2[1], true);
						}
					}
					else
					{
						global::a.a(list2[0], text2, true);
					}
				}
				else
				{
					global::a.a("Run as administrator!");
				}
				Directory.Delete(text2, true);
			}
			else
			{
				switch (list2.Count)
				{
				case 1:
					global::a.f(list2[0]);
					break;
				case 2:
					global::a.a(list2[0], list2[1], true);
					break;
				case 3:
					global::a.a(list2[0], list2[1], list2[2], true);
					break;
				default:
				{
					bool flag2 = true;
					if (list.Count == 3)
					{
						string text3 = "";
						string text4 = "";
						string text5 = "";
						foreach (string text6 in list)
						{
							if (global::a.g.Contains(Path.GetExtension(text6)))
							{
								text4 = text6;
							}
							else if (text3 == "")
							{
								text3 = text6;
							}
							else
							{
								text5 = text6;
							}
						}
						if (text3 != "" && text4 != "" && text5 != "")
						{
							SortedSet<TimeSpan> sortedSet = new SortedSet<TimeSpan> { TimeSpan.Zero };
							SortedSet<TimeSpan> sortedSet2 = new SortedSet<TimeSpan> { TimeSpan.Zero };
							foreach (string text7 in list3)
							{
								if (sortedSet.Count == 1)
								{
									foreach (string text8 in text7.Split(new char[] { ',' }))
									{
										TimeSpan timeSpan;
										if ((TimeSpan.TryParse(text8, out timeSpan) || TimeSpan.TryParse("0:" + text8, out timeSpan)) && timeSpan > TimeSpan.Zero)
										{
											sortedSet.Add(timeSpan);
										}
									}
								}
								else if (sortedSet2.Count == 1)
								{
									foreach (string text9 in text7.Split(new char[] { ',' }))
									{
										TimeSpan timeSpan;
										if ((TimeSpan.TryParse(text9, out timeSpan) || TimeSpan.TryParse("0:" + text9, out timeSpan)) && timeSpan > TimeSpan.Zero)
										{
											sortedSet2.Add(timeSpan);
										}
									}
								}
							}
							if (sortedSet.Count == sortedSet2.Count)
							{
								flag2 = false;
								Console.WriteLine("\tTV audio    file: \"" + text3 + "\"");
								Console.WriteLine("\tTV subtitle file: \"" + text4 + "\"");
								Console.Write("\tTV cut times:    ");
								foreach (TimeSpan timeSpan2 in sortedSet)
								{
									string text10 = " ";
									TimeSpan timeSpan3 = timeSpan2;
									Console.Write(text10 + timeSpan3.ToString());
								}
								Console.WriteLine();
								Console.WriteLine("\tBD audio    file: \"" + text5 + "\"");
								Console.Write("\tBD cut times:    ");
								foreach (TimeSpan timeSpan4 in sortedSet2)
								{
									string text11 = " ";
									TimeSpan timeSpan3 = timeSpan4;
									Console.Write(text11 + timeSpan3.ToString());
								}
								Console.WriteLine();
								List<string> list5;
								List<string> list6;
								List<string> list7;
								if (sortedSet.Count > 1)
								{
									list5 = global::a.a(text3, sortedSet, false);
									list6 = global::a.a(text5, sortedSet2, false);
									list7 = global::a.a(text4, sortedSet, false);
								}
								else
								{
									list5 = new List<string> { text3 };
									list6 = new List<string> { text5 };
									list7 = new List<string> { text4 };
								}
								global::a.a(Path.GetDirectoryName(list6[0]), list5, list6, list7);
							}
						}
					}
					if (flag2)
					{
						global::a.b("There is something wrong in the text file \"" + A_0 + "\"!");
						if (list2.Count > 0)
						{
							Console.Write("Directories: ");
							foreach (string text12 in list2)
							{
								Console.Write("\"" + text12 + "\", ");
							}
							Console.CursorLeft -= 2;
							Console.WriteLine("  ");
						}
						if (list.Count > 0)
						{
							Console.Write("Files: ");
							foreach (string text13 in list)
							{
								Console.Write("\"" + text13 + "\", ");
							}
							Console.CursorLeft -= 2;
							Console.WriteLine("  ");
						}
						if (list3.Count > 0)
						{
							Console.Write("Other lines:");
							foreach (string text14 in list3)
							{
								Console.WriteLine(text14);
							}
						}
						global::a.a("");
					}
					break;
				}
				}
			}
		}
	}

	private static void a(string A_0, out Dictionary<string, string> A_1, out Dictionary<string, string> A_2)
	{
		Dictionary<string, string> dictionary = new Dictionary<string, string>();
		foreach (string text in Directory.EnumerateFiles(A_0, "*", SearchOption.TopDirectoryOnly))
		{
			if (!text.Contains("sushi."))
			{
				dictionary[Path.GetFileName(text)] = text;
			}
		}
		A_1 = new Dictionary<string, string>();
		A_2 = new Dictionary<string, string>();
		foreach (string text2 in dictionary.Keys)
		{
			string extension = Path.GetExtension(text2);
			if (!(extension == ""))
			{
				int num = -1;
				if (text2.Contains(".From.") || text2.Contains(".track") || text2.Contains(".."))
				{
					num = text2.LastIndexOf('.');
				}
				else
				{
					for (int i = 0; i < text2.Length; i++)
					{
						if (text2[i] == 'E' || text2[i] == 'e' || text2[i] == '第')
						{
							i++;
							if (text2[i] == 'P' || text2[i] == 'p')
							{
								i++;
							}
							if (char.IsDigit(text2[i]))
							{
								i++;
								bool flag = false;
								while ((!flag && text2[i] == '.') || char.IsDigit(text2[i]))
								{
									if (!flag && text2[i] == '.')
									{
										flag = true;
									}
									i++;
								}
								if (text2[i] != '季')
								{
									if (text2[i - 1] == '.')
									{
										num = i - 1;
										break;
									}
									num = i;
									break;
								}
							}
						}
					}
				}
				if (num == -1)
				{
					int num2 = text2.LastIndexOf('$');
					int num3 = text2.LastIndexOf(']', text2.Length - 1, text2.Length - 1 - num2);
					num = text2.IndexOf('.', ((num3 != -1) ? num3 : num2) + 1);
					for (int j = num + 1; j < text2.Length; j++)
					{
						if (!char.IsDigit(text2[j]))
						{
							num = j;
							break;
						}
					}
				}
				string text3 = text2.Substring(0, num);
				string text4 = dictionary[text2];
				if (global::a.g.Contains(extension))
				{
					A_1[text3] = text4;
				}
				else if (!A_2.ContainsKey(text3) || new FileInfo(text4).Length > new FileInfo(A_2[text3]).Length)
				{
					A_2[text3] = text4;
				}
			}
		}
	}

	private static bool a(Dictionary<string, string> A_0, Dictionary<string, string> A_1, out List<string> A_2, out List<string> A_3)
	{
		A_2 = new List<string>();
		A_3 = new List<string>();
		foreach (string text in new SortedSet<string>(A_0.Keys))
		{
			A_2.Add(A_0[text]);
			if (!A_1.ContainsKey(text))
			{
				global::a.a("There is no any media file for the subtitle \"" + Path.GetFileName(A_0[text]) + "\"!");
				return false;
			}
			A_3.Add(A_1[text]);
			A_1.Remove(text);
		}
		return true;
	}

	private static bool a(Dictionary<string, string> A_0, int A_1, out List<string> A_2)
	{
		A_2 = null;
		string text = "";
		Dictionary<string, int> dictionary = new Dictionary<string, int>(StringComparer.OrdinalIgnoreCase);
		Dictionary<string, List<string>> dictionary2 = new Dictionary<string, List<string>>();
		foreach (string text2 in A_0.Values)
		{
			text = text2;
			string extension = Path.GetExtension(text2);
			if (!dictionary.ContainsKey(extension))
			{
				dictionary[extension] = 0;
				dictionary2[extension] = new List<string>();
			}
			Dictionary<string, int> dictionary3 = dictionary;
			string text3 = extension;
			int num = dictionary3[text3] + 1;
			dictionary3[text3] = num;
			dictionary2[extension].Add(text2);
		}
		foreach (string text4 in dictionary.Keys)
		{
			if (dictionary[text4] == A_1 && (A_2 == null || new FileInfo(dictionary2[text4][0]).Length > new FileInfo(A_2[0]).Length))
			{
				A_2 = dictionary2[text4];
			}
		}
		if (A_2 == null)
		{
			global::a.a("Not enough files for Sushi in the directory \"" + Path.GetDirectoryName(text) + "\"!");
			return false;
		}
		A_2.Sort();
		return true;
	}

	private static void a(string A_0, List<string> A_1, List<string> A_2, List<string> A_3)
	{
		Dictionary<string, int> dictionary = new Dictionary<string, int>();
		Dictionary<string, int> dictionary2 = new Dictionary<string, int>();
		StringBuilder stringBuilder = new StringBuilder();
		for (int i = 0; i < A_1.Count; i++)
		{
			decimal num;
			decimal num2;
			stringBuilder.Append(global::a.a(A_1[i], A_2[i], A_3[i], out num, out num2, false));
			if (num != 0m)
			{
				dictionary[A_3[i]] = Convert.ToInt32(num);
			}
			if (num2 != 0m)
			{
				dictionary2[A_3[i]] = Convert.ToInt32(num2);
			}
		}
		if (stringBuilder.Length > 0)
		{
			global::a.a(A_0, stringBuilder.ToString(), dictionary, dictionary2, true);
		}
	}

	private static void f(string A_0)
	{
		global::a.b("Processing directory \"" + A_0 + "\"");
		Dictionary<string, string> dictionary;
		Dictionary<string, string> dictionary2;
		global::a.a(A_0, out dictionary, out dictionary2);
		if (dictionary.Count <= 0 || dictionary.Count * 2 > dictionary2.Count)
		{
			global::a.b("Not enough files for Sushi!");
			Console.WriteLine(string.Format("\"{0}\" subtitle files = {1}", A_0, dictionary.Count));
			Console.WriteLine(string.Format("\"{0}\" media    files = {1}", A_0, dictionary2.Count));
			global::a.a("");
			return;
		}
		List<string> list;
		List<string> list2;
		if (!global::a.a(dictionary, dictionary2, out list, out list2))
		{
			return;
		}
		List<string> list3;
		if (list.Count == dictionary2.Count)
		{
			list3 = new List<string>(new SortedSet<string>(dictionary2.Values));
		}
		else if (!global::a.a(dictionary2, list.Count, out list3))
		{
			return;
		}
		global::a.a(A_0, list2, list3, list);
	}

	private static void a(string A_0, string A_1, bool A_2 = true)
	{
		if (A_0 == A_1)
		{
			global::a.f(A_0);
			return;
		}
		global::a.b(string.Concat(new string[] { "Processing directory \"", A_0, "\" & \"", A_1, "\"" }));
		Dictionary<string, string> dictionary;
		Dictionary<string, string> dictionary2;
		global::a.a(A_0, out dictionary, out dictionary2);
		Dictionary<string, string> dictionary3;
		Dictionary<string, string> dictionary4;
		global::a.a(A_1, out dictionary3, out dictionary4);
		if (A_2 && dictionary3.Count > dictionary.Count)
		{
			string text = A_0;
			A_0 = A_1;
			A_1 = text;
			Dictionary<string, string> dictionary5 = dictionary;
			dictionary = dictionary3;
			dictionary3 = dictionary5;
			Dictionary<string, string> dictionary6 = dictionary2;
			dictionary2 = dictionary4;
			dictionary4 = dictionary6;
		}
		if (dictionary.Count > 0 && dictionary.Count <= dictionary2.Count && dictionary.Count <= dictionary4.Count)
		{
			List<string> list;
			List<string> list2;
			if (dictionary.Count == dictionary2.Count)
			{
				list = new List<string>(new SortedSet<string>(dictionary.Values));
				list2 = new List<string>(new SortedSet<string>(dictionary2.Values));
			}
			else if (!global::a.a(dictionary, dictionary2, out list, out list2))
			{
				return;
			}
			List<string> list3;
			if (list.Count == dictionary4.Count)
			{
				list3 = new List<string>(new SortedSet<string>(dictionary4.Values));
			}
			else if (!global::a.a(dictionary4, list.Count, out list3))
			{
				return;
			}
			global::a.a(A_1, list2, list3, list);
			return;
		}
		global::a.b("Not enough files for Sushi!");
		Console.WriteLine(string.Format("\"{0}\" subtitle files = {1}", A_0, dictionary.Count));
		Console.WriteLine(string.Format("\"{0}\" media    files = {1}", A_0, dictionary2.Count));
		Console.WriteLine(string.Format("\"{0}\" media    files = {1}", A_1, dictionary4.Count));
		global::a.a("");
	}

	private static void a(string A_0, string A_1, string A_2, bool A_3 = true)
	{
		if (A_0 == A_1)
		{
			global::a.a(A_0, A_2, true);
			return;
		}
		if (A_1 == A_2 || A_0 == A_2)
		{
			global::a.a(A_0, A_1, true);
			return;
		}
		global::a.b(string.Concat(new string[] { "Processing directory \"", A_0, "\" & \"", A_1, "\" & \"", A_2, "\"" }));
		Dictionary<string, string> dictionary;
		Dictionary<string, string> dictionary2;
		global::a.a(A_0, out dictionary, out dictionary2);
		Dictionary<string, string> dictionary3;
		Dictionary<string, string> dictionary4;
		global::a.a(A_1, out dictionary3, out dictionary4);
		Dictionary<string, string> dictionary5;
		Dictionary<string, string> dictionary6;
		global::a.a(A_2, out dictionary5, out dictionary6);
		if (A_3)
		{
			if (dictionary.Count > dictionary3.Count)
			{
				if (dictionary.Count > dictionary5.Count)
				{
					string text = A_0;
					A_0 = A_2;
					A_2 = text;
					Dictionary<string, string> dictionary7 = dictionary;
					dictionary = dictionary5;
					dictionary5 = dictionary7;
					Dictionary<string, string> dictionary8 = dictionary2;
					dictionary2 = dictionary6;
					dictionary6 = dictionary8;
				}
			}
			else if (dictionary3.Count > dictionary5.Count)
			{
				string text2 = A_1;
				A_1 = A_2;
				A_2 = text2;
				Dictionary<string, string> dictionary9 = dictionary3;
				dictionary3 = dictionary5;
				dictionary5 = dictionary9;
				Dictionary<string, string> dictionary10 = dictionary4;
				dictionary4 = dictionary6;
				dictionary6 = dictionary10;
			}
			bool flag = true;
			foreach (string text3 in dictionary5.Keys)
			{
				if (!dictionary4.ContainsKey(text3))
				{
					flag = false;
					break;
				}
			}
			if (flag)
			{
				string text4 = A_0;
				A_0 = A_1;
				A_1 = text4;
				Dictionary<string, string> dictionary11 = dictionary;
				dictionary = dictionary3;
				dictionary3 = dictionary11;
				Dictionary<string, string> dictionary12 = dictionary2;
				dictionary2 = dictionary4;
				dictionary4 = dictionary12;
			}
		}
		if (dictionary5.Count > 0 && dictionary5.Count <= dictionary2.Count && dictionary5.Count <= dictionary4.Count)
		{
			List<string> list;
			List<string> list2;
			if (dictionary5.Count == dictionary2.Count)
			{
				list = new List<string>(new SortedSet<string>(dictionary5.Values));
				list2 = new List<string>(new SortedSet<string>(dictionary2.Values));
			}
			else if (!global::a.a(dictionary5, dictionary2, out list, out list2))
			{
				return;
			}
			List<string> list3;
			if (list.Count == dictionary4.Count)
			{
				list3 = new List<string>(new SortedSet<string>(dictionary4.Values));
			}
			else if (!global::a.a(dictionary4, list.Count, out list3))
			{
				return;
			}
			global::a.a(A_1, list2, list3, list);
			return;
		}
		global::a.b("Not enough files for Sushi!");
		Console.WriteLine(string.Format("\"{0}\" subtitle files = {1}", A_2, dictionary5.Count));
		Console.WriteLine(string.Format("\"{0}\" media    files = {1}", A_0, dictionary2.Count));
		Console.WriteLine(string.Format("\"{0}\" media    files = {1}", A_1, dictionary4.Count));
		global::a.a("");
	}

	private static string a(string A_0, string A_1, string A_2, out decimal A_3, out decimal A_4, bool A_5 = false)
	{
		A_3 = 0m;
		A_4 = 0m;
		if (A_5)
		{
			global::a.b(string.Concat(new string[] { "Processing file \"", A_0, "\" & \"", A_1, "\" & \"", A_2, "\"" }));
			string text = Path.GetFileName(A_0);
			string text2 = Path.GetFileName(A_1);
			string text3 = Path.GetFileName(A_2);
			string extension = Path.GetExtension(text);
			string extension2 = Path.GetExtension(text2);
			string extension3 = Path.GetExtension(text3);
			if (extension == "" || extension2 == "" || extension3 == "")
			{
				global::a.a(string.Concat(new string[] { "At least one of \"", text, "\", \"", text2, "\", and \"", text3, "\" doesn't have the extension!" }));
				return "";
			}
			if (!global::a.g.Contains(extension3))
			{
				if (global::a.g.Contains(extension))
				{
					if (global::a.g.Contains(extension2))
					{
						global::a.a(string.Concat(new string[] { "Both \"", text, "\" and \"", text2, "\" are subtitle files!" }));
						return "";
					}
					string text4 = A_0;
					A_0 = A_2;
					A_2 = text4;
					string text5 = text;
					text = text3;
					text3 = text5;
				}
				else
				{
					if (!global::a.g.Contains(extension2))
					{
						global::a.a(string.Concat(new string[] { "One of \"", text, "\", \"", text2, "\", and \"", text3, "\" should be the subtitle file!" }));
						return "";
					}
					string text6 = A_1;
					A_1 = A_2;
					A_2 = text6;
					string text7 = text2;
					text2 = text3;
					text3 = text7;
				}
			}
			else if (global::a.g.Contains(extension) || global::a.g.Contains(extension2))
			{
				global::a.a(string.Concat(new string[] { "More than one of \"", text, "\", \"", text2, "\", and \"", text3, "\" are subtitle files!" }));
				return "";
			}
			string text8 = text.Substring(0, text.IndexOf('.'));
			string text9 = text2.Substring(0, text2.IndexOf('.'));
			string text10 = text3.Substring(0, text3.IndexOf('.'));
			if (text10 == text9)
			{
				if (!(text10 != text8))
				{
					global::a.a(string.Concat(new string[] { "Both \"", text, "\" & \"", text2, "\" could be the media file of \"", text3, "\"!" }));
					return "";
				}
				string text11 = A_0;
				A_0 = A_1;
				A_1 = text11;
			}
			else if (text10 != text8)
			{
				global::a.a("There is no any media file for the subtitle \"" + text3 + "\"!");
				return "";
			}
		}
		string currentDirectory = Directory.GetCurrentDirectory();
		string text12 = Path.GetDirectoryName(A_0);
		if (A_0.Length > 3 && A_1.Length > 3 && A_2.Length > 3 && A_0[0] == A_1[0] && A_1[0] == A_2[0] && A_0[1] == ':' && A_1[1] == ':' && A_2[1] == ':' && A_0[2] == '\\' && A_1[2] == '\\' && A_2[2] == '\\')
		{
			while (text12.Length != 3 && (!A_1.StartsWith(text12) || !A_2.StartsWith(text12)))
			{
				text12 = Path.GetDirectoryName(text12);
			}
			if (text12.Length == 3)
			{
				Directory.SetCurrentDirectory(A_0.Substring(0, 3));
				text12 = A_0.Substring(0, 2);
			}
			else
			{
				Directory.SetCurrentDirectory(text12);
			}
			A_0 = A_0.Substring(text12.Length + 1);
			A_1 = A_1.Substring(text12.Length + 1);
			A_2 = A_2.Substring(text12.Length + 1);
		}
		global::a.b("Get the audio stream indexes of input files");
		Console.WriteLine();
		string text13;
		global::a.a(A_0, out text13, out A_3);
		string text14;
		global::a.a(A_1, out text14, out A_4);
		if (text13 == "" || text14 == "")
		{
			if (text13 == "")
			{
				global::a.b("There is no any audio stream in \"" + A_0 + "\"!");
			}
			if (text14 == "")
			{
				global::a.b("There is no any audio stream in \"" + A_1 + "\"!");
			}
			global::a.a("");
			Directory.SetCurrentDirectory(currentDirectory);
			return "";
		}
		bool flag = false;
		Encoding encoding;
		string text15 = global::a.a(A_2, out encoding);
		if (encoding != Encoding.UTF8)
		{
			flag = true;
			if (encoding == Encoding.Default)
			{
				flag = false;
				string text16 = text15;
				for (int i = 0; i < text16.Length; i++)
				{
					if (text16[i] > '\u007f')
					{
						flag = true;
						break;
					}
				}
			}
			if (flag)
			{
				int num = A_2.LastIndexOf('.');
				A_2 = A_2.Substring(0, num) + ".utf8" + A_2.Substring(num);
				if (global::a.j != "")
				{
					A_2 = Path.Combine(global::a.j, Path.GetFileName(A_2));
				}
				File.WriteAllText(A_2, text15, Encoding.UTF8);
			}
		}
		if (A_3 != 0m)
		{
			string text17 = global::a.a(A_2, new SortedSet<TimeSpan> { TimeSpan.FromMilliseconds((double)A_3) }, true)[0];
			if (flag)
			{
				File.Delete(A_2);
			}
			A_2 = text17;
		}
		Process process = Process.Start(new ProcessStartInfo
		{
			FileName = global::a.r,
			UseShellExecute = false,
			RedirectStandardError = true,
			StandardErrorEncoding = Encoding.UTF8,
			Arguments = string.Concat(new string[]
			{
				"--src \"",
				A_0,
				"\" --dst \"",
				A_1,
				"\" --script \"",
				A_2,
				"\" --src-audio ",
				text13,
				" --dst-audio ",
				text14,
				(global::a.h != "") ? (" --max-window " + global::a.h) : "",
				(global::a.i != "") ? (" --sample-rate " + global::a.i) : "",
				(global::a.j != "") ? (" --temp-dir \"" + global::a.j + "\"") : ""
			})
		});
		StringBuilder stringBuilder = new StringBuilder();
		Dictionary<string, string> dictionary = new Dictionary<string, string>();
		string text18 = "";
		string text19;
		while ((text19 = process.StandardError.ReadLine()) != null)
		{
			text19 = text19.TrimEnd(Array.Empty<char>());
			if (text19.StartsWith("Sushi's "))
			{
				int num2 = text19.IndexOf(" --");
				int num3 = text19.IndexOf(' ', num2 + 3) + 1;
				num2 = text19.IndexOf(" --", num3);
				string text20 = text19.Substring(num3, num2 - num3).Replace("\"", "");
				num3 = text19.IndexOf(' ', num2 + 3) + 1;
				num2 = text19.IndexOf(" --", num3);
				string text21 = text19.Substring(num3, num2 - num3).Replace("\"", "");
				num3 = text19.IndexOf(' ', num2 + 3) + 1;
				num2 = text19.IndexOf(" --", num3);
				string text22 = text19.Substring(num3, num2 - num3).Replace("\"", "");
				if (text20 != A_0)
				{
					dictionary[text20.Substring(0, text20.Length - 3)] = A_0.Substring(0, A_0.Length - 3);
				}
				if (text21 != A_1)
				{
					dictionary[text21.Substring(0, text21.Length - 3)] = A_1.Substring(0, A_1.Length - 3);
				}
				if (text22 != A_2)
				{
					dictionary[text22.Substring(0, text22.Length - 3)] = A_2.Substring(0, A_2.Length - 3);
				}
				using (Dictionary<string, string>.KeyCollection.Enumerator enumerator = dictionary.Keys.GetEnumerator())
				{
					while (enumerator.MoveNext())
					{
						string text23 = enumerator.Current;
						text19 = text19.Replace(text23, dictionary[text23]);
					}
					goto IL_0978;
				}
				goto IL_08A7;
			}
			goto IL_08A7;
			IL_0978:
			Console.WriteLine(text19);
			stringBuilder.AppendLine(text19);
			text18 = text19;
			continue;
			IL_08A7:
			if (text19.StartsWith("ffmpeg args: ") || text19.StartsWith("Done "))
			{
				using (Dictionary<string, string>.KeyCollection.Enumerator enumerator = dictionary.Keys.GetEnumerator())
				{
					while (enumerator.MoveNext())
					{
						string text24 = enumerator.Current;
						text19 = text19.Replace(text24, dictionary[text24]);
					}
					goto IL_0978;
				}
			}
			if (text19.StartsWith("Events from "))
			{
				text19 = "WARNING: " + text19;
				goto IL_0978;
			}
			if (text19.StartsWith("size= ") && text18.StartsWith("size= "))
			{
				Console.SetCursorPosition(0, Console.CursorTop - 1);
				int num4 = text18.Length + Environment.NewLine.Length;
				stringBuilder.Remove(stringBuilder.Length - num4, num4);
				goto IL_0978;
			}
			goto IL_0978;
		}
		process.WaitForExit();
		if (A_4 != 0m)
		{
			string text25 = A_1 + ".sushi" + Path.GetExtension(A_2);
			if (global::a.j != "")
			{
				text25 = Path.Combine(global::a.j, Path.GetFileName(text25));
			}
			string text26 = global::a.a(text25, new SortedSet<TimeSpan> { TimeSpan.FromMilliseconds(0.0 - (double)A_4) }, true)[0];
			File.Delete(text25);
			File.Move(text26, text25);
		}
		if (flag || A_3 != 0m)
		{
			File.Delete(A_2);
		}
		Directory.SetCurrentDirectory(currentDirectory);
		if (!A_5)
		{
			return stringBuilder.ToString();
		}
		Dictionary<string, int> dictionary2 = new Dictionary<string, int>();
		Dictionary<string, int> dictionary3 = new Dictionary<string, int>();
		if (A_3 != 0m)
		{
			dictionary2[A_2] = Convert.ToInt32(A_3);
		}
		if (A_4 != 0m)
		{
			dictionary3[A_2] = Convert.ToInt32(A_4);
		}
		if (stringBuilder.Length > 0)
		{
			global::a.a(text12, stringBuilder.ToString(), dictionary2, dictionary3, false);
		}
		return "";
	}

	private static void a(string A_0, out string A_1, out decimal A_2)
	{
		A_1 = "";
		A_2 = 0m;
		bool flag = false;
		if (global::a.q == "")
		{
			Process process = Process.Start(new ProcessStartInfo
			{
				FileName = global::a.p,
				UseShellExecute = false,
				RedirectStandardError = true,
				StandardErrorEncoding = Encoding.UTF8,
				Arguments = "-i \"" + A_0 + "\""
			});
			string text = process.StandardError.ReadToEnd();
			process.WaitForExit();
			flag = text.Contains(": Video:");
			int num = text.IndexOf(": Audio:");
			if (num != -1)
			{
				num = text.LastIndexOf(':', num - 1) + 1;
				int num2 = num + 1;
				while (char.IsDigit(text[num2]))
				{
					num2++;
				}
				A_1 = text.Substring(num, num2 - num);
			}
		}
		else
		{
			Process process2 = Process.Start(new ProcessStartInfo
			{
				FileName = global::a.q,
				UseShellExecute = false,
				RedirectStandardOutput = true,
				StandardOutputEncoding = Encoding.UTF8,
				Arguments = "-v error -show_entries stream=index,codec_type,start_time \"" + A_0 + "\""
			});
			string text2 = process2.StandardOutput.ReadToEnd();
			process2.WaitForExit();
			using (StringReader stringReader = new StringReader(text2))
			{
				bool flag2 = false;
				decimal num3 = 0m;
				decimal num4 = 0m;
				string text3;
				while ((text3 = stringReader.ReadLine()) != null)
				{
					if (text3 == "[STREAM]")
					{
						string text4 = "";
						string text5 = "";
						decimal num5 = 0m;
						while ((text3 = stringReader.ReadLine()) != "[/STREAM]")
						{
							int num6 = text3.IndexOf('=');
							if (num6 != -1)
							{
								string text6 = text3.Substring(0, num6);
								if (!(text6 == "index"))
								{
									if (!(text6 == "codec_type"))
									{
										if (text6 == "start_time")
										{
											decimal.TryParse(text3.Substring(num6 + 1), out num5);
										}
									}
									else
									{
										text5 = text3.Substring(num6 + 1);
									}
								}
								else
								{
									text4 = text3.Substring(num6 + 1);
								}
							}
						}
						if (!(text5 == "video"))
						{
							if (text5 == "audio")
							{
								if (!flag2)
								{
									flag2 = true;
									A_1 = text4;
									num4 = num5;
								}
							}
						}
						else if (!flag)
						{
							flag = true;
							num3 = num5;
						}
						if (flag && flag2)
						{
							A_2 = (num4 - num3) * 1000m;
							break;
						}
					}
				}
			}
		}
		if (!flag)
		{
			int num7 = A_0.IndexOf("DELAY ", StringComparison.OrdinalIgnoreCase);
			if (num7 != -1)
			{
				num7 += "DELAY ".Length;
				int num8 = A_0.IndexOf("ms", num7, StringComparison.OrdinalIgnoreCase);
				if (num8 != -1)
				{
					decimal.TryParse(A_0.Substring(num7, num8 - num7), out A_2);
				}
			}
		}
	}

	private static string a(string A_0, out Encoding A_1)
	{
		byte[] array = File.ReadAllBytes(A_0);
		A_1 = null;
		int num = 0;
		if (array.Length >= 3)
		{
			byte b = array[0];
			if (b != 239)
			{
				if (b != 254)
				{
					if (b == 255)
					{
						if (array[1] == 254)
						{
							A_1 = Encoding.Unicode;
							num = 2;
						}
					}
				}
				else if (array[1] == 255)
				{
					A_1 = Encoding.BigEndianUnicode;
					num = 2;
				}
			}
			else if (array[1] == 187 && array[2] == 191)
			{
				A_1 = Encoding.UTF8;
				num = 3;
			}
			if (A_1 != null)
			{
				return A_1.GetString(array, num, array.Length - num);
			}
		}
		A_1 = Encoding.Default;
		string text = A_1.GetString(array);
		if ((double)array.Length <= (double)A_1.GetByteCount(text) * (global::a.e ? 1.01 : 1.0))
		{
			if (global::a.e)
			{
				text = UAO.GetStringFromBig5Bytes(array);
			}
		}
		else
		{
			A_1 = null;
			string text2;
			if (Path.GetExtension(A_0).Equals(".srt", StringComparison.OrdinalIgnoreCase))
			{
				text2 = " --> ";
			}
			else
			{
				text2 = "\nDialogue:";
			}
			foreach (Encoding encoding in global::a.f)
			{
				text = encoding.GetString(array);
				if (text.Contains(text2))
				{
					A_1 = encoding;
					break;
				}
			}
			if (A_1 == null)
			{
				A_1 = Encoding.UTF8;
				text = A_1.GetString(array);
			}
		}
		return text;
	}

	private static string e(string A_0)
	{
		if (!File.Exists(A_0))
		{
			return "";
		}
		A_0 = Path.GetFullPath(A_0);
		string text = Path.GetDirectoryName(A_0);
		if (text[text.Length - 1] != '\\')
		{
			text += "\\";
		}
		string text2 = Path.GetFileNameWithoutExtension(A_0) + ".";
		string extension = Path.GetExtension(A_0);
		DateTime lastWriteTime = File.GetLastWriteTime(A_0);
		string text3 = text + text2 + lastWriteTime.ToString("yyyyMMdd.HHmmss") + extension;
		if (File.Exists(text3))
		{
			text2 += lastWriteTime.ToString("yyyyMMdd.HHmmss.");
			int num = 0;
			do
			{
				string text4 = text;
				string text5 = text2;
				int num2;
				num = (num2 = num + 1);
				text3 = text4 + text5 + num2.ToString() + extension;
			}
			while (File.Exists(text3));
		}
		File.Move(A_0, text3);
		return text3;
	}

	private static List<string> a(string A_0, SortedSet<TimeSpan> A_1, bool A_2 = false)
	{
		TimeSpan timeSpan = new TimeSpan(23, 59, 59);
		List<TimeSpan> list = new List<TimeSpan>(A_1);
		List<string> list2 = new List<string>();
		bool flag = !global::a.g.Contains(Path.GetExtension(A_0));
		ProcessStartInfo processStartInfo = new ProcessStartInfo
		{
			FileName = global::a.p,
			UseShellExecute = false,
			RedirectStandardError = true,
			StandardErrorEncoding = Encoding.UTF8
		};
		if (flag)
		{
			processStartInfo.Arguments = "-hide_banner -i \"" + A_0 + "\"";
			Process process = Process.Start(processStartInfo);
			string text = process.StandardError.ReadToEnd();
			process.WaitForExit();
			TimeSpan timeSpan2 = TimeSpan.Parse(text.Substring(text.IndexOf("Duration: ") + 10, 11));
			int num = list.Count - 1;
			while (num > 0 && list[num] > timeSpan2)
			{
				list.RemoveAt(num);
				num--;
			}
		}
		list.Add(timeSpan);
		if (!A_2)
		{
			processStartInfo.RedirectStandardError = false;
			processStartInfo.StandardErrorEncoding = null;
		}
		string text2 = ((global::a.j != "") ? global::a.j : Path.GetDirectoryName(A_0));
		if (text2.EndsWith("\\"))
		{
			text2 = text2.Substring(0, text2.Length - 1);
		}
		text2 += (A_2 ? "\\" : "\\[CA]\\");
		List<string> list3 = global::a.a(list, A_2);
		for (int i = 0; i <= list.Count - 2; i++)
		{
			Directory.CreateDirectory(text2);
			string text3 = string.Concat(new string[]
			{
				text2,
				Path.GetFileNameWithoutExtension(A_0),
				".From.",
				list3[i],
				".to.",
				list3[i + 1],
				flag ? ".wav" : Path.GetExtension(A_0)
			});
			if (flag)
			{
				processStartInfo.Arguments = string.Concat(new string[]
				{
					string.Format("-hide_banner -i \"{0}\" -ss {1} -to {2} -y -map 0:a:0 -ar ", A_0, list[i], list[i + 1]),
					(global::a.i != "") ? global::a.i : "12000",
					" -ac 1 -acodec pcm_s16le \"",
					text3,
					"\""
				});
			}
			else
			{
				processStartInfo.Arguments = string.Format("-hide_banner -i \"{0}\" -ss {1} -to {2} -c copy \"{3}\"", new object[]
				{
					A_0,
					list[i],
					list[i + 1],
					text3
				});
			}
			Process process = Process.Start(processStartInfo);
			if (A_2)
			{
				process.StandardError.ReadToEnd();
			}
			process.WaitForExit();
			if (File.Exists(text3))
			{
				list2.Add(text3);
			}
		}
		return list2;
	}

	private static List<string> a(List<TimeSpan> A_0, bool A_1 = false)
	{
		List<string> list = new List<string>();
		for (int i = 0; i <= A_0.Count - 2; i++)
		{
			TimeSpan timeSpan = A_0[i];
			StringBuilder stringBuilder = new StringBuilder();
			if (!A_1 && timeSpan.TotalMilliseconds < 0.0)
			{
				stringBuilder.Append('-');
			}
			int num = 0;
			if (A_1)
			{
				if (timeSpan.Hours != 0)
				{
					num = 0;
				}
				else if (timeSpan.Minutes != 0)
				{
					num = 1;
				}
				else if (timeSpan.Seconds != 0)
				{
					num = 2;
				}
				else
				{
					num = 3;
				}
			}
			int num2;
			if (timeSpan.Milliseconds != 0 || timeSpan.TotalMilliseconds == 0.0)
			{
				num2 = 4;
			}
			else if (timeSpan.Seconds != 0)
			{
				num2 = 3;
			}
			else if (timeSpan.Minutes != 0)
			{
				num2 = 2;
			}
			else
			{
				num2 = 1;
			}
			if (A_1)
			{
				switch (num)
				{
				case 0:
					stringBuilder.Append(timeSpan.Hours.ToString() + "h");
					break;
				case 1:
					stringBuilder.Append(timeSpan.Minutes.ToString() + "m");
					break;
				case 2:
					stringBuilder.Append(timeSpan.Seconds.ToString() + "s");
					break;
				case 3:
					stringBuilder.Append(timeSpan.Milliseconds.ToString() + "ms");
					break;
				}
			}
			else
			{
				stringBuilder.Append(timeSpan.Hours.ToString() + "h");
			}
			for (int j = (A_1 ? (num + 1) : 1); j < num2; j++)
			{
				switch (j)
				{
				case 1:
					stringBuilder.Append(Math.Abs(timeSpan.Minutes).ToString("00") + "m");
					break;
				case 2:
					stringBuilder.Append(Math.Abs(timeSpan.Seconds).ToString("00") + "s");
					break;
				case 3:
					stringBuilder.Append(Math.Abs(timeSpan.Milliseconds).ToString("000") + "ms");
					break;
				}
			}
			list.Add(stringBuilder.ToString());
		}
		list.Add("End");
		return list;
	}

	private static void a(string A_0, string A_1, Dictionary<string, int> A_2, Dictionary<string, int> A_3, bool A_4 = true)
	{
		string text = A_0;
		if (global::a.n != "")
		{
			text = global::a.n;
		}
		string text2 = text + "\\sushi.txt";
		global::a.e(text2);
		string text3 = text + "\\sushi.fixed.txt";
		string text4 = global::a.e(text3);
		if (text4 != "")
		{
			int num = text4.LastIndexOf(".fixed");
			File.Move(text4, text4.Substring(0, num) + text4.Substring(num + 6, text4.Length - num - 10) + ".fixed.txt");
		}
		StringBuilder stringBuilder = new StringBuilder();
		if (A_2.Count > 0)
		{
			stringBuilder.AppendLine();
			foreach (string text5 in new SortedSet<string>(A_2.Keys))
			{
				stringBuilder.AppendLine("Subtitle file: \"" + text5 + "\"");
				stringBuilder.AppendLine("Source audio delay: " + A_2[text5].ToString() + "ms");
				if (A_3.ContainsKey(text5))
				{
					stringBuilder.AppendLine("Destination audio delay: " + A_3[text5].ToString() + "ms");
					A_3.Remove(text5);
				}
			}
			A_2.Clear();
		}
		if (A_3.Count > 0)
		{
			stringBuilder.AppendLine();
			foreach (string text6 in new SortedSet<string>(A_3.Keys))
			{
				stringBuilder.AppendLine("Subtitle file: \"" + text6 + "\"");
				stringBuilder.AppendLine("Destination audio delay: " + A_3[text6].ToString() + "ms");
			}
			A_3.Clear();
		}
		string text7 = "";
		if (stringBuilder.Length > 0)
		{
			text7 = stringBuilder.ToString();
			stringBuilder.Clear();
			foreach (string text8 in text7.Split(new string[] { Environment.NewLine }, StringSplitOptions.None))
			{
				if (text8 == "")
				{
					Console.WriteLine();
				}
				else
				{
					global::a.b(text8);
				}
			}
		}
		else
		{
			Console.WriteLine();
		}
		using (StreamWriter streamWriter = new StreamWriter(text2, false, Encoding.Default))
		{
			streamWriter.Write(A_1 + text7);
		}
		string text9 = global::a.c(A_1);
		if (A_1 != text9)
		{
			using (StreamWriter streamWriter2 = new StreamWriter(text3, false, Encoding.Default))
			{
				streamWriter2.Write(text9 + text7);
			}
		}
		foreach (string text10 in Directory.EnumerateFiles(A_0, "*.sushi.*", SearchOption.TopDirectoryOnly))
		{
			global::a.d(text10);
		}
		if (A_4)
		{
			Process.Start(text);
		}
	}

	private static void d(string A_0)
	{
		bool flag = Path.GetExtension(A_0).Equals(".srt", StringComparison.OrdinalIgnoreCase);
		string text = "";
		StringBuilder stringBuilder = new StringBuilder();
		using (StreamReader streamReader = new StreamReader(A_0, Encoding.UTF8))
		{
			TimeSpan.FromHours(2.0);
			int num = 0;
			if (flag)
			{
				string[] array = new string[] { " --> " };
				string text2;
				while ((text2 = streamReader.ReadLine()) != null)
				{
					num++;
					text = text2;
					bool flag2 = false;
					string[] array2 = text2.Split(array, StringSplitOptions.None);
					if (array2.Length > 1)
					{
						TimeSpan timeSpan = TimeSpan.Parse(array2[0].Replace(',', '.'));
						TimeSpan timeSpan2 = TimeSpan.Parse(array2[1].Replace(',', '.'));
						if (timeSpan < TimeSpan.Zero)
						{
							flag2 = true;
							array2[0] = "00:00:00,000";
						}
						if (timeSpan2 < TimeSpan.Zero)
						{
							flag2 = true;
							array2[1] = "00:00:00,000";
						}
					}
					if (flag2)
					{
						stringBuilder.AppendLine(array2[0] + array[0] + array2[1]);
					}
					else
					{
						stringBuilder.AppendLine(text2);
					}
				}
			}
			else
			{
				string text2;
				while ((text2 = streamReader.ReadLine()) != null)
				{
					num++;
					text = text2;
					bool flag3 = false;
					string[] array3 = text2.Split(new char[] { ',' });
					if (array3.Length > 3 && (array3[0].Contains("Dialogue:") || array3[0].Contains("Comment:")))
					{
						TimeSpan timeSpan3 = TimeSpan.Parse(array3[1]);
						TimeSpan timeSpan4 = TimeSpan.Parse(array3[2]);
						if (timeSpan3 < TimeSpan.Zero)
						{
							flag3 = true;
							array3[1] = "0:00:00.00";
						}
						if (timeSpan4 < TimeSpan.Zero)
						{
							flag3 = true;
							array3[2] = "0:00:00.00";
						}
					}
					if (flag3)
					{
						stringBuilder.Append(array3[0]);
						for (int i = 1; i < array3.Length; i++)
						{
							stringBuilder.Append("," + array3[i]);
						}
						stringBuilder.AppendLine();
					}
					else
					{
						stringBuilder.AppendLine(text2);
					}
				}
			}
			if (!string.IsNullOrEmpty(text) && text[0] == '\u001a')
			{
				stringBuilder.Remove(stringBuilder.Length - text.Length - 2, text.Length + 2);
			}
		}
		if (flag && text != "")
		{
			stringBuilder.AppendLine();
		}
		string text3 = ((global::a.n == "") ? A_0 : (global::a.n + "\\" + Path.GetFileName(A_0)));
		using (StreamWriter streamWriter = new StreamWriter(text3, false, Encoding.UTF8))
		{
			global::a.b("Rewriting \"" + text3 + "\"");
			streamWriter.Write(stringBuilder.ToString());
		}
	}

	private static string c(string A_0)
	{
		StringBuilder stringBuilder = new StringBuilder();
		using (StringReader stringReader = new StringReader(A_0))
		{
			string[] array = new string[] { ": shift: ", ", diff: " };
			string[] array2 = new string[] { "Group (start: ", ", end: ", ", lines: ", "), shifts (start: ", ", end: ", ", average: ", ")" };
			string text = "0.############################";
			decimal num = 0.01m;
			List<string[]> list = new List<string[]>();
			int num2 = 0;
			decimal num3 = 0m;
			decimal num4 = 0m;
			List<string> list2 = new List<string>();
			StringBuilder stringBuilder2 = new StringBuilder();
			string text2;
			while ((text2 = stringReader.ReadLine()) != null)
			{
				if (text2.Length > 21 && text2.Substring(21).StartsWith(array[0]))
				{
					string text3 = text2.Substring(0, 10);
					string[] array3 = text2.Substring(11).Split(array, StringSplitOptions.RemoveEmptyEntries);
					decimal num5 = decimal.Parse(array3[1]);
					array3[1] = num5.ToString(text);
					if (num2 == 0 || Math.Abs(num3 - num5) >= num)
					{
						list.Add(new string[]
						{
							text3,
							array3[0],
							"1",
							array3[1],
							array3[1],
							array3[1]
						});
						num2 = 1;
						num4 = num5;
						num3 = num5;
					}
					else
					{
						int num6 = list.Count - 1;
						num2++;
						num4 += num5;
						num3 = num4 / num2;
						list[num6][1] = array3[0];
						list[num6][2] = num2.ToString();
						list[num6][4] = array3[1];
						list[num6][5] = num3.ToString(text);
					}
					stringBuilder.AppendLine(text2);
				}
				else if (text2.StartsWith(array2[0]))
				{
					string[] array4 = text2.Split(array2, StringSplitOptions.RemoveEmptyEntries);
					list2.Add(array4[array4.Length - 1]);
					stringBuilder2.AppendLine(text2);
				}
				else
				{
					if (text2.StartsWith("Done in "))
					{
						bool flag = false;
						if (list.Count > 1)
						{
							for (int i = list.Count - 1; i >= 0; i--)
							{
								string[] array5 = list[i];
								if (array5[2] == "1")
								{
									if (i == list.Count - 1)
									{
										string[] array6 = list[i - 1];
										array6[1] = array5[1];
										array6[2] = (int.Parse(array6[2]) + 1).ToString();
										list.RemoveAt(i);
									}
									else if (i == 0)
									{
										string[] array7 = list[i + 1];
										array7[0] = array5[0];
										array7[2] = (int.Parse(array7[2]) + 1).ToString();
										list.RemoveAt(i);
									}
									else
									{
										string[] array6 = list[i - 1];
										string[] array7 = list[i + 1];
										decimal num7 = decimal.Parse(array6[5]);
										decimal num8 = decimal.Parse(array7[5]);
										if (Math.Abs(num8 - num7) < num)
										{
											int num9 = int.Parse(array6[2]);
											int num10 = int.Parse(array7[2]);
											array6[1] = array7[1];
											array6[2] = (num9 + 1 + num10).ToString();
											array6[4] = array7[4];
											array6[5] = ((num7 * num9 + num8 * num10) / (num9 + num10)).ToString(text);
											list.RemoveAt(i);
											list.RemoveAt(i);
										}
									}
								}
							}
						}
						if (list.Count == list2.Count)
						{
							for (int j = 0; j < list.Count; j++)
							{
								if (Math.Abs(decimal.Parse(list[j][5]) - decimal.Parse(list2[j], NumberStyles.AllowLeadingWhite | NumberStyles.AllowTrailingWhite | NumberStyles.AllowLeadingSign | NumberStyles.AllowTrailingSign | NumberStyles.AllowDecimalPoint | NumberStyles.AllowThousands | NumberStyles.AllowExponent)) >= num)
								{
									flag = true;
									break;
								}
							}
						}
						else
						{
							flag = true;
						}
						if (flag)
						{
							using (List<string[]>.Enumerator enumerator = list.GetEnumerator())
							{
								while (enumerator.MoveNext())
								{
									string[] array8 = enumerator.Current;
									for (int k = 0; k < array2.Length - 1; k++)
									{
										stringBuilder.Append(array2[k] + array8[k]);
									}
									stringBuilder.AppendLine(array2[array2.Length - 1]);
								}
								goto IL_04A4;
							}
							goto IL_0496;
						}
						goto IL_0496;
						IL_04A4:
						list.Clear();
						num2 = 0;
						num3 = 0m;
						num4 = 0m;
						list2.Clear();
						stringBuilder2.Clear();
						stringBuilder.AppendLine(text2);
						continue;
						IL_0496:
						stringBuilder.Append(stringBuilder2.ToString());
						goto IL_04A4;
					}
					stringBuilder.AppendLine(text2);
				}
			}
		}
		return stringBuilder.ToString();
	}

	private static void a()
	{
		global::a.l = (global::a.m = (global::a.n = (global::a.o = "")));
		string text = global::a.a.Substring(0, global::a.a.Length - 4) + ".ini";
		if (!File.Exists(text))
		{
			text = global::a.b + "\\SushiHelper.ini";
			if (!File.Exists(text))
			{
				return;
			}
		}
		using (StringReader stringReader = new StringReader(File.ReadAllText(text, Encoding.UTF8)))
		{
			bool flag = false;
			string text2;
			while ((text2 = stringReader.ReadLine()) != null)
			{
				if (!flag)
				{
					if (!(text2 == "[SushiHelper]"))
					{
						break;
					}
					flag = true;
					global::a.b("Reading settings from \"" + text + "\"");
				}
				else if (!string.IsNullOrEmpty(text2) && text2[0] != ';')
				{
					int num = text2.IndexOf('=');
					if (num > 0 && num != text2.Length - 1)
					{
						string text3 = text2.Substring(0, num).Trim();
						string text4 = text2.Substring(num + 1).Trim();
						while (text4.Length >= 2 && text4[0] == '"' && text4[text4.Length - 1] == '"')
						{
							text4 = text4.Substring(1, text4.Length - 2);
						}
						if (text4[text4.Length - 1] == '\\')
						{
							text4 = text4.Substring(0, text4.Length - 1);
						}
						global::a.b(text3 + " = " + text4);
						if (text3 != null)
						{
							switch (text3.Length)
							{
							case 5:
								if (text3 == "sushi")
								{
									global::a.r = text4;
								}
								break;
							case 6:
								if (text3 == "ffmpeg")
								{
									global::a.p = text4;
								}
								break;
							case 7:
								if (text3 == "ffprobe")
								{
									global::a.q = text4;
								}
								break;
							case 8:
								if (text3 == "FinalDir")
								{
									global::a.o = text4;
								}
								break;
							case 9:
							{
								char c = text3[0];
								if (c != 'O')
								{
									if (c == 'S')
									{
										if (text3 == "SourceDir")
										{
											global::a.l = text4;
										}
									}
								}
								else if (text3 == "OutputDir")
								{
									global::a.n = text4;
								}
								break;
							}
							case 14:
								if (text3 == "DestinationDir")
								{
									global::a.m = text4;
								}
								break;
							}
						}
					}
				}
			}
			if (flag)
			{
				Console.WriteLine();
			}
		}
	}

	private static void b(string A_0)
	{
		ConsoleColor foregroundColor = Console.ForegroundColor;
		Console.ForegroundColor = ConsoleColor.Yellow;
		Console.Write("SushiHelper: ");
		Console.ForegroundColor = foregroundColor;
		Console.WriteLine(A_0);
	}

	private static void a(string A_0 = "")
	{
		if (A_0 != "")
		{
			ConsoleColor foregroundColor = Console.ForegroundColor;
			Console.ForegroundColor = ConsoleColor.Red;
			Console.Write("SushiHelper: ");
			Console.ForegroundColor = foregroundColor;
			Console.WriteLine(A_0);
		}
		Console.WriteLine();
		Console.WriteLine("Press ENTER to continue");
		Console.ReadLine();
	}

	private static readonly string a = Process.GetCurrentProcess().MainModule.FileName;

	private static readonly string b = Path.GetDirectoryName(global::a.a);

	private static readonly string c = Environment.GetEnvironmentVariable("Path");

	private static readonly Encoding d = Console.OutputEncoding;

	private static readonly bool e = global::a.d.CodePage == 950;

	private static readonly Encoding[] f = new Encoding[]
	{
		Encoding.UTF8,
		Encoding.Unicode,
		Encoding.BigEndianUnicode
	};

	private static readonly HashSet<string> g = new HashSet<string>(StringComparer.OrdinalIgnoreCase) { ".ass", ".ssa", ".srt" };

	private static string h = "";

	private static string i = "";

	private static string j = "";

	private static bool k = false;

	private static string l = "";

	private static string m = "";

	private static string n = "";

	private static string o = "";

	private static string p = "";

	private static string q = "";

	private static string r = "";

	private enum a {a, b}
}


用python3写一个与上述功能完全一样的程序，尽量不用第三方包，变量名要用有意义的名字，功能一定要跟源代码对应且一定要全部实现不能有缺漏，代码要完整并测试过可运行不报错。注意：要再三检查，一定要实现全部功能细节不能有缺漏，特别是sushi.fixed.txt文件那部分逻辑，源程序会产生什么文件，你就要产生什么文件。我不需要你告诉我你的粉丝思路如何，我只需要带注释的代码结果。用中文回答