diff --git a/.github/CONTRIBUTING.md b/.github/CONTRIBUTING.md deleted file mode 100644 index 59d7d805e9..0000000000 --- a/.github/CONTRIBUTING.md +++ /dev/null @@ -1,117 +0,0 @@ -# How to Contribute? - -## Testing - -* Test the latest changes to WinUtil by running the pre-release and reporting issues you are encountering to help us continually improve WinUtil! - -#### **Run the latest pre-release** - ```ps1 - irm christitus.com/windev | iex - ``` - -!!! bug "Keep in mind" - - This is a pre-release and should be treated as such. It exists for developers to test the utility and report or fix bugs before they get added to the stable release. Don't use it in production! - -## Issues - -* If you encounter any challenges or problems with the script, I kindly request that you submit them via the "Issues" tab on the GitHub repository. By filling out the provided template, you can provide specific details about the issue, allowing me (and others in the community) to promptly address any bugs or consider feature requests. - -## Contribute Code - -* Pull requests are now handled directly on the **MAIN branch**. This was done since we can now select specific releases to launch via releases in GitHub. - -* If you're doing code changes, then you can submit a PR to `main` branch, but I am very selective about these. - -!!! warning "Important" - - Do not use a code formatter, make massive amounts of line changes, or make multiple feature changes. EACH FEATURE CHANGE SHOULD BE IT'S OWN PULL REQUEST! - -* When creating pull requests, it is essential to thoroughly document all changes made. This includes, but is not limited to, documenting any additions made to the `tweaks` section and corresponding `undo tweak`, so users are able to remove the newly added tweaks if necessary, and comprehensive documentation is required for all code changes. Document your changes and briefly explain why you made your changes in your Pull Request Description. Failure to adhere to this format may result in the denial of the pull request. Additionally, any code lacking sufficient documentation may also be denied. - -* By following these guidelines, we can maintain a high standard of quality and ensure that the codebase remains organized and well-documented. - -!!! note - - When creating a function, please include "WPF" or "WinUtil" in the file name so it can be loaded into the runspace. - -## Walk through - -* This is a guide for beginners. If you are still having issues, look at the following official GitHub documentation: - * [Commit through WEB](https://docs.github.com/en/pull-requests/committing-changes-to-your-project/creating-and-editing-commits/about-commits) - * [Commit through GitHub Desktop](https://docs.github.com/en/desktop/making-changes-in-a-branch/committing-and-reviewing-changes-to-your-project-in-github-desktop#about-commits) - * [Create a Pull Request](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/proposing-changes-to-your-work-with-pull-requests/creating-a-pull-request) - - -### Overview - -``` mermaid -%%{init: {"flowchart": {"curve": "cardinal"}} }%% -graph TD -  A[Fork Project] --> B[Clone Repository]; -  B --> C[Create New Branch]; -  C --> D[Make Changes]; -  D --> G[Test Changes]; -  G --> H{Tests Passed?}; -  H -->|Yes| E[Commit Changes]; -  H -->|No| J[Fix Issues]; -  J --> G; -  E --> F[Push Branch]; -  F --> K[Create Pull Request]; -  K --> L[Fill out PR template]; - classDef default stroke:#333,stroke-width:4px,font-size:12pt; -``` -!!! info - - This is a diagram to guide you through the process. It may vary depending on the type of change you're making. - -### Fork the Repo -* Fork the WinUtil Repository [here](https://github.com/ChrisTitusTech/winutil) to create a copy that will be available in your repository list. - -![Fork Image](assets/Fork-Button-Dark.png#only-dark) - -![Fork Image](assets/Fork-Button-Light.png#only-light) - -### Clone the Fork -!!! tip - - While you can make your changes directly through the Web, we recommend cloning the repo to your device using the application GitHub Desktop (available in WinUtil) to test your fork easily. - -* Install GitHub Desktop if it is not already installed. -* Log in using the same GitHub account you used to fork WinUtil. -* Choose the fork under "Your Repositories" and press "clone {repo name}" -* Create a new branch and name it something relatable to your changes. - -* Now you can modify WinUtil to your liking using your preferred text editor. - - -### Testing your changes - -* To test to see if your changes work as intended run following commands in a powershell teminal as admin: - -* Change the directory where you are running the commands to the forked project. -* `cd {path to the folder with the compile.ps1}` -* Run the following command to compile and run WinUtil: -* `.\Compile.ps1 -run` - -![Compile](assets/Compile.png) - -* After seeing that your changes work properly, feel free to commit the changes to the repository and make a PR. For help on that, follow the documentation below. - -### Committing the changes -* Before committing your changes, please discard changes made to the `winutil.ps1` file, like the following: - -![Push Commit Image](assets/Discard-GHD.png) - -* Now, commit your changes once you are happy with the result. - -![Commit Image](assets/Commit-GHD.png) - -* Push the changes to upload them to your fork on github.com. - -![Push Commit Image](assets/Push-Commit.png) - -### Making a PR -* To make a PR on your repo under a new branch linking to the main branch, a button will show and say Preview and Create pull request. Click that button and fill in all the information that is provided on the template. Once all the information is filled in correctly, check your PR to make sure there is not a WinUtil.ps1 file attached to the PR. Once everything is good, make the PR and wait for Chris (the maintainer) to accept or deny your PR. Once it is accepted by Chris, you will be able to see your changes in the "/windev" build. -* If you do not see your feature in the main "/win" build, that is fine. All new changes go into the /windev build to make sure everything is working OK before going fully public. -* Congratulations! You just submitted your first PR. Thank you so much for contributing to WinUtil. diff --git a/.github/mkdocs.yml b/.github/mkdocs.yml index a4c7dfe23d..8b9700bcd3 100644 --- a/.github/mkdocs.yml +++ b/.github/mkdocs.yml @@ -11,6 +11,9 @@ nav: - Known Issues: 'KnownIssues.md' - FAQ: 'faq.md' +not_in_nav: | + dev/ + theme: name: material custom_dir: '../overrides' diff --git a/Compile.ps1 b/Compile.ps1 index 83be24067f..f427e3551c 100644 --- a/Compile.ps1 +++ b/Compile.ps1 @@ -73,8 +73,8 @@ Get-ChildItem "functions" -Recurse -File | ForEach-Object { } Update-Progress "Adding: Config *.json" 40 Get-ChildItem "config" | Where-Object {$psitem.extension -eq ".json"} | ForEach-Object { - $json = (Get-Content $psitem.FullName).replace("'","''") - $jsonAsObject = $json | convertfrom-json + $json = (Get-Content $psitem.FullName -Raw) + $jsonAsObject = $json | ConvertFrom-Json # Add 'WPFInstall' as a prefix to every entry-name in 'applications.json' file if ($psitem.Name -eq "applications.json") { @@ -85,12 +85,13 @@ Get-ChildItem "config" | Where-Object {$psitem.extension -eq ".json"} | ForEach- } } - # The replace at the end is required, as without it the output of 'converto-json' will be somewhat weird for Multiline Strings - # Most Notably is the scripts in some json files, making it harder for users who want to review these scripts, which're found in the compiled script - $json = ($jsonAsObject | convertto-json -Depth 3).replace('\r\n',"`r`n") + # Line 90 requires no whitespace inside the here-strings, to keep formatting of the JSON in the final script. + $json = @" +$($jsonAsObject | ConvertTo-Json -Depth 3) +"@ - $sync.configs.$($psitem.BaseName) = $json | convertfrom-json - $script_content.Add($(Write-output "`$sync.configs.$($psitem.BaseName) = '$json' `| convertfrom-json" )) + $sync.configs.$($psitem.BaseName) = $json | ConvertFrom-Json + $script_content.Add($(Write-Output "`$sync.configs.$($psitem.BaseName) = @'`n$json`n'@ `| ConvertFrom-Json" )) } # Read the entire XAML file as a single string, preserving line breaks diff --git a/README.md b/README.md index 0e9ad22d5c..b38c65b767 100644 --- a/README.md +++ b/README.md @@ -52,7 +52,7 @@ If you have Issues, refer to [Known Issues](https://christitustech.github.io/win These are the sponsors that help keep this project alive with monthly contributions. -Yusuke SaitoTriHyderaMark AmosJason A. DiegmuellerwyattRMSStefanthaddlPaulDave JonesAnthony MendezxPandakuClaudemodsTimothy CookDursleyGuyMITH ツ +Yusuke SaitoTriHyderaMark AmosJason A. DiegmuellerwyattRMSStefanthaddlPaulDave JonesAnthony MendezxPandakuClaudemodsTimothy CookDursleyGuyMITH ツSandman616 ## 🏅 Thanks to all Contributors Thanks a lot for spending your time helping Winutil grow. Thanks a lot! Keep rocking 🍻. diff --git a/config/dns.json b/config/dns.json index 6c2ffbbd16..6ba26a766a 100644 --- a/config/dns.json +++ b/config/dns.json @@ -46,5 +46,23 @@ "Secondary": "94.140.15.16", "Primary6": "2a10:50c0::bad1:ff", "Secondary6": "2a10:50c0::bad2:ff" + }, + "dns0.eu_Open":{ + "Primary": "193.110.81.254", + "Secondary": "185.253.5.254", + "Primary6": "2a0f:fc80::ffff", + "Secondary6": "2a0f:fc81::ffff" + }, + "dns0.eu_ZERO":{ + "Primary": "193.110.81.9", + "Secondary": "185.253.5.9", + "Primary6": "2a0f:fc80::9", + "Secondary6": "2a0f:fc81::9" + }, + "dns0.eu_KIDS":{ + "Primary": "193.110.81.1", + "Secondary": "185.253.5.1", + "Primary6": "2a0f:fc80::1", + "Secondary6": "2a0f:fc81::1" } } diff --git a/config/feature.json b/config/feature.json index 5da5aa47e3..afa423a7ee 100644 --- a/config/feature.json +++ b/config/feature.json @@ -323,5 +323,13 @@ "Type": "Button", "ButtonWidth": "300", "link": "https://christitustech.github.io/winutil/dev/features/Powershell-Profile/PSProfileUninstall" + }, + "WPFWinUtilSSHServer": { + "Content": "Enable OpenSSH Server", + "category": "Remote Access", + "panel": "2", + "Order": "a084_", + "Type": "Button", + "ButtonWidth": "300" } } diff --git a/config/tweaks.json b/config/tweaks.json index 157b8d6191..5672916497 100644 --- a/config/tweaks.json +++ b/config/tweaks.json @@ -1600,13 +1600,6 @@ "Value": "0", "OriginalValue": "1" }, - { - "Path": "HKLM:\\SOFTWARE\\Policies\\Microsoft\\Edge", - "Name": "EdgeEnhanceImagesEnabled", - "Type": "DWord", - "Value": "0", - "OriginalValue": "1" - }, { "Path": "HKLM:\\SOFTWARE\\Policies\\Microsoft\\Edge", "Name": "PersonalizationReportingEnabled", @@ -1656,13 +1649,6 @@ "Value": "0", "OriginalValue": "1" }, - { - "Path": "HKLM:\\SOFTWARE\\Policies\\Microsoft\\Edge", - "Name": "EdgeFollowEnabled", - "Type": "DWord", - "Value": "0", - "OriginalValue": "1" - }, { "Path": "HKLM:\\SOFTWARE\\Policies\\Microsoft\\Edge", "Name": "EdgeShoppingAssistantEnabled", @@ -1726,13 +1712,6 @@ "Value": "0", "OriginalValue": "1" }, - { - "Path": "HKLM:\\SOFTWARE\\Policies\\Microsoft\\Edge", - "Name": "ConfigureDoNotTrack", - "Type": "DWord", - "Value": "1", - "OriginalValue": "0" - }, { "Path": "HKLM:\\SOFTWARE\\Policies\\Microsoft\\Edge", "Name": "WalletDonationEnabled", @@ -2430,12 +2409,6 @@ "Order": "a001_", "InvokeScript": [ " - # Check if the user has administrative privileges - if (-Not ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)) { - Write-Host \"Please run this script as an administrator.\" - return - } - # Check if System Restore is enabled for the main drive try { # Try getting restore points to check if System Restore is enabled @@ -2690,72 +2663,72 @@ } # Check if OneDrive got Uninstalled if (-not (Test-Path $regPath)) { - Write-Host \"Copy downloaded Files from the OneDrive Folder to Root UserProfile\" - Start-Process -FilePath powershell -ArgumentList \"robocopy '$($OneDrivePath)' '$($env:USERPROFILE.TrimEnd())\\' /mov /e /xj\" -NoNewWindow -Wait + Write-Host \"Copy downloaded Files from the OneDrive Folder to Root UserProfile\" + Start-Process -FilePath powershell -ArgumentList \"robocopy '$($OneDrivePath)' '$($env:USERPROFILE.TrimEnd())\\' /mov /e /xj\" -NoNewWindow -Wait - Write-Host \"Removing OneDrive leftovers\" - Remove-Item -Recurse -Force -ErrorAction SilentlyContinue \"$env:localappdata\\Microsoft\\OneDrive\" - Remove-Item -Recurse -Force -ErrorAction SilentlyContinue \"$env:localappdata\\OneDrive\" - Remove-Item -Recurse -Force -ErrorAction SilentlyContinue \"$env:programdata\\Microsoft OneDrive\" - Remove-Item -Recurse -Force -ErrorAction SilentlyContinue \"$env:systemdrive\\OneDriveTemp\" - reg delete \"HKEY_CURRENT_USER\\Software\\Microsoft\\OneDrive\" -f - # check if directory is empty before removing: - If ((Get-ChildItem \"$OneDrivePath\" -Recurse | Measure-Object).Count -eq 0) { - Remove-Item -Recurse -Force -ErrorAction SilentlyContinue \"$OneDrivePath\" - } + Write-Host \"Removing OneDrive leftovers\" + Remove-Item -Recurse -Force -ErrorAction SilentlyContinue \"$env:localappdata\\Microsoft\\OneDrive\" + Remove-Item -Recurse -Force -ErrorAction SilentlyContinue \"$env:localappdata\\OneDrive\" + Remove-Item -Recurse -Force -ErrorAction SilentlyContinue \"$env:programdata\\Microsoft OneDrive\" + Remove-Item -Recurse -Force -ErrorAction SilentlyContinue \"$env:systemdrive\\OneDriveTemp\" + reg delete \"HKEY_CURRENT_USER\\Software\\Microsoft\\OneDrive\" -f + # check if directory is empty before removing: + If ((Get-ChildItem \"$OneDrivePath\" -Recurse | Measure-Object).Count -eq 0) { + Remove-Item -Recurse -Force -ErrorAction SilentlyContinue \"$OneDrivePath\" + } - Write-Host \"Remove Onedrive from explorer sidebar\" - Set-ItemProperty -Path \"HKCR:\\CLSID\\{018D5C66-4533-4307-9B53-224DE2ED1FE6}\" -Name \"System.IsPinnedToNameSpaceTree\" -Value 0 - Set-ItemProperty -Path \"HKCR:\\Wow6432Node\\CLSID\\{018D5C66-4533-4307-9B53-224DE2ED1FE6}\" -Name \"System.IsPinnedToNameSpaceTree\" -Value 0 + Write-Host \"Remove Onedrive from explorer sidebar\" + Set-ItemProperty -Path \"HKCR:\\CLSID\\{018D5C66-4533-4307-9B53-224DE2ED1FE6}\" -Name \"System.IsPinnedToNameSpaceTree\" -Value 0 + Set-ItemProperty -Path \"HKCR:\\Wow6432Node\\CLSID\\{018D5C66-4533-4307-9B53-224DE2ED1FE6}\" -Name \"System.IsPinnedToNameSpaceTree\" -Value 0 - Write-Host \"Removing run hook for new users\" - reg load \"hku\\Default\" \"C:\\Users\\Default\\NTUSER.DAT\" - reg delete \"HKEY_USERS\\Default\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run\" /v \"OneDriveSetup\" /f - reg unload \"hku\\Default\" + Write-Host \"Removing run hook for new users\" + reg load \"hku\\Default\" \"C:\\Users\\Default\\NTUSER.DAT\" + reg delete \"HKEY_USERS\\Default\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run\" /v \"OneDriveSetup\" /f + reg unload \"hku\\Default\" - Write-Host \"Removing autostart key\" - reg delete \"HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Run\" /v \"OneDrive\" /f + Write-Host \"Removing autostart key\" + reg delete \"HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Run\" /v \"OneDrive\" /f - Write-Host \"Removing startmenu entry\" - Remove-Item -Force -ErrorAction SilentlyContinue \"$env:userprofile\\AppData\\Roaming\\Microsoft\\Windows\\Start Menu\\Programs\\OneDrive.lnk\" + Write-Host \"Removing startmenu entry\" + Remove-Item -Force -ErrorAction SilentlyContinue \"$env:userprofile\\AppData\\Roaming\\Microsoft\\Windows\\Start Menu\\Programs\\OneDrive.lnk\" - Write-Host \"Removing scheduled task\" - Get-ScheduledTask -TaskPath '\\' -TaskName 'OneDrive*' -ea SilentlyContinue | Unregister-ScheduledTask -Confirm:$false + Write-Host \"Removing scheduled task\" + Get-ScheduledTask -TaskPath '\\' -TaskName 'OneDrive*' -ea SilentlyContinue | Unregister-ScheduledTask -Confirm:$false - # Add Shell folders restoring default locations - Write-Host \"Shell Fixing\" - Set-ItemProperty -Path \"HKCU:\\Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\User Shell Folders\" -Name \"AppData\" -Value \"$env:userprofile\\AppData\\Roaming\" -Type ExpandString - Set-ItemProperty -Path \"HKCU:\\Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\User Shell Folders\" -Name \"Cache\" -Value \"$env:userprofile\\AppData\\Local\\Microsoft\\Windows\\INetCache\" -Type ExpandString - Set-ItemProperty -Path \"HKCU:\\Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\User Shell Folders\" -Name \"Cookies\" -Value \"$env:userprofile\\AppData\\Local\\Microsoft\\Windows\\INetCookies\" -Type ExpandString - Set-ItemProperty -Path \"HKCU:\\Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\User Shell Folders\" -Name \"Favorites\" -Value \"$env:userprofile\\Favorites\" -Type ExpandString - Set-ItemProperty -Path \"HKCU:\\Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\User Shell Folders\" -Name \"History\" -Value \"$env:userprofile\\AppData\\Local\\Microsoft\\Windows\\History\" -Type ExpandString - Set-ItemProperty -Path \"HKCU:\\Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\User Shell Folders\" -Name \"Local AppData\" -Value \"$env:userprofile\\AppData\\Local\" -Type ExpandString - Set-ItemProperty -Path \"HKCU:\\Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\User Shell Folders\" -Name \"My Music\" -Value \"$env:userprofile\\Music\" -Type ExpandString - Set-ItemProperty -Path \"HKCU:\\Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\User Shell Folders\" -Name \"My Video\" -Value \"$env:userprofile\\Videos\" -Type ExpandString - Set-ItemProperty -Path \"HKCU:\\Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\User Shell Folders\" -Name \"NetHood\" -Value \"$env:userprofile\\AppData\\Roaming\\Microsoft\\Windows\\Network Shortcuts\" -Type ExpandString - Set-ItemProperty -Path \"HKCU:\\Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\User Shell Folders\" -Name \"PrintHood\" -Value \"$env:userprofile\\AppData\\Roaming\\Microsoft\\Windows\\Printer Shortcuts\" -Type ExpandString - Set-ItemProperty -Path \"HKCU:\\Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\User Shell Folders\" -Name \"Programs\" -Value \"$env:userprofile\\AppData\\Roaming\\Microsoft\\Windows\\Start Menu\\Programs\" -Type ExpandString - Set-ItemProperty -Path \"HKCU:\\Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\User Shell Folders\" -Name \"Recent\" -Value \"$env:userprofile\\AppData\\Roaming\\Microsoft\\Windows\\Recent\" -Type ExpandString - Set-ItemProperty -Path \"HKCU:\\Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\User Shell Folders\" -Name \"SendTo\" -Value \"$env:userprofile\\AppData\\Roaming\\Microsoft\\Windows\\SendTo\" -Type ExpandString - Set-ItemProperty -Path \"HKCU:\\Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\User Shell Folders\" -Name \"Start Menu\" -Value \"$env:userprofile\\AppData\\Roaming\\Microsoft\\Windows\\Start Menu\" -Type ExpandString - Set-ItemProperty -Path \"HKCU:\\Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\User Shell Folders\" -Name \"Startup\" -Value \"$env:userprofile\\AppData\\Roaming\\Microsoft\\Windows\\Start Menu\\Programs\\Startup\" -Type ExpandString - Set-ItemProperty -Path \"HKCU:\\Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\User Shell Folders\" -Name \"Templates\" -Value \"$env:userprofile\\AppData\\Roaming\\Microsoft\\Windows\\Templates\" -Type ExpandString - Set-ItemProperty -Path \"HKCU:\\Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\User Shell Folders\" -Name \"{374DE290-123F-4565-9164-39C4925E467B}\" -Value \"$env:userprofile\\Downloads\" -Type ExpandString - Set-ItemProperty -Path \"HKCU:\\Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\User Shell Folders\" -Name \"Desktop\" -Value \"$env:userprofile\\Desktop\" -Type ExpandString - Set-ItemProperty -Path \"HKCU:\\Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\User Shell Folders\" -Name \"My Pictures\" -Value \"$env:userprofile\\Pictures\" -Type ExpandString - Set-ItemProperty -Path \"HKCU:\\Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\User Shell Folders\" -Name \"Personal\" -Value \"$env:userprofile\\Documents\" -Type ExpandString - Set-ItemProperty -Path \"HKCU:\\Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\User Shell Folders\" -Name \"{F42EE2D3-909F-4907-8871-4C22FC0BF756}\" -Value \"$env:userprofile\\Documents\" -Type ExpandString - Set-ItemProperty -Path \"HKCU:\\Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\User Shell Folders\" -Name \"{0DDD015D-B06C-45D5-8C4C-F59713854639}\" -Value \"$env:userprofile\\Pictures\" -Type ExpandString - Write-Host \"Restarting explorer\" - taskkill.exe /F /IM \"explorer.exe\" - Start-Process \"explorer.exe\" + # Add Shell folders restoring default locations + Write-Host \"Shell Fixing\" + Set-ItemProperty -Path \"HKCU:\\Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\User Shell Folders\" -Name \"AppData\" -Value \"$env:userprofile\\AppData\\Roaming\" -Type ExpandString + Set-ItemProperty -Path \"HKCU:\\Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\User Shell Folders\" -Name \"Cache\" -Value \"$env:userprofile\\AppData\\Local\\Microsoft\\Windows\\INetCache\" -Type ExpandString + Set-ItemProperty -Path \"HKCU:\\Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\User Shell Folders\" -Name \"Cookies\" -Value \"$env:userprofile\\AppData\\Local\\Microsoft\\Windows\\INetCookies\" -Type ExpandString + Set-ItemProperty -Path \"HKCU:\\Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\User Shell Folders\" -Name \"Favorites\" -Value \"$env:userprofile\\Favorites\" -Type ExpandString + Set-ItemProperty -Path \"HKCU:\\Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\User Shell Folders\" -Name \"History\" -Value \"$env:userprofile\\AppData\\Local\\Microsoft\\Windows\\History\" -Type ExpandString + Set-ItemProperty -Path \"HKCU:\\Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\User Shell Folders\" -Name \"Local AppData\" -Value \"$env:userprofile\\AppData\\Local\" -Type ExpandString + Set-ItemProperty -Path \"HKCU:\\Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\User Shell Folders\" -Name \"My Music\" -Value \"$env:userprofile\\Music\" -Type ExpandString + Set-ItemProperty -Path \"HKCU:\\Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\User Shell Folders\" -Name \"My Video\" -Value \"$env:userprofile\\Videos\" -Type ExpandString + Set-ItemProperty -Path \"HKCU:\\Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\User Shell Folders\" -Name \"NetHood\" -Value \"$env:userprofile\\AppData\\Roaming\\Microsoft\\Windows\\Network Shortcuts\" -Type ExpandString + Set-ItemProperty -Path \"HKCU:\\Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\User Shell Folders\" -Name \"PrintHood\" -Value \"$env:userprofile\\AppData\\Roaming\\Microsoft\\Windows\\Printer Shortcuts\" -Type ExpandString + Set-ItemProperty -Path \"HKCU:\\Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\User Shell Folders\" -Name \"Programs\" -Value \"$env:userprofile\\AppData\\Roaming\\Microsoft\\Windows\\Start Menu\\Programs\" -Type ExpandString + Set-ItemProperty -Path \"HKCU:\\Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\User Shell Folders\" -Name \"Recent\" -Value \"$env:userprofile\\AppData\\Roaming\\Microsoft\\Windows\\Recent\" -Type ExpandString + Set-ItemProperty -Path \"HKCU:\\Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\User Shell Folders\" -Name \"SendTo\" -Value \"$env:userprofile\\AppData\\Roaming\\Microsoft\\Windows\\SendTo\" -Type ExpandString + Set-ItemProperty -Path \"HKCU:\\Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\User Shell Folders\" -Name \"Start Menu\" -Value \"$env:userprofile\\AppData\\Roaming\\Microsoft\\Windows\\Start Menu\" -Type ExpandString + Set-ItemProperty -Path \"HKCU:\\Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\User Shell Folders\" -Name \"Startup\" -Value \"$env:userprofile\\AppData\\Roaming\\Microsoft\\Windows\\Start Menu\\Programs\\Startup\" -Type ExpandString + Set-ItemProperty -Path \"HKCU:\\Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\User Shell Folders\" -Name \"Templates\" -Value \"$env:userprofile\\AppData\\Roaming\\Microsoft\\Windows\\Templates\" -Type ExpandString + Set-ItemProperty -Path \"HKCU:\\Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\User Shell Folders\" -Name \"{374DE290-123F-4565-9164-39C4925E467B}\" -Value \"$env:userprofile\\Downloads\" -Type ExpandString + Set-ItemProperty -Path \"HKCU:\\Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\User Shell Folders\" -Name \"Desktop\" -Value \"$env:userprofile\\Desktop\" -Type ExpandString + Set-ItemProperty -Path \"HKCU:\\Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\User Shell Folders\" -Name \"My Pictures\" -Value \"$env:userprofile\\Pictures\" -Type ExpandString + Set-ItemProperty -Path \"HKCU:\\Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\User Shell Folders\" -Name \"Personal\" -Value \"$env:userprofile\\Documents\" -Type ExpandString + Set-ItemProperty -Path \"HKCU:\\Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\User Shell Folders\" -Name \"{F42EE2D3-909F-4907-8871-4C22FC0BF756}\" -Value \"$env:userprofile\\Documents\" -Type ExpandString + Set-ItemProperty -Path \"HKCU:\\Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\User Shell Folders\" -Name \"{0DDD015D-B06C-45D5-8C4C-F59713854639}\" -Value \"$env:userprofile\\Pictures\" -Type ExpandString + Write-Host \"Restarting explorer\" + taskkill.exe /F /IM \"explorer.exe\" + Start-Process \"explorer.exe\" - Write-Host \"Waiting for explorer to complete loading\" - Write-Host \"Please Note - The OneDrive folder at $OneDrivePath may still have items in it. You must manually delete it, but all the files should already be copied to the base user folder.\" - Write-Host \"If there are Files missing afterwards, please Login to Onedrive.com and Download them manually\" -ForegroundColor Yellow - Start-Sleep 5 + Write-Host \"Waiting for explorer to complete loading\" + Write-Host \"Please Note - The OneDrive folder at $OneDrivePath may still have items in it. You must manually delete it, but all the files should already be copied to the base user folder.\" + Write-Host \"If there are Files missing afterwards, please Login to Onedrive.com and Download them manually\" -ForegroundColor Yellow + Start-Sleep 5 } else { - Write-Host \"Something went Wrong during the Unistallation of OneDrive\" -ForegroundColor Red + Write-Host \"Something went Wrong during the Unistallation of OneDrive\" -ForegroundColor Red } " ], @@ -3441,7 +3414,7 @@ "panel": "1", "Order": "a040_", "Type": "Combobox", - "ComboItems": "Default DHCP Google Cloudflare Cloudflare_Malware Cloudflare_Malware_Adult Open_DNS Quad9 AdGuard_Ads_Trackers AdGuard_Ads_Trackers_Malware_Adult", + "ComboItems": "Default DHCP Google Cloudflare Cloudflare_Malware Cloudflare_Malware_Adult Open_DNS Quad9 AdGuard_Ads_Trackers AdGuard_Ads_Trackers_Malware_Adult dns0.eu_Open dns0.eu_ZERO dns0.eu_KIDS", "link": "https://christitustech.github.io/winutil/dev/tweaks/z--Advanced-Tweaks---CAUTION/changedns" }, "WPFAddUltPerf": { diff --git a/docs/contribute.md b/docs/contribute.md index 457c880c37..87ec1ebc9a 100644 --- a/docs/contribute.md +++ b/docs/contribute.md @@ -1,3 +1,117 @@ ---8<-- ".github/CONTRIBUTING.md" +# How to Contribute? - +## Testing + +* Test the latest changes to WinUtil by running the pre-release and reporting issues you are encountering to help us continually improve WinUtil! + +#### **Run the latest pre-release** + ```ps1 + irm christitus.com/windev | iex + ``` + +!!! bug "Keep in mind" + + This is a pre-release and should be treated as such. It exists for developers to test the utility and report or fix bugs before they get added to the stable release. Don't use it in production! + +## Issues + +* If you encounter any challenges or problems with the script, I kindly request that you submit them via the "Issues" tab on the GitHub repository. By filling out the provided template, you can provide specific details about the issue, allowing me (and others in the community) to promptly address any bugs or consider feature requests. + +## Contribute Code + +* Pull requests are now handled directly on the **MAIN branch**. This was done since we can now select specific releases to launch via releases in GitHub. + +* If you're doing code changes, then you can submit a PR to `main` branch, but I am very selective about these. + +!!! warning "Important" + + Do not use a code formatter, make massive amounts of line changes, or make multiple feature changes. EACH FEATURE CHANGE SHOULD BE IT'S OWN PULL REQUEST! + +* When creating pull requests, it is essential to thoroughly document all changes made. This includes, but is not limited to, documenting any additions made to the `tweaks` section and corresponding `undo tweak`, so users are able to remove the newly added tweaks if necessary, and comprehensive documentation is required for all code changes. Document your changes and briefly explain why you made your changes in your Pull Request Description. Failure to adhere to this format may result in the denial of the pull request. Additionally, any code lacking sufficient documentation may also be denied. + +* By following these guidelines, we can maintain a high standard of quality and ensure that the codebase remains organized and well-documented. + +!!! note + + When creating a function, please include "WPF" or "WinUtil" in the file name so it can be loaded into the runspace. + +## Walk through + +* This is a guide for beginners. If you are still having issues, look at the following official GitHub documentation: + * [Commit through WEB](https://docs.github.com/en/pull-requests/committing-changes-to-your-project/creating-and-editing-commits/about-commits) + * [Commit through GitHub Desktop](https://docs.github.com/en/desktop/making-changes-in-a-branch/committing-and-reviewing-changes-to-your-project-in-github-desktop#about-commits) + * [Create a Pull Request](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/proposing-changes-to-your-work-with-pull-requests/creating-a-pull-request) + + +### Overview + +``` mermaid +%%{init: {"flowchart": {"curve": "cardinal"}} }%% +graph TD +  A[Fork Project] --> B[Clone Repository]; +  B --> C[Create New Branch]; +  C --> D[Make Changes]; +  D --> G[Test Changes]; +  G --> H{Tests Passed?}; +  H -->|Yes| E[Commit Changes]; +  H -->|No| J[Fix Issues]; +  J --> G; +  E --> F[Push Branch]; +  F --> K[Create Pull Request]; +  K --> L[Fill out PR template]; + classDef default stroke:#333,stroke-width:4px,font-size:12pt; +``` +!!! info + + This is a diagram to guide you through the process. It may vary depending on the type of change you're making. + +### Fork the Repo +* Fork the WinUtil Repository [here](https://github.com/ChrisTitusTech/winutil) to create a copy that will be available in your repository list. + +![Fork Image](assets/Fork-Button-Dark.png#only-dark#gh-dark-mode-only) + +![Fork Image](assets/Fork-Button-Light.png#only-light#gh-light-mode-only) + +### Clone the Fork +!!! tip + + While you can make your changes directly through the Web, we recommend cloning the repo to your device using the application GitHub Desktop (available in WinUtil) to test your fork easily. + +* Install GitHub Desktop if it is not already installed. +* Log in using the same GitHub account you used to fork WinUtil. +* Choose the fork under "Your Repositories" and press "clone {repo name}" +* Create a new branch and name it something relatable to your changes. + +* Now you can modify WinUtil to your liking using your preferred text editor. + + +### Testing your changes + +* To test to see if your changes work as intended run following commands in a powershell teminal as admin: + +* Change the directory where you are running the commands to the forked project. +* `cd {path to the folder with the compile.ps1}` +* Run the following command to compile and run WinUtil: +* `.\Compile.ps1 -run` + +![Compile](assets/Compile.png) + +* After seeing that your changes work properly, feel free to commit the changes to the repository and make a PR. For help on that, follow the documentation below. + +### Committing the changes +* Before committing your changes, please discard changes made to the `winutil.ps1` file, like the following: + +![Push Commit Image](assets/Discard-GHD.png) + +* Now, commit your changes once you are happy with the result. + +![Commit Image](assets/Commit-GHD.png) + +* Push the changes to upload them to your fork on github.com. + +![Push Commit Image](assets/Push-Commit.png) + +### Making a PR +* To make a PR on your repo under a new branch linking to the main branch, a button will show and say Preview and Create pull request. Click that button and fill in all the information that is provided on the template. Once all the information is filled in correctly, check your PR to make sure there is not a WinUtil.ps1 file attached to the PR. Once everything is good, make the PR and wait for Chris (the maintainer) to accept or deny your PR. Once it is accepted by Chris, you will be able to see your changes in the "/windev" build. +* If you do not see your feature in the main "/win" build, that is fine. All new changes go into the /windev build to make sure everything is working OK before going fully public. +* Congratulations! You just submitted your first PR. Thank you so much for contributing to WinUtil. diff --git a/docs/userguide.md b/docs/userguide.md index a529bb678d..47a49473d8 100644 --- a/docs/userguide.md +++ b/docs/userguide.md @@ -34,8 +34,9 @@ * By default Winutil will use winget to install/upgrade/remove packages and fallback to Chocolatey. This option reverses the preference. * This preference will be used for all Buttons on the Install page and persist across Winutil restarts -![Install Image](assets/Install-Tab-Dark.png#only-dark) -![Install Image](assets/Install-Tab-Light.png#only-light) +![Install Image](assets/Install-Tab-Dark.png#only-dark#gh-dark-mode-only) +![Install Image](assets/Install-Tab-Light.png#only-light#gh-light-mode-only) + !!! tip If you have trouble finding an application, press `ctrl + f` and search the name of it. Applications will filter depending on your input. @@ -43,8 +44,8 @@ ## Tweaks --- -![Tweaks Image](assets/Tweaks-Tab-Dark.png#only-dark) -![Tweaks Image](assets/Tweaks-Tab-Light.png#only-light) +![Tweaks Image](assets/Tweaks-Tab-Dark.png#only-dark#gh-dark-mode-only) +![Tweaks Image](assets/Tweaks-Tab-Light.png#only-light#gh-light-mode-only) ### Run Tweaks * **Open Tweaks Tab**: Navigate to the 'Tweaks' tab in the application. @@ -141,6 +142,10 @@ Open old-school Windows panels directly from WinUtil. Following Panels are avail * System Properties * User Accounts +### Remote Access + +Enables OpenSSH server on your windows machine. + ## Updates --- @@ -175,8 +180,8 @@ The utility provides three distinct settings for managing Windows updates: Defau * **MicroWin** lets you customize your Windows 10 and 11 installation images by debloating them however you want. -![Microwin](assets/Microwin-Dark.png#only-dark) -![Microwin](assets/Microwin-Light.png#only-light) +![Microwin](assets/Microwin-Dark.png#only-dark#gh-dark-mode-only) +![Microwin](assets/Microwin-Light.png#only-light#gh-light-mode-only) #### Basic usage @@ -234,12 +239,12 @@ With MicroWin, you can also configure your user before proceeding if you don't w * Some features are available through automation. This allows you to save your config file, pass it to WinUtil, walk away and come back to a finished system. Here is how you can set it up currently with Winutil >24.01.15 * On the Install Tab, click "Get Installed", this will get all installed apps **supported by Winutil** on the system. -![GetInstalled](assets/Get-Installed-Dark.png#only-dark) -![GetInstalled](assets/Get-Installed-Light.png#only-light) +![GetInstalled](assets/Get-Installed-Dark.png#only-dark#gh-dark-mode-only) +![GetInstalled](assets/Get-Installed-Light.png#only-light#gh-light-mode-only) * Click on the Settings cog in the upper right corner and choose Export. Choose file file and location; this will export the setting file. -![SettingsExport](assets/Settings-Export-Dark.png#only-dark) -![SettingsExport](assets/Settings-Export-Light.png#only-light) +![SettingsExport](assets/Settings-Export-Dark.png#only-dark#gh-dark-mode-only) +![SettingsExport](assets/Settings-Export-Light.png#only-light#gh-light-mode-only) * Copy this file to a USB or somewhere you can use it after Windows installation. diff --git a/functions/private/Invoke-WinUtilMicroWin-Helper.ps1 b/functions/private/Invoke-WinUtilMicroWin-Helper.ps1 index fff2b6bee9..1f80269b95 100644 --- a/functions/private/Invoke-WinUtilMicroWin-Helper.ps1 +++ b/functions/private/Invoke-WinUtilMicroWin-Helper.ps1 @@ -145,6 +145,7 @@ function Remove-Packages { $_ -NotLike "*ParentalControls*" -AND $_ -NotLike "*Win32WebViewHost*" -AND $_ -NotLike "*InputApp*" -AND + $_ -NotLike "*DirectPlay*" -AND $_ -NotLike "*AccountsControl*" -AND $_ -NotLike "*AsyncTextService*" -AND $_ -NotLike "*CapturePicker*" -AND diff --git a/functions/private/Invoke-WinUtilSSHServer.ps1 b/functions/private/Invoke-WinUtilSSHServer.ps1 new file mode 100644 index 0000000000..7185af7ed3 --- /dev/null +++ b/functions/private/Invoke-WinUtilSSHServer.ps1 @@ -0,0 +1,81 @@ +function Invoke-WinUtilSSHServer { + <# + .SYNOPSIS + Enables OpenSSH server to remote into your windows device + #> + + # Get the latest version of OpenSSH Server + $FeatureName = Get-WindowsCapability -Online | Where-Object { $_.Name -like "OpenSSH.Server*" } + + # Install the OpenSSH Server feature if not already installed + if ($FeatureName.State -ne "Installed") { + Write-Host "Enabling OpenSSH Server" + Add-WindowsCapability -Online -Name $FeatureName.Name + } + + # Sets up the OpenSSH Server service + Write-Host "Starting the services" + Start-Service -Name sshd + Set-Service -Name sshd -StartupType Automatic + + # Sets up the ssh-agent service + Start-Service 'ssh-agent' + Set-Service -Name 'ssh-agent' -StartupType 'Automatic' + + # Confirm the required services are running + $SSHDaemonService = Get-Service -Name sshd + $SSHAgentService = Get-Service -Name 'ssh-agent' + + if ($SSHDaemonService.Status -eq 'Running') { + Write-Host "OpenSSH Server is running." + } else { + try { + Write-Host "OpenSSH Server is not running. Attempting to restart..." + Restart-Service -Name sshd -Force + Write-Host "OpenSSH Server has been restarted successfully." + } catch { + Write-Host "Failed to restart OpenSSH Server: $_" + } + } + if ($SSHAgentService.Status -eq 'Running') { + Write-Host "ssh-agent is running." + } else { + try { + Write-Host "ssh-agent is not running. Attempting to restart..." + Restart-Service -Name sshd -Force + Write-Host "ssh-agent has been restarted successfully." + } catch { + Write-Host "Failed to restart ssh-agent : $_" + } + } + + #Adding Firewall rule for port 22 + Write-Host "Setting up firewall rules" + $firewallRule = (Get-NetFirewallRule -Name 'sshd').Enabled + if ($firewallRule) { + Write-Host "Firewall rule for OpenSSH Server (sshd) already exists." + } else { + New-NetFirewallRule -Name sshd -DisplayName 'OpenSSH Server (sshd)' -Enabled True -Direction Inbound -Protocol TCP -Action Allow -LocalPort 22 + Write-Host "Firewall rule for OpenSSH Server created and enabled." + } + + # Check for the authorized_keys file + $sshFolderPath = "$env:HOMEDRIVE\$env:HOMEPATH\.ssh" + $authorizedKeysPath = "$sshFolderPath\authorized_keys" + + if (-not (Test-Path -Path $sshFolderPath)) { + Write-Host "Creating ssh directory..." + New-Item -Path $sshFolderPath -ItemType Directory -Force + } + + if (-not (Test-Path -Path $authorizedKeysPath)) { + Write-Host "Creating authorized_keys file..." + New-Item -Path $authorizedKeysPath -ItemType File -Force + Write-Host "authorized_keys file created at $authorizedKeysPath." + } else { + Write-Host "authorized_keys file already exists at $authorizedKeysPath." + } + Write-Host "OpenSSH server was successfully enabled." + Write-Host "The config file can be located at C:\ProgramData\ssh\sshd_config " + Write-Host "Add your public keys to this file -> $authorizedKeysPath" +} diff --git a/functions/private/Set-WinUtilRegistry.ps1 b/functions/private/Set-WinUtilRegistry.ps1 index e3f66e2e3e..397ce84c1c 100644 --- a/functions/private/Set-WinUtilRegistry.ps1 +++ b/functions/private/Set-WinUtilRegistry.ps1 @@ -36,7 +36,12 @@ function Set-WinUtilRegistry { } Write-Host "Set $Path\$Name to $Value" - Set-ItemProperty -Path $Path -Name $Name -Type $Type -Value $Value -Force -ErrorAction Stop | Out-Null + if ($Value -ne ""){ + Set-ItemProperty -Path $Path -Name $Name -Type $Type -Value $Value -Force -ErrorAction Stop | Out-Null + } + else{ + Remove-ItemProperty -Path $Path -Name $Name -Force -ErrorAction Stop | Out-Null + } } catch [System.Security.SecurityException] { Write-Warning "Unable to set $Path\$Name to $Value due to a Security Exception" } catch [System.Management.Automation.ItemNotFoundException] { diff --git a/functions/public/Invoke-WPFButton.ps1 b/functions/public/Invoke-WPFButton.ps1 index 376aa3e49e..5c927026ec 100644 --- a/functions/public/Invoke-WPFButton.ps1 +++ b/functions/public/Invoke-WPFButton.ps1 @@ -59,5 +59,6 @@ function Invoke-WPFButton { "MicrowinScratchDirBT" {Invoke-ScratchDialog} "WPFWinUtilInstallPSProfile" {Invoke-WinUtilInstallPSProfile} "WPFWinUtilUninstallPSProfile" {Invoke-WinUtilUninstallPSProfile} + "WPFWinUtilSSHServer" {Invoke-WinUtilSSHServer} } } diff --git a/functions/public/Invoke-WPFImpex.ps1 b/functions/public/Invoke-WPFImpex.ps1 index 43d835de95..83f1887f2d 100644 --- a/functions/public/Invoke-WPFImpex.ps1 +++ b/functions/public/Invoke-WPFImpex.ps1 @@ -19,44 +19,59 @@ function Invoke-WPFImpex { $Config = $null ) - if ($type -eq "export") { - $FileBrowser = New-Object System.Windows.Forms.SaveFileDialog - } - if ($type -eq "import") { - $FileBrowser = New-Object System.Windows.Forms.OpenFileDialog - } - - if (-not $Config) { - $FileBrowser.InitialDirectory = [Environment]::GetFolderPath('Desktop') - $FileBrowser.Filter = "JSON Files (*.json)|*.json" - $FileBrowser.ShowDialog() | Out-Null + function ConfigDialog { + if (!$Config) { + switch ($type) { + "export" { $FileBrowser = New-Object System.Windows.Forms.SaveFileDialog } + "import" { $FileBrowser = New-Object System.Windows.Forms.OpenFileDialog } + } + $FileBrowser.InitialDirectory = [Environment]::GetFolderPath('Desktop') + $FileBrowser.Filter = "JSON Files (*.json)|*.json" + $FileBrowser.ShowDialog() | Out-Null - if($FileBrowser.FileName -eq "") { - return + if ($FileBrowser.FileName -eq "") { + return $null + } else { + return $FileBrowser.FileName + } } else { - $Config = $FileBrowser.FileName + return $Config } } - if ($type -eq "export") { - $jsonFile = Get-WinUtilCheckBoxes -unCheck $false - $jsonFile | ConvertTo-Json | Out-File $FileBrowser.FileName -Force - $runscript = "iex ""& { `$(irm christitus.com/win) } -Config '$($FileBrowser.FileName)'""" - $runscript | Set-Clipboard - } - if ($type -eq "import") { - $jsonFile = Get-Content $Config | ConvertFrom-Json - - $flattenedJson = @() - $jsonFile.PSObject.Properties | ForEach-Object { - $category = $_.Name - foreach ($checkboxName in $_.Value) { - if ($category -ne "Install") { - $flattenedJson += $checkboxName + switch ($type) { + "export" { + try { + $Config = ConfigDialog + if ($Config) { + $jsonFile = Get-WinUtilCheckBoxes -unCheck $false | ConvertTo-Json + $jsonFile | Out-File $Config -Force + "iex ""& { `$(irm christitus.com/win) } -Config '$Config'""" | Set-Clipboard } + } catch { + Write-Error "An error occurred while exporting: $_" + } + } + "import" { + try { + $Config = ConfigDialog + if ($Config) { + try { + if ($Config -match '^https?://') { + $jsonFile = (Invoke-WebRequest "$Config").Content | ConvertFrom-Json + } else { + $jsonFile = Get-Content $Config | ConvertFrom-Json + } + } catch { + Write-Error "Failed to load the JSON file from the specified path or URL: $_" + return + } + $flattenedJson = $jsonFile.PSObject.Properties.Where({ $_.Name -ne "Install" }).ForEach({ $_.Value }) + Invoke-WPFPresets -preset $flattenedJson -imported $true + } + } catch { + Write-Error "An error occurred while importing: $_" } } - - Invoke-WPFPresets -preset $flattenedJson -imported $true } } diff --git a/tools/Invoke-Preprocessing.ps1 b/tools/Invoke-Preprocessing.ps1 index 090dd17818..0569bc3565 100644 --- a/tools/Invoke-Preprocessing.ps1 +++ b/tools/Invoke-Preprocessing.ps1 @@ -72,80 +72,45 @@ function Invoke-Preprocessing { throw "[Invoke-Preprocessing] Invalid Paramter Value for 'WorkingDir', passed value: '$WorkingDir'. Either the path is a File or Non-Existing/Invlid, please double check your code." } - $count = $ExcludedFiles.Count - - # Make sure there's a * at the end of folders in ExcludedFiles list - for ($i = 0; $i -lt $count; $i++) { - $excludedFile = $ExcludedFiles[$i] - $isFolder = ($excludedFile) -match '\\$' - if ($isFolder) { $ExcludedFiles[$i] = $excludedFile + '*' } + $InternalExcludedFiles = [System.Collections.Generic.List[string]]::new($ExcludedFiles.Count) + ForEach ($excludedFile in $ExcludedFiles) { + $InternalExcludedFiles.Add($excludedFile) | Out-Null } - # Validate the ExcludedFiles List before continuing on, - # that's if there's a list in the first place, and '-SkipExcludedFilesValidation' was not provided. - if (-not $SkipExcludedFilesValidation) { - for ($i = 0; $i -lt $count; $i++) { - $excludedFile = $ExcludedFiles[$i] + # Validate the ExcludedItems List before continuing on, + # that's if there's a list in the first place, and '-SkipInternalExcludedFilesValidation' was not provided. + if ($ExcludedFiles.Count -gt 0) { + ForEach ($excludedFile in $ExcludedFiles) { $filePath = "$(($WorkingDir -replace ('\\$', '')) + '\' + ($excludedFile -replace ('\.\\', '')))" - - # Handle paths with wildcards in a different implementation - $matches = ($filePath) -match '^.*?\*' - - if ($matches) { - if (-NOT (Get-ChildItem -Recurse -Path "$filePath" -File -Force)) { - $failedFilesList += "'$filePath', " + $files = Get-ChildItem -Recurse -Path "$filePath" -File -Force + if ($files.Count -gt 0) { + ForEach ($file in $files) { + $InternalExcludedFiles.Add("$($file.FullName)") | Out-Null } - } else { - if (-NOT (Test-Path -Path "$filePath")) { - $failedFilesList += "'$filePath', " - } - } + } else { $failedFilesList += "'$filePath', " } } $failedFilesList = $failedFilesList -replace (',\s*$', '') - if (-NOT $failedFilesList -eq "") { + if ((-not $failedFilesList -eq "") -and (-not $SkipExcludedFilesValidation)) { throw "[Invoke-Preprocessing] One or more File Paths and/or File Patterns were not found, you can use '-SkipExcludedFilesValidation' switch to skip this check, the failed to validate are: $failedFilesList" } } # Get Files List - [System.Collections.ArrayList]$files = Get-ChildItem $WorkingDir -Recurse -Exclude $ExcludedFiles -File -Force - $numOfFiles = $files.Count + [System.Collections.ArrayList]$files = Get-ChildItem -LiteralPath $WorkingDir -Recurse -Exclude $InternalExcludedFiles -File -Force # Only keep the 'FullName' Property for every entry in the list - for ($i = 0; $i -lt $numOfFiles; $i++) { + for ($i = 0; $i -lt $files.Count; $i++) { $file = $files[$i] $files[$i] = $file.FullName } # If a file(s) are found in Exclude List, # Remove the file from files list. - for ($j = 0; $j -lt $excludedFiles.Count; $j++) { - # Prepare some variables - $excluded = $excludedFiles[$j] - $pathToFind = ($excluded) -replace ('^\.\\', '') - $pathToFind = $WorkingDir + '\' + $pathToFind - $index = -1 # reset index on every iteration - - # Handle paths with wildcards in a different implementation - $matches = ($pathToFind) -match '^.*?\*' - - if ($matches) { - $filesToCheck = Get-ChildItem -Recurse -Path "$pathToFind" -File -Force - if ($filesToCheck) { - for ($k = 0; $k -lt $filesToCheck.Count; $k++) { - $fileToCheck = $filesToCheck[$k] - $index = $files.IndexOf("$fileToCheck") - if ($index -ge 0) { $files.RemoveAt($index) } - } - } - } else { - $index = $files.IndexOf("$pathToFind") - if ($index -ge 0) { $files.RemoveAt($index) } - } + ForEach ($excludedFile in $InternalExcludedFiles) { + $index = $files.IndexOf("$excludedFile") + if ($index -ge 0) { $files.RemoveAt($index) } } - # Make sure 'numOfFiles' is synced with the actual Number of Files found in '$files' - # This's done because previous may or may not edit the files list, so we should update it $numOfFiles = $files.Count if ($numOfFiles -eq 0) {