Esempio n. 1
0
        public void getFiles_KuaiPan(string path)
        {
            KuaiPanSDK.Model.MetaData filesList = KuaiPan.getFilesList(path);

            foreach (KuaiPanSDK.Model.FileData file in filesList.Files)
            {
                FileElement finfo = new FileElement();
                finfo.name = file.Name;
                if (file.Type == KuaiPanSDK.TypeEnum.Folder)
                {
                    finfo.isdir = System.IO.FileAttributes.Directory;
                    getFiles_KuaiPan(path + "/" + finfo.name);
                }
                else
                {
                    finfo.isdir = System.IO.FileAttributes.Normal;
                }

                finfo.accessTime = file.ModifyTime;
                finfo.motifyTime = file.ModifyTime;
                finfo.createTime = file.Createtime;
                finfo.origin = 1;
                finfo.parentPath = path + "/";
                finfo.size = file.Size;

                AllFiles.Add(finfo);
            }
        }
Esempio n. 2
0
        public void getFiles_Baidu(string path)
        {
            FilesList myFiles = BaiduPan.getFilesList(path);
            for (int i = 0; i < myFiles.list.Length; i++)
            {
                FileElement finfo = new FileElement();
                //int nameIndex = myFiles.list[i].path.Split(new Char[] { '/' }).Length;
                //string name = myFiles.list[i].path.Split(new Char[] { '/' })[nameIndex - 1];
                finfo.name = GetFileName(myFiles.list[i].path);

                if (myFiles.list[i].isdir == 1)
                {
                    finfo.isdir = System.IO.FileAttributes.Directory;
                    getFiles_Baidu(path + "/" + finfo.name);

                }
                else
                {
                    finfo.isdir = System.IO.FileAttributes.Normal;
                }
                finfo.accessTime = getRightTime(myFiles.list[i].mtime);
                finfo.motifyTime = getRightTime(myFiles.list[i].mtime);
                finfo.createTime = getRightTime(myFiles.list[i].ctime);
                finfo.parentPath = path + "/";
                finfo.size = (long)myFiles.list[i].size;
                finfo.origin = 0;
                AllFiles.Add(finfo);
            }
        }
Esempio n. 3
0
        public bool removeFile(string path)
        {
            bool result = true;
            FileElement fileTobeRemoved = null;
            foreach (FileElement file in AllFiles)
            {
                if (file.parentPath + file.name == path)
                {
                    if (file.origin == 0)
                    {
                        result = BaiduPan.DeleteFile(path);
                    }

                    else if (file.origin == 1)
                    {
                        result = KuaiPan.DeleteFile(path);
                    }
                    else if (file.origin == 2)
                    {
                        //others
                    }
                    fileTobeRemoved = file;
                }
            }

            AllFiles.Remove(fileTobeRemoved);
            return result;
        }
Esempio n. 4
0
 public FileElement initialUploadFile(string path)
 {
     FileElement newfile = new FileElement();
     newfile.name = GetFileName(path);
     newfile.accessTime = DateTime.Now;
     newfile.createTime = DateTime.Now;
     newfile.motifyTime = DateTime.Now;
     newfile.isdir = FileAttributes.Normal;
     newfile.parentPath = GetPathPart(path);
     newfile.size = 0;
     AllFiles.Add(newfile);
     return newfile;
 }
