Ejemplo n.º 1
0
        /// <summary>
        /// Načte ikonu souboru podle jeho typu
        /// </summary>
        public void LoadIcon()
        {
            if (Name == null)
            {
                return;
            }

            Icon icon;

            if (FileName != "" && File.Exists(FullPath))
            {
                icon = ShellIcon.GetSmallIcon(FullPath);
            }
            else
            {
                string ext = Path.GetExtension(Name);
                if (ext == "")
                {
                    ext = Name;
                }
                icon = ShellIcon.GetSmallIconFromExtension(ext);
            }
            var bmpSrc = Imaging.CreateBitmapSourceFromHIcon(icon.Handle, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions());

            icon.Dispose();
            Icon = bmpSrc;
        }
Ejemplo n.º 2
0
 public frmMyDlg()
 {
     InitializeComponent();
     imageList1.Images.Add(ShellIcon.GetLargeFolderIcon());
     imageList1.Images.Add(ShellIcon.GetSmallIconFromExtension(".txt"));
     fileTree.ImageList = imageList1;
     SetTree();
 }
Ejemplo n.º 3
0
        private static ListViewItem InitListviewItem(FileSystemInfo info)
        {
            var list = SmallImageList;
            var item = new ShellInfoItem(info);

            string[] row = item.ToArray();
            int      key = list.Images.IndexOfKey("unknown");

            if (info.Attributes.HasFlag(FileAttributes.Directory))
            {
                var dir = (DirectoryInfo)info;
                try
                {
                    dir.GetAccessControl();
                    if (dir.Attributes.HasFlag(FileAttributes.Hidden))
                    {
                        key = list.Images.IndexOfKey("hidden_folder");
                    }
                    else
                    {
                        key = list.Images.IndexOfKey("FolderIcon");
                    }
                }
                catch (UnauthorizedAccessException)
                {
                    //key = list.Images.IndexOfKey("locked_folder");
                    key = list.Images.IndexOfKey("LockFolder");
                }
            }
            else
            {
                var    icon = ShellIcon.GetIcon(info.FullName);
                string ext  = item.Ext;
                if (icon != null)
                {
                    AddKeyToImageList(info.FullName, icon);
                    key = list.Images.IndexOfKey(info.FullName);
                }
                else if (!String.IsNullOrEmpty(ext))
                {
                    icon = ShellIcon.GetSmallIconFromExtension(ext);
                    AddKeyToImageList(ext, icon);
                    key = list.Images.IndexOfKey(ext);
                }
            }
            var lvi = new ListViewItem(row, key)
            {
                Tag = info.FullName
            };

            return(lvi);
        }
Ejemplo n.º 4
0
        private BaseNode TraverseFileSystem(DirectoryInfo folder, BaseNode parentNode, BaseNode rootNode)
        {
            try
            {
                //if (myNode == null)
                BaseNode myNode = new FolderNode(folder);
                myNode.LoadedData = true;

                if (parentNode != null)
                {
                    parentNode.Children.Add(myNode);
                    myNode.ParentNode = parentNode;
                }
                myNode.RootNode = rootNode;

                try
                {
                    foreach (DirectoryInfo d in folder.GetDirectories())
                    {
                        //TraverseFileSystem(d, myNode, rootNode);
                        //do not go to next level, just add the first level under the current
                        BaseNode myFolderNode = new FolderNode(d);
                        myNode.Children.Add(myFolderNode);
                        myFolderNode.ParentNode = myNode;
                        myFolderNode.RootNode   = rootNode;
                    }
                }
                catch (Exception)
                {
                    //SPCoderForm.MainForm.LogException(exc);
                }


                foreach (FileInfo file in folder.GetFiles())
                {
                    BaseNode myFileNode = new FileNode(file);
                    myNode.Children.Add(myFileNode);
                    myFileNode.ParentNode = myNode;
                    myFileNode.RootNode   = rootNode;
                    try
                    {
                        //Icon icon = Icon.ExtractAssociatedIcon(file.FullName);
                        Icon icon = ShellIcon.GetSmallIconFromExtension(file.Extension);
                        myFileNode.IconObject = icon.ToBitmap();
                        if (myFileNode.IconObject.Width != 16)
                        {
                            myFileNode.IconObject = new Bitmap(myFileNode.IconObject, 16, 16);
                        }/**/
                    }
                    catch (Exception)
                    {
                        //skip if exception happens here... the default icon will be shown
                    }
                }
                return(myNode);
            }
            catch (Exception)
            {
                return(null);
                //SPCoderForm.MainForm.LogException(exc);
            }
        }
