setup_examples.ps1 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. ###############################################################################
  2. #
  3. # Execute this file to replace all example .dproj-files with files
  4. # based on the template.dproj file.
  5. #
  6. ###############################################################################
  7. #
  8. # The script transforms the template for each project in the following
  9. # way:
  10. #
  11. # 1) Replaces the project GUID to ensure that the files are unique.
  12. #
  13. # 2) Updates the name of the project and the .dpr-file.
  14. #
  15. # 3) Updates unit references.
  16. # For each .pas-file in the project folder a reference will be added.
  17. #
  18. # 4) Updates resource script reference.
  19. # For each .rc-file in the project folder a reference will be added.
  20. #
  21. # It is assumed that the example project has the following properties:
  22. #
  23. # 1) The project is located two levels down from the Examples folder.
  24. # For example: Examples\Foo\Bar\MyProject.dpr
  25. #
  26. ###############################################################################
  27. #
  28. # Get content of template file (-raw because we're doing multi line matches)
  29. #
  30. $template = Get-Content -path .\template.dproj -Raw
  31. #
  32. # Get list of project files in child folders
  33. #
  34. $Files = Get-ChildItem -Recurse -Filter '*.dproj' -Exclude template.dproj
  35. #
  36. # Iterate project file list
  37. #
  38. foreach ($File in $Files) {
  39. "Processing $($File.BaseName)..."
  40. #
  41. # Adjust template to match project name
  42. #
  43. $Output = $template `
  44. -Replace '(\<ProjectGuid\>)\{.*\}(\</ProjectGuid\>)', "`$1{$(New-Guid)}`$2" `
  45. -Replace '(\<MainSource\>).*(\.dpr\</MainSource\>)', "`$1$($File.BaseName)`$2" `
  46. -Replace '(\<SanitizedProjectName\>).*(\</SanitizedProjectName\>)', "`$1$($File.BaseName)`$2" `
  47. -Replace '(\<Source Name=\"MainSource\"\>).*(\.dpr\</Source\>)', "`$1$($File.BaseName)`$2"
  48. #
  49. # Construct list of references to .pas- and .dfm-files
  50. #
  51. $References = ''
  52. $Units = Get-ChildItem -Path $File.Directory -Filter '*.pas'
  53. foreach ($Unit in $Units) {
  54. $References = $References + "<DCCReference Include=`"$($Unit.Name)`"/>`n"
  55. }
  56. # Replace unit reference placeholder with new list of references
  57. $Output = $Output `
  58. -Replace '\<DCCReference.*/\>', $References
  59. #
  60. # Construct list of references to .rc-files
  61. #
  62. $References = ''
  63. $Units = Get-ChildItem -Path $File.Directory -Filter '*.rc'
  64. foreach ($Unit in $Units) {
  65. $References = $References + "<RcCompile Include=`"$($Unit.Name)`"><Form>$($Unit.BaseName).res</Form></RcCompile>`n"
  66. }
  67. # Replace resource file reference placeholder with new list of references
  68. $Output = $Output `
  69. -Replace '(?si)\<RcCompile.*\</RcCompile\>', $References
  70. #
  71. # Replace project file
  72. #
  73. $Output | Out-File -Encoding UTF8 -FilePath $File.FullName
  74. }