Example #1
0
        public static bool Move(ExplorerNode nodemove, ExplorerNode newparent, string newname = null)
        {
            if (nodemove.GetRoot.NodeType.Email != newparent.GetRoot.NodeType.Email || nodemove.GetRoot.NodeType.Type != newparent.GetRoot.NodeType.Type)
            {
                throw new Exception("Cloud not match.");
            }
            DropboxRequestAPIv2        client   = GetAPIv2(nodemove.GetRoot.NodeType.Email);
            IDropbox_Response_MetaData metadata = client.move(
                new Dropbox_Request_MoveCopy(nodemove.GetFullPathString(false),
                                             newparent.GetFullPathString(false) + "/" + newname == null ? nodemove.Info.Name : newname
                                             ));

            return(newparent.GetFullPathString(false) == metadata.path_display);
        }
Example #2
0
        public static bool Delete(ExplorerNode node, bool PernamentDelete)
        {
            string path = node.GetFullPathString();

            if (PernamentDelete)//delete
            {
                FileInfo info = new FileInfo(path);
                if (info.Exists)
                {
                    info.Delete();
                    return(true);
                }
                else
                {
                    DirectoryInfo dinfo = new DirectoryInfo(path);
                    if (dinfo.Exists)
                    {
                        dinfo.Delete(true);
                        return(true);
                    }
                }
                return(false);
            }
            else//trash
            {
                return(FileOperationAPIWrapper.SendRecycleBin(path));
            }
        }
Example #3
0
        public static ExplorerNode GetListFileFolder(ExplorerNode node)
        {
            string path = node.GetFullPathString();

            node.Child.Clear();
            foreach (string item in Directory.GetDirectories(path))
            {
                DirectoryInfo info = new DirectoryInfo(item);
                if (CheckAttribute(info.Attributes, FileAttributes.System) | CheckAttribute(info.Attributes, FileAttributes.Offline))
                {
                    continue;
                }
                ExplorerNode f = new ExplorerNode();
                f.Info.Name    = info.Name;
                f.Info.Size    = -1;
                f.Info.DateMod = info.LastWriteTime;
                node.AddChild(f);
            }
            foreach (string item in Directory.GetFiles(path))
            {
                FileInfo info = new FileInfo(item);
                if (CheckAttribute(info.Attributes, FileAttributes.System) | CheckAttribute(info.Attributes, FileAttributes.Offline))
                {
                    continue;
                }
                ExplorerNode f = new ExplorerNode();
                f.Info.Name    = info.Name;
                f.Info.Size    = info.Length;
                f.Info.DateMod = info.LastWriteTime;
                node.AddChild(f);
            }
            return(node);
        }
Example #4
0
        void uploadfile()
        {
            OpenFileDialog ofd = new OpenFileDialog();

            ofd.Multiselect      = true;
            ofd.Filter           = PCPath.FilterAllFiles;
            ofd.InitialDirectory = PCPath.Mycomputer;
            DialogResult result = ofd.ShowDialog();

            if (result != DialogResult.OK | result != DialogResult.Yes)
            {
                return;
            }
            List <ExplorerNode> items = new List <ExplorerNode>();
            ExplorerNode        root  = ExplorerNode.GetNodeFromDiskPath(System.IO.Path.GetDirectoryName(ofd.FileNames[0]));

            foreach (string s in ofd.SafeFileNames)
            {
                ExplorerNode n = new ExplorerNode();
                n.Info.Name = s;
                root.AddChild(n);
                FileInfo info = new FileInfo(n.GetFullPathString());
                n.Info.Size    = info.Length;
                n.Info.DateMod = info.LastWriteTime;
                items.Add(n);
            }
            Setting_UI.reflection_eventtocore.ExplorerAndManagerFile.TransferItems(items, root, managerexplorernodes.NodeWorking(), false);
        }
Example #5
0
        private void OpenItemLV()
        {
            if (LV_item.SelectedItems.Count != 1)
            {
                return;
            }
            ExplorerNode find = FindNodeLV(LV_item.SelectedItems[0]);

            if (find != null)
            {
                if (find.Info.Size > 0)                                    //file
                {
                    if (find.GetRoot.NodeType.Type != CloudType.LocalDisk) //cloud
                    {
                        MessageBox.Show("Not support now.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Stop);
                    }
                    else//disk
                    {
                        System.Diagnostics.Process.Start(find.GetFullPathString());
                    }
                }
                else//folder
                {
                    managerexplorernodes.Next(find);
                    ExplorerCurrentNode();
                }
            }
        }
Example #6
0
        public static void CreateFolder(ExplorerNode node)
        {
            DirectoryInfo dinfo = new DirectoryInfo(node.GetFullPathString());

            if (!dinfo.Exists)
            {
                dinfo.Create();
            }
        }
Example #7
0
        public static ExplorerNode GetMetaData(ExplorerNode node)
        {
            DropboxRequestAPIv2        client   = GetAPIv2(node.GetRoot.NodeType.Email);
            IDropbox_Response_MetaData metadata = client.GetMetadata(
                new Dropbox_Request_Metadata(string.IsNullOrEmpty(node.Info.ID) ? node.GetFullPathString(false, true) : "id:" + node.Info.ID));

            node.Info.Name    = metadata.name;
            node.Info.DateMod = DateTime.Parse(metadata.server_modified);
            node.Info.Size    = metadata.size;
            return(node);
        }
Example #8
0
        public static ExplorerNode GetFileInfo(ExplorerNode node)
        {
            FileInfo info = new FileInfo(node.GetFullPathString());

            if (info.Exists)
            {
                node.Info.Size       = info.Length;
                node.Info.DateMod    = info.LastWriteTimeUtc;
                node.Info.permission = info.IsReadOnly ? Permission.Read : Permission.Owner;
            }
            return(node);
        }
Example #9
0
        public static bool Delete(ExplorerNode node, bool PernamentDelete)
        {
            DropboxRequestAPIv2 dropbox_client = GetAPIv2(node.GetRoot.NodeType.Email);
            string path = node.GetFullPathString(false);

            if (PernamentDelete)
            {
                dropbox_client.permanently_delete(new Dropbox_path(path));
                return(true);
            }
            else
            {
                IDropbox_Response_MetaData metadata = dropbox_client.delete(new Dropbox_path(path));
                return(true);
            }
        }
Example #10
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);
        }
