Esempio n. 1
0
        private void loadLastFoldersList()
        {
            int cont    = vars.get("lastFolders.count", 0).AsInt - 1;
            int loadeds = 0;

            recentesToolStripMenuItem.DropDownItems.Clear();

            List <string> addedToMenu = new List <string>();

            while ((loadeds < 10) && (cont >= 0))
            {
                string currName = vars.get("lastFolders." + cont.ToString(), "").AsString;
                if (!addedToMenu.Contains(currName))
                {
                    addedToMenu.Add(currName);
                    EasyThread.StartNew(delegate(EasyThread thPointer, object arguments)
                    {
                        string curr = (string)((object[])arguments)[1];


                        //recentesToolStripMenuItem
                        try
                        {
                            if (Directory.Exists(curr))
                            {
                                ToolStripMenuItem temp = new ToolStripMenuItem(curr);
                                temp.Click            += delegate(object sender, EventArgs e)
                                {
                                    this.loadFolder(((ToolStripMenuItem)sender).Text);
                                };
                                this.Invoke((MethodInvoker) delegate()
                                {
                                    recentesToolStripMenuItem.DropDownItems.Add(temp);
                                });
                            }
                        }
                        catch { }
                    }, false, new object[] { cont, currName });
                }
                cont--;
            }
        }
Esempio n. 2
0
        public void loadGlobalDb(string globalDbPath)
        {
            EasyThread.StartNew(delegate(EasyThread sender, object arguments)
            {
                //define a lista de nodos atual como sendo o nodo raíz do treeview
                var parentAtt = treeView1.Nodes;

                ivk(delegate()
                {
                    progressBar1.Maximum = 1;
                    progressBar1.Value   = 0;
                    progressBar1.Show();
                });
                try
                {
                    //lista os arquivos
                    List <string> filesT = getVarsFiles(globalDbPath).ToList();
                    //filesT.Sort((item1, item2) => item1.CompareTo(item2));
                    filesT.Sort(delegate(string item1, string item2) {
                        if (item1 != null && item2 != null)
                        {
                            string[] fName1 = item1.Split(new char[] { '.', '/', '\\' });
                            string[] fName2 = item2.Split(new char[] { '.', '/', '\\' });

                            int c = 0;
                            Parallel.For(c, fName1.Length, delegate(int curr)
                            {
                                if (isNumber(fName1[curr]))
                                {
                                    fName1[curr] = int.Parse(fName1[curr]).ToString("000000000000000");
                                }
                            });

                            c = 0;
                            Parallel.For(c, fName2.Length, delegate(int curr)
                            {
                                if (isNumber(fName2[curr]))
                                {
                                    fName2[curr] = int.Parse(fName2[curr]).ToString("000000000000000");
                                }
                            });


                            string compFName1 = "";
                            foreach (var curr in fName1)
                            {
                                compFName1 += curr + ".";
                            }

                            string compFName2 = "";
                            foreach (var curr in fName2)
                            {
                                compFName2 += curr + ".";
                            }

                            return(compFName1.CompareTo(compFName2));
                        }
                        else
                        {
                            return(0);
                        }
                    });
                    string[] files = filesT.ToArray();


                    ivk(delegate()
                    {
                        treeView1.Nodes.Clear();
                        progressBar1.Maximum = files.Length;
                        //treeView1.Hide();
                    });

                    foreach (var attFname in files)
                    {
                        ivk(delegate()
                        {
                            parentAtt          = treeView1.Nodes;
                            progressBar1.Value = progressBar1.Value + 1;
                        });

                        //var att = Path.GetFileName(attFname);
                        var att = attFname.Substring(globalDbPath.Length + 1);

                        if (att.ToLower().Contains("time"))
                        {
                            ;
                        }
                        char sep = '.';
                        if (att.Contains("\\"))
                        {
                            sep = '\\';
                        }
                        else if (att.Contains("/"))
                        {
                            sep = '/';
                        }

                        string[] names      = att.Split(sep);
                        string completeName = globalDbPath + "\\";

                        foreach (var nameAtt in names)
                        {
                            completeName += nameAtt;

                            //verifica se o nome atual já está na lista parent
                            ivk(delegate()
                            {
                                if (parentAtt.ContainsKey(completeName))
                                {
                                    //define o nodo encontrado como o parentAtt
                                    parentAtt = parentAtt[parentAtt.IndexOfKey(completeName)].Nodes;
                                }
                                else
                                {
                                    //adiciona o nodo na lista e o define como parent
                                    parentAtt = parentAtt.Add(completeName, nameAtt).Nodes;
                                }
                            });
                            completeName += sep;
                            //Application.DoEvents();
                        }
                    }

                    /*ivk(delegate ()
                     * {
                     *  treeView1.TreeViewNodeSorter = new NodeSorter();
                     *  treeView1.Sort();
                     * });*/
                }
                catch { }
                ivk(delegate()
                {
                    progressBar1.Hide();
                    //treeView1.Show();
                });
            }, false);
        }
Esempio n. 3
0
        /*private void delNode(TreeNode node)
         * {
         *
         *
         *
         * // Application.DoEvents();
         *  if (node.Nodes.Count > 0)
         *  {
         *      while (node.Nodes.Count > 0)
         *          delNode(node.Nodes[0]);
         *  }
         *
         *  var parentNode = node.Parent;
         *  if (parentNode != null)
         *  {
         *      if (parentNode.Nodes.Contains(node))
         *          parentNode.Nodes.Remove(node);
         *  }
         *  else
         *  {
         *      if (treeView1.Nodes.Contains(node))
         *          treeView1.Nodes.Remove(node);
         *  }
         *
         *  if (File.Exists(node.Name))
         *  {
         *      File.Delete(node.Name);
         *  }
         *
         *
         *
         * }*/

        private void delNode(TreeNode node)
        {
            var parentNode = node.Parent;

            if (parentNode != null)
            {
                if (parentNode.Nodes.Contains(node))
                {
                    parentNode.Nodes.Remove(node);
                }
            }
            else
            {
                if (treeView1.Nodes.Contains(node))
                {
                    treeView1.Nodes.Remove(node);
                }
            }


            EasyThread.StartNew(delegate(EasyThread sender, object args)
            {
                string fName = "";
                ivk(delegate() { fName = node.Name; });

                List <string> childs = new List <string>();
                childs.Add(fName);
                Directory.GetFiles(Path.GetDirectoryName(fName), Path.GetFileName(fName) + "*").ToString();

                int max = 1;
                while (childs.Count > 0)
                {
                    if (File.Exists(childs.Last()))
                    {
                        File.Delete(childs.Last());
                        childs.RemoveAt(childs.Count - 1);
                    }
                    else if (Directory.Exists(childs.Last()))
                    {
                        var tempFiles   = Directory.GetFiles(childs.Last());
                        var tempFolders = Directory.GetDirectories(childs.Last());

                        if ((tempFiles.Length == 0) && (tempFolders.Length == 0))
                        {
                            Directory.Delete(childs.Last(), true);
                            childs.RemoveAt(childs.Count - 1);
                        }
                        else
                        {
                            childs.AddRange(tempFiles);
                            childs.AddRange(tempFolders);

                            max += tempFiles.Length + tempFolders.Length;
                        }
                    }
                    else
                    {
                        childs.RemoveAt(childs.Count - 1);
                    }

                    ivk(delegate()
                    {
                        progressBar1.Maximum = max;
                        progressBar1.Value   = max - childs.Count;
                    });
                }


                ivk(delegate()
                {
                    progressBar1.Hide();
                });
            }, false);
        }