IEnumerable <KeyValuePairX <string, string> > GetXProp(Shell32.FolderItem2 src, params string[] xPropNames) { foreach (var xpn in xPropNames) { var tmp = src.ExtendedProperty(xpn); if (tmp != null) { var rz = tmp.ToString(); if (!string.IsNullOrWhiteSpace(rz)) { yield return new KeyValuePairX <string, string>() { Key = xpn, Value = rz } } ; } } } string GetFfProbePath() { const string ffProbeKey = "ffProbe.Path"; string rz = AppContext.Current.GetAppCfgItem(ffProbeKey); if (rz == null) { throw new BizException(string.Format("Invalid configuration: appSetings['{0}'] must point to the ffProbe.exe", ffProbeKey)); } return(rz); }
public static void populateFiles(BackgroundWorker bgWork = null) { if (bgWork == null) { bgWork = new BackgroundWorker(); } //---- To find videos resolution; Used to placed in separate method, but to replace get all files method here Shell32.Shell shell = new Shell32.Shell(); Shell32.Folder shellFolder; List <string> allFolders = new List <string>(); List <string> allFiles = new List <string>(); Dictionary <int, string> shellHeaders = new Dictionary <int, string>(); int errorFolders = 0; foreach (Folder item in folders) { if (Directory.Exists(item.path)) { allFolders.Add(item.path); //Add root Directories string[] subdir = Directory.GetDirectories(item.path, "*", SearchOption.AllDirectories); allFolders.AddRange(subdir); //Add root All Sub-Directories } else { warnings.Add("\"" + item.path + "\" not found!"); errorFolders++; } } if (folders.Count <= errorFolders) { return; } totalFiles = 0; foreach (string x in allFolders) { totalFiles = totalFiles + Directory.GetFiles(x).Count(); DebugCount dc = new DebugCount(x, totalFiles); debugCount.Add(dc); } if (totalFiles <= 0) { warnings.Add("No file(s) found in directory(s)!"); return; } double progBGStep = (double)100 / (double)totalFiles; double currProg = 0; double lastStep = 0; bool tooLong = false; foreach (string fitem in allFolders) { shellFolder = shell.NameSpace(fitem); //To find out the header in shell 32 if (shellHeaders.Count <= 0) { for (int i = 0; i < short.MaxValue; i++) { string header = shellFolder.GetDetailsOf(null, i); if (String.IsNullOrEmpty(header)) { break; } if (header.Contains("Name") || header.Contains("Frame") || header.Contains("Path")) { shellHeaders.Add(i, header); } } } string[] folderFiles = Directory.GetFiles(fitem); foreach (string filename in folderFiles) { //debugCount[debugCount.FindIndex(0, x => x.folder.Equals(fitem))].increaseAcc(); //#DEBUGONLY string sFilename = Path.GetFileName(filename); Shell32.FolderItem2 aa = null; string fullPath = fitem + "\\" + sFilename; if (fullPath.Length > 260) { continue; tooLong = true; } FileAttributes attr = File.GetAttributes(fitem + "\\" + sFilename); if (attr.HasFlag(FileAttributes.Directory)) { continue; //is Directory } var item = shellFolder.ParseName(sFilename); string sFrameheight = shellFolder.GetDetailsOf(item, shellHeaders.FirstOrDefault(k => k.Value.Equals("Frame height")).Key); int videoHeight = 0; videoHeight = cIntNull(sFrameheight); FileTags newFile = new FileTags(fitem, videoHeight, sFilename); files.Add(newFile); currProg = currProg + progBGStep; if (currProg - lastStep < 1 || currProg > 100) //To make progress +1% only and not overlimit { continue; } lastStep = currProg; System.Threading.Thread.Sleep(1); // if using sleep thread sometimes get stucked bgWork.ReportProgress(Convert.ToInt32(currProg)); } if (tooLong) { //warnings.Add(" } } }