Skip to content

Commit

Permalink
Added ability to set installation path for update file extraction. This
Browse files Browse the repository at this point in the history
resolves ravibpatel#215, resolves ravibpatel#333 and resolves ravibpatel#352.
  • Loading branch information
ravibpatel committed Feb 2, 2020
1 parent 2e26d4d commit f64dd15
Show file tree
Hide file tree
Showing 9 changed files with 65 additions and 25 deletions.
21 changes: 13 additions & 8 deletions AutoUpdater.NET/AutoUpdater.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,17 +73,22 @@ public static class AutoUpdater
/// <summary>
/// Set it to folder path where you want to download the update file. If not provided then it defaults to Temp folder.
/// </summary>
public static String DownloadPath;
public static string DownloadPath;

/// <summary>
/// If you are using a zip file as an update file then you can set this value to path where your app is installed. This is only necessary when your installation directory differs from your executable path.
/// </summary>
public static string InstallationPath;

/// <summary>
/// Set the Application Title shown in Update dialog. Although AutoUpdater.NET will get it automatically, you can set this property if you like to give custom Title.
/// </summary>
public static String AppTitle;
public static string AppTitle;

/// <summary>
/// URL of the xml file that contains information about latest version of the application.
/// </summary>
public static String AppCastURL;
public static string AppCastURL;

/// <summary>
/// Login/password/domain for FTP-request
Expand Down Expand Up @@ -118,18 +123,18 @@ public static class AutoUpdater
/// <summary>
/// If this is true users can see the skip button.
/// </summary>
public static Boolean ShowSkipButton = true;
public static bool ShowSkipButton = true;

/// <summary>
/// If this is true users can see the Remind Later button.
/// </summary>
public static Boolean ShowRemindLaterButton = true;
public static bool ShowRemindLaterButton = true;

/// <summary>
/// If this is true users see dialog where they can set remind later interval otherwise it will take the interval from
/// RemindLaterAt and RemindLaterTimeSpan fields.
/// </summary>
public static Boolean LetUserSelectRemindLater = true;
public static bool LetUserSelectRemindLater = true;

