コード例 #1
0
ファイル: NodeManager.cs プロジェクト: sebclarke/Glomp
        public static float[] GetColourForNode(FileNode node)
        {
            if(node.Description.Length > 0) {
                // step 1, calculate MD5 hash from input
                System.Security.Cryptography.MD5 md5 = System.Security.Cryptography.MD5.Create();
                byte[] inputBytes = System.Text.Encoding.ASCII.GetBytes(COLOUR_SALT + node.Description);
                byte[] hash = md5.ComputeHash(inputBytes);

                // step 2, extract last 3 bytes from string
                float[] returnable = new float[3];
                returnable[0] = (((int)hash[hash.Length-1])/700.0f) + 0.3f;
                returnable[1] = (((int)hash[hash.Length-2])/700.0f) + 0.4f;
                returnable[2] = (((int)hash[hash.Length-3])/700.0f) + 0.4f;
                return returnable;

            } else {
                float[] returnable = {0.2f, 0.6f, 0.6f};
                return returnable;
            }
        }
コード例 #2
0
ファイル: NodeManager.cs プロジェクト: sebclarke/Glomp
        public static FileNode GetFileNode(int nodeType, String fileName, FileSlice owner)
        {
            int fileDisplayList;

            if(listGenerated[nodeType]) {
                fileDisplayList = displayLists[nodeType];
            } else {
                fileDisplayList = displayLists[nodeType] = GenerateDisplayList(nodeType);
            }

            GLib.File fi = GLib.FileFactory.NewForPath(fileName);

            FileNode node = new FileNode(fi.Basename);
            node.File = fileName;
            //node.NumChildren = fi.
            GLib.FileInfo info = fi.QueryInfo("access::can-execute,thumbnail::path,filesystem::readonly,time::modified", GLib.FileQueryInfoFlags.None, null);
            node.SetDisplayList(fileDisplayList);

            node.SetParent(owner);

            if(nodeType == DIR_NODE) {
                node.IsDirectory = true;
                try {
                    node.NumDirs = Directory.GetDirectories(fileName).Length;
                    node.NumFiles = Directory.GetFiles(fileName).Length;
                    node.NumChildren = node.NumDirs + node.NumFiles;
                    node.DirHeight = GetHeightForFolder(node.NumChildren);
                } catch {
                    node.NumChildren = 0;
                    node.DirHeight = 1f;
                }
            } else {
                String description = Gnome.Vfs.Mime.GetDescription(fi.QueryInfo("standard::content-type", GLib.FileQueryInfoFlags.None, null).ContentType);
                if(description == null) {
                    // use the extension
                    String[] split = node.FileName.Split('.');
                    if(split.Length > 1) {
                        description = split[split.Length-1] + " file";
                    } else {
                        // no extension either
                        description = "unknown";
                    }
                }
                node.Description = description;

                if(info.GetAttributeBoolean("filesystem::readonly")) {
                    node.IsReadOnly = true;
                } else if(info.GetAttributeBoolean("access::can-execute")) {
                    node.IsExecutable = true;
                } else {
                    node.TypeColour = NodeManager.GetColourForNode(node);
                }
            }

            node.ModifyTime = ConvertFromUnixTimestamp(Convert.ToUInt64(info.GetAttributeAsString("time::modified")));
            //Console.WriteLine(node.File + " : " + node.ModifyTime.ToString("MMMM dd, yyyy"));

            string previewPath = info.GetAttributeByteString("thumbnail::path");
            if(previewPath != null) {
                node.ThumbFileName = previewPath;
            }

            return node;
        }
