示例#1
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;
            }
        }
示例#2
0
        // Undos the previous moves and deletions
        private void UndoMove()
        {
            if (_movedItems.Count == 0)
            {
                return;
            }
            _changed = true;

            try {
                DisplayItem fileToUndo = _movedItems.ElementAt(0);

                if (fileToUndo.HasBeenDeleted)
                {
                    // Based on
                    // https://stackoverflow.com/questions/6025311/how-to-restore-files-from-recycle-bin?lq=1

                    string         Item     = fileToUndo.GetFilePath().Replace(@"\\", @"\"); // restore is sensitive to double backslashes
                    Shell          Shl      = new Shell();
                    Shell32.Folder Recycler = Shl.NameSpace(10);
                    foreach (FolderItem FI in Recycler.Items())
                    {
                        string FileName = Recycler.GetDetailsOf(FI, 0);
                        if (Path.GetExtension(FileName) == "")
                        {
                            FileName += Path.GetExtension(FI.Path);
                        }
                        //Necessary for systems with hidden file extensions.
                        string FilePath = Recycler.GetDetailsOf(FI, 1);
                        if (Item == Path.Combine(FilePath, FileName))
                        {
                            File.Move(FI.Path, fileToUndo.GetFilePath());
                            fileToUndo.HasBeenDeleted = false;
                            break;
                        }
                    }
                }
                else
                {
                    File.Move(fileToUndo.GetFilePath(), fileToUndo.GetOldFilePath());
                    fileToUndo.SetFilePath(fileToUndo.GetOldFilePath());
                }

                _displayItems.Insert(_displayedItemIndex, fileToUndo);
                isInCache.Insert(_displayedItemIndex, false);
                _movedItems.RemoveAt(0);
            }
            catch
            {
                Interaction.MsgBox("File is currently being used by another program or has been removed");
            }

            UpdateContent();
        }
示例#3
0
        //Generates list of songs within the passed directory
        static private void GenerateLib(Shell32.Folder dir, String path)
        {
            foreach (Shell32.FolderItem2 item in dir.Items())
            {
                Console.WriteLine("{0},{1},{2},{3},{4},{5},{6}", dir.GetDetailsOf(item, 0), dir.GetDetailsOf(item, 1), dir.GetDetailsOf(item, 2), dir.GetDetailsOf(item, 10), dir.GetDetailsOf(item, 14), dir.GetDetailsOf(item, 15), dir.GetDetailsOf(item, 16));
                //if there is a folder check inside the folder
                if (dir.GetDetailsOf(item, 2) == "File folder")
                {
                    //Go to the folder
                    String folderPath = path + "\\" + dir.GetDetailsOf(item, 0);
                    Console.WriteLine(folderPath);
                    Shell32.Folder weMustGoDeeper = GetShell32Folder(folderPath);

                    //Generate the list of songs in the folderw
                    GenerateLib(weMustGoDeeper, folderPath);
                }
            }
        }
示例#4
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);
        }
示例#5
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);
        }
示例#6
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);
        }
示例#7
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);
        }
示例#8
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);
            }
        }
示例#9
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("上传图片的像素不正确,请重新上传");
                }
            }
        }