Пример #1
0
        private string GetFileInfo()
        {
            string dirname;
            string filename;
            string header;
            string data;
            string info = "";

            Shell32.Shell shell = new Shell32.Shell();
            dirname  = Path.GetDirectoryName(trackPath);
            filename = Path.GetFileName(trackPath);
            Shell32.Folder     folder     = shell.NameSpace(dirname);
            Shell32.FolderItem folderitem = folder.ParseName(filename);
            info = filename + "\n";
            for (int i = 1; i <= 350; i++)
            {
                header = folder.GetDetailsOf(null, i);
                data   = folder.GetDetailsOf(folderitem, i);
                if (!(String.IsNullOrEmpty(header)) && !(String.IsNullOrEmpty(data)))
                {
                    if (header == "Wolne miejsce" || header == "Całkowity rozmiar")
                    {
                        i++;
                    }
                    else
                    {
                        info += $"{header}: {data}\r";
                    }
                }
            }
            return(info);
        }
Пример #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
                Shell32.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
        private static ProcessStartInfo LaunchShortcut(string shortcutPath)
        {
            Shell32.Shell  shell  = new Shell32.ShellClass();
            Shell32.Folder folder = shell.NameSpace(Path.GetDirectoryName(shortcutPath));

            bool runAs = IsMarkedRunAs(shortcutPath);

            string filenameOnly = System.IO.Path.GetFileName(shortcutPath);

            Shell32.FolderItem folderItem = folder.ParseName(filenameOnly);

            if (folderItem != null)
            {
                Shell32.ShellLinkObject link = (Shell32.ShellLinkObject)folderItem.GetLink;

                ProcessStartInfo info = new ProcessStartInfo(link.Path, link.Arguments)
                {
                    WorkingDirectory = link.WorkingDirectory,
                };

                if (runAs)
                {
                    info.Verb = "runas";
                }

                return(info);
            }

            return(null);
        }
        private void Setup_PreviewPane()
        {
            Dispatcher.BeginInvoke(DispatcherPriority.Background, (ThreadStart)(() =>
            {
                if (SelectedItem != null)
                {
                    if (!Browser.SelectedItems.Any())
                    {
                        return;
                    }
                    if (this.SelectedItem.IsFolder)
                    {
                        return;
                    }

                    //http://www.codeproject.com/Articles/7987/Retrieve-detailed-information-of-a-File
                    var sh = new Shell32.ShellClass();
                    Shell32.Folder dir = sh.NameSpace(System.IO.Path.GetDirectoryName(SelectedItem.ParsingName));
                    Shell32.FolderItem item = dir.ParseName(System.IO.Path.GetFileName(SelectedItem.ParsingName));

                    // loop through the Folder Items
                    for (int i = 0; i < 30; i++)
                    {
                        // read the current detail Info from the FolderItem Object
                        //(Retrieves details about an item in a folder. For example, its size, type, or the time of its last modification.)
                        // some examples:
                        // 0 Retrieves the name of the item.
                        // 1 Retrieves the size of the item.
                        // 2 Retrieves the type of the item.
                        // 3 Retrieves the date and time that the item was last modified.
                        // 4 Retrieves the attributes of the item.
                        // -1 Retrieves the info tip information for the item.
                        string colName = dir.GetDetailsOf(String.Empty, i);
                        string value = dir.GetDetailsOf(item, i);
                        // Create a helper Object for holding the current Information
                        // an put it into a ArrayList
                    }


                    //this.SelectedItem.Thumbnail.CurrentSize = new System.Windows.Size(this.ActualHeight - 20, this.ActualHeight - 20);
                    //this.SelectedItem.Thumbnail.FormatOption = BExplorer.Shell.Interop.ShellThumbnailFormatOption.Default;
                    //this.SelectedItem.Thumbnail.RetrievalOption = BExplorer.Shell.Interop.ShellThumbnailRetrievalOption.Default;
                    //icon.Source = this.SelectedItem.Thumbnail.BitmapSource;

                    //txtDisplayName.Text = SelectedItem.DisplayName;
                    //txtFileType.Text = "Extension: " + SelectedItem.Extension;
                    //txtPath.Text = "Location : " + SelectedItem.FileSystemPath;

                    //var OpenWirgList = SelectedItem.GetAssocList();
                    //if (OpenWirgList.Any()) {
                    //	txtOpenWith.Text = "Opens With: " + OpenWirgList.First().DisplayName;
                    //}

                    var File = new System.IO.FileInfo(Browser.SelectedItems[0].ParsingName);
                    txtFileSize.Text = "Size: " + File.Length.ToString();
                    txtFileCreated.Text = "Created: " + File.CreationTime.ToLongDateString();
                    txtFileModified.Text = "Modified: " + File.LastWriteTime.ToLongDateString();
                }
            }));
        }
