Esempio n. 1
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
            }
Esempio n. 2
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;
                    }
                }
            }
        }
Esempio n. 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);
        }
Esempio n. 4
0
        /// <summary>
        /// シェルのファイルオブジェクト
        /// </summary>
        /// <param name="fullPath"></param>
        /// <param name="name"></param>
        /// <returns></returns>
        private FileAccesser GetFile(string fullPath, string name)
        {
            var dir = System.IO.Path.GetDirectoryName(fullPath);
            var key = dir.ToLower();


            Shell32.Folder folder = null;
            if (!this.cache.TryGetValue(key, out folder))
            {
                lock (this.syncObject)
                {
                    if (!this.cache.ContainsKey(key))
                    {
                        folder = this.GetFolder(dir);
                        this.cache.Add(key, folder);
                    }
                    else
                    {
                        folder = this.cache[key];
                    }
                }
            }


            return(new FileAccesser(fullPath, name, folder));
        }
Esempio n. 5
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);
        }
Esempio n. 6
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;
            }
        }
 public MetadataReader(string folderpath, string musikNumber)
 {
     _musikNumber = musikNumber;
     _folder = folderpath;
     _objFolder = _shell.NameSpace(_folder);
     findItem();
     Setter();
 }
Esempio n. 8
0
        private Shell32.Folder GetShellFolder(string directoryFullName)
        {
            Type   shellAppType = Type.GetTypeFromProgID("Shell.Application");
            object shell        = Activator.CreateInstance(shellAppType);

            Shell32.Folder folder = (Shell32.Folder)shellAppType.InvokeMember("NameSpace", System.Reflection.BindingFlags.InvokeMethod, null, shell, new object[] { directoryFullName });
            return(folder);
        }
Esempio n. 9
0
        //http://csharphelper.com/blog/2018/06/get-information-about-windows-shortcuts-in-c/
        internal static string GetShortcutInfo(string full_name,
                                               out string name, out string path, out string descr,
                                               out string working_dir, out string args)
        {
            name        = "";
            path        = "";
            descr       = "";
            working_dir = "";
            args        = "";
            try
            {
                // Make a Shell object.
                Shell32.Shell shell = new Shell32.Shell();

                // Get the shortcut's folder and name.
                string shortcut_path =
                    full_name.Substring(0, full_name.LastIndexOf("\\"));
                string shortcut_name =
                    full_name.Substring(full_name.LastIndexOf("\\") + 1);
                if (!shortcut_name.EndsWith(".lnk"))
                {
                    shortcut_name += ".lnk";
                }

                // Get the shortcut's folder.
                Shell32.Folder shortcut_folder =
                    shell.NameSpace(shortcut_path);

                // Get the shortcut's file.
                Shell32.FolderItem folder_item =
                    shortcut_folder.Items().Item(shortcut_name);

                if (folder_item == null)
                {
                    return("Cannot find shortcut file '" + full_name + "'");
                }
                if (!folder_item.IsLink)
                {
                    return("File '" + full_name + "' isn't a shortcut.");
                }

                // Display the shortcut's information.
                Shell32.ShellLinkObject lnk =
                    (Shell32.ShellLinkObject)folder_item.GetLink;
                name        = folder_item.Name;
                descr       = lnk.Description;
                path        = lnk.Path;
                working_dir = lnk.WorkingDirectory;
                args        = lnk.Arguments;
                return("");
            }
            catch (Exception ex)
            {
                return(ex.Message);
            }
        }
Esempio n. 10
0
 public static IEnumerable <string> GetContents()
 {
     Shell = new Shell();
     Shell32.Folder RecycleBin = Shell.NameSpace(10);
     foreach (FolderItem2 Entry in RecycleBin.Items())
     {
         yield return(Entry.Path);
     }
     Marshal.FinalReleaseComObject(Shell);
 }
Esempio n. 11
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();
        }
Esempio n. 12
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);
        }
