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.

36 lines
952 B

  1. #! /usr/bin/env python3
  2. #
  3. # Fixes encoding of the project files to add UTF-8 BOM.
  4. #
  5. # Visual Studio insists on having the BOM in project files, and will
  6. # restore it on first edit. This script will go through the relevant
  7. # files and ensure the BOM is included, which should prevent too many
  8. # irrelevant changesets.
  9. #
  10. from pathlib import Path
  11. __author__ = "Steve Dower <steve.dower@python.org>"
  12. __version__ = "1.0.0.0"
  13. def fix(p):
  14. with open(p, 'r', encoding='utf-8-sig') as f:
  15. data = f.read()
  16. with open(p, 'w', encoding='utf-8-sig') as f:
  17. f.write(data)
  18. ROOT_DIR = Path(__file__).resolve().parent
  19. if __name__ == '__main__':
  20. count = 0
  21. print('Fixing:')
  22. for f in ROOT_DIR.glob('*.vcxproj'):
  23. print(f' - {f.name}')
  24. fix(f)
  25. count += 1
  26. for f in ROOT_DIR.glob('*.vcxproj.filters'):
  27. print(f' - {f.name}')
  28. fix(f)
  29. count += 1
  30. print()
  31. print(f'Fixed {count} files')