Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
3 changes: 2 additions & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
src/UniGetUI.PackageEngine.Managers.Chocolatey/choco-cli/** linguist-vendored
src/UniGetUI.PackageEngine.Managers.Chocolatey/choco-cli/** linguist-vendored
.githooks/* text eol=lf
38 changes: 38 additions & 0 deletions .githooks/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#!/usr/bin/env sh

set -eu

repo_root=$(git rev-parse --show-toplevel)
cd "$repo_root"

staged_files=$(git diff --cached --name-only --diff-filter=ACMR -- src | grep -E '\.(cs|csproj|props|targets|editorconfig|json|sln|slnx)$' || true)

if [ -z "$staged_files" ]; then
exit 0
fi

unstaged_files=$(git diff --name-only -- $staged_files || true)
if [ -n "$unstaged_files" ]; then
echo "pre-commit: relevant files have unstaged changes."
echo "Stage or stash them before committing so dotnet format does not rewrite mixed content."
printf '%s\n' "$unstaged_files"
exit 1
fi

if ! command -v dotnet >/dev/null 2>&1; then
echo "pre-commit: dotnet CLI not found; skipping whitespace formatting."
exit 0
fi

echo "pre-commit: running dotnet format whitespace on staged src files"

# shellcheck disable=SC2086
dotnet format whitespace src --folder --verbosity minimal --include $staged_files

if ! git diff --quiet -- $staged_files; then
git add -- $staged_files
echo "pre-commit: formatting updates were staged. Review them and run git commit again."
exit 1
fi

exit 0
13 changes: 13 additions & 0 deletions .github/workflows/dotnet-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,21 @@ on:
paths:
- '**.cs'
- '**.csproj'
- '**.props'
- '**.targets'
- '**.sln'
- 'src/.editorconfig'
- '.github/workflows/dotnet-test.yml'

pull_request:
branches: [ "main" ]
paths:
- '**.cs'
- '**.csproj'
- '**.props'
- '**.targets'
- '**.sln'
- 'src/.editorconfig'
- '.github/workflows/dotnet-test.yml'

workflow_dispatch:
Expand Down Expand Up @@ -47,6 +53,13 @@ jobs:
working-directory: src
run: dotnet restore UniGetUI.sln

- name: Check whitespace formatting
run: dotnet format whitespace src --folder --verify-no-changes --verbosity minimal

- name: Check code style formatting
working-directory: src
run: dotnet format style UniGetUI.sln --no-restore --verify-no-changes --verbosity minimal

- name: Run Tests
working-directory: src
run: dotnet test UniGetUI.sln --no-restore --verbosity q --nologo
Expand Down
8 changes: 8 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,14 @@ Before reading: All of the rules below are guidelines, which means that they sho
- Draft pull requests should be properly identified as [draft pull requests](https://github.blog/2019-02-14-introducing-draft-pull-requests/) to avoid confusion.
- When modifying/coding, please follow the guidelines below:

## Formatting:
- Run `pwsh ./scripts/install-git-hooks.ps1` once after cloning to enable the repository pre-commit hook.
- The pre-commit hook runs `dotnet format whitespace src --folder` on staged files under `src` when the `dotnet` CLI is available, and stops the commit if it had to rewrite files so you can review the changes and commit again.
- CI enforces whitespace formatting with `dotnet format whitespace src --folder --verify-no-changes` and code-style verification with `dotnet format style src/UniGetUI.sln --no-restore --verify-no-changes` in `.github/workflows/dotnet-test.yml`.
- The pre-commit hook intentionally does not run `dotnet format style` because solution loading makes it take roughly the same time for one staged C# file as for the full solution.
- If you want to check the same style rules locally before pushing, run `dotnet format style src/UniGetUI.sln --no-restore --verify-no-changes` from the repository root.
- If you want to prepare a dedicated formatting-only commit, run `dotnet format whitespace src --folder` from the repository root.

## Coding:
- As a repository standard, every function and variable name should use camelCase.
- Correct usage: `updatesCount = 0`, `def searchForUpdates(packageManager):`
Expand Down
8 changes: 8 additions & 0 deletions scripts/install-git-hooks.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
$ErrorActionPreference = 'Stop'

$repoRoot = (Resolve-Path (Join-Path $PSScriptRoot '..')).Path

git -C $repoRoot config core.hooksPath .githooks

Write-Host 'Configured git hooks path to .githooks' -ForegroundColor Green
Write-Host 'The pre-commit hook will run dotnet format whitespace on staged files under src.' -ForegroundColor Green
11 changes: 10 additions & 1 deletion src/.editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ dotnet_diagnostic.CA2246.severity = warning
dotnet_diagnostic.CA2249.severity = warning

# IDE0005: Remove unnecessary usings
dotnet_diagnostic.IDE0005.severity = warning
dotnet_diagnostic.IDE0005.severity = suggestion

# IDE0011: Curly braces to surround blocks of code
dotnet_diagnostic.IDE0011.severity = warning
Expand Down Expand Up @@ -343,6 +343,15 @@ dotnet_diagnostic.IDE0200.severity = warning
dotnet_style_allow_multiple_blank_lines_experimental = false
dotnet_diagnostic.IDE2000.severity = warning

# WinUI code-behind relies on XAML-wired event handlers that Roslyn cannot
# reliably see as C# references.
[UniGetUI/**.cs]
dotnet_diagnostic.IDE0051.severity = suggestion
dotnet_diagnostic.IDE0060.severity = suggestion

[UniGetUI/Controls/SourceManager.xaml.cs]
dotnet_diagnostic.IDE0044.severity = suggestion

###### End of EditorConfig from dotnet/aspnetcore repository

### Our rules
Expand Down
18 changes: 14 additions & 4 deletions src/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,16 @@
</PropertyGroup>

<PropertyGroup>
<BuildSharedWindowsTargetFrameworks Condition="$([MSBuild]::IsOSPlatform('Windows')) == 'true' or '$(EnableWindowsTargeting)' == 'true'">true</BuildSharedWindowsTargetFrameworks>
<SharedTargetFrameworks Condition="'$(BuildSharedWindowsTargetFrameworks)' == 'true'">$(PortableTargetFramework);$(WindowsTargetFramework)</SharedTargetFrameworks>
<SharedTargetFrameworks Condition="'$(SharedTargetFrameworks)' == ''">$(PortableTargetFramework)</SharedTargetFrameworks>
<BuildSharedWindowsTargetFrameworks
Condition="$([MSBuild]::IsOSPlatform('Windows')) == 'true' or '$(EnableWindowsTargeting)' == 'true'"
>true</BuildSharedWindowsTargetFrameworks
>
<SharedTargetFrameworks Condition="'$(BuildSharedWindowsTargetFrameworks)' == 'true'"
>$(PortableTargetFramework);$(WindowsTargetFramework)</SharedTargetFrameworks
>
<SharedTargetFrameworks Condition="'$(SharedTargetFrameworks)' == ''"
>$(PortableTargetFramework)</SharedTargetFrameworks
>
</PropertyGroup>

<PropertyGroup Condition="'$(TargetFramework)' == '' and '$(TargetFrameworks)' == ''">
Expand All @@ -31,7 +38,10 @@
<WindowsSdkPackageVersion>10.0.26100.56</WindowsSdkPackageVersion>
<WindowsAppSDKSelfContained>true</WindowsAppSDKSelfContained>
<RuntimeIdentifiers>win-x64;win-arm64</RuntimeIdentifiers>
<RuntimeIdentifier Condition="'$(Platform)' != '' and '$(Platform)' != 'AnyCPU' and '$(Platform)' != 'Any CPU'">win-$(Platform)</RuntimeIdentifier>
<RuntimeIdentifier
Condition="'$(Platform)' != '' and '$(Platform)' != 'AnyCPU' and '$(Platform)' != 'Any CPU'"
>win-$(Platform)</RuntimeIdentifier
>
</PropertyGroup>

<PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>$(WindowsTargetFramework)</TargetFramework>
<TargetFrameworks />
</PropertyGroup>



<PropertyGroup>
<TargetFramework>$(WindowsTargetFramework)</TargetFramework>
<TargetFrameworks />
</PropertyGroup>
</Project>
16 changes: 8 additions & 8 deletions src/ExternalLibraries.FilePickers/Classes/FileOpenDialogRCW.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
using System.Runtime.InteropServices;
using System.Runtime.InteropServices;
using ExternalLibraries.Pickers.Guids;

namespace ExternalLibraries.Pickers.Classes;

// ---------------------------------------------------
// .NET classes representing runtime callable wrappers
[ComImport,
ClassInterface(ClassInterfaceType.None),
TypeLibType(TypeLibTypeFlags.FCanCreate),
Guid(CLSIDGuid.FileOpenDialog)]
internal class FileOpenDialogRCW
{
}
[
ComImport,
ClassInterface(ClassInterfaceType.None),
TypeLibType(TypeLibTypeFlags.FCanCreate),
Guid(CLSIDGuid.FileOpenDialog)
]
internal class FileOpenDialogRCW { }
16 changes: 8 additions & 8 deletions src/ExternalLibraries.FilePickers/Classes/FileSaveDialogRCW.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
using System.Runtime.InteropServices;
using System.Runtime.InteropServices;
using ExternalLibraries.Pickers.Guids;

namespace ExternalLibraries.Pickers.Classes;

// ---------------------------------------------------
// .NET classes representing runtime callable wrappers
[ComImport,
ClassInterface(ClassInterfaceType.None),
TypeLibType(TypeLibTypeFlags.FCanCreate),
Guid(CLSIDGuid.FileSaveDialog)]
internal class FileSaveDialogRCW
{
}
[
ComImport,
ClassInterface(ClassInterfaceType.None),
TypeLibType(TypeLibTypeFlags.FCanCreate),
Guid(CLSIDGuid.FileSaveDialog)
]
internal class FileSaveDialogRCW { }
19 changes: 14 additions & 5 deletions src/ExternalLibraries.FilePickers/Classes/Helper.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System.Runtime.InteropServices;
using System.Runtime.InteropServices;
using ExternalLibraries.Pickers.Enums;
using ExternalLibraries.Pickers.Interfaces;
using ExternalLibraries.Pickers.Structures;
Expand All @@ -24,7 +24,9 @@ internal static string ShowOpen(nint windowHandle, FOS fos, List<string>? typeFi
if (typeFilters is not null)
{
typeFilters.Insert(0, string.Join("; ", typeFilters));
COMDLG_FILTERSPEC[] filterSpecs = typeFilters.Select(f => new COMDLG_FILTERSPEC(f)).ToArray();
COMDLG_FILTERSPEC[] filterSpecs = typeFilters
.Select(f => new COMDLG_FILTERSPEC(f))
.ToArray();

dialog.SetFileTypes((uint)filterSpecs.Length, filterSpecs);
}
Expand All @@ -46,7 +48,12 @@ internal static string ShowOpen(nint windowHandle, FOS fos, List<string>? typeFi
}
}

internal static string ShowSave(nint windowHandle, FOS fos, List<string>? typeFilters = null, string name = "")
internal static string ShowSave(
nint windowHandle,
FOS fos,
List<string>? typeFilters = null,
string name = ""
)
{
FileSaveDialog dialog = new();
try
Expand All @@ -55,7 +62,9 @@ internal static string ShowSave(nint windowHandle, FOS fos, List<string>? typeFi

if (typeFilters is not null)
{
COMDLG_FILTERSPEC[] filterSpecs = typeFilters.Select(f => new COMDLG_FILTERSPEC(f)).ToArray();
COMDLG_FILTERSPEC[] filterSpecs = typeFilters
.Select(f => new COMDLG_FILTERSPEC(f))
.ToArray();

dialog.SetFileTypes((uint)filterSpecs.Length, filterSpecs);
}
Expand All @@ -78,7 +87,7 @@ internal static string ShowSave(nint windowHandle, FOS fos, List<string>? typeFi
if (fileExtension.Length > 0 && fileExtension[0] == '*')
fileExtension = fileExtension.TrimStart('*');

return path.Contains(fileExtension)? path: path + fileExtension;
return path.Contains(fileExtension) ? path : path + fileExtension;
}
finally
{
Expand Down
2 changes: 1 addition & 1 deletion src/ExternalLibraries.FilePickers/Enums/FDAP.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace ExternalLibraries.Pickers.Enums;
namespace ExternalLibraries.Pickers.Enums;

// https://learn.microsoft.com/en-us/windows/win32/api/shobjidl_core/ne-shobjidl_core-fdap
internal enum FDAP
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
namespace ExternalLibraries.Pickers.Enums;
namespace ExternalLibraries.Pickers.Enums;

// https://learn.microsoft.com/en-us/windows/win32/api/shobjidl_core/ne-shobjidl_core-fde_overwrite_response
internal enum FDE_OVERWRITE_RESPONSE
{
FDEOR_DEFAULT = 0x00000000,
FDEOR_ACCEPT = 0x00000001,
FDEOR_REFUSE = 0x00000002
FDEOR_REFUSE = 0x00000002,
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
namespace ExternalLibraries.Pickers.Enums;
namespace ExternalLibraries.Pickers.Enums;

// https://learn.microsoft.com/en-us/windows/win32/api/shobjidl_core/ne-shobjidl_core-fde_shareviolation_response
internal enum FDE_SHAREVIOLATION_RESPONSE
{
FDESVR_DEFAULT = 0x00000000,
FDESVR_ACCEPT = 0x00000001,
FDESVR_REFUSE = 0x00000002
FDESVR_REFUSE = 0x00000002,
}
4 changes: 2 additions & 2 deletions src/ExternalLibraries.FilePickers/Enums/FOS.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace ExternalLibraries.Pickers.Enums;
namespace ExternalLibraries.Pickers.Enums;

[Flags]
// https://learn.microsoft.com/ru-ru/windows/win32/api/shobjidl_core/ne-shobjidl_core-_fileopendialogoptions
Expand All @@ -23,5 +23,5 @@ internal enum FOS : uint
FOS_NODEREFERENCELINKS = 0x00100000,
FOS_DONTADDTORECENT = 0x02000000,
FOS_FORCESHOWHIDDEN = 0x10000000,
FOS_DEFAULTNOMINIMODE = 0x20000000
FOS_DEFAULTNOMINIMODE = 0x20000000,
}
4 changes: 2 additions & 2 deletions src/ExternalLibraries.FilePickers/Enums/HRESULT.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
namespace ExternalLibraries.Pickers.Enums;
namespace ExternalLibraries.Pickers.Enums;

internal enum HRESULT : long
{
S_FALSE = 0x0001,
S_OK = 0x0000,
E_INVALIDARG = 0x80070057,
E_OUTOFMEMORY = 0x8007000E,
ERROR_CANCELLED = 0x800704C7
ERROR_CANCELLED = 0x800704C7,
}
20 changes: 10 additions & 10 deletions src/ExternalLibraries.FilePickers/Enums/SIGDN.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
namespace ExternalLibraries.Pickers.Enums;
namespace ExternalLibraries.Pickers.Enums;

// https://learn.microsoft.com/en-us/windows/win32/api/shobjidl_core/ne-shobjidl_core-sigdn
internal enum SIGDN : uint
{
SIGDN_NORMALDISPLAY = 0x00000000, // SHGDN_NORMAL
SIGDN_PARENTRELATIVEPARSING = 0x80018001, // SHGDN_INFOLDER | SHGDN_FORPARSING
SIGDN_DESKTOPABSOLUTEPARSING = 0x80028000, // SHGDN_FORPARSING
SIGDN_PARENTRELATIVEEDITING = 0x80031001, // SHGDN_INFOLDER | SHGDN_FOREDITING
SIGDN_DESKTOPABSOLUTEEDITING = 0x8004c000, // SHGDN_FORPARSING | SHGDN_FORADDRESSBAR
SIGDN_FILESYSPATH = 0x80058000, // SHGDN_FORPARSING
SIGDN_URL = 0x80068000, // SHGDN_FORPARSING
SIGDN_PARENTRELATIVEFORADDRESSBAR = 0x8007c001, // SHGDN_INFOLDER | SHGDN_FORPARSING | SHGDN_FORADDRESSBAR
SIGDN_PARENTRELATIVE = 0x80080001 // SHGDN_INFOLDER
SIGDN_NORMALDISPLAY = 0x00000000, // SHGDN_NORMAL
SIGDN_PARENTRELATIVEPARSING = 0x80018001, // SHGDN_INFOLDER | SHGDN_FORPARSING
SIGDN_DESKTOPABSOLUTEPARSING = 0x80028000, // SHGDN_FORPARSING
SIGDN_PARENTRELATIVEEDITING = 0x80031001, // SHGDN_INFOLDER | SHGDN_FOREDITING
SIGDN_DESKTOPABSOLUTEEDITING = 0x8004c000, // SHGDN_FORPARSING | SHGDN_FORADDRESSBAR
SIGDN_FILESYSPATH = 0x80058000, // SHGDN_FORPARSING
SIGDN_URL = 0x80068000, // SHGDN_FORPARSING
SIGDN_PARENTRELATIVEFORADDRESSBAR = 0x8007c001, // SHGDN_INFOLDER | SHGDN_FORPARSING | SHGDN_FORADDRESSBAR
SIGDN_PARENTRELATIVE = 0x80080001, // SHGDN_INFOLDER
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>$(WindowsTargetFramework)</TargetFramework>
<TargetFrameworks />
</PropertyGroup>



<PropertyGroup>
<TargetFramework>$(WindowsTargetFramework)</TargetFramework>
<TargetFrameworks />
</PropertyGroup>
</Project>
2 changes: 1 addition & 1 deletion src/ExternalLibraries.FilePickers/FileOpenPicker.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using ExternalLibraries.Pickers.Classes;
using ExternalLibraries.Pickers.Classes;
using ExternalLibraries.Pickers.Enums;

namespace ExternalLibraries.Pickers;
Expand Down
2 changes: 1 addition & 1 deletion src/ExternalLibraries.FilePickers/FileSavePicker.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using ExternalLibraries.Pickers.Classes;
using ExternalLibraries.Pickers.Classes;
using ExternalLibraries.Pickers.Enums;

namespace ExternalLibraries.Pickers;
Expand Down
2 changes: 1 addition & 1 deletion src/ExternalLibraries.FilePickers/FolderPicker.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using ExternalLibraries.Pickers.Classes;
using ExternalLibraries.Pickers.Classes;
using ExternalLibraries.Pickers.Enums;

namespace ExternalLibraries.Pickers;
Expand Down
2 changes: 1 addition & 1 deletion src/ExternalLibraries.FilePickers/Guids/CLSIDGuid.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace ExternalLibraries.Pickers.Guids;
namespace ExternalLibraries.Pickers.Guids;

internal static class CLSIDGuid
{
Expand Down
Loading
Loading