You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

47 rivejä
1.3 KiB

  1. using System.Linq;
  2. using System.Text;
  3. using System.IO;
  4. public class UniWebViewGradlePropertyPatcher {
  5. private readonly string filePath;
  6. private readonly UniWebViewEditorSettings settings;
  7. // Construct a patcher with file path.
  8. public UniWebViewGradlePropertyPatcher(string filePath, UniWebViewEditorSettings settings)
  9. {
  10. this.filePath = filePath;
  11. this.settings = settings;
  12. }
  13. public void Patch()
  14. {
  15. var result = UpdatedString();
  16. File.WriteAllText(filePath, result);
  17. }
  18. public string UpdatedString()
  19. {
  20. var lines = File.ReadAllLines(filePath);
  21. var hasAndroidXProperty = lines.Any(text => text.Contains("android.useAndroidX"));
  22. var hasJetifierProperty = lines.Any(text => text.Contains("android.enableJetifier"));
  23. var builder = new StringBuilder();
  24. foreach(var each in lines) {
  25. builder.AppendLine(each);
  26. }
  27. if (!hasAndroidXProperty) {
  28. builder.AppendLine("android.useAndroidX=true");
  29. }
  30. if (!hasJetifierProperty && settings.enableJetifier) {
  31. builder.AppendLine("android.enableJetifier=true");
  32. }
  33. // AppendLine will add a new line at the end of the string, so we need to trim it to keep the file clean.
  34. return builder.ToString().Trim();
  35. }
  36. }