コード例 #1
0
        public static SHFILEINFOx GetFileInfo(string path)
        {
            SHFILEINFO  info  = new SHFILEINFO();
            SHFILEINFOx infox = new SHFILEINFOx();
            IntPtr      icon;


            icon        = SHGetFileInfo(path, 0, ref info, (uint)Marshal.SizeOf(info), SHGFI_ICON | SHGFI_TYPENAME | SHGFI_SMALLICON);
            infox.hIcon = info.hIcon;
            System.Drawing.Icon.FromHandle(info.hIcon).Dispose();
            DestroyIcon(info.hIcon);
            infox.dwAttributes  = info.dwAttributes;
            infox.szDisplayName = info.szDisplayName;
            infox.szTypeName    = info.szTypeName;


            return(infox);
        }
コード例 #2
0
        private void SetState(FileSystemInfo fileInfo)
        {
            _path = fileInfo.FullName;
            _name = fileInfo.Name;
            _ext  = fileInfo.Extension;
            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
            using (Win32.SHFILEINFOx info = Win32.ShellGetFileInfo.GetFileInfo(fileInfo.FullName)) {
                _type = info.szTypeName;

                // Get ICON
                CategoryState = "";


                try {
                    _iconIndex = GetIconIndex(fileInfo.FullName);
                    _icon      = _smallImageList[_iconIndex].Iconx;
                    //System.Drawing.Icon.FromHandle(info.hIcon).Dispose();
                    //DestroyIcon(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         = _plusIcon;
                    }
                    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         = _minusIcon;
                    }
                    if (categoryState == "Child")
                    {
                        CategoryState = categoryState;
                    }
                } catch (Exception ex) {
                    string myname = "wade";
                    //DestroyIcon(info.hIcon);
                    // I think this error is just occurring during debugging
                }
            }
        }