Esempio n. 5
0
        public int CreateFile(
            string filename,
            System.IO.FileAccess access,
            System.IO.FileShare share,
            System.IO.FileMode mode,
            System.IO.FileOptions options,
            DokanFileInfo info)
        {
            Console.WriteLine("Dokan CreateFile, filename is " + filename);
            Dokan.DokanNet.DokanResetTimeout(1000 * 30, info);
            info.Context = Context++;
            string targetPath = filename.Replace("\\", "/");
            String name       = GetFileName(targetPath);

            #region 老方法 - 废弃,参考
            //try
            //{
            //    if (filename == "\\")
            //    {

            //        //info.IsDirectory = true;
            //        return DokanNet.DOKAN_SUCCESS;

            //    }


            //    if (name == "desktop.ini" || name == "folder.jpg" || name == "folder.gif" || name == @".svn") return -DokanNet.ERROR_FILE_NOT_FOUND;



            //    #region 通过List<FileElement>查询文件
            //    FileElement file = allinone.getSingleFileInfo(targetPath);
            //    if (file == null)
            //    {

            //    }

            //    else if ((access & System.IO.FileAccess.Read) == System.IO.FileAccess.Read)
            //    {


            //        if (file.isdir == System.IO.FileAttributes.Directory)
            //        {
            //            info.IsDirectory = true;
            //            return DokanNet.DOKAN_SUCCESS;
            //        }
            //        else
            //        {
            //            return DokanNet.DOKAN_SUCCESS;
            //        }

            //    }

            //    #endregion

            //    #region Mem盘的方法  - 废弃
            //    //FileElement file = allinone.getSingleFileInfo(targetPath);
            //    //if (file!=null)
            //    //{
            //    //    //this is a folder?
            //    //    info.IsDirectory = true;
            //    //    if (mode == FileMode.Open || mode == FileMode.OpenOrCreate)
            //    //    {
            //    //        //info.IsDirectory = true;
            //    //        return DokanNet.DOKAN_SUCCESS;
            //    //    }

            //    //    // you can't make a file with the same name as a folder;
            //    //    return -DokanNet.ERROR_ALREADY_EXISTS;
            //    //}
            //    #endregion
            //    // there's no folder with this name, the parent exists;
            //    // attempt to use the file
            //    switch (mode)
            //    {
            //        // Opens the file if it exists and seeks to the end of the file,
            //        // or creates a new file
            //        case FileMode.Append:

            //            return DokanNet.DOKAN_SUCCESS;

            //        // Specifies that the operating system should create a new file.
            //        // If the file already exists, it will be overwritten.
            //        case FileMode.Create:
            //            //if (!thisFile.Exists())

            //            //else
            //            //	thisFile.Content = new Thought.Research.AweBuffer(1024); //MemoryStream();
            //            return DokanNet.DOKAN_SUCCESS;

            //        // Specifies that the operating system should create a new file.
            //        // If the file already exists, an IOException is thrown.
            //        case FileMode.CreateNew:
            //            Console.WriteLine("try to create new file, file name is " + name);
            //            return DokanNet.DOKAN_SUCCESS;

            //        // Specifies that the operating system should open an existing file.
            //        // A System.IO.FileNotFoundException is thrown if the file does not exist.
            //        case FileMode.Open:

            //            return DokanNet.DOKAN_SUCCESS;

            //        // Specifies that the operating system should open a file if it exists;
            //        // otherwise, a new file should be created.
            //        case FileMode.OpenOrCreate:

            //            return DokanNet.DOKAN_SUCCESS;

            //        // Specifies that the operating system should open an existing file.
            //        // Once opened, the file should be truncated so that its size is zero bytes
            //        case FileMode.Truncate:


            //            return DokanNet.DOKAN_SUCCESS;
            //    }



            //}
            //catch (Exception e)
            //{
            //    Console.WriteLine(e);
            //}

            //return DokanNet.DOKAN_SUCCESS;

            #endregion

            #region 13/11/1添加改用新方法

            if (filename == "\\")
            {
                //info.IsDirectory = true;
                return(DokanNet.DOKAN_SUCCESS);
            }

            if (mode == FileMode.Open || mode == FileMode.OpenOrCreate)
            {
                FileElement file = allinone.getSingleFileInfo(targetPath);
                if (file != null)
                {
                    if (file.isdir == System.IO.FileAttributes.Normal)
                    {
                        return(DokanNet.DOKAN_SUCCESS);
                    }

                    if (file.isdir == System.IO.FileAttributes.Directory)
                    {
                        info.IsDirectory = true;
                        return(DokanNet.DOKAN_SUCCESS);
                    }
                }

                return(-DokanNet.ERROR_FILE_NOT_FOUND);
            }

            return(DokanNet.DOKAN_SUCCESS);

            #endregion
        }
