Skip to content
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
22 changes: 22 additions & 0 deletions src/NAppUpdate.Framework/Common/Logger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,13 @@ public void Dump(string filePath)
filePath = Path.Combine(workingDir ?? string.Empty, @"NauUpdate.log");
}

if (File.Exists(filePath))
{
var oldBackupFile = SelectBackupLogFileName(filePath);
if (oldBackupFile != null)
File.Move(filePath, oldBackupFile);
}

lock (LogItems)
{
using (StreamWriter w = File.CreateText(filePath))
Expand All @@ -104,5 +111,20 @@ public void Dump(string filePath)
}
}
}

private string SelectBackupLogFileName(string filePath)
{
var directory = Path.GetDirectoryName(filePath);
if (directory == null)
directory = ".";
for (var i = 0; i < 10; i++)
{
filePath = Path.Combine(directory, "NauUpdate." + i + ".log");
if(File.Exists(filePath))
continue;
return filePath;
}
return null;
}
}
}
22 changes: 11 additions & 11 deletions src/NAppUpdate.Framework/Conditions/BooleanCondition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,29 +39,29 @@ public static ConditionType ConditionTypeFromString(string type)
}
#endregion

protected class ConditionItem
public class ConditionItem
{
public ConditionItem(IUpdateCondition cnd, ConditionType typ)
{
this._Condition = cnd;
this._ConditionType = typ;
this.Condition = cnd;
this.ConditionType = typ;
}

internal bool HasConditionType(ConditionType type)
{
return (_ConditionType & type) > 0;
return (ConditionType & type) > 0;
}

public readonly IUpdateCondition _Condition;
public readonly ConditionType _ConditionType;
public IUpdateCondition Condition { get; private set; }
public ConditionType ConditionType { get; private set; }
}

public BooleanCondition()
{
Attributes = new Dictionary<string, string>();
}

protected LinkedList<ConditionItem> ChildConditions { get; set; }
public LinkedList<ConditionItem> ChildConditions { get; private set; }
public int ChildConditionsCount { get { if (ChildConditions != null) return ChildConditions.Count; return 0; } }

public void AddCondition(IUpdateCondition cnd)
Expand All @@ -77,8 +77,8 @@ public void AddCondition(IUpdateCondition cnd, ConditionType type)

public IUpdateCondition Degrade()
{
if (ChildConditionsCount == 1 && (ChildConditions.First.Value._ConditionType & ConditionType.NOT) == 0)
return ChildConditions.First.Value._Condition;
if (ChildConditionsCount == 1 && (ChildConditions.First.Value.ConditionType & ConditionType.NOT) == 0)
return ChildConditions.First.Value.Condition;

return this;
}
Expand Down Expand Up @@ -110,13 +110,13 @@ public bool IsMet(Tasks.IUpdateTask task)
{
if (item.HasConditionType(ConditionType.OR))
{
var checkResult = item._Condition.IsMet(task);
var checkResult = item.Condition.IsMet(task);
passed = item.HasConditionType(ConditionType.NOT) ? !checkResult : checkResult;
}
}
else
{
var checkResult = item._Condition.IsMet(task);
var checkResult = item.Condition.IsMet(task);
passed = item.HasConditionType(ConditionType.NOT) ? !checkResult : checkResult;
}
}
Expand Down
5 changes: 5 additions & 0 deletions src/NAppUpdate.Framework/Conditions/FileChecksumCondition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,10 @@ public bool IsMet(IUpdateTask task)

return false;
}

public override string ToString()
{
return "Checksum [" + ChecksumType + "] equals " + Checksum;
}
}
}
5 changes: 5 additions & 0 deletions src/NAppUpdate.Framework/Conditions/FileDateCondition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,5 +62,10 @@ public bool IsMet(Tasks.IUpdateTask task)
}
return result;
}

public override string ToString()
{
return "Timestamp " + ComparisonType + " " + Timestamp;
}
}
}
5 changes: 5 additions & 0 deletions src/NAppUpdate.Framework/Conditions/FileExistsCondition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,10 @@ public bool IsMet(Tasks.IUpdateTask task)

return File.Exists(localPath);
}

public override string ToString()
{
return "File exists";
}
}
}
5 changes: 5 additions & 0 deletions src/NAppUpdate.Framework/Conditions/FileSizeCondition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,10 @@ public bool IsMet(Tasks.IUpdateTask task)
}
return FileSize > localFileSize;
}

public override string ToString()
{
return "FileSize " + ComparisonType + " " + FileSize;
}
}
}
5 changes: 5 additions & 0 deletions src/NAppUpdate.Framework/Conditions/FileVersionCondition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,5 +50,10 @@ public bool IsMet(Tasks.IUpdateTask task)
return updateVersion > localVersion;
}
}

public override string ToString()
{
return "Version " + ComparisonType + " " + Version;
}
}
}
5 changes: 5 additions & 0 deletions src/NAppUpdate.Framework/Conditions/OSCondition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,5 +93,10 @@ static extern IntPtr GetProcAddress(IntPtr hModule,
static extern bool IsWow64Process(IntPtr hProcess, out bool wow64Process);

#endregion

public override string ToString()
{
return "OS bitness is " + OsBits;
}
}
}
7 changes: 5 additions & 2 deletions src/NAppUpdate.Framework/Resources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions src/NAppUpdate.Framework/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -112,13 +112,13 @@
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<assembly alias="System.Windows.Forms" name="System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<assembly alias="System.Windows.Forms" name="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<data name="updater" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>Updater\updater.exe;System.Byte[], mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
<value>updater\updater.exe;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
</root>
7 changes: 7 additions & 0 deletions src/NAppUpdate.Framework/Tasks/FileUpdateTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ public override bool Rollback()

