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

Issue #95 + Issue #39 #96

Closed
wants to merge 3 commits into from
Closed
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
107 changes: 54 additions & 53 deletions src/NAppUpdate.Framework/Common/NauConfigurations.cs
Original file line number Diff line number Diff line change
@@ -1,53 +1,54 @@
using System;
using System.Collections.Generic;
using System.IO;

namespace NAppUpdate.Framework.Common
{
[Serializable]
public class NauConfigurations
{
public string TempFolder { get; set; }

/// <summary>
/// Path to the backup folder used by the update process
/// </summary>
public string BackupFolder
{
set
{
if (UpdateManager.Instance.State == UpdateManager.UpdateProcessState.NotChecked
|| UpdateManager.Instance.State == UpdateManager.UpdateProcessState.Checked)
{
string path = value.TrimEnd(Path.AltDirectorySeparatorChar, Path.DirectorySeparatorChar);
_backupFolder = Path.IsPathRooted(path) ? path : Path.Combine(TempFolder, path);
}
else
throw new ArgumentException("BackupFolder can only be specified before update has started");
}
get
{
return _backupFolder;
}
}
internal string _backupFolder;

public string UpdateProcessName { get; set; }

/// <summary>
/// The name for the executable file to extract and run cold updates with. Default is foo.exe. You can change
/// it to whatever you want, but pay attention to names like "updater.exe" and "installer.exe" - they will trigger
/// an UAC prompt in all cases.
/// </summary>
public string UpdateExecutableName { get; set; }

/// <summary>
/// A list of files (relative paths only) to be copied along with the NAppUpdate DLL and updater host
/// when performing cold updates. You need to set this only when you have a custom IUpdateTask that
/// takes dependency of an external DLL, or require other files side by side with them.
/// Custom IUpdateTasks taking dependencies of external DLLs which may require cold update, MUST reside
/// in an external class-library, never in the application EXE, for that reason.
/// </summary>
public List<string> DependenciesForColdUpdate { get; set; }
}
}
using System;
using System.Collections.Generic;
using System.IO;

namespace NAppUpdate.Framework.Common
{
[Serializable]
public class NauConfigurations
{
public string TempFolder { get; set; }
public string RelaunchAppArgs { get; set; }

/// <summary>
/// Path to the backup folder used by the update process
/// </summary>
public string BackupFolder
{
set
{
if (UpdateManager.Instance.State == UpdateManager.UpdateProcessState.NotChecked
|| UpdateManager.Instance.State == UpdateManager.UpdateProcessState.Checked)
{
string path = value.TrimEnd(Path.AltDirectorySeparatorChar, Path.DirectorySeparatorChar);
_backupFolder = Path.IsPathRooted(path) ? path : Path.Combine(TempFolder, path);
}
else
throw new ArgumentException("BackupFolder can only be specified before update has started");
}
get
{
return _backupFolder;
}
}
internal string _backupFolder;

public string UpdateProcessName { get; set; }

/// <summary>
/// The name for the executable file to extract and run cold updates with. Default is foo.exe. You can change
/// it to whatever you want, but pay attention to names like "updater.exe" and "installer.exe" - they will trigger
/// an UAC prompt in all cases.
/// </summary>
public string UpdateExecutableName { get; set; }

/// <summary>
/// A list of files (relative paths only) to be copied along with the NAppUpdate DLL and updater host
/// when performing cold updates. You need to set this only when you have a custom IUpdateTask that
/// takes dependency of an external DLL, or require other files side by side with them.
/// Custom IUpdateTasks taking dependencies of external DLLs which may require cold update, MUST reside
/// in an external class-library, never in the application EXE, for that reason.
/// </summary>
public List<string> DependenciesForColdUpdate { get; set; }
}
}
26 changes: 18 additions & 8 deletions src/NAppUpdate.Framework/UpdateManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -143,13 +143,21 @@ public void CheckForUpdates()
lock (UpdatesToApply)
{
UpdatesToApply.Clear();
var tasks = UpdateFeedReader.Read(UpdateSource.GetUpdatesFeed());
foreach (var t in tasks)
float num = 0f;
var tasks = UpdateFeedReader.Read(UpdateSource.GetUpdatesFeed());
int count = tasks.Count;
foreach (var t in tasks)
{
if (ShouldStop)
throw new UserAbortException();

if (t.UpdateConditions == null || t.UpdateConditions.IsMet(t)) // Only execute if all conditions are met
this.ReportProgress(new UpdateProgressInfo {
Message = "Checking",
Percentage = (int)((num += 1f) / (float)count * 100f),
TaskDescription = t.Description,
TaskId = (int)num,
StillWorking = true
});
if (t.UpdateConditions == null || t.UpdateConditions.IsMet(t)) // Only execute if all conditions are met
UpdatesToApply.Add(t);
}
}
Expand Down Expand Up @@ -238,8 +246,9 @@ public void PrepareUpdates()

var t = task;
task.ProgressDelegate += status => TaskProgressCallback(status, t);

try
this.TaskProgressCallback(new UpdateProgressInfo{
Message = "Preparing"}, t);
try
{
task.Prepare(UpdateSource);
}
Expand Down Expand Up @@ -402,8 +411,9 @@ public void ApplyUpdates(bool relaunchApplication, bool updaterDoLogging, bool u
{
IUpdateTask t = task;
task.ProgressDelegate += status => TaskProgressCallback(status, t);

try
this.TaskProgressCallback(new UpdateProgressInfo{
Message = "Applying"}, t);
try
{
// Execute the task
task.ExecutionStatus = task.Execute(false);
Expand Down
Binary file modified src/NAppUpdate.Framework/Updater/updater.exe
Binary file not shown.
5 changes: 3 additions & 2 deletions src/NAppUpdate.Updater/AppStart.cs
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,9 @@ private static void PerformUpdates()
// Get some required environment variables
string appPath = _dto.AppPath;
string appDir = _dto.WorkingDirectory ?? Path.GetDirectoryName(appPath) ?? string.Empty;
string relaunchAppArgs = _dto.Configs.RelaunchAppArgs;

if (!string.IsNullOrEmpty(_dto.AppPath))
if (!string.IsNullOrEmpty(_dto.AppPath))
{
_logFilePath = Path.Combine(Path.GetDirectoryName(_dto.AppPath), @"NauUpdate.log"); // now we can log to a more accessible location
}
Expand Down Expand Up @@ -205,7 +206,7 @@ private static void PerformUpdates()
UseShellExecute = useShellExecute,
WorkingDirectory = appDir,
FileName = appPath,
Arguments = "-nappupdate-afterrestart"
Arguments = "-nappupdate-afterrestart" + " " + relaunchAppArgs
};

try
Expand Down