Пример #5
0
        private void applyWallpaperWin7(string path)
        {
            Shell32.Shell           shell      = new Shell32.ShellClass();
            Shell32.Folder          folder     = shell.NameSpace(Path.GetDirectoryName(path)) as Shell32.Folder;
            Shell32.FolderItem      folderItem = folder.ParseName(System.IO.Path.GetFileName(path));
            Shell32.FolderItemVerbs vs         = folderItem.Verbs();

            bool wallpaperSet = false;

            for (int i = 0; i < vs.Count; i++)
            {
                Shell32.FolderItemVerb ib = vs.Item(i);

                if (ib.Name.Contains("&b") || ib.Name.Contains("&B"))
                {
                    if (ib.Name.ToLower().Contains("background") || ib.Name.ToLower().Contains("背景"))
                    {
                        wallpaperSet = true;
                        ib.DoIt();
                    }
                }
            }

            if (wallpaperSet == false)
            {
                applyWallpaperXP(path);
            }
            else
            {
                downloadAndApplyWallpaperSucceeded();
            }
        }
Пример #6
0
        internal static bool IsShortcut(string path)
        {
            if (!File.Exists(path))
            {
                return(false);
            }

            string directory = Path.GetDirectoryName(path);
            string file      = Path.GetFileName(path);

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

                if (folderItem != null)
                {
                    return(folderItem.IsLink);
                }
            }
            catch { }

            return(false);
        }
Пример #7
0
        // ファイルのプロパティからイメージの高さを取得
        private int GetFileHeightProperty(string filePath)
        {
            Shell32.Shell shell  = new Shell32.Shell();
            string        res    = "";
            int           height = 0;

            try
            {
                Shell32.Folder     objFolder  = shell.NameSpace(System.IO.Path.GetDirectoryName(filePath));
                Shell32.FolderItem folderItem = objFolder.ParseName(System.IO.Path.GetFileName(filePath));

                for (int i = 0; i < 300; i++)
                {
                    if (objFolder.GetDetailsOf("", i) == "高さ")
                    {
                        res = objFolder.GetDetailsOf(folderItem, i);
                        break;
                    }
                }

                Regex regex = new Regex("[0-9]+");
                Match match = regex.Match(res);
                if (match.Success)
                {
                    height = int.Parse(match.Value);
                }
            }
            catch
            {
                height = 0;
            }

            return(height);
        }
Пример #8
0
        private string GetFileInfo()
        {
            // TODO: Add exception-handling. What if file can't be found or is invalid?
            string dirname;
            string filename;
            string header;
            string data;
            string info = "";

            Shell32.Shell shell = new Shell32.ShellClass();
            dirname  = Path.GetDirectoryName(trackPath);
            filename = Path.GetFileName(trackPath);
            Shell32.Folder     folder     = shell.NameSpace(dirname);
            Shell32.FolderItem folderitem = folder.ParseName(filename);
            info = filename;
            for (int i = 0; i <= 315; i++)
            {
                header = folder.GetDetailsOf(null, i);
                data   = folder.GetDetailsOf(folderitem, i);
                if (!(String.IsNullOrEmpty(header)) && !(String.IsNullOrEmpty(data)))
                {
                    info += $"{header}: {data}\r";
                }
            }
            return(info);
        }
