示例#1
0
        private static string GetShortcutTargetPath(string shortcutPath)
        {
            string directory = Path.GetDirectoryName(shortcutPath);
            string filename  = Path.GetFileName(shortcutPath);

            try
            {
                Type       t          = Type.GetTypeFromProgID("Shell.Application");
                object     shell      = Activator.CreateInstance(t);
                Folder     folder     = (Folder)t.InvokeMember("NameSpace", BindingFlags.InvokeMethod, null, shell, new object[] { directory });
                FolderItem folderItem = folder.ParseName(filename);

                if (folderItem != null)
                {
                    ShellLinkObject link = (ShellLinkObject)folderItem.GetLink;
                    return(link.Path);
                }
            }
            catch (Exception e)
            {
                DebugHelper.WriteException(e);
            }

            return(null);
        }
示例#2
0
        /// <summary>
        /// Get duration(ms) of audio or vedio by Shell32.dll
        /// </summary>
        /// <param name="filePath">audio/vedio's path</param>
        /// <returns>Duration in original format, duration in milliseconds</returns>
        /// <remarks>return value from Shell32.dll is in format of: "00:10:16"</remarks>
        public override Tuple <string, long> GetDuration(string filePath)
        {
            try
            {
                string dir = Path.GetDirectoryName(filePath);

                // From Add Reference --> COM
                Shell              shell      = new Shell32.Shell();
                Shell32.Folder     folder     = shell.NameSpace(dir);
                Shell32.FolderItem folderitem = folder.ParseName(Path.GetFileName(filePath));

                string duration = null;

                // Deal with different versions of OS
                if (Environment.OSVersion.Version.Major >= 6)
                {
                    duration = folder.GetDetailsOf(folderitem, 27);
                }
                else
                {
                    duration = folder.GetDetailsOf(folderitem, 21);
                }

                duration = string.IsNullOrEmpty(duration) ? "00:00:00" : duration;
                return(Tuple.Create(duration, GetTimeInMillisecond(duration)));
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
示例#3
0
        public List <LinkType> LoadLinksFromStartup()
        {
            DirectoryInfo di = new DirectoryInfo(GetStartupPath());

            FileInfo[]      files       = di.GetFiles("*DelayStartup.lnk");
            List <LinkType> listOfLinks = new List <LinkType>();

            foreach (FileInfo fi in files)
            {
                //parse link into string
                string pathOnly     = Path.GetDirectoryName(fi.FullName);
                string filenameOnly = Path.GetFileName(fi.FullName);

                Shell32.Shell      shell      = new Shell32.ShellClass();
                Shell32.Folder     folder     = shell.NameSpace(pathOnly);
                Shell32.FolderItem folderItem = folder.ParseName(filenameOnly);

                if (folderItem != null)
                {
                    Shell32.ShellLinkObject link = (Shell32.ShellLinkObject)folderItem.GetLink;
                    LinkType a = new LinkType(link, fi);
                    listOfLinks.Add(a);
                }
            }
            return(listOfLinks);
        }
示例#4
0
            private static string GetShortcutTargetFile(string shortcutFilename)
            {
                string pathOnly     = Path.GetDirectoryName(shortcutFilename);
                string filenameOnly = Path.GetFileName(shortcutFilename);

                Type ShellAppType = Type.GetTypeFromProgID("Shell.Application");

                if (ShellAppType != null)
                {
                    Shell32.Shell shell = Activator.CreateInstance(ShellAppType) as Shell32.Shell;
                    if (shell != null)
                    {
                        Shell32.Folder folder = shell.NameSpace(pathOnly);
                        if (folder != null)
                        {
                            Shell32.FolderItem folderItem = folder.ParseName(filenameOnly);
                            if (folderItem != null)
                            {
                                Shell32.ShellLinkObject link = (Shell32.ShellLinkObject)folderItem.GetLink;
                                return(link.Path);
                            }
                        }
                    }
                }
                return(String.Empty); // Not found
            }
示例#5
0
        public static void PinUnpinTaskBar(string filePath, bool pin)
        {
            if (!string.IsNullOrEmpty(filePath) && File.Exists(filePath))
            {
                string directory = Path.GetDirectoryName(filePath);
                string filename  = Path.GetFileName(filePath);

                Shell      shell      = new ShellClass();
                Folder     folder     = shell.NameSpace(directory);
                FolderItem folderItem = folder.ParseName(filename);

                FolderItemVerbs verbs = folderItem.Verbs();

                for (int i = 0; i < verbs.Count; i++)
                {
                    FolderItemVerb verb     = verbs.Item(i);
                    string         verbName = verb.Name.Replace(@"&", "");

                    if ((pin && verbName.Equals("pin to taskbar", StringComparison.InvariantCultureIgnoreCase)) ||
                        (!pin && verbName.Equals("unpin from taskbar", StringComparison.InvariantCultureIgnoreCase)))
                    {
                        verb.DoIt();
                        return;
                    }
                }
            }
        }
示例#6
0
        public static MP3File ReadID3Tags(string FileFullPath)
        {
            MP3File mp3File = new MP3File();

            //parse file name
            string fileName = FileFullPath.Substring(FileFullPath.LastIndexOf("\\") + 1);
            //parse file path
            string filePath = FileFullPath.Substring(0, FileFullPath.LastIndexOf("\\"));

            //create shell instance
            Shell32.Shell shell = new Shell32.ShellClass();
            //set the namespace to file path
            Shell32.Folder folder = shell.NameSpace(filePath);
            //get ahandle to the file
            Shell32.FolderItem folderItem = folder.ParseName(fileName);
            //did we get a handle ?
            if (folderItem != null)
            {
                mp3File.FileName = fileName.Trim();
                //query information from shell regarding file
                mp3File.ArtistName = folder.GetDetailsOf(folderItem, 16).Trim();
                mp3File.AlbumName  = folder.GetDetailsOf(folderItem, 17).Trim();
                mp3File.SongTitle  = folder.GetDetailsOf(folderItem, 10).Trim();
                mp3File.Genre      = folder.GetDetailsOf(folderItem, 20).Trim();
                mp3File.Time       = folder.GetDetailsOf(folderItem, 21).Trim();
                mp3File.Duration   = folder.GetDetailsOf(folderItem, 27).Trim();
                string[] tags = new string[25];
                for (int i = 0; i < 25; i++)
                {
                    try
                    {
                        tags[i] = folder.GetDetailsOf(folderItem, i);
                    }
                    catch
                    {
                    }
                }
                mp3File.FileFullPath = FileFullPath.Trim();
                try
                {
                    mp3File.TrackNumber = Int32.Parse(folder.GetDetailsOf(folderItem, 19));
                }
                catch
                {
                }
            }
            //clean ip
            folderItem = null;
            folder     = null;
            shell      = null;
            //return mp3File instance
            return(mp3File);
        }
示例#7
0
        /// <summary>
        /// 获取媒体文件播放时长///
        /// </summary>
        /// <param name="path">媒体文件路径</param>
        /// <returns></returns>
        public TimeSpan GetMediaTimeLen(string path)
        {
            Shell32.Shell shell = new Shell32.ShellClass( );
            //文件路径
            Shell32.Folder folder = shell.NameSpace(path.Substring(0, path.LastIndexOf("\\")));
            //文件名称
            Shell32.FolderItem folderitem = folder.ParseName(path.Substring(path.LastIndexOf("\\") + 1));
            string             _duration  = Regex.Match(folder.GetDetailsOf(folderitem, -1), "\\d:\\d{2}:\\d{2}").Value;

            string[] sp = _duration.Split(new char[] { ':' });
            TimeSpan ts = new TimeSpan(int.Parse(sp[0]), int.Parse(sp[1]), int.Parse(sp[2]));

            return(ts);
        }
示例#8
0
        public string GetShortcutTargetFile(string shortcutFilename)
        {
            string pathOnly     = Path.GetDirectoryName(shortcutFilename);
            string filenameOnly = Path.GetFileName(shortcutFilename);
            Shell  shell        = new ShellClass();

            Shell32.Folder folder     = shell.NameSpace(pathOnly);
            FolderItem     folderItem = folder.ParseName(filenameOnly);

            if (folderItem != null)
            {
                ShellLinkObject link = (ShellLinkObject)folderItem.GetLink;
                return(link.Path);
            }
            return(String.Empty);
        }
示例#9
0
        public static string GetShortcutTargetFile(string shortcutFilename)
        {
            string directory = Path.GetDirectoryName(shortcutFilename);
            string filename  = Path.GetFileName(shortcutFilename);

            S32.Shell      shell  = new S32.ShellClass();
            S32.Folder     folder = shell.NameSpace(directory);
            S32.FolderItem item   = folder.ParseName(filename);

            if (item == null)
            {
                return(String.Empty);
            }

            S32.ShellLinkObject link = (S32.ShellLinkObject)item.GetLink;
            return(link.Path);
        }
示例#10
0
        //锁定到任务栏
        public static void LockToTaskbar(bool isLock)
        {
            Shell shell = new Shell();

            Shell32.Folder folder = shell.NameSpace(Path.GetDirectoryName(Application.StartupPath + "\\Aurora Player.exe"));
            FolderItem     app    = folder.ParseName(Path.GetFileName(Application.StartupPath + "\\Aurora Player.exe"));
            string         sVerb  = isLock ? "锁定到任务栏(&K)" : "从任务栏脱离(&K)";

            foreach (FolderItemVerb Fib in app.Verbs())
            {
                if (Fib.Name == sVerb)
                {
                    Fib.DoIt();
                    return;
                }
            }

            return;
        }
示例#11
0
    // Implement an equivalent of the Perl -l file operator (Resolve symbolic Link, this is a Link/Shortcut on Windows)
    // Returns false if path is not a Link/Shortcut file
    // Returns true and full path (via out target) of resolved Link/Shortcut if path is a link
    //
    // In C# we need to return the target of the link with an out string parameter
    //
    public static bool Link(string path, out string target)
    {
        const string ShortcutExtension = ".lnk";

        target = path; // Return original path if we don't find a link

        FileInfo fi = new FileInfo(path);

        if (fi.Exists && (fi.Extension.ToLower() == ShortcutExtension))
        {
            string directory = Path.GetDirectoryName(path);
            string file      = Path.GetFileName(path);

            // Shell32.Shell shell = new Shell32.Shell();               // Doesn't work on Windows 8 and later
            // Shell32.Folder folder = shell.NameSpace(directory);
            Shell32.Folder     folder     = GetShell32NameSpaceFolder(directory);
            Shell32.FolderItem folderItem = folder.ParseName(file);


            if ((folderItem != null) && folderItem.IsLink)
            {
                try
                {
                    Shell32.ShellLinkObject link = (Shell32.ShellLinkObject)folderItem.GetLink;
                    target = link.Path;
                    return(true);
                }
                catch     // Silently catch any Access is denied excepions or other exceptions
                {
                    return(false);
                }
            }
            else
            {
                return(false);
            }
        }
        else
        {
            return(false);
        }
    }
示例#12
0
        public WmaMessage(string path)
        {
            //create shell instance
            Shell32.Shell shell = new Shell32.ShellClass();
            //set the namespace to file path
            Shell32.Folder folder = shell.NameSpace(path.Substring(0, path.LastIndexOf("\\")));
            //get ahandle to the file
            Shell32.FolderItem folderItem = folder.ParseName(path.Substring(path.LastIndexOf("\\") + 1));
            //did we get a handle ?

            title   = folder.GetDetailsOf(folderItem, 9);
            artist  = folder.GetDetailsOf(folderItem, 16);
            album   = folder.GetDetailsOf(folderItem, 10);
            pubyear = folder.GetDetailsOf(folderItem, 18);
            genre   = folder.GetDetailsOf(folderItem, 12);
            size    = folder.GetDetailsOf(folderItem, 1);
            type    = folder.GetDetailsOf(folderItem, 2);
            bps     = folder.GetDetailsOf(folderItem, 22);
            track   = folder.GetDetailsOf(folderItem, 34);
        }
示例#13
0
        ///// <summary>
        ///// 文件地址
        ///// </summary>
        //public string Url
        //{
        //    get { return url; }
        //}
        public Mp3Message(string FilePath)
        {
            //url = GetRootURI()+FilePath.Remove(0,FilePath.IndexOf("\\upload\\")).Replace("\\","/");
            Shell32.Shell shell = new Shell32.ShellClass();
            //set the namespace to file path
            Shell32.Folder folder = shell.NameSpace(FilePath.Substring(0, FilePath.LastIndexOf("\\")));
            //get ahandle to the file
            Shell32.FolderItem folderItem = folder.ParseName(FilePath.Substring(FilePath.LastIndexOf("\\") + 1));
            //did we get a handle ?

            title   = folder.GetDetailsOf(folderItem, 9);
            artist  = folder.GetDetailsOf(folderItem, 16);
            album   = folder.GetDetailsOf(folderItem, 10);
            pubyear = folder.GetDetailsOf(folderItem, 18);
            genre   = folder.GetDetailsOf(folderItem, 12);
            size    = folder.GetDetailsOf(folderItem, 1);
            type    = folder.GetDetailsOf(folderItem, 2);
            bps     = folder.GetDetailsOf(folderItem, 22);
            track   = folder.GetDetailsOf(folderItem, 34);
        }
示例#14
0
        /// <summary>
        /// ファイルの再生時間取得(Win7用)
        /// </summary>
        /// <param name="path">ファイルパス</param>
        /// <returns></returns>
        private TimeSpan GetFileTime(string path)
        {
            TimeSpan ts = new TimeSpan(0, 0, 0, 0);

            Shell32.Folder folder = null;

            string someDirectory = System.IO.Path.GetDirectoryName(path);

            string someFile = System.IO.Path.GetFileName(path);

            try
            {
                Type   wshell      = Type.GetTypeFromProgID("Shell.Application");
                object wshInstance = Activator.CreateInstance(wshell);
                folder = (Shell32.Folder)wshell.InvokeMember("NameSpace", System.Reflection.BindingFlags.InvokeMethod, null, wshInstance, new object[] { someDirectory });
            }
            catch {
                return(ts);
            }

            Shell32.FolderItem folderitem = folder.ParseName(someFile);

            try
            {
                // 再生時間の表示。ただし7上。XPでは 27 ではなく 21 となる。
                string   times       = folder.GetDetailsOf(folderitem, 27);
                string[] stArrayData = times.Split(':');
                int      o           = int.Parse(stArrayData[0]);
                int      m           = int.Parse(stArrayData[1]);
                int      s           = int.Parse(stArrayData[2]);

                ts = new TimeSpan(o, m, s);
                return(ts);
            }
            catch {
                return(ts);
            }
        }
示例#15
0
        private static string GetShortcutTargetFile(string nomeAtalho)
        {
            string caminhoPasta = Path.GetDirectoryName(nomeAtalho);
            string nomePrograma = Path.GetFileName(nomeAtalho);

            try
            {
                Shell      shell      = new Shell(); //Erro
                Folder     pasta      = shell.NameSpace(caminhoPasta);
                FolderItem folderItem = pasta.ParseName(nomePrograma);
                if (folderItem != null)
                {
                    ShellLinkObject link = (ShellLinkObject)folderItem.GetLink;
                    return(link.Path);
                }
            }
            catch (InvalidCastException)
            {
                return(string.Empty);
            }

            return(string.Empty);
        }
示例#16
0
            public FileAccesser(string fullPath, string name, Shell32.Folder folder)
            {
                this.FullPath = fullPath;

                this.file = null;
                if (folder != null)
                {
                    try
                    {
                        this.file   = folder.ParseName(name);
                        this.folder = folder;
                    }
                    catch
                    {
                        this.file   = null;
                        this.folder = null;
                    }
                }
                else
                {
                    this.file   = null;
                    this.folder = null;
                }
            }
示例#17
0
        private static string GetShortcutTargetPath(string shortcutPath)
        {
            string directory = Path.GetDirectoryName(shortcutPath);
            string filename  = Path.GetFileName(shortcutPath);

            try
            {
                Shell      shell      = new ShellClass();
                Folder     folder     = shell.NameSpace(directory);
                FolderItem folderItem = folder.ParseName(filename);

                if (folderItem != null)
                {
                    ShellLinkObject link = (ShellLinkObject)folderItem.GetLink;
                    return(link.Path);
                }
            }
            catch (Exception e)
            {
                DebugHelper.WriteException(e);
            }

            return(null);
        }
示例#18
0
        private void Label_MouseUp(object sender, MouseButtonEventArgs e)
        {
            var dialog = new OpenFileDialog();
            var str    = (sender as System.Windows.Controls.Label).Tag.ToString();
            int width  = 0;
            int height = 0;

            if (str.ToLower() == "top")
            {
                maxwidth  = 1366;
                maxheight = 126;
            }
            else if (str.ToLower() == "bottom")
            {
                maxwidth  = 1366;
                maxheight = 80;
            }
            else if (str.ToLower() == "left")
            {
                maxwidth  = 306;
                maxheight = 562;
            }
            else if (str.ToLower() == "right")
            {
                maxwidth  = 31;
                maxheight = 562;
            }
            else if (str.ToLower().Contains("button"))
            {
                maxwidth  = 201;
                maxheight = 49;
            }
            dialog.Filter = @"PNG 文件(*.png)|*.png";
            if (dialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                string         path = dialog.FileName;
                ShellClass     sh   = new ShellClass();
                Shell32.Folder dir  = sh.NameSpace(System.IO.Path.GetDirectoryName(path));
                FolderItem     item = dir.ParseName(System.IO.Path.GetFileName(path));
                string         det  = dir.GetDetailsOf(item, 31);

                Regex r = new Regex(@"(\d+)[^\d]+(\d+)");
                if (r.IsMatch(det))
                {
                    var m = r.Match(det);
                    width  = Convert.ToInt32(m.Groups[1].Value);
                    height = Convert.ToInt32(m.Groups[2].Value);
                }

                if (width == maxwidth && height == maxheight)
                {
                    this.Dispatcher.BeginInvoke(new Action(() =>
                    {
                        Upload(path, str.ToLower());
                    }));
                }
                else
                {
                    System.Windows.MessageBox.Show("上传图片的像素不正确,请重新上传");
                }
            }
        }