示例#1
0
        private string setCreateTime(string folderPath, string fileName) //파일에서 시간 가져오는 함수
        {
            Shell32.Shell  shell = new Shell32.Shell();
            Shell32.Folder objFolder;
            objFolder = shell.NameSpace(folderPath);
            Shell32.FolderItem fi;
            fi = objFolder.ParseName(fileName);
            string temp = objFolder.GetDetailsOf(fi, 4);

            temp = temp.Split('오')[1];
            string AmPm = temp.Split(' ')[0];
            string hour = temp.Split(' ')[1].Split(':')[0];
            string min  = temp.Split(' ')[1].Split(':')[1];

            if (AmPm == "후")
            {
                int h = Int32.Parse(hour) + 12;
                if (h == 24)
                {
                    h = 12;
                }
                hour = h.ToString();
            }
            else if (Int32.Parse(hour) == 12)
            {
                hour = "0";
            }
            return(hour + ":" + min);
        }
        private static void ProcessExcelFiles(ApplicationContext AppContext)
        {
            Program.Shell = new Shell32.Shell();
            Excel.Application ExcelApp = null;

            try
            {
                EventLogger.Log(AppContext, "Start", "Excel", "Start Excel application");

#pragma warning disable IDE0017 // Simplify object initialization
                ExcelApp = new Excel.Application();
#pragma warning restore IDE0017 // Simplify object initialization

                ExcelApp.Visible = false;

                // loop through relevant files
                // sort by write date
                foreach (var FileInfo in RetrieveExcelFileInfoList().OrderBy(x => x.Value))
                {
                    ProcessExcelFile(ExcelApp, AppContext, FileInfo.Key);
                }
            }
            catch (Exception ex)
            {
                EventLogger.Log(AppContext, "Error", "Application", "Error: " + ex.Message);
            }
            finally
            {
                EventLogger.Log(AppContext, "Quit", "Excel", "Quitting Excel application.");
                ExcelApp.Quit();
                Marshal.FinalReleaseComObject(ExcelApp);
            }
        }
示例#3
0
        static void Main(string[] args)
        {
            Shell32.Shell  oShell;
            Shell32.Folder oFldr;
            oShell = new Shell32.Shell();
            oFldr  = oShell.NameSpace(Shell32.ShellSpecialFolderConstants.ssfDESKTOP); //point to the desktop

            foreach (Shell32.FolderItem oFItm in oFldr.Items())                        //get the shotrcuts
            {
                if (oFItm.IsLink)
                {
                    Console.WriteLine("{0} {1} ", oFItm.Name, oFItm.Path);

                    bool isArchive = ((File.GetAttributes(oFItm.Path) & FileAttributes.Archive) == FileAttributes.Archive);
                    //bool isHidden = ((File.GetAttributes(oFItm.Path) & FileAttributes.Hidden) == FileAttributes.Hidden);

                    if (isArchive)         //Warning, here you must define the condition for hide the shortcut. in this case only check if has set the Archive atribute.
                    {
                        //Now you can set  FileAttributes.Hidden atribute
                        //File.SetAttributes(oFItm.Path, File.GetAttributes(oFItm.Path) | FileAttributes.Hidden);
                    }
                }
                else
                {
                    Console.WriteLine("{0} {1} ", oFItm.Name, oFItm.Path);
                }
            }

            Console.ReadKey();
        }
示例#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
        private static ItemProviderResult <FileItem> GetRootItems()
        {
            IEnumerable <FileItem> rootItems = null;
            string path = null;

            Application.Current.Dispatcher.Invoke(() =>
            {
                var compi = new Shell32.Shell().NameSpace(ShellSpecialFolderConstants.ssfDRIVES);
                rootItems = compi.Items().Cast <FolderItem2>()
                            //.Where(f => Directory.Exists(f.Path))
                            .Select(i => new FileItem(i.Path, i.IsFolder ? ItemType.Container : ItemType.Item, i.Name));
                path = compi.Title;

                return(new ItemProviderResult <FileItem>
                {
                    Items = rootItems,
                    PathName = path
                });
            });

            return(new ItemProviderResult <FileItem>
            {
                Items = rootItems,
                PathName = path
            });
        }
    // note: author and title also available
    public static Dictionary <string, string> GetMediaProperties(string file)
    {
        Dictionary <string, string> xtd = new Dictionary <string, string>();

        Shell32.Shell  shell = new Shell32.Shell();
        Shell32.Folder folder;
        folder = shell.NameSpace(Path.GetDirectoryName(file));
        foreach (var s in folder.Items())
        {
            if (folder.GetDetailsOf(s, 0).ToLowerInvariant() ==
                Path.GetFileName(file).ToLowerInvariant())
            {
                // see if it is video
                // possibly check FileKind ???
                if (folder.GetDetailsOf(s, PerceivedType).ToLowerInvariant() ==
                    "video")
                {
                    // there are 35 known items
                    // add the ones we want using the int array of column indices
                    foreach (int n in info)
                    {
                        xtd.Add(folder.GetDetailsOf(folder.Items(), n),
                                folder.GetDetailsOf(s, n));
                    }
                }
                break;
            }
            // ToDo:  freak out when it is not a video or audio type
            // depending what you are trying to do
        }
        return(xtd);
    }
示例#7
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;
            }
        }
示例#8
0
        public string GetSpecificFileProperties(string file, params int[] indexes)
        {
            string fileName   = Path.GetFileName(file);
            string folderName = Path.GetDirectoryName(file);

            Shell32.Shell  shell = new Shell32.Shell();
            Shell32.Folder objFolder;
            objFolder = shell.NameSpace(folderName);
            StringBuilder sb = new StringBuilder();

            foreach (Shell32.FolderItem2 item in objFolder.Items())
            {
                if (fileName == item.Name)
                {
                    for (int i = 0; i < indexes.Length; i++)
                    {
                        sb.Append(objFolder.GetDetailsOf(item, indexes[i]) + ",");
                    }

                    break;
                }
            }

            string result = sb.ToString().Trim();

            //Protection for no results causing an exception on the `SubString` method
            if (result.Length == 0)
            {
                return(string.Empty);
            }
            return(result.Substring(0, result.Length - 1));
        }
示例#9
0
        public override void Open()
        {
            var        shell       = new Shell32.Shell();
            var        path        = Workspace.CurrentItem?.Path ?? Workspace.ActiveLister.Path;
            var        dir         = Path.GetDirectoryName(path);
            var        file        = Path.GetFileName(path);
            var        shellFolder = shell.NameSpace(dir) as Folder3;
            FolderItem folderItem  = shellFolder?.ParseName(file) as FolderItem2;

            if (folderItem != null)
            {
                _verbs = folderItem.Verbs().Cast <FolderItemVerb>().ToList();
            }

            BaseItems =
                _verbs.Where(v => !string.IsNullOrEmpty(v.Name))
                .Select(v => new BaseItem(v.Name.Replace("&", ""))
            {
                Path = v.Name
            });

            Items = BaseItems;
            SetHeaderIconByKey("appbar_lines_horizontal_4");
            base.Open();
        }
示例#10
0
        private static string GetLnkTarget(string lnkPath)
        {
            Shell           shl = null;
            Folder          dir = null;
            FolderItem      itm = null;
            ShellLinkObject lnk = null;

            try
            {
                shl     = new Shell32.Shell(); // Move this to class scope
                lnkPath = System.IO.Path.GetFullPath(lnkPath);
                dir     = shl.NameSpace(System.IO.Path.GetDirectoryName(lnkPath));
                itm     = dir.Items().Item(System.IO.Path.GetFileName(lnkPath));


                lnk = (Shell32.ShellLinkObject)itm.GetLink;

                Console.WriteLine(lnk.Target.Type);
                if (lnk.Target.Type.Equals("System Folder"))
                {
                    Console.WriteLine("explore.exe");
                    return(Environment.GetEnvironmentVariable("windir") + @"\explorer.exe");
                }

                try
                {
                    var p = lnk.Target.Path;
                    Console.WriteLine(p);

                    return(p);
                }
                catch (COMException)
                {
                    return(null);
                }
            }
            finally
            {
                if (shl != null)
                {
                    Marshal.ReleaseComObject(shl);
                }
                if (dir != null)
                {
                    Marshal.ReleaseComObject(dir);
                }
                if (itm != null)
                {
                    Marshal.ReleaseComObject(itm);
                }
                if (lnk != null)
                {
                    Marshal.ReleaseComObject(lnk);
                }
            }
        }
示例#11
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);
            }
        }
        public static string GetLnkTarget(string lnkPath)
        {
            var shl = new Shell32.Shell();                     // Move this to class scope

            lnkPath = Path.GetFullPath(lnkPath);
            var dir = shl.NameSpace(Path.GetDirectoryName(lnkPath));
            var itm = dir.Items().Item(Path.GetFileName(lnkPath));
            var lnk = (Shell32.ShellLinkObject)itm.GetLink;

            return(lnk.Target.Path);
        }
示例#13
0
    // 바로가기 파일의 목적지경로를 리턴 -> Win7 포함한 일부 환경에 문제 있어 사용안함!!!
    public static string GetLnkTarget(string lnkPath)
    {
        var shl = new Shell32.Shell();

        lnkPath = System.IO.Path.GetFullPath(lnkPath);
        var dir = shl.NameSpace(System.IO.Path.GetDirectoryName(lnkPath));
        var itm = dir.Items().Item(System.IO.Path.GetFileName(lnkPath));
        var lnk = (Shell32.ShellLinkObject)itm.GetLink;

        return(lnk.Target.Path);
    }
示例#14
0
        private bool ZipCopyFile(String strFile)
        {
            Shell32.Shell Shell = new Shell32.Shell();
            int           iCnt  = Shell.NameSpace(strPath).Items().Count;

            Shell.NameSpace(strPath).CopyHere(strFile, 0); // Copy file in Zip
            if (Shell.NameSpace(strPath).Items().Count == (iCnt + 1))
            {
                System.Threading.Thread.Sleep(100);
            }
            return(true);
        }
示例#15
0
        private static void GetExtendedProperties(object fp)
        {
            try
            {
                string filePath  = (fp as object[])[0] as string;
                string directory = Path.GetDirectoryName(filePath);
                if (directory != null)
                {
                    Shell      shell       = new Shell32.Shell();
                    Folder     shellFolder = shell.NameSpace(directory);
                    string     fileName    = Path.GetFileName(filePath);
                    FolderItem folderitem  = shellFolder.ParseName(fileName);
                    Dictionary <string, string> dictionary = new Dictionary <string, string>();
                    int i = -1;
                    while (++i < 320)
                    {
                        string header = shellFolder.GetDetailsOf(null, i);
                        if (String.IsNullOrEmpty(header))
                        {
                            continue;
                        }

                        string value = shellFolder.GetDetailsOf(folderitem, i);
                        if (!dictionary.ContainsKey(header) && !string.IsNullOrWhiteSpace(value))
                        {
                            dictionary.Add(header, value);
                        }

                        //Console.WriteLine(header + ": " + value);
                    }

                    Marshal.ReleaseComObject(shell);
                    Marshal.ReleaseComObject(shellFolder);
                    Console.WriteLine("Got " + filePath);
                    _infoList.Add(dictionary);
                }
                else
                {
                    Console.Error.WriteLine("ERROR Directory null");
                    var serializeObject = JsonConvert.SerializeObject(fp);
                    File.AppendAllText($"{OPTIONS.JsonFile}error.txt", serializeObject + Environment.NewLine);
                }
            }
            catch (Exception e)
            {
                if (fp != null)
                {
                    var serializeObject = JsonConvert.SerializeObject(fp);
                    Console.Error.WriteLine("ERROR " + serializeObject);
                    File.AppendAllText($"{OPTIONS.JsonFile}error.txt", serializeObject + Environment.NewLine);
                }
            }
        }
示例#16
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);
        }
示例#17
0
        public void Execute(object parameter)
        {
            var shell       = new Shell32.Shell();
            var path        = _workspace.CurrentItem.Path;
            var dir         = Path.GetDirectoryName(path);
            var file        = Path.GetFileName(path);
            var shellFolder = shell.NameSpace(dir) as Folder3;
            var verbs       = shellFolder?.ParseName(file)?.Verbs().Cast <FolderItemVerb>();
            var properties  = verbs?.FirstOrDefault(fi => fi.Name == "P&roperties" || fi.Name == "E&igenschaften"); //TODO: avoid this hack

            properties?.DoIt();
        }
示例#18
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);
 }
示例#19
0
        public static string GetShortcutTargetFile(string shortcutFilename)
        {
            string pathOnly     = System.IO.Path.GetDirectoryName(shortcutFilename);
            string filenameOnly = System.IO.Path.GetFileName(shortcutFilename);

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

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

            return(string.Empty);
        }
示例#20
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);
    }
示例#21
0
        public static string GetWindowsShortcutTargetFileArguments(string shortcutFilename)
        {
            string pathOnly     = System.IO.Path.GetDirectoryName(shortcutFilename);
            string filenameOnly = System.IO.Path.GetFileName(shortcutFilename);

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

            if (folderItem != null)
            {
                Shell32.ShellLinkObject link = (Shell32.ShellLinkObject)folderItem.GetLink;
                string args = link.Arguments.Trim('"');
                return(args);
            }

            return(string.Empty);
        }
        public string GetSpecificFileProperties(string file, params int[] indexes)
        {
            var result = string.Empty;

            try
            {
                var fileName   = Path.GetFileName(file);
                var folderName = Path.GetDirectoryName(file);

                if (string.IsNullOrEmpty(folderName))
                {
                    return(string.Empty);
                }

                var shell     = new Shell32.Shell();
                var objFolder = shell.NameSpace(folderName);
                var sb        = new StringBuilder();

                foreach (FolderItem2 item in objFolder.Items())
                {
                    if (fileName != item.Name)
                    {
                        continue;
                    }

                    foreach (var index in indexes)
                    {
                        sb.Append(objFolder.GetDetailsOf(item, index) + ",");
                    }

                    break;
                }

                result = sb.ToString().Trim();
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }

            // Protection for no results causing an exception on the `SubString` method.
            return(result.Length == 0 ? string.Empty : result.Substring(0, result.Length - 1));
        }
示例#23
0
 private static Func <TreeViewItem> GetMyComputerItem()
 {
     return(() =>
     {
         var myComputer = new TreeViewItem(@"", ItemType.Container, Constants.RootName)
         {
             IsExpanded = true
         };
         var compi = new Shell32.Shell().NameSpace(ShellSpecialFolderConstants.ssfDRIVES);
         var rootItems = compi.Items().Cast <FolderItem2>()
                         .Where(f => Directory.Exists(f.Path))
                         .Select(i => new TreeViewItem(i.Path, i.IsFolder ? ItemType.Container : ItemType.Item, i.Name));
         foreach (var item in rootItems)
         {
             myComputer.Children.Add(item);
         }
         return myComputer;
     });
 }
        private void processBtn_Click(object sender, EventArgs e)
        {
            String message = "Are you sure you want to create a wrappers for each GOG.com game shortcut in " + Environment.NewLine + batchProcess_folderBrowserDialog.SelectedPath + " ?";
            DialogResult result = MessageBox.Show(message, "Confirm wrapper creation", MessageBoxButtons.YesNo);
            if (result != DialogResult.Yes)
            {
                return;
            }

            label1.Text = "Generating wrappers";
            string [] fileEntries = Directory.GetFiles(batchProcess_folderBrowserDialog.SelectedPath);
            int i = 0;
            foreach(string filenames in fileEntries)
            {

                if(!filenames.EndsWith(".lnk",true,null)){
                    continue;
                }
                String shortcutTempPath = Application.StartupPath + @"\temp.lnk";
                File.Copy(filenames, shortcutTempPath,true);
                var shl = new Shell32.Shell();         // Move this to class scope
                var dir = shl.NameSpace(System.IO.Path.GetDirectoryName(shortcutTempPath));
                var itm = dir.Items().Item(System.IO.Path.GetFileName(shortcutTempPath));
                var lnk = (Shell32.ShellLinkObject)itm.GetLink;
                String iconPath;
                lnk.GetIconLocation(out iconPath);

                if (Path.GetFileName(iconPath) != "gfw_high.ico"){
                    continue;
                }

                Creation.createWrapper(filenames, Path.GetFileName(filenames), iconPath);
                System.IO.File.Copy(Application.StartupPath+@"\wrapper.exe",batchProcess_folderBrowserDialog.SelectedPath+@"\"+Path.GetFileNameWithoutExtension(filenames)+".exe",true);
                Creation.cleanup(Path.GetFileName(filenames));
                i++;

            }
            MessageBox.Show("Processed "+i+" files in folder"+Environment.NewLine+batchProcess_folderBrowserDialog.SelectedPath);
            Process.Start("explorer.exe",batchProcess_folderBrowserDialog.SelectedPath);
            Application.Exit();
        }
        /// <summary>
        /// mp3情報の取得
        /// </summary>
        /// <returns></returns>
        public List <string> getInfo(string filePath)
        {
            // mp3情報を取得
            List <string> ret = new List <string>();

            Shell32.Shell shell    = new Shell32.Shell();
            string        fileName = System.IO.Path.GetFileName(filePath);
            string        path     = filePath.Replace(fileName, "");

            Folder     f    = shell.NameSpace(path);
            FolderItem item = f.ParseName(fileName);

            // ※下記の設定は Windows10 のもの
            //
            ret.Add(f.GetDetailsOf(item, 13)); // アーティスト情報
            ret.Add(f.GetDetailsOf(item, 21)); // タイトル情報
            ret.Add(f.GetDetailsOf(item, 16)); // ジャンル情報
            ret.Add(f.GetDetailsOf(item, 24)); // コメント情報
            ret.Add(f.GetDetailsOf(item, 14)); // アルバムタイトル情報
            ret.Add(f.GetDetailsOf(item, 15)); // 年情報

            return(ret);
        }
示例#26
0
        public static DateTime GetDateTakenFromAvi(string path)
        {
            Shell32.Shell shell = new Shell32.Shell();
            string folderName = Path.GetDirectoryName(path);
            string fileName = Path.GetFileName(path);
            Folder folder = shell.NameSpace(folderName);
            FolderItem file = folder.ParseName(fileName);

            // These are the characters that are not allowing me to parse into a DateTime
            char[] charactersToRemove = new char[] {
                (char)8206,
                (char)8207
            };

            // Getting the "Media Created" label (don't really need this, but what the heck)
            //string name = folder.GetDetailsOf(null, 191);
            string value = folder.GetDetailsOf(file, 201).Trim();
            //if (string.IsNullOrEmpty(value))
            //{
            //    value = folder.GetDetailsOf(file, 191).Trim();
            //}
            //for (int i = 0; i < 500; ++i)
            //{
            //    value = folder.GetDetailsOf(file, i).Trim();
            //    if (!string.IsNullOrEmpty(value))
            //    {
            //        Console.WriteLine(value);
            //    }
            //}
            // Removing the suspect characters
            foreach (char c in charactersToRemove)
                value = value.Replace((c).ToString(), "").Trim();

            // If the value string is empty, return DateTime.MinValue, otherwise return the "Media Created" date
            return value == string.Empty ? DateTime.MinValue : DateTime.Parse(value);
        }
 private ConfigurationHelper()
 {
     this.mProgramMonitorRoot = Registry.LocalMachine.CreateSubKey(@"software\Program Monitor");
     this.mShell = new Shell();
 }
示例#28
0
        private static void GetEpisodeInfoFromMetaData(ref RecTV show)
        {
            try {
                Shell32.Shell  shell = new Shell32.Shell();
                Shell32.Folder objFolder;

                objFolder = shell.NameSpace(show.parentDir);

                //get the index of the path item
                int              index      = -1;
                FileInfo         fh         = new FileInfo(show.filePath);
                DirectoryInfo    dh         = fh.Directory;
                FileSystemInfo[] dirContent = dh.GetFileSystemInfos();

                int desktopINIOffset = 0;
                if (dirContent.Where(f => f.Name == "desktop.ini").ToList().Count() > 0)
                {
                    desktopINIOffset = 1;
                }
                int tempRecOffset = 0;
                if (dirContent.Where(f => f.Name == "TempRec").ToList().Count() > 0)
                {
                    tempRecOffset = 1;
                }
                int tempSBEOffset = 0;
                if (dirContent.Where(f => f.Name == "TempSBE").ToList().Count() > 0)
                {
                    tempSBEOffset = 1;
                }
                int thumbsOffset = 0;
                if (dirContent.Where(f => f.Name == "Thumbs.db").ToList().Count() > 0)
                {
                    thumbsOffset = 1;
                }

                for (int i = 0; i < dh.GetFileSystemInfos().Count(); i++)
                {
                    if (dh.GetFileSystemInfos().ElementAt(i).Name == fh.Name) //we've found the item in the folder
                    {
                        if (fh.Name.CompareTo("Thumbs.db") > 0)
                        {
                            index = i - desktopINIOffset - tempRecOffset - tempSBEOffset - thumbsOffset;
                        }
                        else
                        {
                            if (fh.Name.CompareTo("TempSBE") > 0)
                            {
                                index = i - desktopINIOffset - tempRecOffset - tempSBEOffset;
                            }
                            else
                            {
                                if (fh.Name.CompareTo("TempRec") > 0)
                                {
                                    index = i - desktopINIOffset - tempRecOffset;
                                }
                                else
                                {
                                    if (fh.Name.CompareTo("desktop.ini") > 0)
                                    {
                                        index = i - desktopINIOffset;
                                    }
                                    else
                                    {
                                        index = i;
                                    }
                                }
                            }
                        }
                        break;
                    }
                }

                if (index > -1)
                {
                    FolderItem fi   = objFolder.Items().Item(index);
                    string     name = fi.Name;
                    if (name == show.fileName + show.fileExt)
                    {
                        //Episode name is 254
                        string episodeName = objFolder.GetDetailsOf(fi, 254);
                        show.epName = episodeName;
                        if (episodeName != "")
                        {
                            File.AppendAllText(logPath, "\tFound episode name: " + episodeName + " for file " + name + Environment.NewLine);
                        }

                        //Episode description is 259
                        string episodeDesc = objFolder.GetDetailsOf(fi, 259);
                        show.epDesc = episodeDesc;
                    }
                    else
                    {
                        File.AppendAllText(logPath, "\tError: " + show.fileName + show.fileExt + " does not match " + name + Environment.NewLine);
                    }
                }
            }
            catch (Exception ex)
            {
                File.AppendAllText(logPath, DateTime.Now.ToString() + ": " + ex.Message + Environment.NewLine + ex.StackTrace + Environment.NewLine);
                Console.WriteLine("Errors occurred. Check the log file at " + logPath);
            }
        }
示例#29
0
 //构造
 public PLM()
 {
     sh = new Shell();
 }
示例#30
0
 public Shortcut()
 {
     this.shellAppType = Type.GetTypeFromProgID("Shell.Application");
     this._shell       = (Shell32.Shell)Activator.CreateInstance(shellAppType);
     this.IconIndex    = 0;
 }
示例#31
0
 private void pcr_desktop_Click(object sender, EventArgs e)
 {
     Shell32.Shell shell = new Shell32.Shell();
     shell.MinimizeAll();
 }
示例#32
0
        public Dictionary<string, string> GetFileDetails(string fileFolder, string filePath)
        {
            Dictionary<string,string> arrHeaders = new Dictionary<string,string>();

            Shell shell = new Shell32.Shell();
            Folder fileshellfolder = shell.NameSpace(fileFolder);

            for (int i = 0; i <= 303; i++)
            {
                try
                {
                    arrHeaders.Add(((infoFile)i).ToString(), fileshellfolder.GetDetailsOf(fileshellfolder.ParseName(filePath), i));
                }
                catch { }
            }

            return arrHeaders;
        }
示例#33
0
        private static string GetLnkTarget(string lnkPath)
        {
            Shell shl = null;
            Folder dir = null;
            FolderItem itm = null;
            ShellLinkObject lnk = null;

            try
            {
                shl = new Shell32.Shell(); // Move this to class scope
                lnkPath = System.IO.Path.GetFullPath(lnkPath);
                dir = shl.NameSpace(System.IO.Path.GetDirectoryName(lnkPath));
                itm = dir.Items().Item(System.IO.Path.GetFileName(lnkPath));


                lnk = (Shell32.ShellLinkObject)itm.GetLink;

                Console.WriteLine(lnk.Target.Type);
                if (lnk.Target.Type.Equals("System Folder"))
                {
                    Console.WriteLine("explore.exe");
                    return Environment.GetEnvironmentVariable("windir") + @"\explorer.exe";

                }

                try
                {
                    var p = lnk.Target.Path;
                    Console.WriteLine(p);

                    return p;
                }
                catch (COMException)
                {
                    return null;
                }

            }
            finally
            {
                if (shl != null) Marshal.ReleaseComObject(shl);
                if (dir != null) Marshal.ReleaseComObject(dir);
                if (itm != null) Marshal.ReleaseComObject(itm);
                if (lnk != null) Marshal.ReleaseComObject(lnk);
            }


        }
示例#34
0
        //http://csharphelper.com/blog/2018/06/get-information-about-windows-shortcuts-in-c/
        // Get information about this link.
        // Return an error message if there's a problem.
        internal static string GetShortcutInfo(string full_name,
                                               out ShortcutItem vSI)
        {
            //name = "";
            //path = "";
            //descr = "";
            //working_dir = "";
            //args = "";
            //var sc = Keys.Control && Keys.LShiftKey && Keys.A;
            //var txt = new KeysConverter().ConvertToString((Keys)sc);
            //Console.WriteLine(txt);



            vSI = new ShortcutItem();

            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;

                vSI.Arguments   = lnk.Arguments;
                vSI.Description = lnk.Description;
                //vSI.Hotkey = lnk.Hotkey.ToString();
                lnk.GetIconLocation(out string bps);
                vSI.IconPath     = bps;
                vSI.Name         = folder_item.Name;
                vSI.ShortcutPath = lnk.Path;
                FolderItem fi = lnk.Target;
                vSI.Target = GetShortcutTargetFile(full_name);//fi.IsFolder.ToString();
                //vSI.WindowStyle = "1";
                vSI.WorkingDirectory          = lnk.WorkingDirectory;
                vSI.ShortcutPathSpecialFolder = "Other";

                WshShell    theShell    = new WshShell();
                WshShortcut theShortcut = (WshShortcut)theShell.CreateShortcut(full_name);
                vSI.WindowStyle = frmMain.WindowStyleToInt(theShortcut.WindowStyle);
                vSI.Hotkey      = theShortcut.Hotkey.ToString();

                //name = folder_item.Name;
                //descr = lnk.Description;
                //path = lnk.Path;
                //working_dir = lnk.WorkingDirectory;
                //args = lnk.Arguments;

                return("");
            }
            catch (Exception ex)
            {
                return(ex.Message);
            }
        }