Пример #9
0
        private static void FindCustomLinkFiles(ref CTempGameSet tempGameSet)
        {
            List <string> fileList = Directory.EnumerateFiles(Path.Combine(CDock.currentPath, CUSTOM_GAME_FOLDER), "*", SearchOption.TopDirectoryOnly).Where(s => s.EndsWith(".lnk")).ToList();

            string strPlatform = GetPlatformString(ENUM);

            foreach (string file in fileList)
            {
                string strPathOnly = Path.GetDirectoryName(file);
                strPathOnly = Path.GetFullPath(strPathOnly);
                string strFilenameOnly = Path.GetFileName(file);

                Shell32.Shell      shell      = new();
                Shell32.Folder     folder     = shell.NameSpace(strPathOnly);
                Shell32.FolderItem folderItem = folder.ParseName(strFilenameOnly);
                if (folderItem != null)
                {
                    Shell32.ShellLinkObject link = (Shell32.ShellLinkObject)folderItem.GetLink;
                    string strID    = Path.GetFileNameWithoutExtension(file);
                    string strTitle = strID;
                    CLogger.LogDebug($"- {strTitle}");
                    string strLaunch    = link.Path;
                    string strUninstall = "";                      // N/A
                    string strAlias     = GetAlias(strTitle);
                    if (strAlias.Equals(strTitle, CDock.IGNORE_CASE))
                    {
                        strAlias = "";
                    }
                    tempGameSet.InsertGame(strID, strTitle, strLaunch, strLaunch, strUninstall, true, false, true, false, strAlias, strPlatform, new List <string>(), DateTime.MinValue, 0, 0, 0f);
                }
            }
        }
Пример #10
0
        public void GetData(string location)
        {
            try
            {
                ShellObject song = ShellObject.FromParsingName(location);
                nameTextBox.Text    = Index.GetValue(song.Properties.GetProperty(SystemProperties.System.FileName));
                aArtistTextBox.Text = Index.GetValue(song.Properties.GetProperty(SystemProperties.System.Music.AlbumArtist));
                titleTextBox.Text   = Index.GetValue(song.Properties.GetProperty(SystemProperties.System.Title));
                albumTextBox.Text   = Index.GetValue(song.Properties.GetProperty(SystemProperties.System.Music.AlbumTitle));
                yearTextBox.Text    = Index.GetValue(song.Properties.GetProperty(SystemProperties.System.Media.Year));
                lyricsTextBox.Text  = Index.GetValue(song.Properties.GetProperty(SystemProperties.System.Music.Lyrics));

                Shell32.Shell      shell      = new Shell32.Shell();
                Shell32.Folder     objFolder  = shell.NameSpace(System.IO.Path.GetDirectoryName(location));
                Shell32.FolderItem folderItem = objFolder.ParseName(System.IO.Path.GetFileName(location));
                contributingTextBox.Text = objFolder.GetDetailsOf(folderItem, 13);
                genreBox.Text            = objFolder.GetDetailsOf(folderItem, 16);
            }
            catch (ShellException)
            {
                MessageBox.Show("File not found exception!", "Error");
                Close();
            }
            catch (Exception e)
            {
                MessageBox.Show(e.ToString(), "Error");
                Close();
            }
        }
        /// <summary>
        /// 获取MD5和播放时长
        /// </summary>
        /// <param name="FilePathName"></param>
        /// <returns></returns>
        public ViewModelVideoItem GetItem(string FilePathName)
        {
            ViewModelVideoItem newItem = new ViewModelVideoItem();

            newItem.Name          = FilePathName.Substring(FilePathName.LastIndexOf("\\") + 1);
            newItem.ReRelativeUrl = FilePathName;
            int sum = 0;

            if (newItem.Name.Substring(newItem.Name.LastIndexOf(".")) == ".wmv" || newItem.Name.Substring(newItem.Name.LastIndexOf(".")) == ".WMV")
            {
                Shell32.Shell      shell      = new Shell32.Shell();
                Shell32.Folder     folder     = shell.NameSpace(FilePathName.Substring(0, FilePathName.LastIndexOf("\\")));
                Shell32.FolderItem folderitem = folder.ParseName(newItem.Name);
                string             len;
                if (Environment.OSVersion.Version.Major >= 6)
                {
                    len = folder.GetDetailsOf(folderitem, 27);
                }
                else
                {
                    len = folder.GetDetailsOf(folderitem, 21);
                }

                string[] str = len.Split(new char[] { ':' });

                sum = int.Parse(str[0]) * 3600 + int.Parse(str[1]) * 60 + int.Parse(str[2]) + 1;
            }
            newItem.SunTime  = sum;
            newItem.MD5Value = SeatManage.SeatManageComm.SeatComm.GetMD5HashFromFile(newItem.ReRelativeUrl);
            return(newItem);
        }
