I have no idea what the heck the MetaProgressObserver was doing,

but it wasn't doing the right thing. Fixed it.

I honestly have no idea how this was working. Maybe it just wasn't.
Maybe we never noticed before because with the per-step progress
bars we weren't seeing it exceed 100 percent.

And then use that instead of the UnifiedProgressObserver I wrote,
before I saw MetaProgressObserver.
This commit is contained in:
Ray Greenwell
2012-03-08 15:21:12 +00:00
parent b5fd81f963
commit 0d7cf4f67f
2 changed files with 9 additions and 46 deletions
@@ -82,6 +82,7 @@ import com.threerings.getdown.net.HTTPDownloader;
import com.threerings.getdown.tools.Patcher; import com.threerings.getdown.tools.Patcher;
import com.threerings.getdown.util.ConfigUtil; import com.threerings.getdown.util.ConfigUtil;
import com.threerings.getdown.util.LaunchUtil; import com.threerings.getdown.util.LaunchUtil;
import com.threerings.getdown.util.MetaProgressObserver;
import com.threerings.getdown.util.ProgressObserver; import com.threerings.getdown.util.ProgressObserver;
import static com.threerings.getdown.Log.log; import static com.threerings.getdown.Log.log;
@@ -687,11 +688,12 @@ public abstract class Getdown extends Thread
updateStatus("m.patching"); updateStatus("m.patching");
// create a new ProgressObserver that divides the different patching phases // create a new ProgressObserver that divides the different patching phases
UnifiedProgressObserver uProgObs = new UnifiedProgressObserver(list.size(), _progobs); MetaProgressObserver mprog = new MetaProgressObserver(_progobs, list.size());
for (Resource prsrc : list) { for (Resource prsrc : list) {
mprog.startElement(1);
try { try {
Patcher patcher = new Patcher(); Patcher patcher = new Patcher();
patcher.patch(prsrc.getLocal().getParentFile(), prsrc.getLocal(), uProgObs); patcher.patch(prsrc.getLocal().getParentFile(), prsrc.getLocal(), mprog);
} catch (Exception e) { } catch (Exception e) {
log.warning("Failed to apply patch", "prsrc", prsrc, e); log.warning("Failed to apply patch", "prsrc", prsrc, e);
} }
@@ -701,7 +703,6 @@ public abstract class Getdown extends Thread
log.warning("Failed to delete '" + prsrc + "'."); log.warning("Failed to delete '" + prsrc + "'.");
prsrc.getLocal().deleteOnExit(); prsrc.getLocal().deleteOnExit();
} }
uProgObs.stepComplete();
} }
} }
@@ -1152,43 +1153,6 @@ public abstract class Getdown extends Thread
} }
}; };
/** A simple combiner of multiple 0->100 progresses into one. */
protected static class UnifiedProgressObserver
implements ProgressObserver
{
/**
* Constructor.
*/
public UnifiedProgressObserver (int steps, ProgressObserver delegate)
{
_steps = steps;
_delegate = delegate;
}
/**
* Call prior to moving on to a next step.
*/
public void stepComplete ()
{
_step++;
}
// from ProgressObserver
public void progress (int percent)
{
_delegate.progress(((_step * 100) + percent) / _steps);
}
/** The total number of steps. */
protected final int _steps;
/** Our delegate observer. */
protected final ProgressObserver _delegate;
/** The current step. */
protected int _step;
}
protected Application _app; protected Application _app;
protected Application.UpdateInterface _ifc = new Application.UpdateInterface(); protected Application.UpdateInterface _ifc = new Application.UpdateInterface();
@@ -39,19 +39,18 @@ public class MetaProgressObserver implements ProgressObserver
public void startElement (long elementSize) public void startElement (long elementSize)
{ {
_currentSize += elementSize; // add the previous size
_accum += (_elementSize * 100);
// then set the new one
_elementSize = elementSize; _elementSize = elementSize;
} }
// documentation inherited from interface // documentation inherited from interface
public void progress (int percent) public void progress (int percent)
{ {
if (_target != null && _elementSize > 0) { _target.progress((int)((_accum + (percent * _elementSize)) / _totalSize));
long position = _currentSize + (100 * percent / _elementSize);
_target.progress((int)(100 * position / _totalSize));
}
} }
protected ProgressObserver _target; protected ProgressObserver _target;
protected long _totalSize, _currentSize, _elementSize; protected long _totalSize, _accum, _elementSize;
} }