This commit is contained in:
nsnail 2022-12-13 17:18:48 +08:00
parent e74157ec78
commit c53bd85c72
6 changed files with 39 additions and 34 deletions

12
dot.sln
View File

@ -30,10 +30,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "meta", "meta", "{AD79881E-7
switcher.json = switcher.json switcher.json = switcher.json
EndProjectSection EndProjectSection
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NSExt", "..\..\..\..\ForkedGitReps\ns-ext\src\NSExt.csproj", "{E937021D-2D7D-4741-8B59-DE835F7D0E09}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Spectre.Console.Cli", "..\..\..\..\ForkedGitReps\spectre.console\src\Spectre.Console.Cli\Spectre.Console.Cli.csproj", "{7C7321B4-C4BD-4DB4-9DF4-E487EFB8F307}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "tests", "tests\tests.csproj", "{15EF00AD-DFA8-4BE2-985E-85DA8092CB2F}" Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "tests", "tests\tests.csproj", "{15EF00AD-DFA8-4BE2-985E-85DA8092CB2F}"
EndProject EndProject
Global Global
@ -49,14 +45,6 @@ Global
{E7608D54-4A3B-4B4B-ADA0-7852987CA21F}.Debug|Any CPU.Build.0 = Debug|Any CPU {E7608D54-4A3B-4B4B-ADA0-7852987CA21F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E7608D54-4A3B-4B4B-ADA0-7852987CA21F}.Release|Any CPU.ActiveCfg = Release|Any CPU {E7608D54-4A3B-4B4B-ADA0-7852987CA21F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E7608D54-4A3B-4B4B-ADA0-7852987CA21F}.Release|Any CPU.Build.0 = Release|Any CPU {E7608D54-4A3B-4B4B-ADA0-7852987CA21F}.Release|Any CPU.Build.0 = Release|Any CPU
{E937021D-2D7D-4741-8B59-DE835F7D0E09}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E937021D-2D7D-4741-8B59-DE835F7D0E09}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E937021D-2D7D-4741-8B59-DE835F7D0E09}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E937021D-2D7D-4741-8B59-DE835F7D0E09}.Release|Any CPU.Build.0 = Release|Any CPU
{7C7321B4-C4BD-4DB4-9DF4-E487EFB8F307}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{7C7321B4-C4BD-4DB4-9DF4-E487EFB8F307}.Debug|Any CPU.Build.0 = Debug|Any CPU
{7C7321B4-C4BD-4DB4-9DF4-E487EFB8F307}.Release|Any CPU.ActiveCfg = Release|Any CPU
{7C7321B4-C4BD-4DB4-9DF4-E487EFB8F307}.Release|Any CPU.Build.0 = Release|Any CPU
{15EF00AD-DFA8-4BE2-985E-85DA8092CB2F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {15EF00AD-DFA8-4BE2-985E-85DA8092CB2F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{15EF00AD-DFA8-4BE2-985E-85DA8092CB2F}.Debug|Any CPU.Build.0 = Debug|Any CPU {15EF00AD-DFA8-4BE2-985E-85DA8092CB2F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{15EF00AD-DFA8-4BE2-985E-85DA8092CB2F}.Release|Any CPU.ActiveCfg = Release|Any CPU {15EF00AD-DFA8-4BE2-985E-85DA8092CB2F}.Release|Any CPU.ActiveCfg = Release|Any CPU

View File

@ -7,12 +7,6 @@
"commands": [ "commands": [
"t4" "t4"
] ]
},
"dotnet-consolidate": {
"version": "2.0.0",
"commands": [
"dotnet-consolidate"
]
} }
} }
} }

View File