Пример #12
0
        // File processing
        private void ShowInfo()
        {
            string dirname;
            string filename;
            string header;
            string data;

            Shell32.Shell shell = new Shell32.ShellClass();
            dirname  = Path.GetDirectoryName(trackPath);
            filename = Path.GetFileName(trackPath);
            Shell32.Folder     folder     = shell.NameSpace(dirname);
            Shell32.FolderItem folderitem = folder.ParseName(filename);
            infoBox.Text = dirname + "\n" + filename;
            for (int i = 0; i <= 315; i++)
            {
                header = folder.GetDetailsOf(null, i);
                data   = folder.GetDetailsOf(folderitem, i);
                if (String.IsNullOrEmpty(header))
                {
                    header = "[Unknown header]";
                }
                if (String.IsNullOrEmpty(data))
                {
                    data = "[No data]";
                }
                infoBox.AppendText($"\n{i} {header} {data}");
            }
        }
Пример #13
0
        private bool tryGetMediaCreated(FileInfo file, out DateTime mediaCreated)
        {
            try
            {
                Shell32.Folder     folder     = GetShell32NameSpaceFolder(file.DirectoryName);
                Shell32.FolderItem folderItem = folder.ParseName(file.Name);

                string created   = folder.GetDetailsOf(folderItem, 209);
                string sanitized = "";
                foreach (char c in created.ToCharArray())
                {
                    if ((int)c < 128)
                    {
                        sanitized += c;
                    }
                }
                mediaCreated = DateTime.Parse(sanitized);
                return(true);
            }
            catch (Exception e)
            {
                Console.WriteLine("Non-video file type found");
                Console.WriteLine(e.ToString());
            }
            mediaCreated = DateTime.MinValue;
            return(false);
        }
Пример #14
0
        /// <summary>
        /// 长度秒(支持mp4?)
        /// </summary>
        /// <param name="path"></param>
        /// <returns></returns>
        public static int GetMediaTimeLenSecond(string path)
        {
            try
            {
                Shell32.Shell shell = new Shell32.Shell();
                //文件路径
                Shell32.Folder folder = shell.NameSpace(path.Substring(0, path.LastIndexOf("\\")));
                //文件名称
                Shell32.FolderItem folderitem = folder.ParseName(path.Substring(path.LastIndexOf("\\") + 1));
                string             len;
                if (Environment.OSVersion.Version.Major >= 6)
                {
                    len = folder.GetDetailsOf(folderitem, 27);
                }
                else
                {
                    len = folder.GetDetailsOf(folderitem, 21);
                }

                string[] str = len.Split(new char[] { ':' });
                int      sum = 0;
                sum = int.Parse(str[0]) * 60 * 60 + int.Parse(str[1]) * 60 + int.Parse(str[2]);

                return(sum);
            }
            catch (Exception ex) { return(0); }
        }
