找回密码
 立即注册→加入我们

QQ登录

只需一步,快速开始

搜索
热搜: 下载 VB C 实现 编写
查看: 2917|回复: 2

编写程序下载reactos所有开源代码

[复制链接]

307

主题

228

回帖

7349

积分

用户组: 真·技术宅

UID
2
精华
76
威望
291 点
宅币
5599 个
贡献
253 次
宅之契约
0 份
在线时间
949 小时
注册时间
2014-1-25
发表于 2014-1-29 13:35:08 | 显示全部楼层 |阅读模式

欢迎访问技术宅的结界,请注册或者登录吧。

您需要 登录 才可以下载或查看,没有账号?立即注册→加入我们

×
http://svn.reactos.org/下目录不能直接用svn下载,svn工具只可下载其下某个子目录的文件夹,这是因为第一个链接放的是根目录,因此构成了循环结构,svn工具会报错,但是看着里面的结构想把所有资源都down下来,只好自己写了一个java程序:150行 五易其稿以铸神器。我用的tortoise svn,用svn工具多了,就会发现经常会有奇怪的错误,什么sql啦,lock啦,种种怪事情,自己写就ok
  1. package resolve;
  2. import java.io.File;
  3. import java.io.FileOutputStream;
  4. import java.io.IOException;
  5. import java.io.InputStream;
  6. import java.net.URL;
  7. import java.net.URLConnection;
  8. import org.jsoup.Jsoup;
  9. import org.jsoup.nodes.Document;
  10. import org.jsoup.nodes.Element;
  11. import org.jsoup.select.Elements;

  12. public class resolve
  13. {
  14.         public static String url="http://svn.reactos.org/";
  15.         public static String path="k:/reactos/";
  16.         public static int filethreadnum=0;

  17.         public static class FileThread extends Thread
  18.         {
  19.                 String filepath;
  20.                 String curnode;

  21.                 FileThread(String filepath,String curnode)
  22.                 {
  23.                         this.filepath=filepath;
  24.                         this.curnode=curnode;
  25.                 }

  26.                 public void run()
  27.                 {
  28.                         try
  29.                         {
  30.                                 while(filethreadnum>36)
  31.                                 {
  32.                                         sleep(1000);
  33.                                 }
  34.                                 filethreadnum++;
  35.                                 int byteread=0;
  36.                                 int bytesum=0;
  37.                                 URL weburl=new URL(url+filepath+curnode);
  38.                                 URLConnection con=weburl.openConnection();
  39.                                 InputStream instream=con.getInputStream();
  40.                                 FileOutputStream fs=new FileOutputStream((path+filepath+curnode).replace("%20"," "));
  41.                                 byte[] buffer=new byte[65536];
  42.                                 while((byteread=instream.read(buffer)) != -1)
  43.                                 {
  44.                                         bytesum+=byteread;
  45.                                         fs.write(buffer,0,byteread);
  46.                                         System.out.println("\t\t当前下载文件:"+filepath+curnode+"\t当前大小:"+bytesum);
  47.                                 }
  48.                                 fs.close();
  49.                                 instream.close();
  50.                                 filethreadnum--;
  51.                         }
  52.                         catch(Exception e)
  53.                         {
  54.                                 System.out.println("error");
  55.                         }
  56.                 }
  57.         }

  58.         public static String createFolder(String folderPath)
  59.         {
  60.                 String txt = folderPath;
  61.                 try
  62.                 {
  63.                         File myFilePath = new File(txt);
  64.                         txt = folderPath;
  65.                         if (!myFilePath.exists())
  66.                         {
  67.                                 myFilePath.mkdir();
  68.                         }
  69.                 }
  70.                 catch (Exception e)
  71.                 {
  72.                         System.out.println("错误!");
  73.                 }
  74.                 return txt;
  75.         }

  76.         public static void myresolve(Element e,String filepath) throws IOException
  77.         {
  78.                 try
  79.                 {
  80.                         String curnode=e.attr("href");
  81.                         if(!curnode.equals("../") && !curnode.equals("svn/"))
  82.                         {//非父目录
  83.                                 if(curnode.charAt(curnode.length()-1) == '/')
  84.                                 {//目录
  85.                                         createFolder((path+filepath+curnode).replace("%20"," "));
  86.                                         Document doc=Jsoup.connect(url+filepath+curnode).timeout(0).get();
  87.                                         System.out.println("当前目录:"+url+filepath+curnode);
  88.                                         Elements items=doc.select("tbody tr a");
  89.                                         for(Element ele1:items)
  90.                                         {
  91.                                                 myresolve(ele1,filepath+curnode);
  92.                                         }
  93.                                         items.clear();
  94.                                         items=doc.select("ul li a");
  95.                                         for(Element ele2:items)
  96.                                         {
  97.                                                 myresolve(ele2,filepath+curnode);
  98.                                         }
  99.                                 }
  100.                                 else
  101.                                 {//文件
  102.                                         File curfile=new File((path+filepath+curnode).replace("%20"," "));
  103.                                         if(curfile.exists())
  104.                                                 return;
  105.                                         while(filethreadnum>36)
  106.                                         {
  107.                                                 Thread.sleep(1000);
  108.                                         }
  109.                                         (new FileThread(filepath,curnode)).start();
  110.                                 }
  111.                         }
  112.                 }
  113.                 catch(Exception exc)
  114.                 {
  115.                         System.out.println("错误!");
  116.                 }
  117.         }

  118.         public static void main(String[] args) throws IOException
  119.         {
  120.                 try
  121.                 {
  122.                         Document doc = Jsoup.connect(url).timeout(0).get();
  123.                         Elements items=doc.select("tbody tr a");
  124.                         createFolder(path);
  125.                         for(Element e1:items)
  126.                         {
  127.                                 myresolve(e1,"");
  128.                         }
  129.                         items=doc.select("ul li a");
  130.                         for(Element e2:items)
  131.                         {
  132.                                 myresolve(e2,"");
  133.                         }
  134.                         while(filethreadnum != 0)
  135.                         {
  136.                                 Thread.sleep(1000);
  137.                         }
  138.                 }
  139.                 catch(Exception exc)
  140.                 {
  141.                         System.out.println("错误!");
  142.                 }
  143.         }
  144. }
复制代码
回复

使用道具 举报

0

主题

19

回帖

51

积分

用户组: 小·技术宅

UID
158
精华
0
威望
1 点
宅币
30 个
贡献
0 次
宅之契约
0 份
在线时间
0 小时
注册时间
2014-3-26
发表于 2014-3-26 16:36:13 | 显示全部楼层
多谢分享
回复

使用道具 举报

1

主题

13

回帖

51

积分

用户组: 小·技术宅

UID
146
精华
0
威望
1 点
宅币
35 个
贡献
0 次
宅之契约
0 份
在线时间
4 小时
注册时间
2014-3-23
发表于 2014-4-1 08:49:25 | 显示全部楼层
顶.........
回复

使用道具 举报

QQ|Archiver|小黑屋|技术宅的结界 ( 滇ICP备16008837号 )|网站地图

GMT+8, 2024-5-3 14:45 , Processed in 0.040269 second(s), 31 queries , Gzip On.

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表