From 6a8fcd80b716a296d54881e85d41f45a888bbc30 Mon Sep 17 00:00:00 2001 From: Ray Greenwell Date: Wed, 21 Jun 2006 01:02:26 +0000 Subject: [PATCH] Added a method to ensure a particular capacity for client preferences. We'll call this with a big fat number whenever a non-guest logs in. The first time we ask, the user will authorize the big fat storage, and it will never ask again. Hopefully we can make it look like part of the login... git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@4202 542714f4-19e9-0310-aa3c-eee0fc999fb1 --- src/as/com/threerings/util/Config.as | 43 ++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/src/as/com/threerings/util/Config.as b/src/as/com/threerings/util/Config.as index a30d04a5e..b059e1249 100644 --- a/src/as/com/threerings/util/Config.as +++ b/src/as/com/threerings/util/Config.as @@ -1,6 +1,9 @@ package com.threerings.util { +import flash.events.NetStatusEvent; + import flash.net.SharedObject; +import flash.net.SharedObjectFlushStatus; public class Config { @@ -40,6 +43,46 @@ public class Config _so.flush(); // flushing is not strictly necessary } + /** + * Ensure that we can store preferences up to the specified size. + * Note that calling this method may pop up a dialog to the user, asking + * them if it's ok to increase the capacity. The result listener may + * never be called if the user doesn't answer the pop-up. + * + * @param rl an optional listener that will be informed as to whether + * the request succeeded. + */ + public function ensureCapacity (kilobytes :int, rl :ResultListener) :void + { + // flush with the size, see if we're cool + var result :String = _so.flush(1024 * kilobytes); + if (rl == null) { + return; + } + + // success + if (result == SharedObjectFlushStatus.FLUSHED) { + rl.requestCompleted(this); + return; + } + + // otherwise we'll hear back in a sec + var thisConfig :Config = this; + var listener :Function = function (evt :NetStatusEvent) :void { + // TODO: as of beta3 there is a bug where the status + // is always "SharedObject.Flush.Failed", even on success + //trace("================[" + evt.info.code + "]"); + if ("SharedObject.Flush.Success" == evt.info.code) { + rl.requestCompleted(thisConfig); + } else { + rl.requestFailed(new Error(String(evt.info.code))); + } + _so.removeEventListener(NetStatusEvent.NET_STATUS, listener); + }; + + _so.addEventListener(NetStatusEvent.NET_STATUS, listener); + } + /** The shared object that contains our preferences. */ protected var _so :SharedObject; }