Пример #15
0
        static void runRenamer(string p)
        {
            string songTitle = "bartFart";
            //File songFile = Directory.get
            string songArtist = "ShortLife";

            string path       = p;
            string targetPath = @"C:\NewSongs\";

            //get the file(s)
            string[] songfiles = Directory.GetFiles(path);

            foreach (string song in songfiles)
            {
                List <string> arrHeaders = new List <string>();

                Shell32.Shell      shell      = new Shell32.Shell();
                Shell32.Folder     objFolder  = shell.NameSpace(System.IO.Path.GetDirectoryName(song));
                Shell32.FolderItem folderItem = objFolder.ParseName(System.IO.Path.GetFileName(song));

                for (int i = 0; i < short.MaxValue; i++)
                {
                    string header = objFolder.GetDetailsOf(null, i);
                    if (String.IsNullOrEmpty(header))
                    {
                        break;
                    }
                    arrHeaders.Add(header);
                }

                for (int i = 0; i < arrHeaders.Count; i++)
                {
                    Console.WriteLine("{0}\t{1}: {2}", i, arrHeaders[i], objFolder.GetDetailsOf(folderItem, i));
                }
                songTitle  = objFolder.GetDetailsOf(folderItem, 21);
                songArtist = objFolder.GetDetailsOf(folderItem, 13);
                FileAttributes attributes = File.GetAttributes(song);

                FileInfo fi = new FileInfo("bart.txt");
                //fi.a

                ////get the file property

                ////check if the dir exists
                if (!System.IO.Directory.Exists(targetPath + songArtist))
                {
                    Directory.CreateDirectory(targetPath + songArtist);
                }
                ////copy the file to target dir


                System.IO.File.Move(song, targetPath + songArtist + @"\" + songTitle + ".m4a");
                //rename the file to the Title of the Song
            }
            Console.ReadLine();
        }
Пример #16
0
        private static IEnumerable <JumpListLink> ShortcutsToLinks(string folderName)
        {
            Shell32.Shell  shell  = new Shell32.ShellClass();
            Shell32.Folder folder = shell.NameSpace(folderName);

            foreach (string filename in Directory.GetFiles(folderName, "*.lnk", SearchOption.TopDirectoryOnly).OrderBy(x => x, new StringLogicalComparer()))
            {
                string filenameOnly = System.IO.Path.GetFileName(filename);

                if (filenameOnly.StartsWith("-"))
                {
                    continue;
                }

                bool runAs = Program.IsMarkedRunAs(filename);

                Shell32.FolderItem folderItem = folder.ParseName(filenameOnly);
                if (folderItem != null)
                {
                    Shell32.ShellLinkObject link = (Shell32.ShellLinkObject)folderItem.GetLink;

                    string iconPath;
                    int    iconId = link.GetIconLocation(out iconPath);

                    if (String.IsNullOrEmpty(iconPath))
                    {
                        iconPath = link.Path;
                        iconId   = 0;
                    }

                    JumpListLink jumpLink;
                    if (runAs)
                    {
                        jumpLink = new JumpListLink(Application.ExecutablePath, GetDisplayName(filenameOnly))
                        {
                            Arguments        = BuildCommand("--launch", filename),
                            WorkingDirectory = Directory.GetCurrentDirectory(),
                        };
                    }
                    else
                    {
                        jumpLink = new JumpListLink(link.Path, GetDisplayName(filenameOnly))
                        {
                            Arguments        = link.Arguments,
                            WorkingDirectory = link.WorkingDirectory,
                            ShowCommand      = Enum.IsDefined(typeof(WindowShowCommand), link.ShowCommand) ?
                                               (WindowShowCommand)link.ShowCommand : WindowShowCommand.Default,
                        };
                    }

                    jumpLink.IconReference = new IconReference(iconPath, iconId);
                    yield return(jumpLink);
                }
            }
        }
Пример #17
0
 private int video_handle(string path)
 {
     try
     {
         log("{0} 视频信息读取 ing..", path);
         Shell32.Shell shell = new Shell32.Shell();
         //文件路径
         Shell32.Folder folder = shell.NameSpace(path.Substring(0, path.LastIndexOf("\\")));
         //文件名称
         Shell32.FolderItem folderitem = folder.ParseName(path.Substring(path.LastIndexOf("\\") + 1));
         string             len;
         //string kbps = folder.GetDetailsOf(folderitem, 308);
         //int i = 0;
         //while (true)
         //{
         //    //获取属性名称
         //    string key = folder.GetDetailsOf(null, i);
         //    if (string.IsNullOrEmpty(key))
         //    {
         //        //当无属性可取时,退出循环
         //        break;
         //    }
         //    //获取属性值
         //    string value = folder.GetDetailsOf(folderitem, i);
         //    Console.WriteLine("{0}:{1}", key, value);
         //    i++;
         //}
         //多系统兼容
         if (Environment.OSVersion.Version.Major >= 6)
         {
             len = folder.GetDetailsOf(folderitem, 27);
         }
         else
         {
             len = folder.GetDetailsOf(folderitem, 21);
         }
         string[] str = len.Split(new char[] { ':' });
         int      sum = 0;
         if (str.Length == 3)
         {
             sum = int.Parse(str[0]) * 60 * 60 + int.Parse(str[1]) * 60 + int.Parse(str[2]);
             log("视频信息{0}s", sum);
         }
         else
         {
             error("视频信息读取失败,也行是系统功能被限制!");
         }
         return(sum);
     }
     catch (Exception ex)
     {
         error("读取视频信息发生错误{0}", ex.Message);
         return(0);
     }
 }
        /// <summary>
        /// 添加媒体文件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnAdditem_Click(object sender, RoutedEventArgs e)
        {
            OpenFileDialog ofd = new OpenFileDialog();

            ofd.Multiselect = false;
            ofd.Filter      = "媒体文件|*.jpg;*.bmp;*.jpeg;*.png;*.wmv;";
            ofd.ShowDialog();
            if (!string.IsNullOrEmpty(ofd.FileName))
            {
                PlaylistItemViewModel itemVM = new PlaylistItemViewModel();
                itemVM.Name     = ofd.SafeFileName;
                itemVM.FilePath = ofd.FileName;
                int sum = 0;
                if (itemVM.Name.Substring(itemVM.Name.LastIndexOf(".")) == ".wmv" || itemVM.Name.Substring(itemVM.Name.LastIndexOf(".")) == ".WMV")
                {
                    Shell32.Shell      shell      = new Shell32.Shell();
                    Shell32.Folder     folder     = shell.NameSpace(ofd.FileName.Substring(0, ofd.FileName.LastIndexOf("\\")));
                    Shell32.FolderItem folderitem = folder.ParseName(ofd.SafeFileName);
                    string             len;
                    if (Environment.OSVersion.Version.Major >= 6)
                    {
                        len = folder.GetDetailsOf(folderitem, 27);
                    }
                    else
                    {
                        len = folder.GetDetailsOf(folderitem, 21);
                    }
                    string[] str = len.Split(new char[] { ':' });

                    sum = int.Parse(str[0]) * 3600 + int.Parse(str[1]) * 60 + int.Parse(str[2]) + 1;
                }
                else
                {
                    if (Playlist.ItemList.Count > 0)
                    {
                        for (int i = Playlist.ItemList.Count - 1; i >= 0; i--)
                        {
                            if (Playlist.ItemList[i].Name.Substring(Playlist.ItemList[i].Name.LastIndexOf(".")) != ".WMV" && Playlist.ItemList[i].Name.Substring(Playlist.ItemList[i].Name.LastIndexOf(".")) != ".wmv")
                            {
                                sum = Playlist.ItemList[i].SunTime;
                                break;
                            }
                        }
                    }
                }
                if (sum == 0)
                {
                    sum = 10;
                }
                itemVM.SunTime  = sum;
                itemVM.Md5Value = SeatManage.SeatManageComm.SeatComm.GetMD5HashFromFile(itemVM.FilePath);
                Playlist.ItemList.Add(itemVM);
            }
        }
        private LinkFile CreateLinkItem(FileSystemInfo item, FileInfo fi)
        {
            string directory = Path.GetDirectoryName(item.FullName);
            string file      = Path.GetFileName(item.FullName);

            Shell32.Shell           shell      = new Shell32.Shell();
            Shell32.Folder          folder     = shell.NameSpace(directory);
            Shell32.FolderItem      folderItem = folder.ParseName(file);
            Shell32.ShellLinkObject link       = (Shell32.ShellLinkObject)folderItem.GetLink;
            return(ItemFactory.CreateLink(item.FullName, item.Name, fi.Length.ToString(), GetOwner(fi), (FileType)item.Attributes, item.CreationTime, !fi.IsReadOnly, item.LastAccessTime, item.LastWriteTime, item.Extension, link.Path, new string[] { link.Arguments }, link.Description));
        }
Пример #20
0
        public string ReadLink(string path)
        {
            string directory = Path.GetDirectoryName(path);
            string file      = Path.GetFileName(path);

            Shell32.Shell           shell      = new Shell32.Shell();
            Shell32.Folder          folder     = shell.NameSpace(directory);
            Shell32.FolderItem      folderItem = folder.ParseName(file);
            Shell32.ShellLinkObject link       = (Shell32.ShellLinkObject)folderItem.GetLink;
            return(link.Path);
        }
Пример #21
0
        public bool IsLink(string path)
        {
            string directory = Path.GetDirectoryName(path);
            string file      = Path.GetFileName(path);

            Shell32.Shell      shell      = new Shell32.Shell();
            Shell32.Folder     folder     = shell.NameSpace(directory);
            Shell32.FolderItem folderItem = folder.ParseName(file);

            return(folderItem?.IsLink ?? false);
        }
Пример #22
0
        private void ChangeTitleToolStripMenuItem_Click(object sender, EventArgs e)
        {
            try
            {
                string[] files = Directory.GetFiles(path, "*.mp3", SearchOption.AllDirectories);

                for (int i = 0; i < files.Length; i++)
                {
                    FileInfo file = new FileInfo(files[i]);
                    if (NameCheck(file.Name) == "")
                    {
                        var fileshell = ShellFile.FromFilePath(file.DirectoryName + "\\" + file.Name);

                        Shell32.Shell      shell       = new Shell32.Shell();
                        var                strFileName = file.DirectoryName + "\\" + file.Name;
                        Shell32.Folder     objFolder   = shell.NameSpace(System.IO.Path.GetDirectoryName(strFileName));
                        Shell32.FolderItem folderItem  = objFolder.ParseName(System.IO.Path.GetFileName(strFileName));
                        var                title       = objFolder.GetDetailsOf(folderItem, 21);

                        if (title == "" || title.Contains("ntitled") || title.Contains("nknown") || title.Contains("nknown") || title.Contains("http") || title.Contains("www.") || title.Contains(".com") || title.Contains("Track"))
                        {
                            string   name    = objFolder.GetDetailsOf(folderItem, 0);
                            string[] newName = Regex.Split(name, "-");

                            if (newName.Length >= 2 && newName[1] != null)
                            {
                                string[] newest = Regex.Split(newName[1], "\\.");

                                ShellPropertyWriter propertyWriter = fileshell.Properties.GetPropertyWriter();
                                try
                                {
                                    propertyWriter.WriteProperty(SystemProperties.System.Title, new string[] { newest[0] });
                                }
                                finally
                                {
                                    propertyWriter.Close();
                                }
                            }
                        }
                    }
                    progressBar1.Value = Convert.ToInt32(100 * (i + 1) / files.Length);

                    if (i == files.Length - 1)
                    {
                        progressBar1.Value = 100;
                    }
                }
            }
            catch (FileNotFoundException)
            {
                MessageBox.Show("Files not found exception!", "Error!");
            }
        }
Пример #23
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, 9).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();
                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);
        }
