Ejemplo n.º 1
0
        public static void AutoCreateFolder(ExplorerNode node)
        {
            List <ExplorerNode> list = node.GetFullPath();

            if (list[0].NodeType.Type != CloudType.Mega)
            {
                throw new Exception("Mega only.");
            }
            MegaApiClient client = GetClient(list[0].NodeType.Email);

            list.RemoveAt(0);
            foreach (ExplorerNode child in list)
            {
                if (string.IsNullOrEmpty(child.Info.ID))
                {
                    MegaNzNode m_p_node = new MegaNzNode(child.Parent.Info.ID);
                    INode      c_node   = client.GetNodes(m_p_node).Where(n => n.Name == child.Info.Name).First();//find
                    if (c_node == null)
                    {
                        c_node = client.CreateFolder(child.Info.Name, m_p_node);               //if not found -> create
                    }
                    child.Info.ID = c_node.Id;
                }
            }
        }
Ejemplo n.º 2
0
        void UpdateData(ExplorerNode newnode)
        {
            int start_index = 0;

            if (node != null)
            {
                ExplorerNode sameparent = newnode.FindSameParent(node);
                if (sameparent == null)
                {
                    start_index = node.GetFullPath().IndexOf(node.GetFullPath().Find(n => n == sameparent)) + 1;
                }
                while (Source.Count - 1 >= start_index)
                {
                    Source.RemoveAt(start_index);
                }
            }
            newnode.GetFullPath().ForEach(n => { Source.Add(new ComboBoxData(n)); });
            if (Source.Count >= 0)
            {
                comboBox.SelectedIndex = Source.Count - 1;
            }
        }
Ejemplo n.º 3
0
        public static void AutoCreateFolder(ExplorerNode node_folder_target)
        {
            List <ExplorerNode> nodelist = node_folder_target.GetFullPath();
            DirectoryInfo       dinfo;

            for (int i = 1; i < nodelist.Count; i++)
            {
                dinfo = new DirectoryInfo(nodelist[i].GetFullPathString());
                if (!dinfo.Exists)
                {
                    dinfo.Create();
                }
            }
        }
Ejemplo n.º 4
0
        public static void CreateFolder(ExplorerNode node)
        {
            string Email = node.GetRoot.NodeType.Email;
            DriveAPIHttprequestv2 gdclient = GetAPIv2(Email);
            string parent_id = "";

            try
            {
                List <ExplorerNode> listnode = node.GetFullPath();
                Monitor.Enter(sync_createfolder);
                int i;
                for (i = listnode.Count - 1; i > 0; i--)
                {
                    if (!string.IsNullOrEmpty(listnode[i].Info.ID))
                    {
                        parent_id = listnode[i].Info.ID; break;
                    }
                }
                i++;
                bool create = false;
                for (; i < listnode.Count; i++)
                {
                    if (!create)
                    {
                        List <ExplorerNode> listsearchnode = Search("'" + parent_id + "' in parents" +
                                                                    " and trashed=false" +
                                                                    " and title='" + listnode[i].Info.Name.Replace("'", "\\'") + "'" +
                                                                    " and mimeType = 'application/vnd.google-apps.folder'", Email).Convert(node);
                        if (listsearchnode.Count == 0)
                        {
                            create = true;
                        }
                        else
                        {
                            parent_id = listsearchnode[0].Info.ID;
                        }
                    }

                    if (create)
                    {
                        gdclient.Extend.CreateFolder(listnode[i].Info.Name, parent_id);
                    }
                }
            }
            finally { Monitor.Exit(sync_createfolder); }
        }