Esempio n. 6
0
        public int GetFileInformation(
            string filename,
            FileInformation fileinfo,
            DokanFileInfo info)
        {
            Console.WriteLine("Dokan GetFileInformation, filename is " + filename);
            string targetPath = filename.Replace("\\", "/");
            String name       = targetPath.Substring(targetPath.LastIndexOf('/') + 1);

            if (name == "desktop.ini" || name == "folder.jpg" || name == "folder.gif")
            {
                return(-1);
            }
            if (filename == "\\")
            {
                fileinfo.Attributes     = System.IO.FileAttributes.Directory;
                fileinfo.LastAccessTime = DateTime.Now;
                fileinfo.LastWriteTime  = DateTime.Now;
                fileinfo.CreationTime   = DateTime.Now;
                //fileinfo.FileName = targetPath.Substring(targetPath.LastIndexOf('/') + 1);
                //fileinfo.Length = 0;


                return(DokanNet.DOKAN_SUCCESS);
            }
            else if (info.IsDirectory)
            {
                fileinfo.Attributes     = System.IO.FileAttributes.Directory;
                fileinfo.LastAccessTime = DateTime.Now;
                fileinfo.LastWriteTime  = DateTime.Now;
                fileinfo.CreationTime   = DateTime.Now;
                fileinfo.FileName       = targetPath.Substring(targetPath.LastIndexOf('/') + 1);
                fileinfo.Length         = 0;


                return(DokanNet.DOKAN_SUCCESS);
            }
            else
            {
                #region 直接去网盘查询文件信息 - 废弃
                //FilesList BaiduFiles = BaiduPan.searchFile("/apps/sjtupan" + targetPath);
                //KuaiPanSDK.Model.MetaData KuaiPanFiles = KuaiPan.getFilesList(targetPath);
                ////Console.WriteLine("BaiduFiles content: " + BaiduFiles + " filename is " + targetPath);

                //if (BaiduFiles == null && KuaiPanFiles == null) return DokanNet.ERROR_FILE_NOT_FOUND;
                //else
                //{
                //    if (BaiduFiles != null)
                //    {
                //        fileinfo.FileName = name;
                //        fileinfo.LastAccessTime = getRightTime(BaiduFiles.list[0].mtime);
                //        fileinfo.LastWriteTime = getRightTime(BaiduFiles.list[0].mtime);
                //        fileinfo.CreationTime = getRightTime(BaiduFiles.list[0].ctime);
                //        fileinfo.Length = (long)BaiduFiles.list[0].size;
                //        if (BaiduFiles.list[0].isdir == 1)
                //        {
                //            fileinfo.Attributes = System.IO.FileAttributes.Directory;
                //        }
                //        else
                //        {
                //            fileinfo.Attributes = System.IO.FileAttributes.Normal;
                //        }
                //    }
                //    else if (KuaiPanFiles != null)
                //    {
                //        if (KuaiPanFiles.Type == KuaiPanSDK.TypeEnum.Folder)
                //        {
                //            fileinfo.Attributes = System.IO.FileAttributes.Directory;
                //        }
                //        else
                //        {
                //            fileinfo.Attributes = System.IO.FileAttributes.Normal;
                //        }
                //        fileinfo.FileName = KuaiPanFiles.Name;
                //        fileinfo.LastAccessTime = KuaiPanFiles.ModifyTime;
                //        fileinfo.LastWriteTime = KuaiPanFiles.ModifyTime;
                //        fileinfo.CreationTime = KuaiPanFiles.Createtime;
                //        fileinfo.Length = KuaiPanFiles.Size;

                //    }

                //}

                #endregion

                #region 查找List<FileElement>中的对应文件信息
                FileElement file = allinone.searchFile(targetPath);
                if (file == null)
                {
                    return(DokanNet.ERROR_FILE_NOT_FOUND);
                }
                else
                {
                    fileinfo.FileName       = file.name;
                    fileinfo.LastAccessTime = file.accessTime;
                    fileinfo.LastWriteTime  = file.motifyTime;
                    fileinfo.CreationTime   = file.createTime;
                    fileinfo.Length         = file.size;
                    fileinfo.Attributes     = file.isdir;
                    return(DokanNet.DOKAN_SUCCESS);
                }


                #endregion
            }
        }