Пример #24
0
        private void GetHeadersToolStripMenuItem_Click(object sender, EventArgs e)
        {
            DisableButtons();
            DataTable table = new DataTable();

            table.Columns.Add("No");
            table.Columns.Add("Header Name");

            List <string> arrHeaders = new List <string>();
            List <Tuple <int, string, string> > attributes = new List <Tuple <int, string, string> >();

            Shell32.Shell shell       = new Shell32.Shell();
            var           strFileName = "C:\\Music";

            Shell32.Folder     objFolder  = shell.NameSpace(System.IO.Path.GetDirectoryName(strFileName));
            Shell32.FolderItem folderItem = objFolder.ParseName(System.IO.Path.GetFileName(strFileName));


            for (int i = 0; i < short.MaxValue; i++)
            {
                string header = objFolder.GetDetailsOf(null, i);
                if (String.IsNullOrEmpty(header))
                {
                    break;
                }
                arrHeaders.Add(header);
            }

            // The attributes list below will contain a tuple with attribute index, name and value
            // Once you know the index of the attribute you want to get,
            // you can get it directly without looping, like this:
            var Authors = objFolder.GetDetailsOf(folderItem, 20);

            for (int i = 0; i < arrHeaders.Count; i++)
            {
                var attrName  = arrHeaders[i];
                var attrValue = objFolder.GetDetailsOf(folderItem, i);
                var attrIdx   = i;

                attributes.Add(new Tuple <int, string, string>(attrIdx, attrName, attrValue));

                //Debug.WriteLine("{0}\t{1}: {2}", i, attrName, attrValue);

                DataRow row = table.NewRow();
                row["No"]          = i + 1;
                row["Header Name"] = attrName;
                table.Rows.Add(row);
            }

            dataGridView1.DataSource = table;
        }
