Exemplo n.º 1
0
    public void Test()
    {
        string stdout = ShellUtilities.WithStdout(NotInstrumented.Bar);

        // our filter doesnt accept any types
        string expected = "";

        Assert.AreEqual(expected.Trim(), stdout);
    }
Exemplo n.º 2
0
    public void Test()
    {
        string stdout = ShellUtilities.WithStdout(RunFooBar);

        string expected =
            @"
TRACE: System.Void Instrumented::Foo()
";

        Assert.AreEqual(expected.Trim(), stdout);
    }
 internal static void SetIcon(DeviceInformation deviceInterface, Action <ShellThumbnail> action)
 {
     if (deviceInterface.Properties.TryGetValue("System.Devices.Icon", out var value) && value is string path)
     {
         var iconIndex = ShellUtilities.ParseIconLocationPath(path, out var iconPath);
         if (iconPath != null)
         {
             action(new ShellThumbnail(DeviceClassFolder.NormalizeIconPath(iconPath), iconIndex));
         }
     }
 }
Exemplo n.º 4
0
    public void TestInstrumentation()
    {
        string stdout = ShellUtilities.WithStdout(Foo);

        string expected = @"
TRACE: System.Void CustomInstrumentationSubject::Foo()
TRACE: System.Void CustomInstrumentationSubject::Bar()
";

        Assert.AreEqual(expected.Trim(), stdout);
    }
Exemplo n.º 5
0
    public void Test()
    {
        string stdout = ShellUtilities.WithStdout(RunBars);

        string expected =
            @"
TRACE: System.Void Foo::Bar()
TRACE: System.Void Fao::Bar()
";

        Assert.AreEqual(expected.Trim(), stdout);
    }
Exemplo n.º 6
0
        private void Open_Click(object sender, RoutedEventArgs e)
        {
            var id  = ShellFolderServer.LocationFolderId;
            var kn  = KnownFolder.Get(id);
            var idl = kn.GetIdList(ShellBoost.Core.WindowsShell.KNOWN_FOLDER_FLAG.KF_FLAG_DEFAULT);

            dynamic window = new ShellUtilities.ShellBrowserWindow();

            ShellUtilities.CoAllowSetForegroundWindow(window);
            window.Visible = true;
            window.Navigate2(idl.Data);
        }
Exemplo n.º 7
0
        /// <summary>
        /// Reads the meta data from assembly attributes and extracts the shell icon to display on the progress dialog
        /// </summary>
        /// <param name="assembly"></param>
        private void DisplayInformationAboutAssembly(System.Reflection.Assembly assembly, bool showVersion)
        {
            try
            {
                ProgressViewer.SetTitle(this, "Loading...");
                ProgressViewer.SetDescription(this, "This operation could take several seconds...");

                if (assembly != null)
                {
                    // snag the name of the file minus path and extention and set it as the heading
                    string filename = Path.GetFileName(assembly.Location);
                    filename = filename.Replace(Path.GetExtension(assembly.Location), null);
                    ProgressViewer.SetHeading(this, filename);

//					DirectoryInfo directory = new DirectoryInfo(Application.StartupPath);
//
////					// snag the version of the assembly, and tack it onto the heading
//					AssemblyAttributeReader reader = new AssemblyAttributeReader(assembly);
////					Version v = reader.GetAssemblyVersion();
////					if (v != null)
//					ProgressViewer.SetHeading(this, filename + (showVersion ? " Version " + SnapInHostingEngine.Instance.AppVersion.ToString(): null));
//
//					// snag the company that made the assembly, and set it in the title
//					System.Reflection.AssemblyCompanyAttribute[] companyAttributes = reader.GetAssemblyCompanyAttributes();
//					if (companyAttributes != null)
//						if (companyAttributes.Length > 0)
//							if (companyAttributes[0].Company != null && companyAttributes[0].Company != string.Empty)
//                                ProgressViewer.SetTitle(this, companyAttributes[0].Company + " " + filename);
//

                    // get the large icon for the info panel
                    Icon largeIcon = ShellUtilities.GetIconFromPath(assembly.Location, IconSizes.LargeIconSize, IconStyles.NormalIconStyle, FileAttributes.Normal);
                    if (largeIcon != null)
                    {
                        ProgressViewer.SetImage(this, largeIcon.ToBitmap() as Image);
                    }

                    // get the small icon for the window
                    Icon smallIcon = ShellUtilities.GetIconFromPath(assembly.Location, IconSizes.SmallIconSize, IconStyles.NormalIconStyle, FileAttributes.Normal);
                    if (smallIcon != null)
                    {
                        this.Icon = smallIcon;
                    }
                }
            }
            catch (Exception ex)
            {
                Log.WriteLine(ex);
            }
        }