Esempio n. 13
0
        private static bool SetNetworkAdapter(bool status)
        {
            const string discVerb          = "停用(&B)";     // "停用(&B)";
            const string connVerb          = "启用(&A)";     // "启用(&A)";
            const string network           = "网络连接";       //"网络连接";
            const string networkConnection = "以太网适配器 以太网"; // "本地连接"
            string       sVerb             = null;

            if (status)
            {
                sVerb = connVerb;
            }
            else
            {
                sVerb = discVerb;
            }
            Shell32.Shell  sh     = new Shell32.Shell();
            Shell32.Folder folder = sh.NameSpace(Shell32.ShellSpecialFolderConstants.ssfCONTROLS);
            try
            {
                //进入控制面板的所有选项
                foreach (Shell32.FolderItem myItem in folder.Items())
                {
                    //进入网络连接
                    if (myItem.Name == network)
                    {
                        Shell32.Folder fd = (Shell32.Folder)myItem.GetFolder;
                        foreach (Shell32.FolderItem fi in fd.Items())
                        {
                            //找到本地连接
                            if ((fi.Name == networkConnection))
                            {
                                //找本地连接的所有右键功能菜单
                                foreach (Shell32.FolderItemVerb Fib in fi.Verbs())
                                {
                                    if (Fib.Name == sVerb)
                                    {
                                        Fib.DoIt();
                                        return(true);
                                    }
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                return(false);
            }
            return(true);
        }
Esempio n. 14
0
 public void UnZip()
 {
     Shell32.Shell sc = new Shell32.Shell();
     //'UPDATE !!
     //Create directory in which you will unzip your files .
     IO.Directory.CreateDirectory("D:\\extractedFiles");
     //Declare the folder where the files will be extracted
     Shell32.Folder output = sc.NameSpace("D:\\extractedFiles");
     //Declare your input zip file as folder  .
     Shell32.Folder input = sc.NameSpace("d:\\myzip.zip");
     //Extract the files from the zip file using the CopyHere command .
     output.CopyHere(input.Items, 4);
 }
Esempio n. 15
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);
        }
Esempio n. 16
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);
        }
Esempio n. 17
0
        static void Main(string[] args)
        {
            //User input for root folder path
            Console.WriteLine("Browse to the root music folder");
            string folderPath       = "";
            FolderBrowserDialog fbd = new FolderBrowserDialog();

            //Await user input
            if (fbd.ShowDialog() == DialogResult.OK)
            {
                folderPath = fbd.SelectedPath;
                Shell32.Folder musicFolder = GetShell32Folder(fbd.SelectedPath);
                Console.WriteLine("Name, Size, Item Type, Owner, Album, Year, Genre");
                GenerateLib(musicFolder, folderPath);
            }
        }
Esempio n. 18
0
        /// <summary>
        /// method for colled info or delete files
        /// </summary>
        /// <param name="flag">flag delete</param>
        /// <returns>information</returns>
        public string CallClear(bool flag)
        {
            Shell shell = new Shell();

            Shell32.Folder Recycler = shell.NameSpace(10);
            if (!flag)
            {
                bool acess = true;
                foreach (FolderItem file in Recycler.Items())
                {
                    if (File.GetAttributes(file.Path).ToString().Contains((FileAttributes.Directory).ToString()))
                    {
                        base.WalkDir(new DirectoryInfo(file.Path), "system", false, ref size, this.wayFile, ref acess);
                        this.wayDirs.Add(file.Path);
                    }
                    else
                    {
                        this.wayFile.Add(file.Path);
                        size += file.Size;
                    }
                }
            }
            else
            {
                MyDeleteFile.DeleteFiles(this.wayFile);
                foreach (var dir in this.wayDirs)
                {
                    try
                    {
                        Directory.Delete(dir, true);
                    }
                    catch (Exception e)
                    {
                        DirectoryInfo del = new DirectoryInfo(dir);
                        del.Attributes = FileAttributes.Normal;
                        try
                        {
                            del.Delete(true);
                        }
                        catch (Exception ex)
                        {
                        }
                    }
                }
            }
            return(string.Format("Recycle files: {0} KB:{1} File(-s)", this.size / 1000, this.wayFile.Count));
        }
Esempio n. 19
0
 /// <summary>
 /// 功能:解压zip格式的文件。
 /// </summary>
 /// <param name="zipFilePath">压缩文件路径</param>
 /// <param name="unZipDir">解压文件存放路径,为空时默认与压缩文件同一级目录下,跟压缩文件同名的文件夹</param>
 /// <param name="err">出错信息</param>
 /// <returns>解压是否成功</returns>
 public static bool UnZipFile(string zipFilePath, string unZipDir, out string err)
 {
     err = "";
     if (zipFilePath.Length == 0)
     {
         err = "压缩文件不能为空!";
         return(false);
     }
     else if (!zipFilePath.EndsWith(".zip"))
     {
         err = "文件格式不正确!";
         return(false);
     }
     else if (!System.IO.File.Exists(zipFilePath))
     {
         err = "压缩文件不存在!";
         return(false);
     }
     //解压文件夹为空时默认与压缩文件同一级目录下,跟压缩文件同名的文件夹
     if (unZipDir.Length == 0)
     {
         unZipDir = zipFilePath.Replace(System.IO.Path.GetFileName(zipFilePath), System.IO.Path.GetFileNameWithoutExtension(zipFilePath));
     }
     if (!unZipDir.EndsWith("\\"))
     {
         unZipDir += "\\";
     }
     if (!System.IO.Directory.Exists(unZipDir))
     {
         System.IO.Directory.CreateDirectory(unZipDir);
     }
     try
     {
         Shell32.ShellClass  sc         = new Shell32.ShellClass();
         Shell32.Folder      SrcFolder  = sc.NameSpace(zipFilePath);
         Shell32.Folder      DestFolder = sc.NameSpace(unZipDir);
         Shell32.FolderItems items      = SrcFolder.Items();
         DestFolder.CopyHere(items, 20);
     }
     catch (Exception ex)
     {
         err = ex.Message;
         return(false);
     }
     return(true);
 }//解压结束
Esempio n. 20
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);
        }