コード例 #3
0
ファイル: FileSlice.cs プロジェクト: sebclarke/Glomp
        public bool MoveCarat(int xMove, int yMove)
        {
            // check that we stay in our grid
            int targetX = activeBox[X] + xMove;
            int targetY = activeBox[Y] + yMove;
            if( (targetX < 0 || targetX > gridWidth-1) || (targetY < 0 || targetY > gridHeight-1) ) {
                return false;
            }

            // check that we have a file under us
            try {
                toNode = fileNodes[(targetY * gridWidth) + targetX];
            } catch {
                return false;
            }

            fileNodes[(activeBox[Y] * gridWidth) + activeBox[X]].Active = false;
            activeBox[X] += xMove;
            activeBox[Y] += yMove;
            toNode.Active = true;
            return true;
        }
コード例 #4
0
        public void ResetVisible()
        {
            // caclulate x,ys for visible nodes
            if (showAllText)
            {
                return;
            }
            int[] minBox = { activeBox[X] + leftVisible, activeBox[Y] + backVisible };
            int[] maxBox = { activeBox[X] + rightVisible, activeBox[Y] + forwardVisible };

            int      genCounter  = 0;
            int      destCounter = 0;
            FileNode myNode      = null;

            // for all visible nodes
            for (int y = minBox[Y]; y < maxBox[Y]; y++)
            {
                // sanity check
                if ((y < 0 || y > gridHeight - 1))
                {
                    continue;
                }

                for (int x = minBox[X]; x < maxBox[X]; x++)
                {
                    // sanity check
                    if ((x < 0 || x > gridWidth - 1))
                    {
                        continue;
                    }

                    // try to get a fileNode for these coords
                    try {
                        myNode = fileNodes[(y * gridWidth) + x];
                    } catch {
                        continue;
                    }

                    if (!myNode.Visible)
                    {
                        myNode.Visible = true;
                        myNode.GenTexture(false);
                        genCounter++;
                    }
                }
            }

            // for all other positions
            for (int i = 0; i < fileNodes.Length; i++)
            {
                int x = i % gridWidth;
                int y = i / gridWidth;

                // dont include visible ones!
                if ((y >= minBox[Y] && y <= maxBox[Y]) && (x >= minBox[X] && x <= maxBox[X]))
                {
                    continue;
                }

                myNode = fileNodes[i];

                if (myNode.Visible)
                {
                    myNode.Visible = false;
                    myNode.DestroyTexture();
                    destCounter++;
                }
            }

            System.Console.WriteLine("Generated " + genCounter + " textures.");
            System.Console.WriteLine("Destroyed " + destCounter + " textures.");
        }
コード例 #5
0
        public FileSlice(String _path, int _sliceHeight, MainWindow parent)
            : base()
        {
            path         = _path;
            sliceHeight  = _sliceHeight;
            parentWindow = parent;

            LinkedList <String> files   = new LinkedList <String>();
            LinkedList <String> folders = new LinkedList <String>();

            // prune hidden files
            if (!showHidden)
            {
                String[] rawFiles   = Directory.GetFiles(path);
                String[] rawFolders = Directory.GetDirectories(path);
                Array.Sort(rawFiles);
                Array.Sort(rawFolders);

                foreach (var file in rawFiles)
                {
                    if (!file.Replace(path, "").StartsWith("/."))
                    {
                        files.AddLast(file);
                    }
                }
                foreach (var file in rawFolders)
                {
                    if (!file.Replace(path, "").StartsWith("/."))
                    {
                        folders.AddLast(file);
                    }
                }
            }
            else
            {
                files   = new LinkedList <String>(Directory.GetFiles(path));
                folders = new LinkedList <String>(Directory.GetDirectories(path));
            }

            // set up storage
            fileNodes = new FileNode[files.Count + folders.Count];
            numFiles  = fileNodes.Length;

            // decide if we will show all the labels, or just the ones near us
            if (fileNodes.Length < SHOW_ALL_LIMIT)
            {
                showAllText = true;
            }

            int nodeCount = 0;

            if (numFiles > 0)
            {
                // set up width and height in boxes
                gridWidth  = (int)Math.Round(Math.Sqrt(fileNodes.Length) / ASPECT_COEFF, 0);
                gridHeight = fileNodes.Length / gridWidth;
                if (fileNodes.Length % gridHeight > 0)
                {
                    gridHeight += 1;
                }

                // generate the nodes
                foreach (var folder in folders)
                {
                    FileNode node      = NodeManager.GetFileNode(NodeManager.DIR_NODE, folder, this);
                    float    xPosition = STARTX - ((nodeCount % gridWidth) * BOX_SPACING);
                    float    zPosition = STARTZ + ((nodeCount / gridWidth) * BOX_SPACING);
                    node.Position = new Vector3(xPosition, STARTY, zPosition);
                    if (nodeCount == 0)
                    {
                        node.Active = true;
                    }
                    fileNodes[nodeCount] = node;
                    nodeCount++;
                }

                foreach (var file in files)
                {
                    FileNode node      = NodeManager.GetFileNode(NodeManager.FILE_NODE, file, this);
                    float    xPosition = STARTX - ((nodeCount % gridWidth) * BOX_SPACING);
                    float    zPosition = STARTZ + ((nodeCount / gridWidth) * BOX_SPACING);

                    node.Position = new Vector3(xPosition, STARTY, zPosition);
                    if (nodeCount == 0)
                    {
                        node.Active = true;
                    }
                    fileNodes[nodeCount] = node;
                    nodeCount++;
                }
            }
            if (showAllText)
            {
                GenerateAllTextures();
            }
            else
            {
                ResetVisible();
            }
        }
