Skip to content

Commit

Permalink
added download and extract progress indicators
Browse files Browse the repository at this point in the history
  • Loading branch information
sampathbalivada committed Jul 19, 2020
1 parent 27fc1b7 commit 91d10aa
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 14 deletions.
42 changes: 38 additions & 4 deletions DownloadSDK/CustomAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
using System.Text;
using System.IO;
using Newtonsoft.Json;
using System.Threading;
using System.ComponentModel;

namespace DownloadAndUnpack
{
Expand All @@ -12,6 +14,30 @@ public class CustomActions
[CustomAction]
public static ActionResult DownloadSDK(Session session)
{
void HandleDownloadProgress (object sender, DownloadProgressChangedEventArgs e)
{
string actionMessage = "Downloading SDK... (" + e.ProgressPercentage.ToString() + "% completed)";
//session.Log(actionMessage);
Record record = new Record("callAddProgressInfo", actionMessage, "");
session.Message(InstallMessage.ActionStart, record);

}

void HandleDownloadComplete(object sender, AsyncCompletedEventArgs e)
{
if(e.Error != null)
{
session.Log(e.Error.Message);
}
Thread.Sleep(10000);
lock (e.UserState)
{
//releases blocked thread
Monitor.Pulse(e.UserState);
}
}


string basePath = @"C:\flutter";
WebClient client = new WebClient();
try
Expand All @@ -22,11 +48,19 @@ public static ActionResult DownloadSDK(Session session)
Directory.CreateDirectory(basePath);
}

// Use this in release mode
client.DownloadFile(InstallerLink.GetLink(), basePath + @"\flutter_sdk.zip");
client.DownloadProgressChanged += HandleDownloadProgress;
client.DownloadFileCompleted += HandleDownloadComplete;

// Use this when debugging using a local server
//client.DownloadFile("http://127.0.0.1:8000/flutter_sdk.zip", basePath + @"\flutter_sdk.zip");
//Uri downloadUri = new Uri("http://127.0.0.1:8000/flutter_sdk.zip");
Uri downloadUri = new Uri(InstallerLink.GetLink());

var syncObject = new Object();
lock (syncObject)
{
client.DownloadFileAsync(downloadUri, basePath + @"\flutter_sdk.zip", syncObject);
//This will block the thread until download completes
Monitor.Wait(syncObject);
}

}
catch (Exception e)
Expand Down
3 changes: 0 additions & 3 deletions FlutterInstaller/Product.wxs
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,6 @@
</InstallExecuteSequence>

<UI>
<!-- Update UI to reflect the current status -->
<ProgressText Action="CA_DownloadSDK">Downloading SDK... (this might take a while depending on your internet)</ProgressText>
<ProgressText Action="CA_UnpackSDK">Extracting Files... (this usually takes 10-15 minutes)</ProgressText>
<!-- Invoke custom action if Exit Dialog checkbox is in checked state -->
<Publish Dialog="ExitDialog" Control="Finish" Event="DoAction" Value="CA_OpenREADME">WIXUI_EXITDIALOGOPTIONALCHECKBOX = 1 and NOT Installed</Publish>
</UI>
Expand Down
3 changes: 0 additions & 3 deletions FlutterInstaller/assets/AboutSDK.txt

This file was deleted.

18 changes: 14 additions & 4 deletions UnpackSDK/CustomAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,17 @@ public class CustomActions
[CustomAction]
public static ActionResult UnpackSDK(Session session)
{
void UnZipProgress(object sender, ExtractProgressEventArgs e)
{
if (e.EventType == ZipProgressEventType.Extracting_AfterExtractEntry)
{
string actionMessage = "Extracting files... (" + e.EntriesExtracted.ToString() + " of " + e.EntriesTotal.ToString() + " files extracted)";
//session.Log(actionMessage);
Record record = new Record("callAddProgressInfo", actionMessage, "");
session.Message(InstallMessage.ActionStart, record);
}
}

try
{
string path = @"C:\flutter\flutter_sdk.zip";
Expand All @@ -19,10 +30,8 @@ public static ActionResult UnpackSDK(Session session)
// Extract flutter_sdk.zip to C:\
using (ZipFile zipFile = new ZipFile(path))
{
foreach (ZipEntry e in zipFile)
{
e.Extract(@"C:\");
}
zipFile.ExtractProgress += UnZipProgress;
zipFile.ExtractAll(@"C:\", ExtractExistingFileAction.OverwriteSilently);
}
}
}
Expand All @@ -36,5 +45,6 @@ public static ActionResult UnpackSDK(Session session)

return ActionResult.Success;
}

}
}

0 comments on commit 91d10aa

Please sign in to comment.