Пример #25
0
        /// <summary>
        /// Returns whether the given path/file is a link
        /// </summary>
        /// <param name="shortcutFilename"></param>
        /// <returns></returns>
        public static bool IsLink(string shortcutFilename)
        {
            string pathOnly     = System.IO.Path.GetDirectoryName(shortcutFilename);
            string filenameOnly = System.IO.Path.GetFileName(shortcutFilename);

            Shell32.Shell      shell      = new Shell32.ShellClass();
            Shell32.Folder     folder     = shell.NameSpace(pathOnly);
            Shell32.FolderItem folderItem = folder.ParseName(filenameOnly);
            if (folderItem != null)
            {
                return(folderItem.IsLink);
            }
            return(false); // not found
        }
Пример #26
0
        private static string GetShortcutTargetFile(string shortcutFilename)
        {
            string pathOnly     = Path.GetDirectoryName(shortcutFilename);
            string filenameOnly = Path.GetFileName(shortcutFilename);

            Shell32.Folder     folder     = GetShell32NameSpace(pathOnly);
            Shell32.FolderItem folderItem = folder.ParseName(filenameOnly);
            if (folderItem != null)
            {
                Shell32.ShellLinkObject link = (Shell32.ShellLinkObject)folderItem.GetLink;
                return(link.Path);
            }

            return(String.Empty); // Not found
        }
    private static string GetTargetPath(string ShortcutPath)
    {
        string pathOnly     = System.IO.Path.GetDirectoryName(ShortcutPath);
        string filenameOnly = System.IO.Path.GetFileName(ShortcutPath);

        Shell32.Shell      shell      = new Shell32.Shell();
        Shell32.Folder     folder     = shell.NameSpace(pathOnly);
        Shell32.FolderItem folderItem = folder.ParseName(filenameOnly);
        if (folderItem != null)
        {
            Shell32.ShellLinkObject link = (Shell32.ShellLinkObject)folderItem.GetLink;
            return(link.Path);
        }
        return("");    // not found
    }