コード例 #6
0
ファイル: NodeManager.cs プロジェクト: dardevelin/Glomp
        public static FileNode GetFileNode(int nodeType, String fileName, FileSlice owner)
        {
            int fileDisplayList;

            if (listGenerated[nodeType])
            {
                fileDisplayList = displayLists[nodeType];
            }
            else
            {
                fileDisplayList = displayLists[nodeType] = GenerateDisplayList(nodeType);
            }


            GLib.File fi = GLib.FileFactory.NewForPath(fileName);

            FileNode node = new FileNode(fi.Basename);

            node.File = fileName;
            //node.NumChildren = fi.
            GLib.FileInfo info = fi.QueryInfo("access::can-execute,thumbnail::path,filesystem::readonly,time::modified", GLib.FileQueryInfoFlags.None, null);
            node.SetDisplayList(fileDisplayList);

            node.SetParent(owner);

            if (nodeType == DIR_NODE)
            {
                node.IsDirectory = true;
                try {
                    node.NumDirs     = Directory.GetDirectories(fileName).Length;
                    node.NumFiles    = Directory.GetFiles(fileName).Length;
                    node.NumChildren = node.NumDirs + node.NumFiles;
                    node.DirHeight   = GetHeightForFolder(node.NumChildren);
                } catch {
                    node.NumChildren = 0;
                    node.DirHeight   = 1f;
                }
            }
            else
            {
                String description = Gnome.Vfs.Mime.GetDescription(fi.QueryInfo("standard::content-type", GLib.FileQueryInfoFlags.None, null).ContentType);
                if (description == null)
                {
                    // use the extension
                    String[] split = node.FileName.Split('.');
                    if (split.Length > 1)
                    {
                        description = split[split.Length - 1] + " file";
                    }
                    else
                    {
                        // no extension either
                        description = "unknown";
                    }
                }
                node.Description = description;

                if (info.GetAttributeBoolean("filesystem::readonly"))
                {
                    node.IsReadOnly = true;
                }
                else if (info.GetAttributeBoolean("access::can-execute"))
                {
                    node.IsExecutable = true;
                }
                else
                {
                    node.TypeColour = NodeManager.GetColourForNode(node);
                }
            }


            node.ModifyTime = ConvertFromUnixTimestamp(Convert.ToUInt64(info.GetAttributeAsString("time::modified")));
            //Console.WriteLine(node.File + " : " + node.ModifyTime.ToString("MMMM dd, yyyy"));

            string previewPath = info.GetAttributeByteString("thumbnail::path");

            if (previewPath != null)
            {
                node.ThumbFileName = previewPath;
            }

            return(node);
        }
