public static string ResolveProcessorArchitecture(string runtimePath) { var runtimeFullName = new DirectoryInfo(runtimePath).Name; var runtimeName = runtimeFullName.Substring(0, runtimeFullName.IndexOf('.')); var arch = runtimeName.Substring(runtimeName.LastIndexOf('-') + 1); return arch; }
/// <summary> /// Scans the given path for image files and creates a hash for every element found. /// </summary> /// <param name="path">The directory to search through.</param> /// <param name="checkSubdirs">Include subdirectories?</param> /// <param name="minDate">Ignore files older than this date.</param> /// <returns>Returns a dictionary with the FileInfo-object of the file as key and its hash as value.</returns> private Dictionary<FileInfo, ulong> Scan(string path, bool checkSubdirs, DateTime minDate) { #region Scan subdirs or not SearchOption __options; if (checkSubdirs) __options = SearchOption.AllDirectories; else __options = SearchOption.TopDirectoryOnly; #endregion //Get all files var __files = new DirectoryInfo(path).GetFiles(new string[] { "*.png", "*.jpg", "*.jpeg", "*.gif", "*.bmp" }, __options).ToList(); #region Filter according to a given date if (minDate != null) __files = __files.Where(f => DateTime.Compare(f.LastWriteTime, minDate) >= 0).ToList(); #endregion State.Max = __files.Count; //todo: Because this is a parallel operation, the ConcurrentDictionary class is used instead of the standard Dictionary (which is not thread-safe) //Critical issue, because doing this parallel saves a huge amount of time //var __images = new ConcurrentDictionary<FileInfo, ulong>(); //__files.AsParallel().ForAll((f) => var __images = new Dictionary<FileInfo, ulong>(); __files.ToList().ForEach((f) => { //Calling the respective overridden method to create a hash (the case where the key already exists can't happen, so it's not implemented properly) __images.Add(f, GetHash(f.FullName)); //Update the State to give information about the current image State.Current = f.Name; State.Count = __files.IndexOf(f) + 1; }); return __images; }