Esempio n. 7
0
        public bool CreateDirectory(string path)
        {
            bool result = true;
            FileElement newfile = new FileElement();
            if (path == "/") return true;
            else
            {
                foreach (FileElement file in AllFiles)
                {
                    if (file.parentPath + file.name == path) return true;
                }
            }
            //经调式,当上传文件时,此方法也会被调用,所以必须使用以上代码判断文件的父目录,若存在则不用新建直接返回true



            if (GetPathPart(path) == "/")
            {
                Random rd = new Random();
                int i = rd.Next(0, 2);
                //Console.WriteLine("Random number is " + i);
                if (i == 0)
                {
                    Console.WriteLine("New directory create in Baidu");
                    result=BaiduPCSDiskUtility.Instance.CreateDirectory(path);
                }
                else if (i == 1)
                {
                    Console.WriteLine("New directory create in KuaiPan");
                    result=KuaiPan.CreateDirectory(path);
                }
                else if (i == 2) { }

                newfile.origin = i;
            }
            else
            {
                foreach (FileElement file in AllFiles)
                {
                    if (file.parentPath + file.name + "/" == GetPathPart(path)) //上传文件时,传入的path型如"/hellosjtu/ss.txt",ss.txt为新文件名
                    {
                        if (file.origin == 0)
                        {

                            Console.WriteLine("New directory create in Baidu");
                            result=BaiduPCSDiskUtility.Instance.CreateDirectory(path);
                        }
                        else if (file.origin == 1)
                        {
                            Console.WriteLine("New directory create in KuaiPan");
                            result=KuaiPan.CreateDirectory(path);
                        }
                        else if (file.origin == 2) { }

                        newfile.origin = file.origin;
                    }
                }


            }
            if (result == true)
            {
                newfile.name = GetFileName(path);
                newfile.accessTime = DateTime.Now;
                newfile.createTime = DateTime.Now;
                newfile.motifyTime = DateTime.Now;
                newfile.isdir = FileAttributes.Directory;
                newfile.parentPath = GetPathPart(path);
                
                newfile.size = 0;
                AllFiles.Add(newfile);
            }
            return result;

        }
Esempio n. 8
0
        public bool uploadFile(string path, byte[] buffer) //upload file
        {
            bool result = true;

            //为了支持大于64KB的文件上传,这里先检察传入的buffer大小,如果为65536则说明文件结束,继续等待下次的buffer传入并累加
            if (ToUploadFile == null) ToUploadFile = initialUploadFile(path);

            if (buffer.Length == 65536)
            {
                if (uploadTotalBuffer == null) uploadTotalBuffer = buffer;
                else
                    uploadTotalBuffer = uploadTotalBuffer.Concat(buffer).ToArray();
                AllFiles.Remove(ToUploadFile);
                ToUploadFile.size = uploadTotalBuffer.Length;
                AllFiles.Add(ToUploadFile);
                return true;
            }
            else
            {
                if (uploadTotalBuffer == null) uploadTotalBuffer = buffer;
                else
                uploadTotalBuffer = uploadTotalBuffer.Concat(buffer).ToArray();
                AllFiles.Remove(ToUploadFile);
                ToUploadFile.size = uploadTotalBuffer.Length;
                
            }
            
            //当buffer size小于65536时,说明文件尾已到,则将合并后的buffer传递至api并上传至网盘
            if (GetPathPart(path) == "/")
            {
                Random rd = new Random();
                int i = rd.Next(0, 2);
                Console.WriteLine("Random number is " + i);
                if (i == 0)
                {
                    Console.WriteLine("New file create in Baidu");
                    result = BaiduPan.UploadFile(path, uploadTotalBuffer);
                }
                else if (i == 1)
                {
                    Console.WriteLine("New file create in KuaiPan");
                    result = KuaiPan.UploadFile(path, uploadTotalBuffer);
                }
                else if (i == 2) { }

                ToUploadFile.origin = i;
            }
            else
            {
                foreach (FileElement file in AllFiles)
                {
                    if (file.parentPath + file.name + "/" == GetPathPart(path)) //上传文件时,传入的path型如"/hellosjtu/ss.txt",ss.txt为新文件名
                    {
                        if (file.origin == 0)
                        {

                            Console.WriteLine("New file create in Baidu");
                            result = BaiduPan.UploadFile(path, uploadTotalBuffer);
                        }
                        else if (file.origin == 1)
                        {
                            Console.WriteLine("New file create in KuaiPan");
                            result = KuaiPan.UploadFile(path, uploadTotalBuffer);
                        }
                        else if (file.origin == 2) { }

                        ToUploadFile.origin = file.origin;
                    }
                }
            }

            if (result == true)
            {

                AllFiles.Add(ToUploadFile);
            }
            else
            {
               
            }
            uploadTotalBuffer = null;
            ToUploadFile = null;
            return result;
        }