Exemplo n.º 1
0
        /// <summary>
        /// 下载文件
        /// </summary>
        /// <param name="subpath">服务器上面,相对lib的目录</param>
        public string DownloadFile(string subpath)
        {
            string path = System.IO.Path.Combine(FileCache.Default.cachefolder, Path.GetFileName(subpath));

            if (System.IO.File.Exists(path))
            {
                path = JianLiIO.FindNewFileName(path);
            }

            FileStream localstream = new FileStream(
                path, FileMode.Create);


            Stream s = client.DownloadFile(subpath);

            byte[] buffer    = new byte[4096];
            int    readbytes = 0;

            while ((readbytes = s.Read(buffer, 0, buffer.Length)) > 0)
            {
                localstream.Write(buffer, 0, readbytes);
            }

            localstream.Close();
            s.Close();
            return(path);
        }
Exemplo n.º 2
0
        public string MoveToLib(string filepath, JianLi3Data.File f)
        {
            string destpath = Path.Combine(BookLibFolder, f.FilePath);

            if (System.IO.File.Exists(destpath))
            {
                destpath = JianLiIO.FindNewFileName(destpath);
            }

            System.IO.File.Move(filepath, destpath);

            return(destpath.Substring(BookLibFolder.Length + 1, destpath.Length - BookLibFolder.Length - 1));
        }
Exemplo n.º 3
0
        //将文件添加进缓存
        public void AddFile(int key, string filepath)
        {
            string destpath = filepath;

            if (!filepath.StartsWith(cachefolder))
            {
                if (System.IO.File.Exists(Path.Combine(cachefolder, Path.GetFileName(filepath))))
                {
                    destpath = JianLiIO.FindNewFileName(
                        Path.Combine(cachefolder, Path.GetFileName(filepath)));
                }
                else
                {
                    destpath = Path.Combine(cachefolder, Path.GetFileName(filepath));
                }
                System.IO.File.Move(filepath, destpath);
            }
            cache.Add(key, destpath);
        }