Exemple #1
0
  public static void main(String[] args) throws InterruptedException {
    Scanner cin = new Scanner(System.in);
    Peers p1 = new Peers(P1ID, P1UploadPort, P1DownloadPort, CheckPort[0]);
    p1.sum = new File("C:/users/ben/Desktop/Peers/P" + p1.PeerID + "/summary" + ".txt");
    p1.downloadfromServer();

    Uploading upload = new Uploading(p1);
    Thread t1 = new Thread(upload);
    Downloading t2 = new Downloading(p1);

    t1.start();
    p1.waitforDownloading();

    Thread.sleep(1000); // 否则会downloadPort开了,但是对应的uploadPort还没开启。
    t2.start();
  }
    @Override
    protected String doInBackground(String... upgradeString) {
      /*Upgrade or copy*/
      // Upgrade existing
      if (db.needsUpgrade) {
        Logging.Log(LOG_TAG, "Upgrading DB");
        success = db.upgradeDB();
        // Copy new one if failure upgrading

        if (!success) {
          try {
            db.copyDB();
          } catch (IOException e) {
            throw new Error("Error copying database");
          }
        }
        // Finally open DB
        try {
          db.openDataBase();
        } catch (SQLException e) {
          Logging.Log(LOG_TAG, "Unable to open database");
          Logging.Log(LOG_TAG, e.getStackTrace().toString());
        }
        // DB is now ready to use
        db.updatePref("splashShown", "true");
        publishProgress(25);
      }

      // Fix bad shows
      ArrayList<ArchiveShowObj> shows = db.getBadShows();
      Logging.Log(LOG_TAG, "Looking for shows to fix, found " + shows.size());
      if (shows.size() > 0) {
        Logging.Log(LOG_TAG, "Starting to fix shows");
        for (ArchiveShowObj s : shows) {
          Searching.getSongs(s, null, db, false);
        }
        publishProgress(50);
      }

      // Update Artists if necessary
      if (needsArtistFetching()) {
        Searching.updateArtists(db);
        publishProgress(75);
      }

      Downloading.syncFilesDirectory(parentScreen, db);

      return "Completed";
    }