Exemplo n.º 8
0
        private void OpenExtension_Click(object sender, RoutedEventArgs e)
        {
            var service = UIUtilities.GetDataContext <DriveService>(sender);

            // services are children of the root folder
            var item = _server?.RootFolder?.ParseItem(service.FileName);

            if (item == null)
            {
                return;
            }

            dynamic window = new ShellUtilities.ShellBrowserWindow();

            ShellUtilities.CoAllowSetForegroundWindow(window);
            window.Visible = true;
            window.Navigate2(item.IdList.Data);
        }
        // gets an icon path for a class (guid)
        private int?GetIconPath(out string filePath)
        {
            filePath = null;
            using (var key = Registry.LocalMachine.OpenSubKey(Path.Combine(@"SYSTEM\CurrentControlSet\Control\Class", ClassGuid.ToString("B")), false))
            {
                if (key == null)
                {
                    return(null);
                }

                var obj = key.GetValue("IconPath");
                if (!(obj is string path))
                {
                    path = (obj as string[])?[0];
                }
                if (string.IsNullOrWhiteSpace(path))
                {
                    return(null);
                }

                return(ShellUtilities.ParseIconLocationPath(path, out filePath));
            }
        }
Exemplo n.º 10
0
        void InitializeTree()
        {
            this.treeListFileSystem.CanExpandGetter = delegate(object x)
            {
                return(((Movie)x).IsFilesystemFolder);
            };

            this.treeListFileSystem.ChildrenGetter = delegate(object x)
            {
                var movie = (Movie)x;
                try
                {
                    var dir = new DirectoryInfo(movie.FilePath);

                    var members = dir.GetFileSystemInfos();

                    return(movie.Children = members.Select(fileSystemInfo => Movie.FromFolderName(fileSystemInfo.FullName)).ToList());
                }
                catch (UnauthorizedAccessException ex)
                {
                    MessageBox.Show(this, ex.Message, "ObjectListViewDemo", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    return(new ArrayList());
                }
            };


            // Show the size of files as GB, MB and KBs. Also, group them by
            // some meaningless divisions
            this.treeColumnSize.AspectGetter = delegate(object x)
            {
                var m = (Movie)x;

                if (!m.IsFilesystemFolder)
                {
                    try
                    {
                        var fileInfo = new FileInfo(((Movie)x).FilePath);

                        return(fileInfo.Length);
                    }
                    catch (System.IO.FileNotFoundException)
                    {
                        // Mono 1.2.6 throws this for hidden files
                        return((long)-2);
                    }
                }
                else
                {
                    return((long)-2);
                }
            };

            // Draw the system icon next to the name
            //var helper = new SysImageListHelper(this.treeListView1);
            this.treeColumnTitle.ImageGetter = delegate(object x)
            {
                return(((Movie)x).ImageIndex);
            };



            this.treeColumnSize.AspectToStringConverter = delegate(object x)
            {
                if ((long)x < 0) // folder
                {
                    return("");
                }
                else
                {
                    return(FormatFileSize((long)x));
                }
            };

            this.treeColumnYear.AspectToStringConverter = delegate(object x)
            {
                if (x + "" == "0") // folder
                {
                    return("");
                }
                else
                {
                    return(x + "");
                }
            };

            this.treeColumnRating.AspectToStringConverter = delegate(object x)
            {
                if (x + "" == "0") // folder
                {
                    return("");
                }
                else
                {
                    return(x + "");
                }
            };

            // Show the system description for this object
            this.treeColumnFileType.AspectGetter = delegate(object x)
            {
                return(ShellUtilities.GetFileType(((Movie)x).FilePath));
            };
        }
Exemplo n.º 11
0
        private void OnWatcherEvent(object sender, LocalFileSystemWatcherEventArgs e)
        {
            // basic checks
            if (!IOUtilities.PathIsChildOrEqual(WebApi.LocalDirectory.FullName, e.Path))
            {
                return;
            }

            // skip some well known files (office, etc.)
            if (!ConsiderForRemote(Path.GetFileName(e.Path)))
            {
                return;
            }

            var isDir = IOUtilities.PathIsDirectory(e.Path);

            Server.Log(TraceLevel.Verbose, "Action:" + e.Action + " Get remote item for local: " + e.Path);
            var item = Server.GetRemoteItem(e.Path);

            if (item != null)
            {
                if (e.Action == WatcherChangeTypes.Deleted)
                {
                    // a delete in a local file doesn't mean a delete in the server
                    ShellUtilities.ChangeNotify(SHCNE.SHCNE_UPDATEITEM, 0, item.IdList);
                }
                else if (e.Action == WatcherChangeTypes.Changed)
                {
                    ShellUtilities.ChangeNotify(isDir ? SHCNE.SHCNE_UPDATEDIR : SHCNE.SHCNE_UPDATEITEM, 0, item.IdList);
                    if (!isDir)
                    {
                        SynchronizeFile(e.Path);
                    }
                }
                else if (e.Action == WatcherChangeTypes.Renamed)
                {
                    ShellUtilities.ChangeNotify(isDir ? SHCNE.SHCNE_RENAMEFOLDER : SHCNE.SHCNE_RENAMEITEM, 0, item.IdList);
                    if (!isDir)
                    {
                        SynchronizeFile(e.Path);
                    }
                }
                // else create do nothing
            }
            else // try parent
            {
                var parentPath = Path.GetDirectoryName(e.Path);
                item = Server.GetRemoteItem(parentPath);
                if (item != null)
                {
                    // new item creation in the local directories? could come from the "New ..." menu in virtual folder's context
                    // we don't use created just changed
                    if (e.Action != WatcherChangeTypes.Deleted && e.Action != WatcherChangeTypes.Created && item is IObjectWithApiItem owa)
                    {
                        var atts = IOUtilities.PathGetAttributes(e.Path);
                        if (atts.HasValue &&
                            !atts.Value.HasFlag(FileAttributes.Directory) &&
                            !atts.Value.HasFlag(FileAttributes.Hidden) &&
                            !atts.Value.HasFlag(FileAttributes.System))
                        {
                            WebApi.CreateAsync(owa.ApiItem.Id, e.Path, null, atts.Value);
                        }
                    }

                    ShellUtilities.ChangeNotify(SHCNE.SHCNE_UPDATEDIR, 0, item.IdList);
                }
            }
        }
Exemplo n.º 12
0
		private static void CopyToTemp(string fname)
		{
			ShellUtilities.CopyToTemp(fname);
		}
Exemplo n.º 13
0
		private static string GetTempPath()
		{
			return ShellUtilities.GetTempPath();
		}
        private void OnChangeNotifierNotify(object sender, ChangeNotifyEventArgs e)
        {
            // get our equivalent item
            if (e.FileSystemPath1 != null)
            {
                // is it really about us?
                if (e.FileSystemPath1.StartsWith(RootPath, StringComparison.OrdinalIgnoreCase))
                {
                    // get relative path and normalize a bit
                    var relPath1 = IOUtilities.PathRemoveStartSlash(e.FileSystemPath1.Substring(RootPath.Length));

                    // build a PIDL corresponding to our namespace from a file system path (not in our namespace)
                    // and get/update the corresponding ShellItem from the cache, if it exists.
                    ShellItem       item;
                    ShellItemIdList idl;
                    switch (e.Event)
                    {
                    case SHCNE.SHCNE_DELETE:
                    case SHCNE.SHCNE_RMDIR:
                        idl  = ShellItemIdList.FromFileSystem(RootPhysical.IdList, relPath1, e.Event == SHCNE.SHCNE_RMDIR ? FileAttributes.Directory : FileAttributes.Normal);
                        item = Server.GetFromCache(idl);
                        if (item != null)
                        {
                            item.NotifyDelete();
                            Server.RemoveFromCache(item.IdList);
                        }
                        break;

                    case SHCNE.SHCNE_RENAMEFOLDER:
                    case SHCNE.SHCNE_RENAMEITEM:
                        idl  = ShellItemIdList.FromFileSystem(RootPhysical.IdList, relPath1, e.Event == SHCNE.SHCNE_RENAMEFOLDER ? FileAttributes.Directory : FileAttributes.Normal);
                        item = Server.GetFromCache(idl);
                        if (item != null)
                        {
                            Server.RemoveFromCache(item.IdList);
                        }

                        // 1 is previous, 2 is new
                        var relPath2 = IOUtilities.PathRemoveStartSlash(e.FileSystemPath2.Substring(RootPath.Length));
                        var idl2     = ShellItemIdList.FromFileSystem(RootPhysical.IdList, relPath2, e.Event == SHCNE.SHCNE_RENAMEFOLDER ? FileAttributes.Directory : FileAttributes.Normal);
                        ShellUtilities.ChangeNotify(e.Event, 0, idl, idl2);
                        break;

                    case SHCNE.SHCNE_UPDATEITEM:
                    case SHCNE.SHCNE_UPDATEDIR:
                        idl  = ShellItemIdList.FromFileSystem(RootPhysical.IdList, relPath1, e.Event == SHCNE.SHCNE_UPDATEDIR ? FileAttributes.Directory : FileAttributes.Normal);
                        item = Server.GetFromCache(idl);
                        if (item != null)
                        {
                            item.NotifyUpdate();
                        }
                        break;

                    case SHCNE.SHCNE_CREATE:
                    case SHCNE.SHCNE_MKDIR:
                        idl  = ShellItemIdList.FromFileSystem(RootPhysical.IdList, relPath1, e.Event == SHCNE.SHCNE_MKDIR ? FileAttributes.Directory : FileAttributes.Normal);
                        item = Server.GetFromCache(idl);
                        if (item != null)     // item should in general be null (creation)
                        {
                            item.NotifyCreate();
                        }
                        else
                        {
                            ShellUtilities.ChangeNotify(e.Event, 0, idl);
                        }
                        break;
                    }
                }
            }
        }
Exemplo n.º 15
0
 public void SetUp()
 {
     ShellUtilities.CopyToTemp(typeof(IObjectContainer).Module.Assembly.Location);
 }
        /// <summary>
        /// Returns the index of the Image/Icon to use in the specified ImageList for the path of the file or folder specified.
        /// </summary>
        /// <param name="imageList">The ImageList where the Image is stored</param>
        /// <param name="path">The file or folder to retrieve the Image/Icon index for</param>
        /// <param name="extractNew">A flag that determines if a cached Image/Icon is used or if the sub-system will extract a new Image/Icon instead</param>
        /// <returns></returns>
        public int GetIconIndex(ImageList imageList, string path, bool extractNew)
        {
            string extension;
            bool   useNormalAttribs = false;

            System.IO.FileAttributes attributes = System.IO.FileAttributes.Normal;

            try
            {
                attributes = File.GetAttributes(path);

                if ((attributes & System.IO.FileAttributes.Directory) == System.IO.FileAttributes.Directory)
                {
                    DirectoryInfo directory = new DirectoryInfo(path);
                    extension = directory.Extension;
                    if (extension == null || extension == string.Empty)
                    {
                        extension = @"Folder";
                    }
                }
                else
                {
                    FileInfo file = new FileInfo(path);

                    // be carefull on these certain extensions! they will prolly contain different icons
                    // if we wanted to be more elegant, these should be loaded from the config for extensibility reasons
                    switch (file.Extension)
                    {
                    case ".exe": extension = file.FullName; break;

                    case ".lnk": extension = file.FullName; break;

                    case ".url": extension = file.FullName; break;

                    case ".ico": extension = file.FullName; break;

                    case ".cur": extension = file.FullName; break;

                    case ".ani": extension = file.FullName; break;

                    case ".msc": extension = file.FullName; break;

                    default: extension = file.Extension; break;
                    }
                }
            }
            catch
            {
                extension        = path;
                useNormalAttribs = true;
            }

            if (!extractNew)
            {
                if (_extensions.ContainsKey(extension))
                {
                    return((int)_extensions[extension]);
                }
            }

            int index = imageList.Images.Count;

            FileAttributes attribs = FileAttributes.Normal;

            if (!useNormalAttribs)
            {
                attribs = ((attributes & FileAttributes.Directory) == FileAttributes.Directory ? FileAttributes.Directory : FileAttributes.Normal);
            }

            imageList.Images.Add(ShellUtilities.GetIconFromPath(path, _size, _style, attribs));

            if (!_extensions.ContainsKey(extension))
            {
                _extensions.Add(extension, index);
            }

            return(index);
        }
Exemplo n.º 17
0
 private void Unregister_Click(object sender, RoutedEventArgs e)
 {
     ShellFolderServer.UnregisterNativeDll(RegistrationMode.User);
     ShellUtilities.RefreshShellViews();
     AppendText("Native proxy was unregistered from HKCU.");
 }
Exemplo n.º 18
0
        private void ListAccounts()
        {
            AddLog();
            AddLog(Settings.Current.Accounts.Count + " valid account(s) where found.");
            for (int i = 0; i < Settings.Current.Accounts.Count; i++)
            {
                var account = Settings.Current.Accounts[i];
                AddLog("Account[" + i + "]");
                AddLog(" User Email Address           : " + account.UserEmailAddress);
                AddLog(" Data Directory Path          : " + account.DataDirectoryPath);
                AddLog(" File System RootId           : " + account.FileSystem.RootId);
                AddLog(" Synchronizer Started         : " + account.Synchronizer.IsStarted);
                if (account.About != null)
                {
                    AddLog(" User Display Name            : " + account.About.User.DisplayName);
                    if (account.About.MaxUploadSize.HasValue)
                    {
                        AddLog(" Max Upload Size              : " + account.About.MaxUploadSize + " bytes (" + ShellUtilities.FormatByteSize(account.About.MaxUploadSize.Value) + ")");
                    }

                    if (account.About.StorageQuota != null)
                    {
                        if (account.About.StorageQuota.Limit.HasValue)
                        {
                            AddLog(" Storage Quota Limit          : " + account.About.StorageQuota.Limit + " bytes (" + ShellUtilities.FormatByteSize(account.About.StorageQuota.Limit.Value) + ")");
                        }

                        if (account.About.StorageQuota.Usage.HasValue)
                        {
                            string ratio = null;
                            if (account.About.StorageQuota.Limit.HasValue && account.About.StorageQuota.Limit.Value != 0)
                            {
                                var percent = (double)account.About.StorageQuota.Usage.Value / account.About.StorageQuota.Limit.Value;
                                ratio = "(" + percent.ToString("P") + ")";
                            }

                            AddLog(" Storage Quota Usage          : " + account.About.StorageQuota.Usage + " bytes (" + ShellUtilities.FormatByteSize(account.About.StorageQuota.Usage.Value) + ")" + ratio);
                        }

                        if (account.About.StorageQuota.UsageInDrive.HasValue)
                        {
                            AddLog(" Storage Quota Usage In Drive : " + account.About.StorageQuota.UsageInDrive + " bytes (" + ShellUtilities.FormatByteSize(account.About.StorageQuota.UsageInDrive.Value) + ")");
                        }

                        if (account.About.StorageQuota.UsageInDrive.HasValue)
                        {
                            AddLog(" Storage Quota Usage In Trash : " + account.About.StorageQuota.UsageInDriveTrash + " bytes (" + ShellUtilities.FormatByteSize(account.About.StorageQuota.UsageInDriveTrash.Value) + ")");
                        }
                    }
                }
            }
        }
Exemplo n.º 19
0
        public ServerEvents(WebShellFolderServer server)
        {
            if (server == null)
            {
                throw new ArgumentNullException(nameof(server));
            }

            Server = server;
            // build SignalR connection
            _connection = new HubConnectionBuilder()
                          .WithUrl(WebApi.RootUrl + "events")
                          .WithAutomaticReconnect()
                          .Build();

            _connection.Closed += async(error) =>
            {
                // restart
                await Task.Delay(new Random().Next(0, 5) * 1000).ConfigureAwait(false);

                await _connection.StartAsync().ConfigureAwait(false);
            };

            // must match server's IFileSystemEvents method signature
            // Change(Guid id, Guid itemId, Guid parentId, WatcherChangeTypes types, DateTime creationTimeUtc, string oldName);
            _connection.On <Guid, Guid, Guid, WatcherChangeTypes, DateTime, string, Guid?>("Change", (id, itemId, parentId, type, creationTimeUtc, oldName, oldParentId) =>
            {
                // invalidate the cache using server information
                // note we don't force files update. this will be done when the use opens it
                server.Log(System.Diagnostics.TraceLevel.Warning, "UpdateCache id: " + id + " itemId: " + itemId + " parentId: " + parentId + " type: " + type + " oldName: " + oldName + " oldParentId: " + oldParentId);
                WebApi.UpdateCache(itemId, parentId, type);

                // tell the Shell that this pidl has changed
                // which will eventually call back in views that may be opened to our folders
                var item = server.GetItem(itemId);
                if (item != null)
                {
                    if (item.IsFolder)
                    {
                        switch (type)
                        {
                        case WatcherChangeTypes.Changed:
                            ShellUtilities.ChangeNotify(SHCNE.SHCNE_UPDATEDIR, 0, item.IdList);
                            break;

                        case WatcherChangeTypes.Created:
                            ShellUtilities.ChangeNotify(SHCNE.SHCNE_MKDIR, 0, item.IdList);
                            break;

                        case WatcherChangeTypes.Deleted:
                            ShellUtilities.ChangeNotify(SHCNE.SHCNE_RMDIR, 0, item.IdList);
                            break;

                        case WatcherChangeTypes.Renamed:
                            ShellUtilities.ChangeNotify(SHCNE.SHCNE_RENAMEFOLDER, 0, item.IdList);
                            break;
                        }
                    }
                    else
                    {
                        switch (type)
                        {
                        case WatcherChangeTypes.Changed:
                            ShellUtilities.ChangeNotify(SHCNE.SHCNE_UPDATEITEM, 0, item.IdList);
                            break;

                        case WatcherChangeTypes.Created:
                            ShellUtilities.ChangeNotify(SHCNE.SHCNE_CREATE, 0, item.IdList);
                            break;

                        case WatcherChangeTypes.Deleted:
                            ShellUtilities.ChangeNotify(SHCNE.SHCNE_DELETE, 0, item.IdList);
                            break;

                        case WatcherChangeTypes.Renamed:
                            ShellUtilities.ChangeNotify(SHCNE.SHCNE_RENAMEITEM, 0, item.IdList);
                            break;
                        }
                    }
                }

                item = server.GetItem(parentId);
                if (item != null)
                {
                    ShellUtilities.ChangeNotify(SHCNE.SHCNE_UPDATEDIR, 0, item.IdList);
                }
            });

            _connection.StartAsync();
        }