/// <summary>
/// Remind Later interval after user should be reminded of update.
Expand Down Expand Up @@ -223,7 +228,7 @@ public static void Start(Assembly myAssembly = null)
/// <param name="appCast">FTP URL of the xml file that contains information about latest version of the application.</param>
/// <param name="ftpCredentials">Credentials required to connect to FTP server.</param>
/// <param name="myAssembly">Assembly to use for version checking.</param>
public static void Start(String appCast, NetworkCredential ftpCredentials, Assembly myAssembly = null)
public static void Start(string appCast, NetworkCredential ftpCredentials, Assembly myAssembly = null)
{
FtpCredentials = ftpCredentials;
Start(appCast, myAssembly);
Expand All @@ -234,7 +239,7 @@ public static void Start(String appCast, NetworkCredential ftpCredentials, Assem
/// </summary>
/// <param name="appCast">URL of the xml file that contains information about latest version of the application.</param>
/// <param name="myAssembly">Assembly to use for version checking.</param>
public static void Start(String appCast, Assembly myAssembly = null)
public static void Start(string appCast, Assembly myAssembly = null)
{
try
{
Expand Down
15 changes: 12 additions & 3 deletions AutoUpdater.NET/DownloadUpdateDialog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,17 @@ private void WebClientOnDownloadFileCompleted(object sender, AsyncCompletedEvent

File.WriteAllBytes(installerPath, Resources.ZipExtractor);

string executablePath = Process.GetCurrentProcess().MainModule.FileName;
string extractionPath = Path.GetDirectoryName(executablePath);

if (!string.IsNullOrEmpty(AutoUpdater.InstallationPath) &&
Directory.Exists(AutoUpdater.InstallationPath))
{
extractionPath = AutoUpdater.InstallationPath;
}

StringBuilder arguments =
new StringBuilder($"\"{tempPath}\" \"{Process.GetCurrentProcess().MainModule.FileName}\"");
new StringBuilder($"\"{tempPath}\" \"{extractionPath}\" \"{executablePath}\"");
string[] args = Environment.GetCommandLineArgs();
for (int i = 1; i < args.Length; i++)
{
Expand Down Expand Up @@ -204,7 +213,7 @@ private void WebClientOnDownloadFileCompleted(object sender, AsyncCompletedEvent
}
}

private static String BytesToString(long byteCount)
private static string BytesToString(long byteCount)
{
string[] suf = {"B", "KB", "MB", "GB", "TB", "PB", "EB"};
if (byteCount == 0)
Expand All @@ -226,7 +235,7 @@ private static void CompareChecksum(string fileName, CheckSum checksum)
if (hashAlgorithm != null)
{
var hash = hashAlgorithm.ComputeHash(stream);
var fileChecksum = BitConverter.ToString(hash).Replace("-", String.Empty).ToLowerInvariant();
var fileChecksum = BitConverter.ToString(hash).Replace("-", string.Empty).ToLowerInvariant();

if (fileChecksum == checksum.Text.ToLower()) return;

Expand Down
Binary file modified AutoUpdater.NET/Resources/ZipExtractor.exe
Binary file not shown.
7 changes: 5 additions & 2 deletions AutoUpdater.NET/Resources/ZipExtractor.exe.config
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" standalone="yes"?>
<configuration>
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/></startup></configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0" />
</startup>
</configuration>
4 changes: 2 additions & 2 deletions AutoUpdater.NET/UpdateInfoEventArgs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,9 @@ public string ChangelogURL
/// </summary>
public string HashingAlgorithm { get; set; }

internal static string GetURL(Uri baseUri, String url)
internal static string GetURL(Uri baseUri, string url)
{
if (!String.IsNullOrEmpty(url) && Uri.IsWellFormedUriString(url, UriKind.Relative))
if (!string.IsNullOrEmpty(url) && Uri.IsWellFormedUriString(url, UriKind.Relative))
{
Uri uri = new Uri(baseUri, url);

Expand Down
10 changes: 9 additions & 1 deletion AutoUpdaterTest/FormMain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ private void FormMain_Load(object sender, EventArgs e)
//};
//timer.Start();

//Uncomment following lines to provide basic authentication credetials to use.
//Uncomment following lines to provide basic authentication credentials to use.

//BasicAuthentication basicAuthentication = new BasicAuthentication("myUserName", "myPassword");
//AutoUpdater.BasicAuthXML = AutoUpdater.BasicAuthDownload = basicAuthentication;
Expand All @@ -107,9 +107,17 @@ private void FormMain_Load(object sender, EventArgs e)
//Uncomment following if you want to update using FTP.
//AutoUpdater.Start("ftp://rbsoft.org/updates/AutoUpdaterTest.xml", new NetworkCredential("FtpUserName", "FtpPassword"));

//Uncomment following lines if you want to persist Remind Later and Skip values in a json file.
//string jsonPath = Path.Combine(Environment.CurrentDirectory, "settings.json");
//AutoUpdater.PersistenceProvider = new JsonFilePersistenceProvider(jsonPath);

//Uncomment following line if you want to set the zip extraction path.
var currentDirectory = new DirectoryInfo(Environment.CurrentDirectory);
if (currentDirectory.Parent != null)
{
AutoUpdater.InstallationPath = currentDirectory.Parent.FullName;
}

AutoUpdater.Start("https://rbsoft.org/updates/AutoUpdaterTest.xml");
}

Expand Down
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,18 @@ You can specify where you want to download the update file by assigning Download
AutoUpdater.DownloadPath = Environment.CurrentDirectory;
````

### Specify where to extract zip file containing updated files

If you are using a zip file as an update file then you can set this value to path where your app is installed. This is only necessary when your installation directory differs from your executable path.

````csharp
var currentDirectory = new DirectoryInfo(Environment.CurrentDirectory);
if (currentDirectory.Parent != null)
{
AutoUpdater.InstallationPath = currentDirectory.Parent.FullName;
}
````

### Specify size of the UpdateForm

You can specify the size of the update form by using below code.
Expand Down
17 changes: 10 additions & 7 deletions ZipExtractor/FormMain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,10 @@ private void FormMain_Shown(object sender, EventArgs e)

_logBuilder.AppendLine();

if (args.Length >= 3)
if (args.Length >= 4)
{
string executablePath = args[3];

// Extract all the files.
_backgroundWorker = new BackgroundWorker
{
Expand All @@ -50,7 +52,7 @@ private void FormMain_Shown(object sender, EventArgs e)
{
try
{
if (process.MainModule.FileName.Equals(args[2]))
if (process.MainModule.FileName.Equals(executablePath))
{
_logBuilder.AppendLine("Waiting for application process to Exit...");

Expand All @@ -66,7 +68,7 @@ private void FormMain_Shown(object sender, EventArgs e)

_logBuilder.AppendLine("BackgroundWorker started successfully.");

var path = Path.GetDirectoryName(args[2]);
var path = args[2];

// Open an existing zip file for reading.
ZipStorer zip = ZipStorer.Open(args[1], FileAccess.Read);
Expand Down Expand Up @@ -117,10 +119,10 @@ private void FormMain_Shown(object sender, EventArgs e)
labelInformation.Text = @"Finished";
try
{
ProcessStartInfo processStartInfo = new ProcessStartInfo(args[2]);
if (args.Length > 3)
ProcessStartInfo processStartInfo = new ProcessStartInfo(executablePath);
if (args.Length > 4)
{
processStartInfo.Arguments = args[3];
processStartInfo.Arguments = args[4];
}

Process.Start(processStartInfo);
Expand Down Expand Up @@ -160,7 +162,8 @@ private void FormMain_FormClosing(object sender, FormClosingEventArgs e)
_backgroundWorker?.CancelAsync();

_logBuilder.AppendLine();
File.AppendAllText(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "ZipExtractor.log"), _logBuilder.ToString());
File.AppendAllText(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "ZipExtractor.log"),
_logBuilder.ToString());
}
}
}
4 changes: 2 additions & 2 deletions ZipExtractor/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.7.0")]
[assembly: AssemblyFileVersion("1.0.7.0")]
[assembly: AssemblyVersion("1.1.0.0")]
[assembly: AssemblyFileVersion("1.1.0.0")]

0 comments on commit f64dd15

Please sign in to comment.