Esempio n. 21
0
    public void Zip()
    {
        //1) Lets create an empty Zip File .
        //The following data represents an empty zip file .

        byte[] startBuffer =
        {
            80,
            75,
            5,
            6,
            0,
            0,
            0,
            0,
            0,
            0,
            0,
            0,
            0,
            0,
            0,
            0,
            0,
            0,
            0,
            0,
            0,
            0
        };
        // Data for an empty zip file .
        FileIO.FileSystem.WriteAllBytes("d:\\empty.zip", startBuffer, false);

        //We have successfully made the empty zip file .

        //2) Use the Shell32 to zip your files .
        // Declare new shell class
        Shell32.Shell sc = new Shell32.Shell();
        //Declare the folder which contains the files you want to zip .
        Shell32.Folder input = sc.NameSpace("D:\\neededFiles");
        //Declare  your created empty zip file as folder  .
        Shell32.Folder output = sc.NameSpace("D:\\empty.zip");
        //Copy the files into the empty zip file using the CopyHere command .
        output.CopyHere(input.Items, 4);
    }
Esempio n. 22
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);
                }
            }
        }
Esempio n. 23
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;
        }
Esempio n. 24
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);
        }
    }
Esempio n. 25
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);
        }
Esempio n. 26
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);
        }
Esempio n. 27
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);
            }
        }
Esempio n. 28
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);
        }
Esempio n. 29
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;
                }
            }
Esempio n. 30
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);
        }
Esempio n. 31
0
        public static bool unzipWDIFiles(string zipFile, string destinationFolder)
        {
            try
            {
                //Shell32.Folder SrcFlder = GetShell32NameSpaceFolder(from);
                //Shell32.Folder DestFlder = GetShell32NameSpaceFolder(to);
                //FolderItems items = SrcFlder.Items();

                //Shell shell = new Shell();
                Shell32.Folder archive       = GetShell32NameSpaceFolder(zipFile);
                Shell32.Folder extractFolder = GetShell32NameSpaceFolder(destinationFolder);

                // Copy each item one-by-one
                foreach (Shell32.FolderItem f in archive.Items())
                {
                    extractFolder.CopyHere(f, 20);
                }
                return(true);
            }
            catch (Exception ex)
            {
                return(false);
            }
        }
 private void Setup()
 {
     _objFolder = _shell.NameSpace(Folderpath);
     FolderItemList = new List<string>();
     _metaList = new List<IMetadataReader>();
 }
 public void SelectFolder()
 {
     _objFolder = _shell.NameSpace(Foldername);
 }
 private void Setup()
 {
     //select folder
     _objFolder = _shell.NameSpace(_folder);
     //select item
     int i = 0;
     foreach (Shell32.FolderItem2 folderItem2 in _objFolder.Items())
     {
         if (i == _objectnumber)
             _item2 = folderItem2;
         i++;
     }
 }