@ -86,13 +86,13 @@ internal partial class Main : ToolBase<Option>
} }
private void WritePart(HttpResponseMessage rsp, string mainFilePath // private void WritePart(HttpResponseMessage rsp, string mainFilePath //
, long startPos, long endPos // , int no, long startPos, long endPos //
, Action<int> rateHandle) , Action<int> rateHandle)
{ {
Span<byte> buf = stackalloc byte[Opt.BufferSize]; Span<byte> buf = stackalloc byte[Opt.BufferSize];
using var stream = rsp.Content.ReadAsStream(); using var stream = rsp.Content.ReadAsStream();
int read; int read;
var file = $"{mainFilePath}.{startPos}-{endPos}.{_PART}"; var file = $"{mainFilePath}.{no}.{startPos}-{endPos}.{_PART}";
using var fs = new FileStream(file, FileMode.Create, FileAccess.Write, FileShare.None); using var fs = new FileStream(file, FileMode.Create, FileAccess.Write, FileShare.None);
while ((read = stream.Read(buf)) != 0) { while ((read = stream.Read(buf)) != 0) {
fs.Write(read == Opt.BufferSize ? buf : buf[..read]); fs.Write(read == Opt.BufferSize ? buf : buf[..read]);
@ -169,7 +169,7 @@ internal partial class Main : ToolBase<Option>
// ReSharper disable once AccessToDisposedClosure // ReSharper disable once AccessToDisposedClosure
using var getRsp using var getRsp
= http.Send(getReq, HttpCompletionOption.ResponseHeadersRead); = http.Send(getReq, HttpCompletionOption.ResponseHeadersRead);
WritePart(getRsp, mainFilePath, startPos, endPos, x => { WritePart(getRsp, mainFilePath, i, startPos, endPos, x => {
tChild.Increment(x); tChild.Increment(x);
tParent.Increment(x); tParent.Increment(x);
}); });

View File

@ -12,7 +12,9 @@
<DefineConstants>$(DefineConstants);NET7_0_WINDOWS</DefineConstants> <DefineConstants>$(DefineConstants);NET7_0_WINDOWS</DefineConstants>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="Spectre.Console" Version="0.45.1-preview.0.46"/> <PackageReference Include="NSExt" Version="1.0.9-alpha.0.1"/>
<PackageReference Include="Spectre.Console.Cli.NS" Version="0.45.1-preview.0.48"/>
<PackageReference Include="Spectre.Console.NS" Version="0.45.1-preview.0.48"/>
<PackageReference Condition="'$(TargetFramework)' == 'net7.0-windows'" Include="TextCopy" Version="6.2.0"/> <PackageReference Condition="'$(TargetFramework)' == 'net7.0-windows'" Include="TextCopy" Version="6.2.0"/>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
@ -21,10 +23,6 @@
<LastGenOutput>Str.Designer.cs</LastGenOutput> <LastGenOutput>Str.Designer.cs</LastGenOutput>
</EmbeddedResource> </EmbeddedResource>
</ItemGroup> </ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\..\..\..\ForkedGitReps\ns-ext\src\NSExt.csproj"/>
<ProjectReference Include="..\..\..\..\..\ForkedGitReps\spectre.console\src\Spectre.Console.Cli\Spectre.Console.Cli.csproj"/>
</ItemGroup>
<ItemGroup> <ItemGroup>
<Reference Include="Spectre.Console"> <Reference Include="Spectre.Console">
<HintPath>..\..\..\..\..\ForkedGitReps\spectre.console\src\Spectre.Console\bin\Debug\net6.0\Spectre.Console.dll</HintPath> <HintPath>..\..\..\..\..\ForkedGitReps\spectre.console\src\Spectre.Console\bin\Debug\net6.0\Spectre.Console.dll</HintPath>

View File

@ -11,11 +11,11 @@
"packages": [ "packages": [
{ {
"packageName": "NSExt", "packageName": "NSExt",
"version": "1.0.8" "version": "1.0.9-alpha.0.1"
}, },
{ {
"packageName": "Spectre.Console.Cli", "packageName": "Spectre.Console.Cli.NS",
"version": "0.45.1-preview.0.46" "version": "0.45.1-preview.0.48"
} }
] ]
} }

View File

@ -1,13 +1,38 @@
using System.Diagnostics;
using System.Security.Cryptography;
namespace Dot.Tests; namespace Dot.Tests;
public class TestGet public class TestGet
{ {
[SetUp] private static string GetFileSha1(string file)
public void Setup() { } {
using var fs = new FileStream(file, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
return BitConverter.ToString(SHA1.HashData(fs));
}
[Test] [Test]
public void Test1() public void DownloadFile()
{ {
Assert.Pass(); var file = Path.Combine(Path.GetTempPath(), $"{Guid.NewGuid()}.tmp");
try {
using var p = Process.Start(new ProcessStartInfo //
{
FileName = "../../../dot/bin/net7.0-windows/dot.exe"
, Arguments = $"get http://dl.360safe.com/360zip_setup.exe -o \"{file}\""
});
p!.WaitForExit();
Assert.That(
p.ExitCode == 0 && "6C2ADC1F69281ABBD2ED7D6782A208FAA621C868" ==
GetFileSha1(file).Replace("-", string.Empty), Is.True);
} }
catch (Exception) {
File.Delete(file);
throw;
}
}
[SetUp]
public void Setup() { }
} }