flex-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aha...@apache.org
Subject [2/3] git commit: [flex-utilities] [refs/heads/develop] - add download caching to Get task
Date Wed, 12 Feb 2014 22:44:56 GMT
add download caching to Get task


Project: http://git-wip-us.apache.org/repos/asf/flex-utilities/repo
Commit: http://git-wip-us.apache.org/repos/asf/flex-utilities/commit/1276a054
Tree: http://git-wip-us.apache.org/repos/asf/flex-utilities/tree/1276a054
Diff: http://git-wip-us.apache.org/repos/asf/flex-utilities/diff/1276a054

Branch: refs/heads/develop
Commit: 1276a054c9ca0f9f21d9a65fe75b30e7e9374329
Parents: b54f16f
Author: Alex Harui <aharui@apache.org>
Authored: Wed Feb 12 14:43:22 2014 -0800
Committer: Alex Harui <aharui@apache.org>
Committed: Wed Feb 12 14:44:47 2014 -0800

----------------------------------------------------------------------
 ant_on_air/src/org/apache/flex/ant/Ant.as      | 10 ++++++
 ant_on_air/src/org/apache/flex/ant/tags/Get.as | 34 +++++++++++++++++++--
 2 files changed, 42 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/1276a054/ant_on_air/src/org/apache/flex/ant/Ant.as
----------------------------------------------------------------------
diff --git a/ant_on_air/src/org/apache/flex/ant/Ant.as b/ant_on_air/src/org/apache/flex/ant/Ant.as
index 754e955..a3b28d8 100644
--- a/ant_on_air/src/org/apache/flex/ant/Ant.as
+++ b/ant_on_air/src/org/apache/flex/ant/Ant.as
@@ -227,5 +227,15 @@ package org.apache.flex.ant
          *  Output for Echo.  Defaults to trace().
          */
         public var output:Function = function(s:String):void { trace(s) };
+        
+        /**
+         *  Whether Get uses a download cache
+         */
+        public static var usingDownloadCache:Boolean;
+        
+        /**
+         *  The folder Get uses as a download cache
+         */
+        public static var downloadCacheFolder:String;
     }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/1276a054/ant_on_air/src/org/apache/flex/ant/tags/Get.as
----------------------------------------------------------------------
diff --git a/ant_on_air/src/org/apache/flex/ant/tags/Get.as b/ant_on_air/src/org/apache/flex/ant/tags/Get.as
index 6e679fa..8c70f37 100644
--- a/ant_on_air/src/org/apache/flex/ant/tags/Get.as
+++ b/ant_on_air/src/org/apache/flex/ant/tags/Get.as
@@ -86,7 +86,22 @@ package org.apache.flex.ant.tags
             s = s.replace("%1", getDestFile().nativePath);
             ant.output(ant.formatOutput("get", s));
             
-            var urlRequest:URLRequest = new URLRequest(src);
+            var actualSrc:String = src;
+            if (Ant.usingDownloadCache)
+            {
+                if (src.indexOf("http") == 0)
+                {
+                    var c:int = src.indexOf("/");
+                    c = src.indexOf("/", c + 1);
+                    c = src.indexOf("/", c + 1);
+                    // that should find the slash after the server.
+                    var cacheFile:File = File.applicationStorageDirectory.resolvePath(Ant.downloadCacheFolder);
+                    cacheFile = cacheFile.resolvePath(src.substr(c + 1));
+                    if (cacheFile.exists)
+                        actualSrc = cacheFile.url;
+                }
+            }
+            var urlRequest:URLRequest = new URLRequest(actualSrc);
             urlRequest.followRedirects = false;
             urlRequest.userAgent = "Java";	// required to get sourceforge redirects to do
the right thing
             urlLoader = new URLLoader();
@@ -177,7 +192,22 @@ package org.apache.flex.ant.tags
                 fs.open(destFile, FileMode.WRITE);
                 fs.writeBytes(urlLoader.data as ByteArray);
                 fs.close();
-            }            
+            }
+            if (Ant.usingDownloadCache)
+            {
+                if (src.indexOf("http") == 0)
+                {
+                    var c:int = src.indexOf("/");
+                    c = src.indexOf("/", c + 1);
+                    c = src.indexOf("/", c + 1);
+                    // that should find the slash after the server.
+                    var cacheFile:File = File.applicationStorageDirectory.resolvePath(Ant.downloadCacheFolder);
+                    cacheFile = cacheFile.resolvePath(src.substr(c + 1));
+                    if (!cacheFile.exists)
+                        destFile.copyTo(cacheFile);
+                }
+            }
+
             dispatchEvent(new Event(Event.COMPLETE));
 			urlLoader = null;
         }


Mime
View raw message