Skip to content
Merged
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
3 changes: 2 additions & 1 deletion src/NAppUpdate.Framework/Conditions/FileChecksumCondition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.IO;
using NAppUpdate.Framework.Common;
using NAppUpdate.Framework.Tasks;
using NAppUpdate.Framework.Utils;

namespace NAppUpdate.Framework.Conditions
{
Expand Down Expand Up @@ -33,7 +34,7 @@ public bool IsMet(IUpdateTask task)

if ("sha256".Equals(ChecksumType, StringComparison.InvariantCultureIgnoreCase))
{
var sha256 = Utils.FileChecksum.GetSHA256Checksum(localPath);
var sha256 = FileChecksum.GetSHA256Checksum(localPath);
if (!string.IsNullOrEmpty(sha256) && sha256.Equals(Checksum, StringComparison.InvariantCultureIgnoreCase))
return true;
}
Expand Down
15 changes: 4 additions & 11 deletions src/NAppUpdate.Framework/Tasks/FileUpdateTask.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
using System;
using System.IO;
using System.Security.AccessControl;
using System.Security.Principal;
using System.Threading;
using NAppUpdate.Framework.Common;
using NAppUpdate.Framework.Utils;
Expand Down Expand Up @@ -60,7 +58,7 @@ public override void Prepare(Sources.IUpdateSource source)

if (!string.IsNullOrEmpty(Sha256Checksum))
{
string checksum = Utils.FileChecksum.GetSHA256Checksum(_tempFile);
string checksum = FileChecksum.GetSHA256Checksum(_tempFile);
if (!checksum.Equals(Sha256Checksum))
throw new UpdateProcessFailedException(string.Format("FileUpdateTask: Checksums do not match; expected {0} but got {1}", Sha256Checksum, checksum));
}
Expand All @@ -78,7 +76,6 @@ public override TaskExecutionStatus Execute(bool coldRun)
}

var dirName = Path.GetDirectoryName(_destinationFile);

if (!Directory.Exists(dirName))
{
Utils.FileSystem.CreateDirectoryStructure(dirName, false);
Expand All @@ -92,7 +89,6 @@ public override TaskExecutionStatus Execute(bool coldRun)
string backupPath = Path.GetDirectoryName(Path.Combine(UpdateManager.Instance.Config.BackupFolder, LocalPath));
Utils.FileSystem.CreateDirectoryStructure(backupPath, false);
}

_backupFile = Path.Combine(UpdateManager.Instance.Config.BackupFolder, LocalPath);
File.Copy(_destinationFile, _backupFile, true);
}
Expand All @@ -118,12 +114,11 @@ public override TaskExecutionStatus Execute(bool coldRun)
try
{
if (File.Exists(_destinationFile))
{
FileSystem.CopyAccessControl(new FileInfo(_destinationFile), new FileInfo(_tempFile));
{
FileSystem.CopyAccessControl(new FileInfo(_destinationFile), new FileInfo(_tempFile));

File.Delete(_destinationFile);
}

File.Move(_tempFile, _destinationFile);
_tempFile = null;
}
Expand All @@ -150,8 +145,7 @@ public override TaskExecutionStatus Execute(bool coldRun)
return TaskExecutionStatus.RequiresPrivilegedAppRestart;
}
return TaskExecutionStatus.RequiresAppRestart;
}

}

public override bool Rollback()
{
Expand All @@ -165,7 +159,6 @@ 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 Down
2 changes: 1 addition & 1 deletion src/NAppUpdate.Framework/Utils/FileChecksum.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public static string GetSHA256Checksum(string filePath)
{
SHA256Managed sha = new SHA256Managed();
byte[] checksum = sha.ComputeHash(stream);
return BitConverter.ToString(checksum).Replace("-", String.Empty);
return BitConverter.ToString(checksum).Replace("-", string.Empty);
}
}

Expand Down