Beispiel #1
0
        /// <summary>
        /// DownLoad Async
        /// </summary>
        /// <param name="url">url to download</param>
        /// <param name="url">filepath to save</param>
        /// /// <param name="url">is Text or not</param>
        private void DownLoadAsync(string url, bool isText = false, string savepath = "")
        {
            Loom.RunAsync(() =>
            {
                asyncTask                = new AsyncTask();
                asyncTask.url            = url;
                asyncTask.isText         = isText;
                asyncTask.asyncTaskState = AsyncTaskState.Prepare;

                try
                {
                    //createfile
                    if (!isText)
                    {
                        string dirpath = savepath.Substring(0, savepath.LastIndexOf("/"));
                        if (Directory.Exists(dirpath) == false)
                        {
                            Directory.CreateDirectory(dirpath);
                        }

                        if (File.Exists(savepath))
                        {
                            fileStream = new FileStream(savepath, FileMode.Append);
                        }
                        else
                        {
                            fileStream = new FileStream(savepath, FileMode.CreateNew);
                        }
                    }

                    HttpWebRequest httpWebRequest = WebRequest.Create(url) as HttpWebRequest;
                    if (!isText)
                    {
                        if (File.Exists(savepath))
                        {
                            httpWebRequest.AddRange((int)fileStream.Length);
                        }
                        else
                        {
                            //httpWebRequest.AddRange(0, AsyncTask.bufferSize);
                        }
                    }



                    asyncTask.httpWebRequest = httpWebRequest;

                    httpWebRequest.BeginGetResponse(new AsyncCallback(ResponseCallback), asyncTask);
                }
                catch (WebException exp)
                {
                    asyncTask.asyncTaskState = AsyncTaskState.Failed;
                    asyncTask.exception      = exp;
                }
                catch (Exception exp)
                {
                    asyncTask.asyncTaskState = AsyncTaskState.Failed;
                    asyncTask.exception      = exp;
                }
            });
        }
Beispiel #2
0
 void Awake()
 {
     mCurrent    = this;
     initialized = true;
 }