Skip to content

Commit 7d60f57

Browse files
committed
fix template download issue
1 parent 7eab9bc commit 7d60f57

1 file changed

Lines changed: 7 additions & 3 deletions

File tree

‎UnityLauncherPro/NewProject.xaml.cs‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1087,12 +1087,15 @@ private async void btnDownloadTemplate_Click(object sender, RoutedEventArgs e)
10871087

10881088
// Download the template (overwrite if exists)
10891089
using (var client = new HttpClient())
1090+
using (var response = await client.GetAsync(template.TarBallURL, HttpCompletionOption.ResponseHeadersRead))
10901091
{
1091-
var response = await client.GetAsync(template.TarBallURL);
10921092
response.EnsureSuccessStatusCode();
10931093

1094-
var fileBytes = await response.Content.ReadAsByteArrayAsync();
1095-
File.WriteAllBytes(targetFilePath, fileBytes);
1094+
using (var contentStream = await response.Content.ReadAsStreamAsync())
1095+
using (var fileStream = new FileStream(targetFilePath, FileMode.Create, FileAccess.Write, FileShare.None, 81920, true))
1096+
{
1097+
await contentStream.CopyToAsync(fileStream);
1098+
}
10961099

10971100
// Mark as downloaded
10981101
template.IsDownloaded = true;
@@ -1119,6 +1122,7 @@ private async void btnDownloadTemplate_Click(object sender, RoutedEventArgs e)
11191122

11201123
private void btnFetchTemplates_Click(object sender, RoutedEventArgs e)
11211124
{
1125+
listOnlineTemplates.ItemsSource = null; // clear previous items
11221126
if (gridAvailableVersions.SelectedItem is UnityInstallation selectedInstallation)
11231127
{
11241128
string baseVersion = Tools.GetBaseVersion(selectedInstallation.Version);

0 commit comments

Comments
 (0)