Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update.exe args proxy config #1463

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 47 additions & 9 deletions src/Update/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using System.IO;
using System.IO.Compression;
using System.Linq;
using System.Net;
using System.Reflection;
using System.Text;
using System.Text.RegularExpressions;
Expand Down Expand Up @@ -110,13 +111,13 @@ int executeCommandLine(string[] args)
Uninstall().Wait();
break;
case UpdateAction.Download:
Console.WriteLine(Download(opt.target).Result);
Console.WriteLine(Download(opt.target, proxyUrl: opt.proxyUrl, proxyUser: opt.proxyUser, proxyPassword: opt.proxyPassword).Result);
break;
case UpdateAction.Update:
Update(opt.target).Wait();
Update(opt.target, proxyUrl: opt.proxyUrl, proxyUser: opt.proxyUser, proxyPassword: opt.proxyPassword).Wait();
break;
case UpdateAction.CheckForUpdate:
Console.WriteLine(CheckForUpdate(opt.target).Result);
Console.WriteLine(CheckForUpdate(opt.target, proxyUrl: opt.proxyUrl, proxyUser: opt.proxyUser, proxyPassword: opt.proxyPassword).Result);
break;
case UpdateAction.UpdateSelf:
UpdateSelf().Wait();
Expand Down Expand Up @@ -187,13 +188,20 @@ public async Task Install(bool silentInstall, ProgressSource progressSource, str
}
}

public async Task Update(string updateUrl, string appName = null)
public async Task Update(string updateUrl, string appName = null, string proxyUrl = null, string proxyUser = null, string proxyPassword = null)
{
FileDownloader fileDownloader = null;
appName = appName ?? getAppNameFromDirectory();

this.Log().Info("Starting update, downloading from " + updateUrl);

using (var mgr = new UpdateManager(updateUrl, appName)) {
if (!string.IsNullOrEmpty(proxyUrl))
{
var webClient = generateProxyWebClient(proxyUrl, proxyUser, proxyPassword);
fileDownloader = new FileDownloader(webClient);
}

using (var mgr = new UpdateManager(updateUrl, appName, urlDownloader: fileDownloader)) {
bool ignoreDeltaUpdates = false;
this.Log().Info("About to update to: " + mgr.RootAppDirectory);

Expand Down Expand Up @@ -234,12 +242,20 @@ public async Task UpdateSelf()
});
}

public async Task<string> Download(string updateUrl, string appName = null)
public async Task<string> Download(string updateUrl, string appName = null, string proxyUrl = null, string proxyUser = null, string proxyPassword = null)
{
FileDownloader fileDownloader = null;
appName = appName ?? getAppNameFromDirectory();

this.Log().Info("Fetching update information, downloading from " + updateUrl);
using (var mgr = new UpdateManager(updateUrl, appName)) {

if (!string.IsNullOrEmpty(proxyUrl))
{
var webClient = generateProxyWebClient(proxyUrl, proxyUser, proxyPassword);
fileDownloader = new FileDownloader(webClient);
}

using (var mgr = new UpdateManager(updateUrl, appName, urlDownloader: fileDownloader)) {
var updateInfo = await mgr.CheckForUpdate(intention: UpdaterIntention.Update, progress: x => Console.WriteLine(x / 3));
await mgr.DownloadReleases(updateInfo.ReleasesToApply, x => Console.WriteLine(33 + x / 3));

Expand All @@ -258,12 +274,20 @@ public async Task<string> Download(string updateUrl, string appName = null)
}
}

public async Task<string> CheckForUpdate(string updateUrl, string appName = null)
public async Task<string> CheckForUpdate(string updateUrl, string appName = null, string proxyUrl = null, string proxyUser = null, string proxyPassword = null)
{
FileDownloader fileDownloader = null;
appName = appName ?? getAppNameFromDirectory();

this.Log().Info("Fetching update information, downloading from " + updateUrl);
using (var mgr = new UpdateManager(updateUrl, appName)) {

if (!string.IsNullOrEmpty(proxyUrl))
{
var webClient = generateProxyWebClient(proxyUrl, proxyUser, proxyPassword);
fileDownloader = new FileDownloader(webClient);
}

using (var mgr = new UpdateManager(updateUrl, appName, urlDownloader: fileDownloader)) {
var updateInfo = await mgr.CheckForUpdate(intention: UpdaterIntention.Update, progress: x => Console.WriteLine(x));
var releaseNotes = updateInfo.FetchReleaseNotes();

Expand Down Expand Up @@ -530,6 +554,20 @@ void waitForParentToExit()
}
}

WebClient generateProxyWebClient(string proxyUrl, string proxyUser, string proxyPassword)
{
var webClient = new WebClient();
var webProxy = new WebProxy(proxyUrl);

if (!string.IsNullOrEmpty(proxyUser) && !string.IsNullOrEmpty(proxyPassword))
{
webProxy.Credentials = new NetworkCredential(proxyUser, proxyPassword);
}

webClient.Proxy = webProxy;
return webClient;
}

async Task<string> createSetupEmbeddedZip(string fullPackage, string releasesDir, string backgroundGif, string signingOpts, string setupIcon)
{
string tempPath;
Expand Down
6 changes: 6 additions & 0 deletions src/Update/StartupOption.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ internal class StartupOption
internal string backgroundGif { get; private set; } = default(string);
internal string signingParameters { get; private set; } = default(string);
internal string baseUrl { get; private set; } = default(string);
internal string proxyUrl { get; private set; } = default(string);
internal string proxyUser { get; private set; } = default(string);
internal string proxyPassword { get; private set; } = default(string);
internal string processStart { get; private set; } = default(string);
internal string processStartArgs { get; private set; } = default(string);
internal string setupIcon { get; private set; } = default(string);
Expand Down Expand Up @@ -60,6 +63,9 @@ internal class StartupOption
{ "n=|signWithParams=", "Sign the installer via SignTool.exe with the parameters given", v => signingParameters = v},
{ "s|silent", "Silent install", _ => silentInstall = true},
{ "b=|baseUrl=", "Provides a base URL to prefix the RELEASES file packages with", v => baseUrl = v, true},
{ "proxyUrl=", "Defines the URL of the proxy", v => proxyUrl = v},
{ "proxyUser=", "Defines the username of the proxy", v => proxyUser = v},
{ "proxyPassword=", "Defines the password of the proxy", v => proxyPassword = v},
{ "a=|process-start-args=", "Arguments that will be used when starting executable", v => processStartArgs = v, true},
{ "l=|shortcut-locations=", "Comma-separated string of shortcut locations, e.g. 'Desktop,StartMenu'", v => shortcutArgs = v},
{ "no-msi", "Don't generate an MSI package", v => noMsi = true},
Expand Down