Skip to content

Commit

Permalink
Merge pull request #4 from jjw24/fix_downloader
Browse files Browse the repository at this point in the history
Fix filepath extension in Downloader
  • Loading branch information
jjw24 authored Feb 8, 2021
2 parents 916a238 + 0d37ac6 commit d593489
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
10 changes: 7 additions & 3 deletions Droplex/Downloader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,17 @@ public static async Task Get(string url, string filePath)
if (File.Exists(filePath))
File.Delete(filePath);

// filePath could be passed in with or without extension
var filePathWithoutExtension =
Path.Combine(Path.GetDirectoryName(filePath), Path.GetFileNameWithoutExtension(filePath));

var client = new HttpClient(new SocketsHttpHandler(), false);
client.DefaultRequestHeaders.Add("User-Agent", UserAgent);

using var response = await client.GetAsync(url).ConfigureAwait(false);
if (response.StatusCode == HttpStatusCode.OK)
{
await using var fileStream = new FileStream(filePath, FileMode.CreateNew);
await using var fileStream = new FileStream(filePathWithoutExtension, FileMode.CreateNew);
await response.Content.CopyToAsync(fileStream).ConfigureAwait(false);
}
else
Expand All @@ -37,12 +41,12 @@ public static async Task Get(string url, string filePath)
}

var extension = Path.GetExtension(url);
var downloadedFile = $"{filePath}{extension}";
var downloadedFile = $"{filePathWithoutExtension}{extension}";

if (File.Exists(downloadedFile))
File.Delete(downloadedFile);

File.Move(filePath, downloadedFile);
File.Move(filePathWithoutExtension, downloadedFile);
}
}
}
6 changes: 3 additions & 3 deletions Droplex/Droplex.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
</PropertyGroup>

<PropertyGroup>
<PackageVersion>1.0.4</PackageVersion>
<AssemblyVersion>1.0.4</AssemblyVersion>
<InformationalVersion>1.0.4</InformationalVersion>
<PackageVersion>1.0.5</PackageVersion>
<AssemblyVersion>1.0.5</AssemblyVersion>
<InformationalVersion>1.0.5</InformationalVersion>
<PackageId>Droplex</PackageId>
<Authors>Jeremy Wu</Authors>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
Expand Down

0 comments on commit d593489

Please sign in to comment.