private void _OpenSelectedFile(FoundFile selectedFile) { if (selectedFile != null) { Process.Start(selectedFile.FilePath); } }
public static void CheckForFilesToBeProcessed(string productVersion, ILogger log) { FoundFile foundFile = null; while (true) { foundFile = null; try { foundFile = AzureFileHelper.ScanForANewFile(); } catch (Exception ex) { LogHelper.LogSystemError(log, productVersion, ex); } if (foundFile == null) { break; } try { string msg = "Processing the file " + foundFile.PlantName + "," + foundFile.AzureFileName; log.LogInformation("*** " + msg + $" at: {DateTime.Now}" + ":" + productVersion); LogHelper.LogMessage(foundFile.PlantName, productVersion, msg); foundFile.ProcessFile(log, productVersion); foundFile.DisposeOfFile(); foundFile.RecordSuccess(); } catch (Exception ex) { LogHelper.LogMessage(foundFile.PlantName, productVersion, "Fatal error with file " + foundFile.AzureFullPathName + " : " + ex.Message + ex.StackTrace); AzureModel.RecordFailure(foundFile.PlantName, foundFile.AzureFullPathName, foundFile.SuccessfulRecords, foundFile.FailedRecords, ex.Message); try { foundFile.DisposeOfFile(true); } catch (Exception ex2) { LogHelper.LogSystemError(log, productVersion, ex2); } } } }
private void _UpdateFoundTextLines(FoundFile selectedFile) { if (selectedFile != null) { FoundTextLines = new ObservableCollection <FoundTextLine>(selectedFile.FoundTextLines); } }
private void _OpenContainingFolder(FoundFile foundFile) { if (foundFile != null) { Process.Start("explorer.exe", "/select," + foundFile.FilePath); } }
void SearchFiles(string currentDirectory) { try { foreach (string fullFileName in Directory.GetFiles(currentDirectory, FileMask)) { if (exit) { return; } var file = FileItem.FromFullPath(BaseDirectory, fullFileName); foreach (IFileFinderComparer comparer in comparer) { if (!comparer.FileMatches(file)) { file = null; break; } } if (file != null) { FoundFile?.Invoke(this, new FileItemEventArgs(file)); } } } catch (Exception ex) { Error?.Invoke(this, new ErrorEventArgs(ex)); } }
public static FoundFile FindText(string searchText, string filePath, string includeFiles, string excludeFiles, bool matchSearchTextCase, bool checkNumberOfLinesBetweenSearchTextEntries, int?linesBetweenSearchText, DateFilterCriteria dateFilterCriteria) { FoundFile foundFile = null; var fileLines = File.ReadAllLines(filePath); FileInfo fileInfo = new FileInfo(filePath); var searchLines = true; if (!string.IsNullOrEmpty(includeFiles)) { searchLines = _DetermineIfMatchesIncludeFilesFilter(includeFiles, fileInfo); } if (searchLines && !string.IsNullOrEmpty(excludeFiles)) { searchLines = _DetermineIfMatchesExcludeFilesFilter(excludeFiles, fileInfo); } if (searchLines) { searchLines = _DetermineIfMatchesDateFilter(fileInfo, dateFilterCriteria); } List <FoundTextLine> foundTextLines = new List <FoundTextLine>(); if (checkNumberOfLinesBetweenSearchTextEntries && linesBetweenSearchText.HasValue) { foundTextLines = _FindTextLinesWithLinesBetweenSearchText(fileLines, searchText, searchLines, matchSearchTextCase, linesBetweenSearchText.Value); } else { foundTextLines = _FindTextLines(fileLines, searchText, searchLines, matchSearchTextCase); } if (foundTextLines.Count > 0) { foundFile = new FoundFile { FileName = fileInfo.Name, FilePath = filePath, FileType = fileInfo.Extension, CreatedOnDate = fileInfo.CreationTime, LastAccessedDate = fileInfo.LastAccessTime, LastModifiedDate = fileInfo.LastWriteTime, FoundTextLines = foundTextLines.ToArray() }; } return(foundFile); }
public static void Run([TimerTrigger("0 */1 * * * *")] TimerInfo myTimer, ExecutionContext context, ILogger log) // triggering every minute { var productVersion = typeof(R2PLoader).Assembly.GetName().Version.ToString(); try { FoundFile.SetConnection(context, log); AzureFileHelper.ProcessModifiedTagMappings(productVersion); } catch (Exception ex) { LogHelper.LogSystemError(log, productVersion, ex); } AzureFileHelper.CheckForFilesToBeProcessed(productVersion, log); }
private void RecursiveFileSearch(string searchDir, string filePattern) { foreach (var f in Directory.GetFiles(searchDir, filePattern)) { mFileList.Add(f); FoundFile?.Invoke(f); } foreach (var d in Directory.GetDirectories(searchDir)) { RecursiveFileSearch(d, filePattern); } }
public static IEnumerable <FoundFile> Find_InterestingFile(Args_Find_InterestingFile args = null) { if (args == null) { args = new Args_Find_InterestingFile(); } if (args.OfficeDocs) { args.Include = new[] { ".doc", ".docx", ".xls", ".xlsx", ".ppt", ".pptx" }; } else if (args.FreshEXEs) { // find .exe's accessed within the last 7 days args.LastAccessTime = DateTime.Now.Date.AddDays(-7); args.Include = new[] { ".exe" }; } var FoundFiles = new List <FoundFile>(); var MappedComputers = new Dictionary <string, bool>(); foreach (var TargetPath in args.Path) { if ((TargetPath.IsRegexMatch(@"\\\\.*\\.*")) && (args.Credential != null)) { var HostComputer = new System.Uri(TargetPath).Host; if (!MappedComputers[HostComputer]) { // map IPC$ to this computer if it's not already AddRemoteConnection.Add_RemoteConnection(new Args_Add_RemoteConnection { ComputerName = new[] { HostComputer }, Credential = args.Credential }); MappedComputers[HostComputer] = true; } } var files = PathExtension.GetDirectoryFiles(TargetPath, args.Include, SearchOption.AllDirectories); //var files = Directory.EnumerateFiles(TargetPath, "*.*", SearchOption.AllDirectories) // .Where(x => args.Include.EndsWith(x, StringComparison.OrdinalIgnoreCase)); foreach (var file in files) { var Continue = true; // check if we're excluding hidden files if (args.ExcludeHidden) { Continue = !File.GetAttributes(file).HasFlag(FileAttributes.Hidden); } // check if we're excluding folders if (args.ExcludeFolders && Directory.Exists(file)) { Logger.Write_Verbose($@"Excluding: {file}"); Continue = false; } if (args.LastAccessTime != null && (File.GetLastAccessTime(file) < args.LastAccessTime.Value)) { Continue = false; } if (args.LastWriteTime != null && (File.GetLastWriteTime(file) < args.LastWriteTime.Value)) { Continue = false; } if (args.CreationTime != null && (File.GetCreationTime(file) < args.CreationTime.Value)) { Continue = false; } if (args.CheckWriteAccess && !Test_Write(file)) { Continue = false; } if (Continue) { String owner; try { owner = File.GetAccessControl(file).GetOwner(typeof(SecurityIdentifier)).Translate(typeof(System.Security.Principal.NTAccount)).Value; } catch { owner = "Access was Denied"; } DateTime lastAccessTime; try { lastAccessTime = File.GetLastAccessTime(file); } catch { lastAccessTime = new DateTime(); } DateTime lastWriteTime; try { lastWriteTime = File.GetLastWriteTime(file); } catch { lastWriteTime = new DateTime(); } DateTime creationTime; try { creationTime = File.GetCreationTime(file); } catch { creationTime = new DateTime(); } long length; try { length = new FileInfo(file).Length; }catch { length = 0; } var FoundFile = new FoundFile { Path = file, Owner = owner, LastAccessTime = lastAccessTime, LastWriteTime = lastWriteTime, CreationTime = creationTime, Length = length }; FoundFiles.Add(FoundFile); } } } // remove the IPC$ mappings foreach (var key in MappedComputers.Keys) { RemoveRemoteConnection.Remove_RemoteConnection(new Args_Remove_RemoteConnection { ComputerName = new[] { key } }); } return(FoundFiles); }
/// <summary> /// 寻找符合条件的文件 /// </summary> /// <param name="Location">路径</param> /// <param name="fileLength">要求大小</param> private void searchFiles(String Location, long fileLength) { DirectoryInfo dir = null; //目录 List <FileInfo> files = null; //文件集合 FoundFile foundFile = null; try { dir = new DirectoryInfo(Location); //初始化目录 Dispatcher.Invoke(showInfo, Location); //在工作的线程上去更新窗体的UI元素,显示正在扫描的文件信息---异步操作,无法让窗体显示某些信息,因为这是一个新线程。 if (cts.IsCancellationRequested) { return; } //启动并行查找--返回指定路径中与搜索模式匹配的文件集合 。 //排除系统文件.sys var query = (from file in dir.GetFiles("*.*", SearchOption.TopDirectoryOnly).AsParallel() where file.Length >= fileLength && (!file.Name.Contains(".sys")) select file); files = query.ToList(); //更新显示 if (files != null) { foreach (var item in files) { //如果收到取消请求 if (cts.IsCancellationRequested) { //Dispatcher.Invoke(showInfo, "搜索已取消"); //Dispatcher.Invoke(EnableSearchButton, true); return; } foundFile = new FoundFile() { Name = item.Name, Length = item.Length, Location = item.DirectoryName }; Action <FoundFile> addFileDelegate = (file) => { FoundFiles.Add(file); }; //线程异步委托 --- 展示在UI界面上 Dispatcher.BeginInvoke(addFileDelegate, foundFile); } } //递归查找每个子文件夹 foreach (var directory in dir.GetDirectories()) { searchFiles(directory.FullName, fileLength); } } catch { Dispatcher.Invoke(showInfo, dir.Name + "无权限访问"); } }
public void SearchFilesInDirectory(string directory, string textToSearch) //Search files in directory. { try { string[] files = Directory.GetFiles(directory); //Get all files in directory foreach (string item in files) { string itemToLowerCase = item.ToLower(); //Make file name in lowercase letters if (itemToLowerCase.Contains(textToSearch.ToLower())) //Check if file name contains searching text in lowercase letters { FoundFile?.Invoke(this, new ResultEventArgs(SearchId, item)); //If matching file found, invoke event and pass him search ID from DB, and matching file name. } } } catch (UnauthorizedAccessException) { CatchException?.Invoke(this, new ExceptionEventArgs("There is no required permission to: " + directory, ConsoleColor.Red)); } catch (DirectoryNotFoundException) { CatchException?.Invoke(this, new ExceptionEventArgs("Path: " + directory + " is not found or is invalid", ConsoleColor.DarkMagenta)); } catch (PathTooLongException) { CatchException?.Invoke(this, new ExceptionEventArgs("Error:The specified path, file name, or both exceed the system-defined maximum length.", ConsoleColor.DarkRed)); } catch (ArgumentException) { CatchException?.Invoke(this, new ExceptionEventArgs("Error:path is a zero-length string, contains only white space, or contains one or more invalid characters.", ConsoleColor.DarkCyan)); } catch (IOException) { CatchException?.Invoke(this, new ExceptionEventArgs("Error. Path: " + directory + " is a file name or a network error has occurred", ConsoleColor.Green)); } catch (Exception ex) { CatchException?.Invoke(this, new ExceptionEventArgs("Error: " + ex.Message, ConsoleColor.DarkBlue)); } try { string[] dirs = Directory.GetDirectories(directory); //Get all directories in selected directory foreach (string item in dirs) { SearchFilesInDirectory(item, textToSearch); //Recursion, search files in every directory in directory. } } catch (UnauthorizedAccessException) { CatchException?.Invoke(this, new ExceptionEventArgs("There is no required permission to: " + directory, ConsoleColor.Red)); } catch (DirectoryNotFoundException) { CatchException?.Invoke(this, new ExceptionEventArgs("Path: " + directory + " is not found or is invalid", ConsoleColor.DarkMagenta)); } catch (ArgumentException) { CatchException?.Invoke(this, new ExceptionEventArgs("Error:path is a zero-length string, contains only white space, or contains one or more invalid characters.", ConsoleColor.DarkCyan)); } catch (PathTooLongException) { CatchException?.Invoke(this, new ExceptionEventArgs("Error:The specified path, file name, or both exceed the system-defined maximum length.", ConsoleColor.DarkRed)); } catch (IOException) { CatchException?.Invoke(this, new ExceptionEventArgs("Error. Path: " + directory + " is a file name", ConsoleColor.Green)); } catch (Exception ex) { CatchException?.Invoke(this, new ExceptionEventArgs("Error: " + ex.Message, ConsoleColor.Blue)); } }
static void Main(string[] args) { if (args.Length != 2) { Console.WriteLine(@"Incorrect number of arguments supplied."); Console.WriteLine(@"Syntax: CreateAuditSubFolders F:\NautilusExports\{auditX} YN"); Console.WriteLine(""); Console.WriteLine("Press any key to exit."); Console.ReadKey(); Environment.Exit(1); } try { string Input = args[0]; if (!Directory.Exists(Input)) { Console.WriteLine(@"Folder does not exist: "+Input); Console.WriteLine(@"Syntax: CreateAuditSubFolders F:\NautilusExports\{auditX} YN"); Console.WriteLine(""); Console.WriteLine("Press any key to exit."); Console.ReadKey(); Environment.Exit(1); } Int32 InputLength = Input.Length; string ConvertYN = args[1]; if (ConvertYN != "Y" && ConvertYN != "N") { Console.WriteLine(@"ConvertYN argument is not Y or N: " + ConvertYN); Console.WriteLine(@"Syntax: CreateAuditSubFolders F:\NautilusExports\{auditX} YN"); Console.WriteLine(""); Console.WriteLine("Press any key to exit."); Console.ReadKey(); Environment.Exit(1); } if (!Directory.Exists(@"F:\NautilusExports\nConvert")) { Console.WriteLine(@"nConvert program folder does not exist at F:\NautilusExports\nConvert"); Console.WriteLine(""); Console.WriteLine("Press any key to exit."); Console.ReadKey(); Environment.Exit(1); } //rename .___ to .TIF String[] FoundFFFs = Directory.GetFiles(Input, "*.___", SearchOption.TopDirectoryOnly); foreach (String FFFile in FoundFFFs) { FileInfo fi = new FileInfo(FFFile); String src = fi.FullName; String dest = fi.FullName.Substring(0,fi.FullName.Length-fi.Extension.Length)+".tif"; File.Copy(src, dest); File.Delete(src); } //remove periods in filename String[] FoundFPs = Directory.GetFiles(Input, "*.*.*", SearchOption.TopDirectoryOnly); foreach (String FPFile in FoundFPs) { FileInfo fi = new FileInfo(FPFile); String fiext = fi.Extension; String finame = fi.FullName.Substring(0, fi.FullName.Length - fi.Extension.Length); if (finame.Contains(".")) { String src = fi.FullName; String dest = fi.FullName.Substring(0, fi.FullName.Length - fi.Extension.Length).Replace(".","") + fi.Extension; File.Copy(src, dest); File.Delete(src); } } //generate CMD file that uses nconvert to change TIFs to PDFs if (ConvertYN == "Y") { String[] FoundTIFs = Directory.GetFiles(Input, "*.tif", SearchOption.TopDirectoryOnly); String TIFPDFcmd = Input + @"\TifToPDF.cmd"; File.Delete(TIFPDFcmd); File.AppendAllText(TIFPDFcmd, "F:\r\n"); File.AppendAllText(TIFPDFcmd, @"cd\NautilusExports\nConvert" + "\r\n"); foreach (String TIFFile in FoundTIFs) { long size = new System.IO.FileInfo(TIFFile).Length; if (size > 2048000) { File.AppendAllText(TIFPDFcmd, "nconvert -xall -multi -o $%% -out pdf -D -c 3 " + TIFFile + "\r\n"); } } File.AppendAllText(TIFPDFcmd, "exit"); //run the CMD file as administrator Process process = new Process(); ProcessStartInfo startInfo = new ProcessStartInfo(); startInfo.WorkingDirectory = @"C:\Windows\System32"; startInfo.FileName = "cmd.exe"; startInfo.Arguments = "/user:Administrator \"cmd /K " + TIFPDFcmd + "\""; process.StartInfo = startInfo; process.Start(); process.WaitForExit(); File.Delete(TIFPDFcmd); } String[] FoundFiles = Directory.GetFiles(Input, "*.*", SearchOption.TopDirectoryOnly); foreach (String FoundFile in FoundFiles) { string LoanNumber = FoundFile.Substring(InputLength + 1, FoundFile.IndexOf("-") - InputLength - 1); string NewDirectory = Input + @"\" + LoanNumber; string FileName = FoundFile.Substring(InputLength); if (!Directory.Exists(NewDirectory)) { Directory.CreateDirectory(NewDirectory); } File.Copy(FoundFile, NewDirectory + @"\" + FileName); File.Delete(FoundFile); } Environment.Exit(0); } catch(System.Exception excpt) { Console.WriteLine(excpt.Message); Console.WriteLine("Press any key to exit."); Console.ReadKey(); Environment.Exit(1); } }
private void StartGameScanner() { DiscordLauncherPresence.Status("Verify Scan", null); Log.Info("VERIFY HASH: Checking and Deleting '.orig' Files and Symbolic Folders"); ScanProgressText.SafeInvokeAction(() => ScanProgressText.Text = "Removing any '.orig' Files in Game Directory"); /* START Show Warning Text */ VerifyHashText.SafeInvokeAction(() => { VerifyHashText.ForeColor = Theming.WinFormWarningTextForeColor; VerifyHashText.Text = "Warning:\nIf '.orig' Files Exist\nIt will be Removed Permanently"; }); /* END Show Warning Text */ try { DirectoryInfo InstallationDirectory = new DirectoryInfo(FileSettingsSave.GameInstallation); foreach (DirectoryInfo FoldersWeFound in InstallationDirectory.GetDirectories()) { if (!ForceStopScan) { foreach (FileInfo FoundFile in InstallationDirectory.EnumerateFiles("*.orig", SearchOption.AllDirectories)) { if (!ForceStopScan) { try { FoundFile.Delete(); LogVerify.Deleted("File: " + FoundFile.Name); } catch (Exception Error) { DeletionError++; LogVerify.Error("File: " + FoundFile.Name + " Error: " + Error.Message); LogVerify.ErrorIC("File: " + FoundFile.Name + " Error: " + Error.HResult); LogVerify.ErrorFR("File: " + FoundFile.Name + " Error: " + Error.ToString()); } } else { break; } } foreach (FileInfo FoundFile in FoldersWeFound.EnumerateFiles("*.orig", SearchOption.AllDirectories)) { if (!ForceStopScan) { try { FoundFile.Delete(); LogVerify.Deleted("File: " + FoundFile.Name); } catch (Exception Error) { DeletionError++; LogVerify.Error("File: " + FoundFile.Name + " Error: " + Error.Message); LogVerify.ErrorIC("File: " + FoundFile.Name + " Error: " + Error.HResult); LogVerify.ErrorFR("File: " + FoundFile.Name + " Error: " + Error.ToString()); } } else { break; } } foreach (DirectoryInfo FoundDirectory in InstallationDirectory.EnumerateDirectories()) { if (!ForceStopScan) { if (ModNetHandler.IsSymbolic(FoundDirectory.FullName)) { if (Directory.Exists(FoundDirectory.FullName)) { try { Directory.Delete(FoundDirectory.FullName, true); LogVerify.Deleted("Folder: " + FoundDirectory.Name); } catch (Exception Error) { DeletionError++; LogVerify.Error("Folder: " + FoundDirectory.Name + " Error: " + Error.Message); LogVerify.ErrorIC("Folder: " + FoundDirectory.Name + " Error: " + Error.HResult); LogVerify.ErrorFR("Folder: " + FoundDirectory.Name + " Error: " + Error.ToString()); } } else if (File.Exists(FoundDirectory.FullName)) { try { File.Delete(FoundDirectory.FullName); LogVerify.Deleted("File: " + FoundDirectory.Name); } catch (Exception Error) { DeletionError++; LogVerify.Error("File: " + FoundDirectory.Name + " Error: " + Error.Message); LogVerify.ErrorIC("File: " + FoundDirectory.Name + " Error: " + Error.HResult); LogVerify.ErrorFR("File: " + FoundDirectory.Name + " Error: " + Error.ToString()); } } } } else { break; } } foreach (DirectoryInfo FoundDirectory in FoldersWeFound.EnumerateDirectories()) { if (!ForceStopScan) { if (ModNetHandler.IsSymbolic(FoundDirectory.FullName)) { if (Directory.Exists(FoundDirectory.FullName)) { try { Directory.Delete(FoundDirectory.FullName, true); LogVerify.Deleted("Folder: " + FoundDirectory.Name); } catch (Exception Error) { DeletionError++; LogVerify.Error("Folder: " + FoundDirectory.Name + " Error: " + Error.Message); LogVerify.ErrorIC("Folder: " + FoundDirectory.Name + " Error: " + Error.HResult); LogVerify.ErrorFR("Folder: " + FoundDirectory.Name + " Error: " + Error.ToString()); } } else if (File.Exists(FoundDirectory.FullName)) { try { File.Delete(FoundDirectory.FullName); LogVerify.Deleted("File: " + FoundDirectory.Name); } catch (Exception Error) { DeletionError++; LogVerify.Error("File: " + FoundDirectory.Name + " Error: " + Error.Message); LogVerify.ErrorIC("File: " + FoundDirectory.Name + " Error: " + Error.HResult); LogVerify.ErrorFR("File: " + FoundDirectory.Name + " Error: " + Error.ToString()); } } } } else { break; } } } else { break; } } if (Directory.Exists(Path.Combine(FileSettingsSave.GameInstallation, "scripts")) && !ForceStopScan) { DirectoryInfo ScriptsFolder = new DirectoryInfo(Path.Combine(FileSettingsSave.GameInstallation, "scripts")); if (ScriptsFolder.EnumerateFiles().Count() > 1) { if (MessageBox.Show("Verify Hash has found files in the Scripts folder.\n" + "If you have installed custom Scripts or have not installed any Scripts" + "\n\nClick Yes, to Allow Deletion of Files" + "\nClick No, to Skip Deletion of Files", "VerifyHash", MessageBoxButtons.YesNo) == DialogResult.Yes) { foreach (FileInfo FoundFile in ScriptsFolder.EnumerateFiles()) { if (FoundFile.Name != "LangPicker.ini") { try { File.Delete(FoundFile.FullName); LogVerify.Deleted("File: " + FoundFile.Name); } catch (Exception Error) { DeletionError++; LogVerify.Error("File: " + FoundFile.Name + " Error: " + Error.Message); LogVerify.ErrorIC("File: " + FoundFile.Name + " Error: " + Error.HResult); LogVerify.ErrorFR("File: " + FoundFile.Name + " Error: " + Error.ToString()); } } } } } } } catch (Exception Error) { LogToFileAddons.OpenLog("VERIFY HASH", null, Error, null, true); } if (DeletionError != 0) { Log.Info("VERIFY HASH: Completed check for '.orig' Files and Symbolic Folders, BUT Encounterd a File or Folder Deletion Error. " + "Check Verify.log for More Details"); if (MessageBox.Show("Verify Hash has encountered File or Folder Deletion Errors.\n" + "Would you like to Open Verify.Log and Stop the Scanner?", "VerifyHash", MessageBoxButtons.YesNo) == DialogResult.Yes) { string LogFile = Strings.Encode(Locations.LogVerify); if (File.Exists(LogFile)) { Process.Start(LogFile); } StopScanner_Click(null, null); } } else { Log.Info("VERIFY HASH: Completed check for '.orig' Files and Symbolic Folders"); } if (!ForceStopScan) { try { FunctionStatus.IsVerifyHashDisabled = true; String[] getFilesToCheck = { }; if (File.Exists("checksums.dat") && EnableInsiderDeveloper.Allowed()) { /* Read Local checksums.dat */ getFilesToCheck = File.ReadAllLines("checksums.dat"); } else { /* Fetch and Read Remote checksums.dat */ ScanProgressText.SafeInvokeAction(() => ScanProgressText.Text = "Downloading Checksums File"); Uri URLCall = new Uri(FinalCDNURL + "/unpacked/checksums.dat"); ServicePointManager.FindServicePoint(URLCall).ConnectionLeaseTimeout = (int)TimeSpan.FromMinutes(1).TotalMilliseconds; var Client = new WebClient { Encoding = Encoding.UTF8 }; if (!WebCalls.Alternative()) { Client = new WebClientWithTimeout { Encoding = Encoding.UTF8 }; } else { Client.Headers.Add("user-agent", "SBRW Launcher " + Application.ProductVersion + " (+https://github.com/SoapBoxRaceWorld/GameLauncher_NFSW)"); } bool ErrorFree = true; try { getFilesToCheck = Client.DownloadString(URLCall).Split('\n'); } catch (Exception Error) { LogToFileAddons.OpenLog("VERIFY HASH CHECKSUMS", "Downloading of the Checksums File has Encountered an Error", Error, "Error", false); ErrorFree = false; } finally { if (Client != null) { Client.Dispose(); } } if (ErrorFree) { File.WriteAllLines("checksums.dat", getFilesToCheck); } else { StopScanner_Click(null, null); } } scannedHashes = new string[getFilesToCheck.Length][]; for (var i = 0; i < getFilesToCheck.Length; i++) { if (!ForceStopScan) { scannedHashes[i] = getFilesToCheck[i].Split(' '); } else { break; } } filesToScan = scannedHashes.Length; totalFilesScanned = 0; /* START Show Warning Text */ VerifyHashText.SafeInvokeAction(() => { VerifyHashText.ForeColor = Theming.WinFormWarningTextForeColor; VerifyHashText.Text = "Warning:\n Stopping the Scan before it is complete\nWill result in needing to start over!"; }); /* END Show Warning Text */ foreach (string[] file in scannedHashes) { if (!ForceStopScan) { String FileHash = file[0].Trim(); String FileName = file[1].Trim(); String RealPathToFile = FileSettingsSave.GameInstallation + FileName; if (!File.Exists(RealPathToFile)) { InvalidFileList.Add(FileName); LogVerify.Missing("File: " + FileName); } else { if (FileHash != SHA.Files(RealPathToFile).Trim()) { InvalidFileList.Add(FileName); LogVerify.Invalid("File: " + FileName); } else { LogVerify.Valid("File: " + FileName); } } totalFilesScanned++; ScanProgressText.SafeInvokeAction(() => ScanProgressText.Text = "Scanning Files: " + (totalFilesScanned * 100 / getFilesToCheck.Length) + "%"); ScanProgressBar.SafeInvokeAction(() => ScanProgressBar.Value = totalFilesScanned * 100 / getFilesToCheck.Length); } else { break; } } Log.Info("VERIFY HASH: Scan Completed"); if (!InvalidFileList.Any() || ForceStopScan) { StartScanner.SafeInvokeAction(() => StartScanner.Visible = false); StopScanner.SafeInvokeAction(() => StopScanner.Visible = false); ScanProgressText.SafeInvokeAction(() => ScanProgressText.Text = ForceStopScan ? "User Stopped Scan." : "Scan Complete. No Files Missing or Invalid!"); /* Hide the DownloadProgressBar as un-needed */ DownloadProgressBar.SafeInvokeAction(() => DownloadProgressBar.Visible = false); DownloadProgressText.SafeInvokeAction(() => DownloadProgressText.Visible = false); /* Update the player messaging that we're done */ VerifyHashText.SafeInvokeAction(() => { if (!ForceStopScan) { VerifyHashText.ForeColor = Theming.WinFormSuccessTextForeColor; } VerifyHashText.Text = ForceStopScan ? "Verify Hash Scan Process has been Terminated" : "Excellent News! There are ZERO\nmissing or invalid Gamefiles!"; }); Integrity(); GameScanner(false); } else { ScanProgressText.SafeInvokeAction(() => ScanProgressText.Text = "Found Invalid or Missing Files"); File.WriteAllLines("invalidfiles.dat", InvalidFileList); Log.Info("VERIFY HASH: Found Invalid or Missing Files and will Start File Downloader"); CorruptedFilesFound(); } } catch (Exception Error) { LogToFileAddons.OpenLog("VERIFY HASH", null, Error, null, true); } } }