Ejemplo n.º 5
0
        public override SPCoder.Utils.Nodes.BaseNode GetSPStructure(string siteUrl)
        {
            //try get with another url (change it to api...
            string newSiteUrl = siteUrl;

            if (siteUrl.StartsWith("https://github.com"))
            {
                string contentsSufix = (siteUrl.EndsWith("/") ? "" : "/");
                newSiteUrl = "https://api.github.com/repos/" + siteUrl.Replace("https://github.com/", "") + contentsSufix + "contents/";
            }

            var ghRoot = TryGetGithubObjectWithUrl(newSiteUrl);

            if (ghRoot == null)
            {
                throw new Exception("Wrong url. Please enter valid api.github url");
            }

            GithubObject rootFolder = new GithubObject();

            if (ghRoot != null && ghRoot.Length > 0)
            {
                var      firstItem = ghRoot[0];
                string   tmpRepos  = firstItem.url.Replace(reposUrl, "");
                string[] tmpArr    = tmpRepos.Split('/');
                if (tmpArr != null && tmpArr.Length > 1)
                {
                    rootFolder.name = tmpArr[0] + " - " + tmpArr[1];
                }
                else
                {
                    rootFolder.name = tmpRepos;
                }

                rootFolder.url      = siteUrl;
                rootFolder.html_url = siteUrl.Replace("api.", "").Replace("repos/", "").Replace("contents/", "");
            }

            BaseNode rootNode = new GithubDirectoryNode(rootFolder);

            rootNode.Title         = RootNodeTitle + rootFolder.name;
            rootNode.NodeConnector = this;
            rootNode.OMType        = ObjectModelType.REMOTE;
            rootNode.LoadedData    = true;
            rootNode.IconPath      = "github.png";

            BaseNode my = new GithubDirectoryNode(rootFolder);

            my.NodeConnector = this;
            my.OMType        = ObjectModelType.REMOTE;
            my.RootNode      = rootNode;
            my.ParentNode    = rootNode;
            my.Title         = rootFolder.name;
            my.SPObject      = rootFolder;
            my.LoadedData    = true;

            rootNode.Children.Add(my);
            ghRoot = ghRoot.OrderBy(m => m.type).ThenBy(m => m.name).ToArray();

            foreach (var node in ghRoot)
            {
                BaseNode childNode = null;
                if (node.type == "file")
                {
                    childNode = new GithubFileNode(node);
                }
                else //dir
                {
                    childNode = new GithubDirectoryNode(node);
                }
                childNode.RootNode   = rootNode;
                childNode.ParentNode = my;
                childNode.SPObject   = node;

                try
                {
                    //
                    if (node.type == "file" && node.name != null && node.name.Contains("."))
                    {
                        var    els       = node.name.Split('.');
                        string extension = "." + els[els.Length - 1];
                        //Icon icon = Icon.ExtractAssociatedIcon(file.FullName);
                        Icon icon = ShellIcon.GetSmallIconFromExtension(extension);
                        childNode.IconObject = icon.ToBitmap();
                        if (childNode.IconObject.Width != 16)
                        {
                            childNode.IconObject = new Bitmap(childNode.IconObject, 16, 16);
                        }/**/
                    }
                }
                catch (Exception)
                {
                    //skip if exception happens here... the default icon will be shown
                }

                my.Children.Add(childNode);
            }


            //HtmlWeb page = new HtmlWeb();
            //HtmlDocument document = page.Load(siteUrl);
            //page.Get(siteUrl, "/");

            //rootNode.Title = page.ResponseUri.Host.ToString();



            //return rootNode;
            //rootNode.SPObject = site;
            //doPageNodes(document.DocumentNode, rootNode, rootNode);
            return(rootNode);
        }

        public override BaseNode ExpandNode(BaseNode node, bool doIfLoaded = false)
        {
            //Ako je web node
            if (node is GithubDirectoryNode)
            {
                //Ako nije ucitan
                if (!node.LoadedData)
                {
                    if (node.ParentNode.Children != null && node.ParentNode.Children.Contains(node))
                    {
                        node.ParentNode.Children.Remove(node);
                    }

                    node = doSubNodes((GithubObject)node.SPObject, node.ParentNode, node.RootNode);
                }
            }
            return(node);
        }

        private BaseNode doSubNodes(GithubObject githubNode, BaseNode parentNode, BaseNode rootNode)
        {
            try
            {
                var response = client.GetAsync(githubNode.url);
                //if (response.)

                var githubObject = response.Result.Content.ReadAsStringAsync();

                System.Web.Script.Serialization.JavaScriptSerializer ser = new System.Web.Script.Serialization.JavaScriptSerializer();
                var ghRoot = ser.Deserialize <GithubObject[]>(githubObject.Result);

                GithubObject rootFolder = new GithubObject();
                if (ghRoot != null && ghRoot.Length > 0)
                {
                    var      firstItem = ghRoot[0];
                    string   tmpRepos  = firstItem.url.Replace(reposUrl, "");
                    string[] tmpArr    = tmpRepos.Split('/');
                    if (tmpArr != null && tmpArr.Length > 1)
                    {
                        rootFolder.name = tmpArr[0] + " - " + tmpArr[1];
                    }
                    else
                    {
                        rootFolder.name = tmpRepos;
                    }
                }

                BaseNode my = new GithubDirectoryNode(rootFolder);
                my.NodeConnector = this;
                my.OMType        = ObjectModelType.REMOTE;
                my.RootNode      = rootNode;
                my.ParentNode    = rootNode;
                my.Title         = rootFolder.name;
                my.SPObject      = rootFolder;

                ghRoot = ghRoot.OrderBy(m => m.type).ThenBy(m => m.name).ToArray();
                foreach (var node in ghRoot)
                {
                    BaseNode childNode = null;
                    if (node.type == "file")
                    {
                        childNode = new GithubFileNode(node);
                    }
                    else //dir
                    {
                        childNode = new GithubDirectoryNode(node);
                    }

                    try
                    {
                        //
                        if (node.type == "file" && node.name != null && node.name.Contains("."))
                        {
                            var    els       = node.name.Split('.');
                            string extension = "." + els[els.Length - 1];
                            //Icon icon = Icon.ExtractAssociatedIcon(file.FullName);
                            Icon icon = ShellIcon.GetSmallIconFromExtension(extension);
                            childNode.IconObject = icon.ToBitmap();
                            if (childNode.IconObject.Width != 16)
                            {
                                childNode.IconObject = new Bitmap(childNode.IconObject, 16, 16);
                            }/**/
                        }
                    }
                    catch (Exception)
                    {
                        //skip if exception happens here... the default icon will be shown
                    }
                    childNode.NodeConnector = this;
                    childNode.OMType        = ObjectModelType.REMOTE;
                    childNode.RootNode      = rootNode;
                    childNode.ParentNode    = my;
                    childNode.SPObject      = node;
                    my.Children.Add(childNode);
                }
                return(my);
            }
Ejemplo n.º 6
0
        private BaseNode DoSPFolder(Microsoft.SharePoint.Client.Folder folder, BaseNode parentNode, BaseNode rootNode, bool isRoot = false)
        {
            BaseNode myNode = null;

            folder.EnsureProperties(f => f.Folders, f => f.Files, f => f.Name, f => f.ServerRelativeUrl);

            try
            {
                myNode = new FolderNode(folder);

                if (!isRoot)
                {
                    parentNode.Children.Add(myNode);
                }

                myNode.SPObject      = folder;
                myNode.ParentNode    = parentNode;
                myNode.RootNode      = rootNode;
                myNode.NodeConnector = this;
                myNode.LoadedData    = true;

                folder.Context.Load(folder.Folders);
                folder.Context.ExecuteQueryRetry();

                try
                {
                    foreach (var subfolder in folder.Folders.OrderBy(f => f.Name))
                    {
                        BaseNode childNode = new FolderNode(subfolder);
                        myNode.Children.Add(childNode);

                        childNode.SPObject      = subfolder;
                        childNode.ParentNode    = myNode;
                        childNode.RootNode      = rootNode;
                        childNode.NodeConnector = this;
                    }

                    foreach (var file in folder.Files.OrderBy(f => f.Name))
                    {
                        BaseNode fileNode = new FileNode(file);
                        myNode.Children.Add(fileNode);

                        fileNode.SPObject      = file;
                        fileNode.ParentNode    = parentNode;
                        fileNode.RootNode      = rootNode;
                        fileNode.NodeConnector = this;

                        try
                        {
                            //
                            if (fileNode.Title != null && fileNode.Title.Contains("."))
                            {
                                var    els       = fileNode.Title.Split('.');
                                string extension = "." + els[els.Length - 1];
                                //Icon icon = Icon.ExtractAssociatedIcon(file.FullName);
                                Icon icon = ShellIcon.GetSmallIconFromExtension(extension);
                                fileNode.IconObject = icon.ToBitmap();
                                if (fileNode.IconObject.Width != 16)
                                {
                                    fileNode.IconObject = new Bitmap(fileNode.IconObject, 16, 16);
                                }/**/
                            }
                        }
                        catch (Exception)
                        {
                            //skip if exception happens here... the default icon will be shown
                        }
                    }
                }
                catch
                {
                    return(myNode);
                }
            }
            catch
            {
                return(myNode);
            }

            return(myNode);
        }
Ejemplo n.º 7
0
        void UpdateResultView()
        {
            if (null == ArrDirsFound || null == ArrFilesFound)
            {
                return;
            }

            List <ListViewItem> lvwItems = new List <ListViewItem>();
            ListViewItem        lvwItem  = null;

            foreach (DirectoryInfo dir in ArrDirsFound)
            {
                string[] row = { dir.FullName };

                try
                {
                    // check for accessing power through exception
                    dir.GetAccessControl();
                    if (dir.Attributes.HasFlag(FileAttributes.Hidden))
                    {
                        lvwItem = new ListViewItem(row, "hidden_folder");
                    }
                    else
                    {
                        lvwItem = new ListViewItem(row, "FolderIcon");
                    }
                }
                catch (UnauthorizedAccessException)
                {
                    lvwItem = new ListViewItem(row, "locked_folder");
                }
                lvwItem.Tag = dir.FullName; // save fullpath to item

                lvwItems.Add(lvwItem);
            }

            foreach (FileInfo file in ArrFilesFound)
            {
                string[] row = { file.FullName };

                // Check to see if the image collection contains an image
                // for this extension, using the extension as a key.
                Icon   icon = ShellIcon.GetIcon(file.FullName);
                string ext  = file.Extension.Replace(".", "");
                if (icon != null)
                {
                    AddKeyToImageList(file.FullName, icon);
                    lvwItem = new ListViewItem(row, file.FullName);
                }
                else if (!String.IsNullOrEmpty(ext))
                {
                    //Icon iconExt = Icon.ExtractAssociatedIcon(file.FullName);
                    Icon iconExt = ShellIcon.GetSmallIconFromExtension(ext);
                    AddKeyToImageList(ext, iconExt);
                    lvwItem = new ListViewItem(row, ext);
                }
                else
                {
                    lvwItem = new ListViewItem(row, "unknown"); // unknow file icon
                }
                lvwItem.Tag = file.FullName;
                lvwItems.Add(lvwItem);
            }

            lvwViewer.Items.Clear();
            lvwViewer.BeginUpdate();
            lvwViewer.Items.AddRange(lvwItems.ToArray());
            lvwViewer.EndUpdate();
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Default handler.Nothing to do here since we don't need to repaint the button.
        /// </summary>
        /// <param name="pe"></param>
        protected override void OnPaint(PaintEventArgs pe)
        {
            base.OnPaint(pe);
            // BEWARE, ORDER IN WICH ELEMENTS ARE PROCESSED HERE AFFECTS THE VISIBILIVTY. DEEPER LAYERS FIRST.
            //1.BACKGROUND
            //2.BORDER
            //3.ICON (if any)
            //4.TEXT
            //5.CROSS (if any)
            Rectangle rFondo = this.DisplayRectangle; //ESTE ES TODO EL ÁREA DEL CONTROL

            //rect = this.ClientRectangle; //ESTE ES LA PARTE VISIBLE SOLO (UN PANEL CON SCROLL BARS SOLO MUESTRA CLIENTRECTANGLE)
            rFondo.X      += 1;
            rFondo.Y      += 1;
            rFondo.Width  -= 2;
            rFondo.Height -= 2;
            Color colorBgToken;
            Color colorBorder;
            Color colorText;
            Font  fontText;

            if (this.isBeingHovered)
            {
                colorBgToken = TokenColorHovered;
                colorBorder  = BorderColorHovered;
                colorText    = ForeColorHovered;
                fontText     = FontHovered;
            }
            else
            {
                colorBgToken = TokenColor;
                colorBorder  = BorderColor;
                colorText    = ForeColor;
                fontText     = Font;
            }

            using (GraphicsPath bb = GetPathRoundCorners(rFondo, Radius))
            {
                //BACKGROUND
                using (Brush br = new SolidBrush(colorBgToken))
                {
                    pe.Graphics.SmoothingMode     = SmoothingMode.HighQuality;
                    pe.Graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
                    pe.Graphics.FillPath(br, bb);
                }

                //BORDER
                using (Brush br = new SolidBrush(colorBorder))
                {
                    pe.Graphics.SmoothingMode     = SmoothingMode.HighQuality;
                    pe.Graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
                    pe.Graphics.DrawPath(new Pen(br, BorderWidth), bb);
                }
            }
            //ICON
            if (this.ShowFileIcon)
            {
                try
                {
                    if (FileExtensionToShow == string.Empty)
                    {
                        pe.Graphics.DrawIcon(Resources.unknownFile, rIcon);
                    }
                    else
                    {
                        Icon ic = ShellIcon.GetSmallIconFromExtension(FileExtensionToShow);
                        pe.Graphics.DrawIcon(ic, rIcon);
                    }
                }
                catch
                {
                    pe.Graphics.DrawIcon(Resources.unknownFile, rIcon);
                }
            }
            //TEXT
            pe.Graphics.TextRenderingHint = System.Drawing.Text.TextRenderingHint.ClearTypeGridFit;
            pe.Graphics.DrawString(this.Text, fontText, new SolidBrush(colorText), rText);

            //CROSS
            if (this.ShowsX)
            {
                if (isBeingHovered)
                {
                    pe.Graphics.DrawImage(Resources.CrossRed, rCloseX);
                }
                else
                {
                    pe.Graphics.DrawImage(Resources.CrossBlack, rCloseX);
                }
            }
        }