Skip to content

Commit

Permalink
Merge pull request #122 from firsinanton/CurrentDirectory-issue
Browse files Browse the repository at this point in the history
using AppDomain.CurrentDomain.BaseDirectory instead of Environment.Cu…
  • Loading branch information
synhershko authored Feb 24, 2018
2 parents 46cccf2 + 891275c commit 8f53d90
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 25 deletions.
6 changes: 4 additions & 2 deletions src/NAppUpdate.Framework/Conditions/FileChecksumCondition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,15 @@ public bool IsMet(IUpdateTask task)
if (string.IsNullOrEmpty(localPath))
return true;

var fullPath = FileSystem.GetFullPath(localPath);

// if the local file does not exist, checksums don't match vacuously
if (!File.Exists(localPath))
if (!File.Exists(fullPath))
return false;

if ("sha256".Equals(ChecksumType, StringComparison.InvariantCultureIgnoreCase))
{
var sha256 = FileChecksum.GetSHA256Checksum(localPath);
var sha256 = FileChecksum.GetSHA256Checksum(fullPath);
if (!string.IsNullOrEmpty(sha256) && sha256.Equals(Checksum, StringComparison.InvariantCultureIgnoreCase))
return true;
}
Expand Down
7 changes: 5 additions & 2 deletions src/NAppUpdate.Framework/Conditions/FileDateCondition.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.IO;
using NAppUpdate.Framework.Common;
using NAppUpdate.Framework.Utils;

namespace NAppUpdate.Framework.Conditions
{
Expand Down Expand Up @@ -36,13 +37,15 @@ public bool IsMet(Tasks.IUpdateTask task)
if (string.IsNullOrEmpty(localPath))
return true;

var fullPath = FileSystem.GetFullPath(localPath);

// if the file doesn't exist it has a null timestamp, and therefore the condition result depends on the ComparisonType
if (!File.Exists(localPath))
if (!File.Exists(fullPath))
return ComparisonType.Equals("older", StringComparison.InvariantCultureIgnoreCase);

// File timestamps seem to be off by a little bit (conversion rounding?), so the code below
// gets around that
var dt = File.GetLastWriteTime(localPath);
var dt = File.GetLastWriteTime(fullPath);
var localPlus = dt.AddSeconds(2).ToFileTimeUtc();
var localMinus = dt.AddSeconds(-2).ToFileTimeUtc();
var remoteFileDateTime = Timestamp.ToFileTimeUtc();
Expand Down
5 changes: 3 additions & 2 deletions src/NAppUpdate.Framework/Conditions/FileExistsCondition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.IO;
using NAppUpdate.Framework.Common;
using NAppUpdate.Framework.Utils;

namespace NAppUpdate.Framework.Conditions
{
Expand All @@ -21,8 +22,8 @@ public bool IsMet(Tasks.IUpdateTask task)
string localPath = !string.IsNullOrEmpty(LocalPath) ? LocalPath : Utils.Reflection.GetNauAttribute(task, "LocalPath") as string;
if (string.IsNullOrEmpty(localPath))
return true;

return File.Exists(localPath);
var fullPath = FileSystem.GetFullPath(localPath);
return File.Exists(fullPath);
}
}
}
7 changes: 5 additions & 2 deletions src/NAppUpdate.Framework/Conditions/FileSizeCondition.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.IO;
using NAppUpdate.Framework.Common;
using NAppUpdate.Framework.Utils;

namespace NAppUpdate.Framework.Conditions
{
Expand Down Expand Up @@ -31,10 +32,12 @@ public bool IsMet(Tasks.IUpdateTask task)
if (string.IsNullOrEmpty(localPath))
return true;

var fullPath = FileSystem.GetFullPath(localPath);

long localFileSize = 0;
if (File.Exists(localPath))
if (File.Exists(fullPath))
{
var fi = new FileInfo(localPath);
var fi = new FileInfo(fullPath);
localFileSize = fi.Length;
}

Expand Down
7 changes: 5 additions & 2 deletions src/NAppUpdate.Framework/Conditions/FileVersionCondition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.IO;
using System.Diagnostics;
using NAppUpdate.Framework.Common;
using NAppUpdate.Framework.Utils;

namespace NAppUpdate.Framework.Conditions
{
Expand Down Expand Up @@ -30,11 +31,13 @@ public bool IsMet(Tasks.IUpdateTask task)
if (string.IsNullOrEmpty(localPath))
return true;

var fullPath = FileSystem.GetFullPath(localPath);

// if the file doesn't exist it has a null version, and therefore the condition result depends on the ComparisonType
if (!File.Exists(localPath))
if (!File.Exists(fullPath))
return ComparisonType.Equals("below", StringComparison.InvariantCultureIgnoreCase);

var versionInfo = FileVersionInfo.GetVersionInfo(localPath);
var versionInfo = FileVersionInfo.GetVersionInfo(fullPath);
if (versionInfo.FileVersion == null) return true; // perform the update if no version info is found

var localVersion = new Version(versionInfo.FileMajorPart, versionInfo.FileMinorPart, versionInfo.FileBuildPart, versionInfo.FilePrivatePart);
Expand Down
36 changes: 21 additions & 15 deletions src/NAppUpdate.Framework/Utils/FileSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,21 +99,27 @@ public static bool IsFileLocked(FileInfo file)
return false;
}

public static void CopyAccessControl(FileInfo src, FileInfo dst)
{
FileSecurity fs = src.GetAccessControl();

bool hasInheritanceRules = fs.GetAccessRules(false, true, typeof(SecurityIdentifier)).Count > 0;
if (hasInheritanceRules)
{
fs.SetAccessRuleProtection(false, false);
}
else
{
fs.SetAccessRuleProtection(true, true);
}

dst.SetAccessControl(fs);
public static void CopyAccessControl(FileInfo src, FileInfo dst)
{
FileSecurity fs = src.GetAccessControl();

bool hasInheritanceRules = fs.GetAccessRules(false, true, typeof(SecurityIdentifier)).Count > 0;
if (hasInheritanceRules)
{
fs.SetAccessRuleProtection(false, false);
}
else
{
fs.SetAccessRuleProtection(true, true);
}

dst.SetAccessControl(fs);
}

public static string GetFullPath(string localPath)
{
var currentDirectory = AppDomain.CurrentDomain.BaseDirectory;
return Path.Combine(currentDirectory, localPath);
}
}
}

0 comments on commit 8f53d90

Please sign in to comment.