Skip to content

Commit

Permalink
fix disk space calc for parity for use in graph
Browse files Browse the repository at this point in the history
  • Loading branch information
aspitel committed Aug 24, 2018
1 parent cc8d5b9 commit ecfaeb3
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions Elucidate/Elucidate/Util.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ public static string ComputeSha256Hash(string rawData)

// Convert byte array to a string
StringBuilder builder = new StringBuilder();

for (int i = 0; i < bytes.Length; i++)
{
builder.Append(bytes[i].ToString("x2"));
Expand All @@ -98,13 +99,16 @@ public static string ComputeSha256Hash(string rawData)

public static bool IsExecutableRunning(string exePath)
{
Process process = new Process();
// Pass your exe file path here.
string path = exePath;

string fileName = Path.GetFileName(path);

// Get the process that is already running as per the exe file name.

if (fileName == null) return false;

Process[] processName = Process.GetProcessesByName(fileName.Substring(0, fileName.LastIndexOf('.')));

return processName.Length > 0;
}

Expand All @@ -118,10 +122,15 @@ public static string SnapRaidLatestVersion()
var request = new RestRequest(Method.GET);

// execute the request

IRestResponse response = client.Execute(request);

var content = response.Content; // raw content as string

var releases = JArray.Parse($"[{content}]");

List<JToken> version = (from p in releases select p["tag_name"]).ToList();

if (version.Count > 0 && version.FirstOrDefault() != null)
{
return version.FirstOrDefault()?.ToString();
Expand Down Expand Up @@ -228,13 +237,15 @@ public static void ParityPathFreeBytesAvailable(string path,
try
{
// get stats for parity location since it might be a folder


string rootPath = StorageUtil.NormalizePath(StorageUtil.GetPathRoot(path));

// ReSharper disable once UnusedVariable
GetDiskFreeSpaceExW(StorageUtil.GetPathRoot(path), out freeBytesAvailable, out ulong totalBytes, out ulong num3);
GetDiskFreeSpaceExW(rootPath, out freeBytesAvailable, out ulong totalBytes, out ulong num3);

ulong driveUsedBytes = totalBytes - freeBytesAvailable;

pathUsedBytes = (ulong) new FileInfo(path).Length;
pathUsedBytes = File.Exists(path) ? (ulong) new FileInfo(path).Length : 0;

if (pathUsedBytes < driveUsedBytes) // Might be driven down a symlink/junction/softlink path or file
{
Expand All @@ -247,7 +258,7 @@ public static void ParityPathFreeBytesAvailable(string path,
}
catch (Exception ex)
{
ExceptionHandler.ReportException(ex);
Log.Instance.Error($"ParityPathFreeBytesAvailable failed for path {path} Exception Message: {ex.Message}");
freeBytesAvailable = 0;
pathUsedBytes = 0;
rootBytesNotCoveredByPath = 0;
Expand Down

0 comments on commit ecfaeb3

Please sign in to comment.