Пример #28
0
        public string GetShortcutTargetFile(string shortcutFilename)
        {
            string pathOnly     = System.IO.Path.GetDirectoryName(shortcutFilename);
            string filenameOnly = System.IO.Path.GetFileName(shortcutFilename);

            Shell32.Shell      shell      = new Shell32.Shell();
            Shell32.Folder     folder     = shell.NameSpace(pathOnly);
            Shell32.FolderItem folderItem = folder.ParseName(filenameOnly);
            if (folderItem != null)
            {
                Shell32.ShellLinkObject link = (Shell32.ShellLinkObject)folderItem.GetLink;
                return(link.Path);
            }
            return(null);
        }
        private static bool IsShortcut(string path)
        {
            string directory = Path.GetDirectoryName(path);
            string file      = Path.GetFileName(path);

            Shell32.Shell      shell      = new Shell32.Shell();
            Shell32.Folder     folder     = shell.NameSpace(directory);
            Shell32.FolderItem folderItem = folder.ParseName(file);

            if (folderItem != null)
            {
                return(folderItem.IsLink);
            }
            return(false);
        }
Пример #30
0
 /// <summary>
 /// 获取媒体文件属性信息
 /// </summary>
 /// <param name="path">媒体文件具体路径</param>
 /// <param name="icolumn">具体属性的顺序值(-1简介信息 1文件大小 21时长 22比特率 34文件描述)</param>
 /// <returns></returns>
 public static string GetFileDetailInfo(string path, int icolumn)
 {
     try
     {
         Shell32.Shell      shell      = new Shell32.Shell();
         Shell32.Folder     folder     = shell.NameSpace(System.IO.Path.GetDirectoryName(path));
         Shell32.FolderItem folderItem = folder.ParseName(path.Substring(path.LastIndexOf("\\") + 1));
         return(folder.GetDetailsOf(folderItem, icolumn));
     }
     catch (Exception ex)
     {
         ex.Message.ToString();
         return("");
     }
 }
Пример #31
0
        public MediaItem(string Path)
        {
            this.Path = Path;

            Folder = Shell.NameSpace(System.IO.Path.GetDirectoryName(Path));
            FolderItem = Folder.ParseName(System.IO.Path.GetFileName(Path));
            
            Execute();
            UpdateContainingMedia();
            //TraceProperties();
        }