Ejemplo n.º 1
0
        public static GD_item MoveItem(ExplorerNode nodemove, ExplorerNode newparent, string newname = null, bool copy = false)
        {
            //Same account
            if (nodemove.GetRoot.NodeType.Email != newparent.GetRoot.NodeType.Email)
            {
                throw new Exception("Email not match.");
            }
            if (nodemove.GetRoot.NodeType.Type != newparent.GetRoot.NodeType.Type)
            {
                throw new Exception("TypeCloud not match.");
            }

            DriveAPIHttprequestv2 gdclient = GetAPIv2(nodemove.GetRoot.NodeType.Email);
            GD_item item_metadata          = JsonConvert.DeserializeObject <GD_item>(gdclient.Files.Patch(nodemove.Info.ID));

            if (nodemove.Parent != newparent)
            {
                if (!copy)
                {
                    foreach (GD_parent parent in item_metadata.parents)
                    {
                        if (parent.id == nodemove.Parent.Info.ID)
                        {
                            item_metadata.parents.Remove(parent);
                            break;
                        }
                    }
                }
                bool isroot = false;
                if (AppSetting.settings.GetCloudRootNode(gdclient.Token.Email, CloudType.GoogleDrive).Info.ID == newparent.Parent.Info.ID)
                {
                    isroot = true;
                }
                item_metadata.parents.Add(new GD_parent()
                {
                    id = newparent.Parent.Info.ID, isRoot = isroot
                });
            }
            if (newname != null)
            {
                item_metadata.title = newname;
            }
            return(JsonConvert.DeserializeObject <GD_item>(gdclient.Files.Patch(nodemove.Info.ID, JsonConvert.SerializeObject(item_metadata))));
        }
Ejemplo n.º 2
0
        public ExplorerNode GetFileInfo(ExplorerNode node)
        {
            switch (node.GetRoot.NodeType.Type)
            {
            case CloudType.Dropbox:
                return(Dropbox.GetMetaData(node));

            case CloudType.GoogleDrive:
                GD_item item = GoogleDrive.GetMetadataItem(node);
                node.Info.Size    = item.fileSize;
                node.Info.Name    = item.title;
                node.Info.DateMod = DateTime.Parse(item.modifiedDate);
                return(node);

            case CloudType.LocalDisk:
                return(LocalDisk.GetFileInfo(node));

            case CloudType.Mega:
                return(MegaNz.GetItem(node));

            default:
                throw new UnknowCloudNameException("Error Unknow Cloud Type: " + node.GetRoot.NodeType.Type.ToString());
            }
        }
Ejemplo n.º 3
0
        public static ExplorerNode GetListFileFolder(ExplorerNode node, bool folderonly = false, bool read_only = false)
        {
            bool         uri       = false;
            ExplorerNode root      = node.GetRoot;
            string       Email     = root.NodeType.Email;
            string       parent_ID = null;
            string       url       = null;
            Regex        rg;
            Match        match;

            if (string.IsNullOrEmpty(Email))
            {
                Email = AppSetting.settings.GetDefaultCloud(CloudType.GoogleDrive); uri = true;
            }

            //Find id folder
            if (uri)//folder url
            {
                if (root.NodeType.uri != null)
                {
                    url   = root.NodeType.uri.ToString();
                    rg    = new Regex(Rg_url_idFolder);
                    match = rg.Match(url);
                    if (match.Success)
                    {
                        parent_ID = match.Value;
                    }
                    else
                    {
                        rg    = new Regex(Rg_url_idFolderOpen);
                        match = rg.Match(url);
                        if (match.Success)
                        {
                            parent_ID = match.Value;
                        }
                    }
                }
            }
            else//explorer node
            {
                parent_ID = "root";//root
                if (!string.IsNullOrEmpty(node.Info.ID))
                {
                    parent_ID = node.Info.ID;                                     //id root or id node
                }
            }

            //if found id is folder
            if (!string.IsNullOrEmpty(parent_ID))
            {
                GD_Files_list list_ = Search("'" + parent_ID + "' in parents and trashed=false", Email);
                if (parent_ID == "root")//save root id
                {
                    foreach (GD_item item in list_.items)
                    {
                        foreach (GD_parent parent in item.parents)
                        {
                            if (parent.isRoot)
                            {
                                parent_ID = parent.id; break;
                            }
                        }
                        if (parent_ID != "root")
                        {
                            break;
                        }
                    }
                    node.Info.ID = parent_ID;
                    AppSetting.settings.SetRootID(Email, CloudType.GoogleDrive, parent_ID);
                }
                node.RenewChilds(list_.Convert(node));
                return(node);
            }
            else if (string.IsNullOrEmpty(url))
            {
                rg    = new Regex(Rg_url_idFile);
                match = rg.Match(url);
                if (match.Success)
                {
                    ExplorerNode n = new ExplorerNode();
                    n.Info.ID        = match.Value;
                    n.NodeType.Email = Email;
                    GD_item item = GoogleDrive.GetMetadataItem(n);
                    n.Info.Size     = item.fileSize;
                    n.Info.Name     = item.title;
                    n.Info.MimeType = item.mimeType;
                    AppSetting.UIMain.FileSaveDialog(PCPath.Mycomputer, item.title, PCPath.FilterAllFiles, n);
                    return(null);
                }
            }
            throw new Exception("Can't Analyze Data Input.");
        }