public static bool IsScreenshotPresent(string fileDescription, string filePath, AhkResult result) { if (string.IsNullOrEmpty(fileDescription)) { fileDescription = @"Kepernyokep fajl"; } else { fileDescription = fileDescription.Trim(); } filePath = PathsHelper.FindFileWithCaseInsensitiveNameMatch(filePath, result); if (!File.Exists(filePath)) { result.AddProblem($"{fileDescription} hianyzik."); return(false); } using (var fs = File.OpenRead(filePath)) { var hash = md5.ComputeHash(fs); if (BitConverter.ToString(hash).Replace("-", "") == knownHash) { result.AddProblem($"{fileDescription} nem lett felulirva."); return(false); } } result.Log($"{fileDescription} letezik"); return(true); }
public static string FindFileWithCaseInsensitiveNameMatch(string filePath, AhkResult result) { var absolutePath = Path.GetFullPath(filePath); var parentDirPath = Path.GetDirectoryName(absolutePath); if (!Directory.Exists(parentDirPath)) { return(absolutePath); } var matchedFiles = Directory.EnumerateFiles(parentDirPath) .Where(f => f.ToUpperInvariant() == absolutePath.ToUpperInvariant()) .ToList(); if (matchedFiles.Count == 1) { return(matchedFiles[0]); } else if (matchedFiles.Count > 1) { result.AddProblem($"Tobb azonos nevu fajl: {filePath}"); return(matchedFiles[0]); } else { return(absolutePath); } }
public static TryResult <T> TryRunOperation <T>(this Func <T> operation, AhkResult ahkResult, string operationNameForError) { try { return(TryResult <T> .Ok(operation())); } catch (Exception ex) { ahkResult.AddProblem(ex, $"{operationNameForError} hibat dob. {operationNameForError} throws error."); return(TryResult <T> .Failed()); } }