コード例 #7
0
        public int GetFileNode(FileSystemInfo element, ParallelLoopState loopState, int elementsCount)
        {
            Trace.WriteLine("GetFileNode");
            String fileNodeBaseName = null;         //only file name without path
            String fileNodeName     = null;         //full path

            DirectoryInfo folder = null;
            FileInfo      file   = null;
            Node          node   = null;

            // Determine if entry is really a directory
            if ((element.Attributes & FileAttributes.Directory) == FileAttributes.Directory)
            {
                folder           = (DirectoryInfo)element;
                fileNodeBaseName = folder.Name;
                fileNodeName     = folder.FullName;
                node             = new DirectoryNode(fileNodeBaseName);

                try {
                    ((DirectoryNode)node).NumDirs     = folder.EnumerateDirectories().Count();
                    ((DirectoryNode)node).NumFiles    = folder.EnumerateFiles().Count();
                    ((DirectoryNode)node).NumChildren = ((DirectoryNode)node).NumDirs + ((DirectoryNode)node).NumFiles;
                    ((DirectoryNode)node).DirHeight   = ((DirectoryNode)node).GetHeightForFolder(((DirectoryNode)node).NumChildren);
                } catch {
                    ((DirectoryNode)node).NumChildren = 0;
                    ((DirectoryNode)node).DirHeight   = 1f;
                }

                // Creation, last access, and last write time
                node.CreationTime   = folder.CreationTime;
                node.LastAccessTime = folder.LastAccessTime;
                node.ModifyTime     = folder.LastWriteTime;
            }
            else                 //FileNode
            {
                file             = (FileInfo)element;
                fileNodeBaseName = file.Name;
                fileNodeName     = file.FullName;
                node             = new FileNode(fileNodeBaseName);
                ((FileNode)node).FileExtension = (file.Extension != string.Empty) ? file.Extension.Substring(1) : string.Empty; //without dot
                ((FileNode)node).Description   = ((FileNode)node).GetMIMEDescription(file.Extension);                           //This will show what type of file it is
                ((FileNode)node).IsReadOnly    = file.IsReadOnly;
                ((FileNode)node).IsExecutable  = (((FileNode)node).FileExtension == "exe");

                //Getting file's ThumbNail (using Windows API Code Pack 1.1)
                ShellObject nodeFile = ShellObject.FromParsingName(fileNodeName);
                nodeFile.Thumbnail.FormatOption = ShellThumbnailFormatOption.ThumbnailOnly;
                try {
                    ((FileNode)node).ThumbBmp = nodeFile.Thumbnail.Bitmap;
                } catch {
                    //NotSupportedException
                    System.Diagnostics.Debug.WriteLine("Error getting the thumbnail. The selected file does not have a valid thumbnail or thumbnail handler.");

                    // If we get an InvalidOperationException and our mode is Mode.ThumbnailOnly,
                    // then we have a ShellItem that doesn't have a thumbnail (icon only).
                    ((FileNode)node).ThumbBmp = null;
                }

                // Creation, last access, and last write time
                node.CreationTime   = file.CreationTime;
                node.LastAccessTime = file.LastAccessTime;
                node.ModifyTime     = file.LastWriteTime;
            }

            node.File = fileNodeName;
            node.SetParent(this);

            lock (this) {             //Locking is needed, as file nodes are being created asynchronously by parallel calls from GetFileNodesCollectionFromLocation()
                if (fileNodes != null)
                {
                    Array.Resize(ref fileNodes, fileNodes.Length + 1);
                    fileNodes[fileNodes.Length - 1] = node;
                }
                else
                {
                    fileNodes     = new Node[1];
                    fileNodes [0] = node;
                }
            }

            return(++elementsCount);
        }