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

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

            list.RemoveAt(0);
            foreach (IItemNode 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
        public static void CreateFolder(IItemNode node)
        {
            string     Email     = node.GetRoot.RootType.Email;
            DriveAPIv2 gdclient  = GetAPIv2(Email);
            string     parent_id = "";

            try
            {
                List <IItemNode> 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 <IItemNode> 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 = listnode[i].Info.ID = listsearchnode[0].Info.ID;
                        }
                    }

                    if (create)
                    {
                        Drivev2_File metadata = new Drivev2_File()
                        {
                            title = listnode[i].Info.Name
                        };
                        metadata.parents = new List <Drivev2_Parent>()
                        {
                            new Drivev2_Parent()
                            {
                                id = parent_id
                            }
                        };

                        Drivev2_File folder = gdclient.Extend.CreateFolder(metadata);
                        parent_id = listnode[i].Info.ID = folder.id;
                    }
                }
            }
            finally { Monitor.Exit(sync_createfolder); }
        }
Ejemplo n.º 3
0
        void UpdateData(IItemNode newnode)
        {
            int start_index = 0;

            if (node != null)
            {
                IItemNode 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.º 4
0
        public static void AutoCreateFolder(IItemNode node_folder_target)
        {
            List <IItemNode> 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.º 5
0
        public IItemNode MakeNodeTo(IItemNode RootFrom, IItemNode RootTo)
        {
            List <IItemNode> FullPathRootFrom = RootFrom.GetFullPath();
            List <IItemNode> NodeFullPath     = this.GetFullPath();
            CloudType        type_rootto      = RootTo.GetRoot.RootType.Type;

            for (int i = NodeFullPath.IndexOf(RootFrom) + 1; i < NodeFullPath.Count; i++)
            {
                ItemNode node = new ItemNode();
                node.Info.Size = NodeFullPath[i].Info.Size;
                node.Info.Name = (type_rootto == CloudType.LocalDisk || type_rootto == CloudType.Dropbox) ? RemoveSpecialChar(NodeFullPath[i].Info.Name) : NodeFullPath[i].Info.Name;
                RootTo.AddChild(node);
                RootTo = node;
            }
            return(RootTo);
        }
Ejemplo n.º 6
0
        public static Stream GetFileSteam(IItemNode 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 <IItemNode> 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.º 7
0
        public IItemNode FindSameParent(IItemNode othernode)
        {
            List <IItemNode> list_other = othernode.GetFullPath();
            List <IItemNode> list_this  = GetFullPath();
            IItemNode        node       = null;
            int max = list_other.Count <= list_this.Count ? list_other.Count : list_this.Count;

            for (int i = 0; i < max; i++)
            {
                if (list_other[i] == list_this[i])
                {
                    node = list_this[i];
                }
                else
                {
                    break;
                }
            }
            return(node);
        }
Ejemplo n.º 8
0
        public static string AutoCreateFolder(IItemNode node)
        {
            if (node.Info.Size > 0)
            {
                throw new Exception("Node is file.");
            }
            DropboxRequestAPIv2 client = GetAPIv2(node.GetRoot.RootType.Email);

            try
            {
                Monitor.Enter(sync_CreateFolder);

                List <IItemNode> 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.º 9
0
        void Make()
        {
            if (node == oldnode)
            {
                return;
            }
            List <IItemNode> list = node.GetFullPath();

            if (oldnode != null)                                     //old node
            {
                IItemNode 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 (IItemNode 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;
        }