Example #11
0
        void LoadFile(ExplorerNode node)
        {
            TransferItem ud_item = new TransferItem();

            //From
            ud_item.From.node = node;
            //group & UI
            GroupData.TotalFileLength += node.Info.Size;
            ud_item.SizeString         = UnitConventer.ConvertSize(node.Info.Size, 2, UnitConventer.unit_size);
            ud_item.status             = StatusTransfer.Waiting;
            //To
            ud_item.To.node           = node.MakeNodeTo(this.fromfolder, this.savefolder);
            ud_item.DataSource.From   = node.GetFullPathString();
            ud_item.DataSource.To     = ud_item.To.node.GetFullPathString();
            ud_item.DataSource.Status = ud_item.status.ToString();

            ud_item.Group = GroupData;
            GroupData.items.Add(ud_item);
            GroupData.DataSource.Progress = "0/" + GroupData.items.Count.ToString();
            RefreshGroupDataToShow(0, 0);
        }
Example #12
0
        public static bool Move(ExplorerNode node, ExplorerNode newparent, string newname = null)
        {
            if (node.GetRoot.NodeType.Type != CloudType.LocalDisk && newparent.GetRoot.NodeType.Type != CloudType.LocalDisk)
            {
                throw new Exception("CloudType is != LocalDisk.");
            }
            string   path_from = node.GetFullPathString();
            string   path_to   = newparent.GetFullPathString() + "\\" + newname == null ? node.Info.Name : newname;
            FileInfo info      = new FileInfo(path_from);

            if (info.Exists)
            {
                info.MoveTo(path_to); return(true);
            }
            DirectoryInfo dinfo = new DirectoryInfo(path_from);

            if (dinfo.Exists)
            {
                dinfo.MoveTo(path_to); return(true);
            }
            return(false);
        }
Example #13
0
        public void LoadListItems()
        {
            this.GroupData.status              = StatusTransfer.Loading;
            this.GroupData.DataSource.From     = fromfolder.GetFullPathString();
            this.GroupData.DataSource.To       = savefolder.GetFullPathString();
            this.GroupData.DataSource.Status   = this.GroupData.status.ToString();
            this.GroupData.DataSource.Progress = "0/0";

            AppSetting.UIMain.UpdateGroup(GroupData, UpdateTransfer_TLVUD.Add);
            //string path = fromfolder.RootInfo.uri == null ? fromfolder.TypeCloud.ToString() + ":" + AppSetting.settings.GetDefaultCloud(fromfolder.TypeCloud) + "?id=" + fromfolder.ID : fromfolder.Path_Raw;
            foreach (ExplorerNode item in items)
            {
                if (item.Info.Size > 0)
                {
                    LoadFile(item);
                }
                else
                {
                    ListAllItemInFolder(item);
                }
            }
            GroupData.status = StatusTransfer.Waiting;
            items.Clear();// clear Declare memory
        }
Example #14
0
        public static void CreateFolder(ExplorerNode node)
        {
            if (node == node.GetRoot)
            {
                throw new Exception("Node is root.");
            }
            DropboxRequestAPIv2        client   = GetAPIv2(node.GetRoot.NodeType.Email);
            IDropbox_Response_MetaData metadata = client.create_folder(new Dropbox_path(node.GetFullPathString(false)));

            node.Info.ID = metadata.id;
        }
Example #15
0
        public static Stream GetFileStream(ExplorerNode node, long Startpos = -1, long endpos = -1)
        {
            DropboxRequestAPIv2 client = GetAPIv2(node.GetRoot.NodeType.Email);

            return(client.Download(new Dropbox_path(node.GetFullPathString(false)), Startpos, endpos));
        }
Example #16
0
        public static ExplorerNode GetListFileFolder(ExplorerNode node)
        {
            DropboxRequestAPIv2 client = GetAPIv2(node.GetRoot.NodeType.Email);

            IDropbox_Response_ListFolder response = client.ListFolder(new Dropbox_Request_ListFolder(node.GetFullPathString(false)));

            node.Child.Clear();
            foreach (IDropbox_Response_MetaData metadata in response.entries)
            {
                if (metadata.tag == "folder")
                {
                    new ExplorerNode(
                        new NodeInfo()
                    {
                        Name = metadata.name, Size = -1, ID = metadata.id
                    }, node);
                }
            }

            foreach (IDropbox_Response_MetaData metadata in response.entries)
            {
                if (metadata.tag == "file")
                {
                    new ExplorerNode(
                        new NodeInfo()
                    {
                        Name = metadata.name, Size = metadata.size, ID = metadata.id, DateMod = DateTime.Parse(metadata.client_modified)
                    }, node);
                }
            }
            return(node);
        }