コード例 #1
0
        public int GetIconIndexOf(string filename)
        {
            string fileExtension = CUtils.GetExtension(filename);

            //patch that fixes a crash on search with .mdf and .mds results if Alcohol 120% is sinstalled
            if (fileExtension == ".mds" || fileExtension == ".mdf")
            {
                filename     += ".iso";
                fileExtension = ".iso";
            }

            if (m_table[fileExtension] != null)
            {
                return((int)m_table[fileExtension]);
            }
            Win32.SHFILEINFO shinfo = new Win32.SHFILEINFO();
            IntPtr           hImgSmall;   //the handle to the system image list

            System.Drawing.Icon myIcon;
            try
            {
                hImgSmall = Win32.SHGetFileInfo(filename, Win32.FILE_ATTRIBUTE_NORMAL, ref shinfo, (uint)Marshal.SizeOf(shinfo),
                                                Win32.SHGFI_USEFILEATTRIBUTES | Win32.SHGFI_ICON | Win32.SHGFI_SMALLICON);
                myIcon = System.Drawing.Icon.FromHandle(shinfo.hIcon);
            }
            catch
            {
                return(-1);
            }
            list.Images.Add(myIcon);
            m_table.Add(fileExtension, list.Images.Count - 1);
            return(list.Images.Count - 1);
        }
コード例 #2
0
ファイル: downloadsListView.cs プロジェクト: biuken/eAnt
        private void OnPreviewFile(object sender, System.EventArgs e)
        {
            if (SelectedItems.Count == 0)
            {
                return;
            }
            sFileDetails FileInfo      = (sFileDetails)krnGateway.GetFileDetails(((InterfaceFile)SelectedItems[0].Tag).strHash);
            string       fileExtension = CUtils.GetExtension(FileInfo.FileName);

            if (CUtils.IsVideo(FileInfo.FileName))
            {
                string player = eAntForm.preferences.GetString("PreviewPlayer");
                if ((player == null) || (player == ""))
                {
                    MessageBox.Show(eAntForm.Globalization["LBL_NOPLAYER"], "Ant", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }
                try
                {
                    Process.Start("\"" + player + "\"", "\"" + FileInfo.DiskFileName + "\"");
                }
                catch {}
            }
            else             //not a video file, try to open the default application for the extension
            {
                try
                {
                    RegistryKey key = Registry.ClassesRoot.OpenSubKey(fileExtension);
                    if (key == null)
                    {
                        return;
                    }
                    string type = (string)key.GetValue("");
                    if (type.Length == 0)
                    {
                        return;
                    }
                    key = Registry.ClassesRoot.OpenSubKey(type + "\\shell\\open\\command");
                    if (key == null)
                    {
                        return;
                    }
                    string command = (string)key.GetValue("");
                    if (command.Length == 0)
                    {
                        return;
                    }
                    string exeCommand;
                    if (command.IndexOf("%1") > 0)
                    {
                        exeCommand = command.Replace("%1", FileInfo.DiskFileName);
                    }
                    else
                    {
                        exeCommand = command.Replace("%L", FileInfo.DiskFileName);
                    }
                    string parameters;

                    if (exeCommand.StartsWith("\""))
                    {
                        parameters = exeCommand.Substring(exeCommand.IndexOf("\"", 2) + 2);
                        exeCommand = exeCommand.Substring(0, exeCommand.IndexOf("\"", 2) + 1);
                    }
                    else
                    {
                        parameters = exeCommand.Substring(exeCommand.IndexOf(" ", 2) + 2);
                        exeCommand = exeCommand.Substring(0, exeCommand.IndexOf(" ", 2) + 1);
                    }
                    if (!parameters.StartsWith("\""))
                    {
                        parameters = "\"" + parameters + "\"";
                    }
                    Debug.WriteLine(exeCommand);
                    Debug.WriteLine(parameters);
                    Process.Start(exeCommand, parameters);
                }
                catch (Exception ex)
                {
                    Debug.WriteLine(ex);
                }
            }
        }