Program.cs 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. using System.Text.Json;
  2. using System.Text.RegularExpressions;
  3. namespace HelloWorld;
  4. class Program
  5. {
  6. static string[] EXTS = { ".txt", ".json",};
  7. static string PATTERN = "\'(.+)\':";
  8. static string IDPATTERN = "ObjectId\\(\"(.+)\"\\)";
  9. static void Main(string[] args)
  10. {
  11. int idx = 0;
  12. foreach (var item in args)
  13. {
  14. Console.WriteLine($"{idx} - {item}");
  15. if (File.Exists(item)) {
  16. string ext = Path.GetExtension(item);
  17. if (EXTS.Contains(ext)) {
  18. string content = File.ReadAllText(item);
  19. content = Regex.Replace(content, PATTERN, "\"$1\":");
  20. content = Regex.Replace(content, IDPATTERN, "\"$1\"");
  21. if (content != null) {
  22. WrapperInfo? wrapper = JsonSerializer.Deserialize<WrapperInfo>(content);
  23. if (wrapper != null) {
  24. if (wrapper.Cn != null && wrapper.Cn.Length > 0) {
  25. wrapper.Cn = StringExtension.Decompress(wrapper.Cn);
  26. }
  27. if (wrapper.En != null && wrapper.En.Length > 0) {
  28. wrapper.En = StringExtension.Decompress(wrapper.En);
  29. }
  30. Console.WriteLine(wrapper.Cn);
  31. Console.WriteLine(wrapper.En);
  32. }
  33. }
  34. }
  35. }
  36. idx++;
  37. }
  38. Console.WriteLine("Press any key...");
  39. Console.ReadLine();
  40. }
  41. }