return true;
}

/// <summary>
/// To mitigate problems with the files being locked even though the application mutex has been released.
/// https://github.com/synhershko/NAppUpdate/issues/35
Expand All @@ -176,5 +177,11 @@ private void FileLockWait()
}
}
}

public override string ToString()
{
var ret = base.ToString();
return string.IsNullOrWhiteSpace(ret) ? LocalPath : ret;
}
}
}
6 changes: 6 additions & 0 deletions src/NAppUpdate.Framework/Tasks/RegistryTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,5 +78,11 @@ public override bool Rollback()
Registry.SetValue(KeyName, KeyValueName, _originalValue);
return true;
}

public override string ToString()
{
var ret = base.ToString();
return string.IsNullOrWhiteSpace(ret) ? KeyName + @"\" + KeyValueName : ret;
}
}
}
5 changes: 5 additions & 0 deletions src/NAppUpdate.Framework/Tasks/UpdateTaskBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,10 @@ public virtual void OnProgress(UpdateProgressInfo pi)
public abstract void Prepare(IUpdateSource source);
public abstract TaskExecutionStatus Execute(bool coldRun);
public abstract bool Rollback();

public override string ToString()
{
return Description;
}
}
}
10 changes: 5 additions & 5 deletions src/NAppUpdate.Framework/UpdateManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ private void TaskProgressCallback(UpdateProgressInfo currentStatus, IUpdateTask
{
if (ReportProgress == null) return;

currentStatus.TaskDescription = task.Description;
currentStatus.TaskDescription = task.ToString();
currentStatus.TaskId = UpdatesToApply.IndexOf(task) + 1;

//This was an assumed int, which meant we never reached 100% with an odd number of tasks
Expand Down Expand Up @@ -247,7 +247,7 @@ public void PrepareUpdates()
{
task.ExecutionStatus = TaskExecutionStatus.FailedToPrepare;
Logger.Log(ex);
throw new UpdateProcessFailedException("Failed to prepare task: " + task.Description, ex);
throw new UpdateProcessFailedException("Failed to prepare task: " + task, ex);
}

task.ExecutionStatus = TaskExecutionStatus.Prepared;
Expand Down Expand Up @@ -411,7 +411,7 @@ public void ApplyUpdates(bool relaunchApplication, bool updaterDoLogging, bool u
catch (Exception ex)
{
task.ExecutionStatus = TaskExecutionStatus.Failed; // mark the failing task before rethrowing
throw new UpdateProcessFailedException("Update task execution failed: " + task.Description, ex);
throw new UpdateProcessFailedException("Update task execution failed: " + task, ex);
}

if (task.ExecutionStatus == TaskExecutionStatus.RequiresAppRestart
Expand All @@ -426,7 +426,7 @@ public void ApplyUpdates(bool relaunchApplication, bool updaterDoLogging, bool u
// We are being quite explicit here - only Successful return values are considered
// to be Ok (cold updates are already handled above)
if (task.ExecutionStatus != TaskExecutionStatus.Successful)
throw new UpdateProcessFailedException("Update task execution failed: " + task.Description);
throw new UpdateProcessFailedException("Update task execution failed: " + task);
}

// If an application restart is required
Expand Down Expand Up @@ -591,4 +591,4 @@ private bool IsAfterRestart()
return false;
}
}
}
}
Binary file modified src/NAppUpdate.Framework/Updater/updater.exe
Binary file not shown.
1 change: 1 addition & 0 deletions src/NAppUpdate.Tests/Integration/SimpleWebSourceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ public class SimpleWebSourceTests
[TestMethod]
public void can_download_ansi_feed()
{
Assert.Inconclusive("This url contains wrong data");
const string expected = "NHibernate.Profiler-Build-";

var ws = new SimpleWebSource("http://builds.hibernatingrhinos.com/latest/nhprof");
Expand Down
7 changes: 4 additions & 3 deletions src/NAppUpdate.Updater/AppStart.cs
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,8 @@ private static void PerformUpdates()
}
}

_logger.LogItems.InsertRange(0, _dto.LogItems);
if(_dto.LogItems != null)
_logger.LogItems.InsertRange(0, _dto.LogItems);
_dto.LogItems = _logger.LogItems;

// Get some required environment variables
Expand All @@ -157,7 +158,7 @@ private static void PerformUpdates()
// Perform the actual off-line update process
foreach (var t in _dto.Tasks)
{
Log("Task \"{0}\": {1}", t.Description, t.ExecutionStatus);
Log("Task \"{0}\": {1}", t.ToString(), t.ExecutionStatus);

if (t.ExecutionStatus != TaskExecutionStatus.RequiresAppRestart && t.ExecutionStatus != TaskExecutionStatus.RequiresPrivilegedAppRestart)
{
Expand All @@ -180,7 +181,7 @@ private static void PerformUpdates()

if (t.ExecutionStatus != TaskExecutionStatus.Successful)
{
string taskFailedMessage = string.Format("Update failed, task execution failed, description: {0}, execution status: {1}", t.Description, t.ExecutionStatus);
string taskFailedMessage = string.Format("Update failed, task execution failed, description: {0}, execution status: {1}", t, t.ExecutionStatus);
throw new Exception(taskFailedMessage, exception);
}
}
Expand Down