Advertisement
Thunder-Menu

CommentOut_static_assert(rightclic).ps1

Mar 29th, 2023
1,191
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PowerShell 1.98 KB | Source Code | 0 0
  1. # Définir la fonction pour ouvrir la boîte de dialogue de sélection de dossier
  2. Function Select-FolderDialog {
  3.     [System.Reflection.Assembly]::LoadWithPartialName("System.windows.forms") | Out-Null
  4.  
  5.     $dialog = New-Object System.Windows.Forms.FolderBrowserDialog
  6.     $dialog.Description = "Select a folder"
  7.     $dialog.RootFolder = "MyComputer"
  8.     $dialog.ShowNewFolderButton = $false
  9.  
  10.     if ($dialog.ShowDialog() -eq [System.Windows.Forms.DialogResult]::OK) {
  11.         $dialog.SelectedPath
  12.     }
  13. }
  14.  
  15. # Vérifier si l'utilisateur dispose des droits d'administrateur
  16. $isAdmin = ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)
  17.  
  18. # Si l'utilisateur n'est pas administrateur, redémarrer en tant qu'administrateur
  19. if (-not $isAdmin) {
  20.     # Relancer le script en tant qu'administrateur
  21.     Start-Process powershell.exe "-File `"$PSCommandPath`"" -Verb RunAs
  22.     # Quitter le script actuel
  23.     Exit
  24. }
  25.  
  26. # Ouvrir la boîte de dialogue de sélection de dossier
  27. $folder_path = Select-FolderDialog
  28.  
  29. # Parcourir tous les fichiers dans le dossier
  30. foreach ($file in Get-ChildItem $folder_path -Recurse) {
  31.     # Ouvrir le fichier en mode lecture/écriture
  32.     $file_contents = Get-Content $file.FullName -Raw
  33.     $file_stream = [System.IO.File]::OpenWrite($file.FullName)
  34.     $file_writer = New-Object System.IO.StreamWriter($file_stream)
  35.  
  36.     # Parcourir toutes les lignes du fichier et commenter les occurrences de static_assert() et #pragma pack()
  37.     foreach ($line in $file_contents -split "`n") {
  38.         if ($line -match "static_assert") {
  39.             $line = "// $line"
  40.         }
  41.         if ($line -match "#pragma pack") {
  42.             $line = "// $line"
  43.         }
  44.        #if ($line -match "#include") {
  45.        #     $line = "// $line"
  46.        # }
  47.         $file_writer.WriteLine($line)
  48.     }
  49.  
  50.     # Fermer le fichier
  51.     $file_writer.Close()
  52.     $file_stream.Close()
  53. }
  54.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement