예제 #1
0
        private void HandleDropFile(IDropInfo dropInfo)
        {
            var oleData = dropInfo.Data as System.Windows.IDataObject;

            if (oleData == null)
            {
                return;
            }

            string[] files = (string[])oleData.GetData(DataFormats.FileDrop);
            foreach (var file in files)
            {
                if (file.EndsWith(".lnk"))
                {
                    string title, command, args, description, iconLocation;
                    int    index;
                    LnkHelper.ResolveShortcut(file, out title, out command, out args, out description, out iconLocation, out index);

                    // todo: 把参数加上
                    Shortcut info = new Shortcut()
                    {
                        Title       = title,
                        Description = description,
                        Icon        = iconLocation,
                        Command     = command
                    };

                    Add(info);
                }
                else if (file.EndsWith(".exe"))
                {
                    System.Diagnostics.FileVersionInfo versionInfo = System.Diagnostics.FileVersionInfo.GetVersionInfo(file);
                    Shortcut info = new Shortcut()
                    {
                        Title       = versionInfo.ProductName,
                        Description = versionInfo.FileDescription,
                        Icon        = null,
                        Command     = file
                    };

                    Add(info);
                }
                else
                {
                    continue;
                }
            }
        }
예제 #2
0
        void Add()
        {
            using (var db = new LiteDatabase(@".\sc.db"))
            {
                var collection = db.GetCollection <Shortcut>();
                var shortcut   = new Shortcut()
                {
                    Command     = @"%windir%\system32\notepad.exe",
                    Description = "记事本",
                    Title       = "Notepad",
                    ShortcutId  = ObjectId.NewObjectId(),
                    Icon        = "$/Icons/notepad.jpg"
                };

                collection.Insert(shortcut);


                var storage = db.GetStorage <string>();
                storage.Upload(shortcut.Icon, @"F:\Works\DriveScan1\DriveScan\Resources\luzhi.JPG");
            }
        }
예제 #3
0
        public void Add(Shortcut shortcut)
        {
            using (var db = new LiteDatabase(@".\sc.db"))
            {
                var collection = db.GetCollection <Shortcut>();
                // 给shortcut加上Id
                shortcut.ShortcutId = ObjectId.NewObjectId();
                collection.Insert(shortcut);


                // 上传图标
                if (!string.IsNullOrEmpty(shortcut.Icon))
                {
                    var storage = db.GetStorage <string>();
                    storage.Upload(shortcut.ShortcutId.ToString(), shortcut.Icon);
                }
                else
                {
                    string key     = shortcut.ShortcutId.ToString();
                    string iconKey = "$/Icons/" + key;
                    shortcut.Icon = iconKey;

                    if (File.Exists(shortcut.Command))
                    {
                        var          icon = ShellIcon.GetLargeIcon(shortcut.Command);
                        MemoryStream ms   = new MemoryStream();
                        icon.Save(ms);

                        var storage = db.GetStorage <string>();
                        storage.Upload(key, iconKey, ms);

                        ms.Dispose();
                    }
                }
            }
        }