private void SetState(FileSystemInfo fileInfo) { _path = fileInfo.FullName; _name = fileInfo.Name; _converterState = false; // Check if not a directory (size is not valid) if (fileInfo is FileInfo) { _size = (fileInfo as FileInfo).Length; } else { _size = -1; } //_modified = fileInfo.LastWriteTime; //_created = fileInfo.CreationTime; // Get Type Name Win32.SHFILEINFO info = Win32.ShellGetFileInfo.GetFileInfo(fileInfo.FullName); _type = info.szTypeName; // Get ICON _icon = System.Drawing.Icon.FromHandle(info.hIcon); }
public const uint SHGFI_TYPENAME = 0x400; // Gets the type name #endregion Fields #region Methods public static SHFILEINFO GetFileInfo(string path) { SHFILEINFO info = new SHFILEINFO(); IntPtr icon; icon = SHGetFileInfo(path, 0, ref info, (uint)Marshal.SizeOf(info), SHGFI_ICON | SHGFI_TYPENAME | SHGFI_SMALLICON); return info; }
public static extern IntPtr SHGetFileInfo(string pszPath, uint dwFileAttributes, ref SHFILEINFO psfi, uint cbSizeFileInfo, uint uFlags);
private void SetState(FileSystemInfo fileInfo) { Methods myActions = new Methods(); _path = fileInfo.FullName; _name = fileInfo.Name; string fileFullName = fileInfo.FullName; _hotkey = ""; _totalExecutions = myActions.GetValueByKeyAsIntForNonCurrentScript("ScriptTotalExecutions", myActions.ConvertFullFileNameToScriptPathWithoutRemoveLastLevel(fileFullName)); _successfulExecutions = myActions.GetValueByKeyAsIntForNonCurrentScript("ScriptSuccessfulExecutions", myActions.ConvertFullFileNameToScriptPathWithoutRemoveLastLevel(fileFullName)); if (_totalExecutions == 0) { _percentSuccesful = 0; } else { decimal decPercentSuccessful = ((decimal)_successfulExecutions / (decimal)_totalExecutions) * 100; _percentSuccesful = Decimal.ToInt32(decPercentSuccessful); } _lastExecuted = myActions.GetValueByKeyAsDateTimeForNonCurrentScript("ScriptStartDateTime", myActions.ConvertFullFileNameToScriptPathWithoutRemoveLastLevel(fileFullName)); _avgExecutionTime = myActions.GetValueByKeyAsIntForNonCurrentScript("AvgSuccessfulExecutionTime", myActions.ConvertFullFileNameToScriptPathWithoutRemoveLastLevel(fileFullName)); _manualExecutionTime = myActions.GetValueByKeyAsIntForNonCurrentScript("ManualExecutionTime", myActions.ConvertFullFileNameToScriptPathWithoutRemoveLastLevel(fileFullName)); _custom = myActions.GetValueByPublicKeyInCurrentFolder("custom", fileFullName); _description = myActions.GetValueByPublicKeyInCurrentFolder("description", fileFullName); _status = myActions.GetValueByPublicKeyInCurrentFolder("status", fileFullName); if (_manualExecutionTime == 0) { _totalSavings = 0; } else { _totalSavings = _successfulExecutions * (_manualExecutionTime - _avgExecutionTime); } // TODO: move the populate of arrayList to higher level _myArrayList = myActions.ReadAppDirectoryKeyToArrayListGlobal("ScriptInfo"); foreach (var item in _myArrayList) { string[] myScriptInfoFields = item.ToString().Split('^'); string scriptName = myScriptInfoFields[0]; if (scriptName == myActions.ConvertFullFileNameToScriptPathWithoutRemoveLastLevel(fileFullName)) { string strHotKey = myScriptInfoFields[1]; //string strTotalExecutions = myScriptInfoFields[2]; //string strSuccessfulExecutions = myScriptInfoFields[3]; //string strLastExecuted = myScriptInfoFields[4]; string strHotKeyExecutable = myScriptInfoFields[5]; //int intTotalExecutions = 0; //Int32.TryParse(strTotalExecutions, out intTotalExecutions); //int intSuccessfulExecutions = 0; //Int32.TryParse(strSuccessfulExecutions, out intSuccessfulExecutions); //DateTime dateLastExecuted = DateTime.MinValue; //DateTime.TryParse(strLastExecuted, out dateLastExecuted); _hotkey = strHotKey; //_totalExecutions = intTotalExecutions; //_successfulExecutions = intSuccessfulExecutions; //if (_totalExecutions == 0) { // _percentSuccesful = 0; //} else { // _percentSuccesful = (_successfulExecutions / _totalExecutions) * 100; //} //_lastExecuted = dateLastExecuted; //if (_lastExecuted == DateTime.MinValue) { // _lastExecuted = null; //} _hotKeyExecutable = strHotKeyExecutable; } } // Check if not a directory (size is not valid) if (fileInfo is FileInfo) { fileInfo.Refresh(); try { _size = (fileInfo as FileInfo).Length; } catch (Exception) { // throw; } } else { _size = -1; } _modified = fileInfo.LastWriteTime; _created = fileInfo.CreationTime; // Get Type Name Win32.SHFILEINFO info = Win32.ShellGetFileInfo.GetFileInfo(fileInfo.FullName); _type = info.szTypeName; // Get ICON CategoryState = ""; NestingLevel = myActions.GetValueByKeyAsInt("NestingLevel"); try { _icon = System.Drawing.Icon.FromHandle(info.hIcon); string scriptName = myActions.ConvertFullFileNameToPublicPath(fileInfo.FullName) + "\\" + fileInfo.Name; string categoryState = myActions.GetValueByPublicKeyForNonCurrentScript("CategoryState", scriptName); string expandCollapseAll = myActions.GetValueByKey("ExpandCollapseAll"); if (categoryState == "Collapsed") { if (expandCollapseAll == "Expand") { categoryState = "Expanded"; myActions.SetValueByPublicKeyForNonCurrentScript("CategoryState", "Expanded", scriptName); } if (expandCollapseAll == "Collapse") { categoryState = "Collapsed"; myActions.SetValueByPublicKeyForNonCurrentScript("CategoryState", "Collapsed", scriptName); } CategoryState = categoryState; _icon = new Icon(Properties.Resources._112_Plus_Grey, 16, 16); } if (categoryState == "Expanded") { if (expandCollapseAll == "Expand") { categoryState = "Expanded"; myActions.SetValueByPublicKeyForNonCurrentScript("CategoryState", "Expanded", scriptName); } if (expandCollapseAll == "Collapse") { categoryState = "Collapsed"; myActions.SetValueByPublicKeyForNonCurrentScript("CategoryState", "Collapsed", scriptName); } CategoryState = categoryState; _icon = new Icon(Properties.Resources._112_Minus_Grey, 16, 16); } if (categoryState == "Child") { CategoryState = categoryState; } } catch (Exception ex) { // I think this error is just occurring during debugging } }