Skip to content

Commit

Permalink
release-ready: Progress bar updates with each Models and Airports sub…
Browse files Browse the repository at this point in the history
…dir sync'd.
  • Loading branch information
open744 committed Aug 12, 2015
1 parent 1f1c449 commit 3355683
Show file tree
Hide file tree
Showing 2 changed files with 89 additions and 62 deletions.
2 changes: 1 addition & 1 deletion MapFrame.java
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public void actionPerformed(ActionEvent e) {
if (a.equals("SYNC")) {
Collection<TileName> set = map.getSelection();
TerraMaster.svn.sync(set);
progressBar.setMaximum(progressBar.getMaximum() + set.size() * 3);
progressBar.setMaximum(progressBar.getMaximum() + set.size() * 2);
progressBar.setVisible(true);
butStop.setEnabled(true);
map.clearSelection();
Expand Down
149 changes: 88 additions & 61 deletions Svn.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class Svn extends Thread implements ISVNDirEntryHandler, ISVNCanceller, ISVNExte
SVNUpdateClient updateClient;
SVNStatusClient statusClient;
SVNLogClient logClient;
SVNWCClient wcClient;
String urlBase = "http://terrascenery.googlecode.com/svn/trunk/data/Scenery/";
String pathBase;
long syncsize, synccount;
Expand All @@ -35,6 +36,7 @@ class Svn extends Thread implements ISVNDirEntryHandler, ISVNCanceller, ISVNExte
updateClient = clientManager.getUpdateClient();
statusClient = clientManager.getStatusClient();
logClient = clientManager.getLogClient();
wcClient = clientManager.getWCClient();
updateClient.setIgnoreExternals(false);

syncList = new LinkedList<TileName>();
Expand Down Expand Up @@ -79,7 +81,6 @@ private String buildPath(String tile) {
public void checkCancelled() throws SVNCancelException
{
if (cancelFlag) {
System.out.println("I SAID STOP!!");
cancelFlag = false;
invokeLater(1); // reset progressBar
throw new SVNCancelException();
Expand Down Expand Up @@ -119,6 +120,17 @@ public void handleDirEntry(SVNDirEntry e)
//e.DIRENT_KIND.equals(SVNNodeKind.DIR)
}

// svn list --verbose --> fills up syncsize/synccount
private void printStats(String path)
{
try {
SVNURL url = SVNURL.parseURIDecoded(urlBase + path);
synccount = syncsize = 0;
logClient.doList(url, SVNRevision.HEAD, SVNRevision.HEAD, false, true, this);
System.out.printf("%s/%d items (%d bytes)... ", path, synccount, syncsize);
} catch (SVNException e) { }
}

/*
SVNStatus stat = statusClient.doStatus(pathBase +
"Terrain/e140s40/e144s38/"), true);
Expand All @@ -144,28 +156,24 @@ private void checkout(String name) {

try {

SVNURL url = SVNURL.parseURIDecoded(urlBase + node);
File f = new File(pathBase + node);

synccount = syncsize = 0;
logClient.doList(url, SVNRevision.HEAD, SVNRevision.HEAD, false, true, this);
System.out.printf("%s%d items (%d bytes)... ", types[i], synccount, syncsize);

// try update, if fails, do checkout (export?)
//updateOrCheckout(url, f);

//verifyTree(f, url);
printStats(node);
long rev = updateNode(f);
if (rev > 0)
System.out.printf("updated to r%d... ", rev);
invokeLater(2); // update progressBar
System.out.printf("updated to r%d.\n", rev);

TerraMaster.addScnMapTile(TerraMaster.mapScenery, f, ntype[i]);

invokeLater(2); // update progressBar

// look for airport codes among the newly sync'd Terrain files
if (i == 0) {
syncAirports(findAirports(f));
invokeLater(2); // update progressBar
String[] apt = findAirports(f);
for (int j = 0; j < apt.length; ++j)
invokeLater(3); // extend progressBar

syncAirports(apt);
}

} catch (SVNException x) {
Expand All @@ -174,11 +182,10 @@ private void checkout(String name) {
// E160013 = URL not found
//if (em.getErrorCode().getCode() != 160013)
System.out.println(x.getMessage());
// 155004 unfinished work items, need svn cleanup
} //catch (Exception x) { System.out.println(x); }

}

System.out.println();
}

// returns an array of unique 3-char prefixes
Expand All @@ -195,29 +202,6 @@ private String[] findAirports(File d)
return set.toArray(new String[1]);
}


private void syncModels()
{
long rev;

try {
verifyRoot(new File(pathBase), SVNURL.parseURIDecoded(urlBase));

File f = new File(pathBase + "Models/");
SVNURL url = SVNURL.parseURIDecoded(urlBase + "Models/");

synccount = syncsize = 0;
logClient.doList(url, SVNRevision.HEAD, SVNRevision.HEAD, false, true, this);
System.out.printf("Models/%d items (%d bytes)... ", synccount, syncsize);

rev = updateNode(f);
if (rev > 0) System.out.printf("updated to r%d.\n", rev);

} catch (SVNException x) {
System.out.println(x.getMessage());
}
}

// sync "Airports/W/A/T"
private void syncAirports(String[] names)
{
Expand All @@ -231,22 +215,64 @@ private void syncAirports(String[] names)
File f = new File(pathBase + node);

try {
printStats(node);
rev = updateNode(f);
if (rev > 0) System.out.printf("updated to r%d.\n", rev);

SVNURL url = SVNURL.parseURIDecoded(urlBase + node);

synccount = syncsize = 0;
logClient.doList(url, SVNRevision.HEAD, SVNRevision.HEAD, false, true, this);
System.out.printf("%s%d items (%d bytes)... ", node, synccount, syncsize);

rev = updateNode(f);
if (rev > 0) System.out.printf("updated to r%d... ", rev);
invokeLater(2); // update progressBar

} catch (SVNException x) {
System.out.println(x.getMessage());
}
}
}

// svn update Models/*
private void syncModels(String name)
{
try {
printStats("Models/" + name);

File f = new File(pathBase + "Models/" + name);
long rev = updateNode(f);
if (rev > 0) System.out.printf("updated to r%d.\n", rev);

invokeLater(2); // update progressBar
} catch (SVNException x) {
System.out.println(x.getMessage());
}
}

// svn update --depth immediate Models
private void syncModels()
{
File d;

try {
verifyRoot(new File(pathBase), SVNURL.parseURIDecoded(urlBase));

d = new File(pathBase + "Models/");

// first update the top level
File[] list = new File[1];
list[0] = d;
long[] rev = updateClient.doUpdate(list, SVNRevision.HEAD, SVNDepth.IMMEDIATES, true, true, true);
} catch (SVNException x) {
System.out.println(x.getMessage());
return;
} finally {
invokeLater(2); // update progressBar
}

// queue each subdir in syncList
synchronized(syncList) {
for (File f : d.listFiles()) { // XXX should filter for dirs only
syncList.add(new TileName("MODELS-" + f.getName()));
invokeLater(3);
}
}
}

public void sync(Collection<TileName> set)
{
synchronized(syncList) {
Expand Down Expand Up @@ -295,17 +321,6 @@ public void delete(Collection<TileName> set)
syncList.remove(n);
}
}

/*
TileData t = TerraMaster.mapScenery.get(tileName.getText());
//Collection<TileName> t = map.getSelection();
try {
System.out.println("rm -r "
+ (t.terrain ? t.dir_terr.getCanonicalFile() : "") + " "
+ (t.objects ? t.dir_obj.getCanonicalFile() : "") );
// showTiles();
} catch (Exception x) {}
*/
}


Expand All @@ -316,6 +331,10 @@ public void quit() {

public void setScnPath(File f) {
pathBase = f.getPath() + "/";

try {
wcClient.doCleanup(f);
} catch (SVNException e) { }
}

private boolean noquit = true;
Expand All @@ -332,10 +351,15 @@ public void run()
synchronized(syncList) {
n = syncList.getFirst();
}

String name = n.getName();
if (name.equals("MODELS"))
syncModels();
else {
if (name.startsWith("MODELS")) {
int i = name.indexOf('-');
if (i > -1)
syncModels(name.substring(i+1));
else
syncModels();
} else {
String path = buildPath(name);
if (path != null)
checkout(path);
Expand Down Expand Up @@ -367,6 +391,9 @@ public void run() {
case 2: // update progressBar
TerraMaster.frame.progressUpdate(1);
break;
case 3: // progressBar maximum++
TerraMaster.frame.progressBar.setMaximum(TerraMaster.frame.progressBar.getMaximum() + 1);
break;
}
}
});
Expand Down

0 comments on commit 3355683

Please sign in to comment.