Ejemplo n.º 5
0
        public static Stream GetFileSteam(ExplorerNode node, bool GetfileForUpload, long Startpos = 0)
        {
            string     path = node.GetFullPathString();
            FileInfo   info = new FileInfo(path);
            FileStream fs;

            if (GetfileForUpload)
            {
                if (!info.Exists)
                {
                    throw new FileNotFoundException("File not found", path);
                }
                if (info.Length == 0)
                {
                    throw new Exception("File size = 0");
                }
                fs = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read);
                if (Startpos >= 0)
                {
                    fs.Seek(Startpos, SeekOrigin.Begin);
                }
                return(fs);
            }
            else if (!info.Exists)
            {
                List <ExplorerNode> nodelist = node.GetFullPath();
                DirectoryInfo       dinfo;
                for (int i = 1; i < nodelist.Count - 1; i++)
                {
                    dinfo = new DirectoryInfo(nodelist[i].GetFullPathString());
                    if (!dinfo.Exists)
                    {
                        dinfo.Create();
                    }
                }
            }
            fs = new FileStream(path, FileMode.OpenOrCreate, FileAccess.Write);
            if (Startpos >= 0)
            {
                fs.Seek(Startpos, SeekOrigin.Begin);
            }
            return(fs);
        }
Ejemplo n.º 6
0
        public static string AutoCreateFolder(ExplorerNode node)
        {
            if (node.Info.Size > 0)
            {
                throw new Exception("Node is file.");
            }
            DropboxRequestAPIv2 client = GetAPIv2(node.GetRoot.NodeType.Email);

            try
            {
                Monitor.Enter(sync_CreateFolder);

                List <ExplorerNode> pathlist = node.GetFullPath();
                int i;
                for (i = 1; i < pathlist.Count; i++)
                {
                    try
                    {
                        client.ListFolder(new Dropbox_Request_ListFolder(pathlist[i].GetFullPathString(false)));
                    }
                    catch (HttpException ex)
                    {
                        if (ex.ErrorCode == 409)
                        {
                            break;
                        }
                        throw ex;
                    }
                }
                for (; i < pathlist.Count; i++)
                {
                    client.create_folder(new Dropbox_path(pathlist[i].GetFullPathString(false)));
                }
                return(pathlist[i - 1].GetFullPathString(false));
            }
            finally { Monitor.Exit(sync_CreateFolder); }
        }
Ejemplo n.º 7
0
        void Make()
        {
            if (node == oldnode)
            {
                return;
            }
            List <ExplorerNode> list = node.GetFullPath();

            if (oldnode != null)                                        //old node
            {
                ExplorerNode sameparent = oldnode.FindSameParent(node); //find sameparent (new node and old node)
                if (sameparent != null)
                {
                    if (list.Count < oldnode.GetFullPath().Count)
                    {
                        up = false;                                                             //explorer to child or parent?
                    }
                    int index = list_n_uc.IndexOf(list_n_uc.Find(uc => uc.Node == sameparent)); //find index sameparent at list showing
                    if (index < list_n_uc.Count && list_n_uc.Count >= 1)                        //remove from (index +1) to (Count -1) at list showing
                    {
                        int i = index + 1;
                        while (i < list_n_uc.Count)
                        {
                            this.Controls.Remove(list_n_uc[i]);
                            list_n_uc.RemoveAt(i);
                        }
                    }
                    list.RemoveRange(0, list.IndexOf(sameparent) + 1);//remove from [root to sameparent] of newlist (need from (index +1) to  (Count -1))


                    //while (list_n_uc[list_n_uc.Count-1].Location.X + list_n_uc[list_n_uc.Count-1].Width > this.Width)
                    //{

                    //}
                }
                else//if not sameparent then clear all
                {
                    list_n_uc.ForEach(n => this.Controls.Remove(n));
                    list_n_uc.Clear();
                }
            }
            foreach (ExplorerNode n in list)//add
            {
                LabelNode n_uc = new LabelNode(n);
                n_uc.Dock     = DockStyle.Left;
                n_uc.AutoSize = true;
                n_uc.Margin   = new Padding(2, 0, 2, 0);
                n_uc.Click   += N_uc_Click;
                n_uc.Padding  = new Padding(0);
                list_n_uc.Add(n_uc);
                this.Controls.Add(n_uc);
                n_uc.BringToFront();
                while (n_uc.Location.X + n_uc.Width > this.Width)
                {
                    try
                    {
                        list_n_uc[list_n_uc_HideIndex].Hide();
                        list_n_uc_HideIndex++;
                    }
                    catch { break; }
                }
            }
            oldnode = node;
        }