-
Notifications
You must be signed in to change notification settings - Fork 753
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Now using BuildArguments method used internally in .NET Standard to b…
…uild arguments string in .NET Framework.
- Loading branch information
1 parent
3d72caf
commit 02662bb
Showing
33 changed files
with
390 additions
and
1,393 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
using System.Collections.ObjectModel; | ||
using System.Linq; | ||
using System.Text; | ||
|
||
namespace AutoUpdaterDotNET; | ||
|
||
internal static class Utils | ||
{ | ||
public static string BuildArguments(Collection<string> argumentList) | ||
{ | ||
var arguments = new StringBuilder(); | ||
if (argumentList is not { Count: > 0 }) | ||
{ | ||
return string.Empty; | ||
} | ||
|
||
foreach (string argument in argumentList) PasteArguments.AppendArgument(ref arguments, argument); | ||
return arguments.ToString(); | ||
} | ||
} | ||
|
||
internal static class PasteArguments | ||
{ | ||
private const char Quote = '\"'; | ||
private const char Backslash = '\\'; | ||
|
||
internal static void AppendArgument(ref StringBuilder stringBuilder, string argument) | ||
{ | ||
if (stringBuilder.Length != 0) | ||
{ | ||
stringBuilder.Append(' '); | ||
} | ||
|
||
// Parsing rules for non-argv[0] arguments: | ||
// - Backslash is a normal character except followed by a quote. | ||
// - 2N backslashes followed by a quote ==> N literal backslashes followed by unescaped quote | ||
// - 2N+1 backslashes followed by a quote ==> N literal backslashes followed by a literal quote | ||
// - Parsing stops at first whitespace outside of quoted region. | ||
// - (post 2008 rule): A closing quote followed by another quote ==> literal quote, and parsing remains in quoting mode. | ||
if (argument.Length != 0 && ContainsNoWhitespaceOrQuotes(argument)) | ||
{ | ||
// Simple case - no quoting or changes needed. | ||
stringBuilder.Append(argument); | ||
} | ||
else | ||
{ | ||
stringBuilder.Append(Quote); | ||
var idx = 0; | ||
while (idx < argument.Length) | ||
{ | ||
char c = argument[idx++]; | ||
switch (c) | ||
{ | ||
case Backslash: | ||
{ | ||
var numBackSlash = 1; | ||
while (idx < argument.Length && argument[idx] == Backslash) | ||
{ | ||
idx++; | ||
numBackSlash++; | ||
} | ||
|
||
if (idx == argument.Length) | ||
{ | ||
// We'll emit an end quote after this so must double the number of backslashes. | ||
stringBuilder.Append(Backslash, numBackSlash * 2); | ||
} | ||
else if (argument[idx] == Quote) | ||
{ | ||
// Backslashes will be followed by a quote. Must double the number of backslashes. | ||
stringBuilder.Append(Backslash, numBackSlash * 2 + 1); | ||
stringBuilder.Append(Quote); | ||
idx++; | ||
} | ||
else | ||
{ | ||
// Backslash will not be followed by a quote, so emit as normal characters. | ||
stringBuilder.Append(Backslash, numBackSlash); | ||
} | ||
|
||
continue; | ||
} | ||
case Quote: | ||
// Escape the quote so it appears as a literal. This also guarantees that we won't end up generating a closing quote followed | ||
// by another quote (which parses differently pre-2008 vs. post-2008.) | ||
stringBuilder.Append(Backslash); | ||
stringBuilder.Append(Quote); | ||
continue; | ||
default: | ||
stringBuilder.Append(c); | ||
break; | ||
} | ||
} | ||
|
||
stringBuilder.Append(Quote); | ||
} | ||
} | ||
|
||
private static bool ContainsNoWhitespaceOrQuotes(string s) | ||
{ | ||
return s.All(c => !char.IsWhiteSpace(c) && c != Quote); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
using System.Windows; | ||
|
||
namespace AutoUpdaterTest; | ||
|
||
/// <summary> | ||
/// Interaction logic for App.xaml | ||
/// </summary> | ||
public partial class App : Application | ||
{ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
using System.Windows; | ||
|
||
[assembly: ThemeInfo( | ||
ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located | ||
//(used if a resource is not found in the page, | ||
// or application resource dictionaries) | ||
ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located | ||
//(used if a resource is not found in the page, | ||
// app, or any theme specific resource dictionaries) | ||
)] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,101 +1,20 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http:https://schemas.microsoft.com/developer/msbuild/2003"> | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> | ||
<Platform Condition=" '$(Platform)' == '' ">x86</Platform> | ||
<ProductVersion>8.0.30703</ProductVersion> | ||
<SchemaVersion>2.0</SchemaVersion> | ||
<ProjectGuid>{FD5AE762-C630-49F8-B814-FCF70E7838D1}</ProjectGuid> | ||
<OutputType>WinExe</OutputType> | ||
<AppDesignerFolder>Properties</AppDesignerFolder> | ||
<RootNamespace>AutoUpdaterTest</RootNamespace> | ||
<AssemblyName>AutoUpdaterTest</AssemblyName> | ||
<TargetFrameworkVersion>v4.6.2</TargetFrameworkVersion> | ||
<FileAlignment>512</FileAlignment> | ||
<TargetFrameworkProfile/> | ||
<TargetFramework>net45</TargetFramework> | ||
<Nullable>enable</Nullable> | ||
<UseWPF>true</UseWPF> | ||
<LangVersion>latest</LangVersion> | ||
<Version>1.0.0</Version> | ||
</PropertyGroup> | ||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|AnyCPU'"> | ||
<DebugSymbols>true</DebugSymbols> | ||
<OutputPath>bin\Debug\</OutputPath> | ||
<DefineConstants>DEBUG;TRACE</DefineConstants> | ||
<DebugType>full</DebugType> | ||
<PlatformTarget>AnyCPU</PlatformTarget> | ||
<ErrorReport>prompt</ErrorReport> | ||
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet> | ||
<Prefer32Bit>false</Prefer32Bit> | ||
</PropertyGroup> | ||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|AnyCPU'"> | ||
<OutputPath>bin\Release\</OutputPath> | ||
<DefineConstants>TRACE</DefineConstants> | ||
<Optimize>true</Optimize> | ||
<DebugType>pdbonly</DebugType> | ||
<PlatformTarget>AnyCPU</PlatformTarget> | ||
<ErrorReport>prompt</ErrorReport> | ||
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet> | ||
<Prefer32Bit>false</Prefer32Bit> | ||
</PropertyGroup> | ||
<PropertyGroup> | ||
<ApplicationManifest>app.manifest</ApplicationManifest> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<Reference Include="Microsoft.CSharp"/> | ||
<Reference Include="Newtonsoft.Json, Version=12.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL"> | ||
<HintPath>..\packages\Newtonsoft.Json.12.0.3\lib\net45\Newtonsoft.Json.dll</HintPath> | ||
</Reference> | ||
<Reference Include="System"/> | ||
<Reference Include="System.Data"/> | ||
<Reference Include="System.Deployment"/> | ||
<Reference Include="System.Drawing"/> | ||
<Reference Include="System.Windows.Forms"/> | ||
<Reference Include="System.Xml"/> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<Compile Include="FormMain.cs"> | ||
<SubType>Form</SubType> | ||
</Compile> | ||
<Compile Include="FormMain.Designer.cs"> | ||
<DependentUpon>FormMain.cs</DependentUpon> | ||
</Compile> | ||
<Compile Include="Program.cs"/> | ||
<Compile Include="Properties\AssemblyInfo.cs"/> | ||
<EmbeddedResource Include="FormMain.resx"> | ||
<DependentUpon>FormMain.cs</DependentUpon> | ||
</EmbeddedResource> | ||
<EmbeddedResource Include="Properties\Resources.resx"> | ||
<Generator>ResXFileCodeGenerator</Generator> | ||
<LastGenOutput>Resources.Designer.cs</LastGenOutput> | ||
<SubType>Designer</SubType> | ||
</EmbeddedResource> | ||
<Compile Include="Properties\Resources.Designer.cs"> | ||
<AutoGen>True</AutoGen> | ||
<DependentUpon>Resources.resx</DependentUpon> | ||
<DesignTime>True</DesignTime> | ||
</Compile> | ||
<None Include="app.config"/> | ||
<None Include="app.manifest"/> | ||
<None Include="packages.config"/> | ||
<None Include="Properties\Settings.settings"> | ||
<Generator>SettingsSingleFileGenerator</Generator> | ||
<LastGenOutput>Settings.Designer.cs</LastGenOutput> | ||
</None> | ||
<Compile Include="Properties\Settings.Designer.cs"> | ||
<AutoGen>True</AutoGen> | ||
<DependentUpon>Settings.settings</DependentUpon> | ||
<DesignTimeSharedInput>True</DesignTimeSharedInput> | ||
</Compile> | ||
<ProjectReference Include="..\AutoUpdater.NET\AutoUpdater.NET.csproj" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\AutoUpdater.NET\AutoUpdater.NET.csproj"> | ||
<Project>{fb9e7e6b-b19f-4f37-a708-2996190cef13}</Project> | ||
<Name>AutoUpdater.NET</Name> | ||
</ProjectReference> | ||
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" /> | ||
</ItemGroup> | ||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets"/> | ||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it. | ||
Other similar extension points exist, see Microsoft.Common.targets. | ||
<Target Name="BeforeBuild"> | ||
</Target> | ||
<Target Name="AfterBuild"> | ||
</Target> | ||
--> | ||
</Project> | ||
|
||
</Project> |
Oops, something went wrong.