Example #1
0
    public IEnumerator DownloadFileIterator()
    {
        if (IsOnlineFile)
        {
            WWW www = new WWW(fileDescriptor.PathOnline);
            //yield return www;

            while (!www.isDone)
            {
                statusText.GetComponent <Text> ().text = "downloaded " + (www.progress * 100).ToString() + "%...";
                yield return(null);
            }
            string fullPath = fileDescriptor.PathLocal;
            if (fileDescriptor.PathLocal == "")
            {
                //string fileName = fileDescriptor.Title + Guid.NewGuid().ToString("N");
                string fileName = fileDescriptor.Title;
                foreach (char c in System.IO.Path.GetInvalidFileNameChars())
                {
                    fileName = fileName.Replace(c, '_');
                }
                fullPath = Application.persistentDataPath + "/" + fileName + ".xml";
            }

            File.WriteAllBytes(fullPath, www.bytes);

            fileDescriptor.PathLocal = fullPath;
            fileDescriptor.PathLocalNode.InnerText = fullPath;
            fileDescriptor.SaveLocalXml();
            localPathText.GetComponent <Text> ().text = fileDescriptor.PathLocal;

            statusText.GetComponent <Text> ().text = "downloaded";
        }
        else
        {
            Debug.Log("not an online file");
        }
    }