CreateFileWithBytes() public static method

public static CreateFileWithBytes ( string path, byte info, int length ) : void
path string
info byte
length int
return void
示例#1
0
 void MoveFile(DownloadFileRequest req, string info, byte[] bytes, int length)
 {
     if (req.fileType == DownloadFileType.TypeText)
     {
         FileManager.CreateFileWithString(req.filePath, info);
     }
     else if (req.fileType == DownloadFileType.TypeAssetBundle)
     {
         FileManager.CreateFileWithBytes(req.filePath, bytes, length);
     }
 }
 static public int CreateFileWithBytes_s(IntPtr l)
 {
     try {
         System.String a1;
         checkType(l, 1, out a1);
         System.Byte[] a2;
         checkType(l, 2, out a2);
         System.Int32 a3;
         checkType(l, 3, out a3);
         FileManager.CreateFileWithBytes(a1, a2, a3);
         pushValue(l, true);
         return(1);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
示例#3
0
        /// <summary>
        /// 从源目录中同步资源到目的目录
        /// </summary>
        /// <returns></returns>
        IEnumerator UpdateAB(string srcURL,
                             string desURL,
                             Action onSuccAction,
                             Action <float, string> onProgressAction,
                             Action <string> onFailAction)
        {
            string srcPath = SplitURL(srcURL);
            string desPath = SplitURL(desURL);

            Debug.Log(string.Format("UpdateAB, src:{0}, des:{1}, srcPath:{2},desPath:{3}", srcURL, desURL, srcPath, desPath));

            string platformName      = Platform.GetPlatformName();
            string srcAssetBundleURL = string.Format("{0}/{1}", srcURL, platformName);
            WWW    www = new WWW(srcAssetBundleURL);

            yield return(www);

            if (www.error != null)
            {
                Debug.Log("srcUrl assetbundlemainfest is null, error: " + www.error + " url:" + srcAssetBundleURL);
                onFailAction(www.error);
                yield return(null);
            }

            byte[] srcAssetBundleContent    = www.bytes;
            AssetBundleManifest srcManifest = www.assetBundle.LoadAsset("AssetBundleManifest") as AssetBundleManifest;

            www.assetBundle.Unload(false);

            // 下载AssetBundleManifest
            string srcAssetBundleManifestURL = string.Format("{0}/{1}.manifest", srcURL, platformName);

            www = new WWW(srcAssetBundleManifestURL);
            yield return(www);

            byte[] srcAssetBundleManifestContent = www.bytes;

            List <string> downloadAssetBundleList = new List <string>();

            string desAssetBundleURL = string.Format("{0}/{1}", desURL, platformName);

            www = new WWW(desAssetBundleURL);
            yield return(www);

            if (www.error != null)
            {
                // 如果目标目录不存在manifest文件就下载源目录的所有文件
                string[] srcAssetBundles = srcManifest.GetAllAssetBundles();
                for (int i = 0; i < srcAssetBundles.Length; ++i)
                {
                    downloadAssetBundleList.Add(srcAssetBundles[i]);
                }
            }
            else
            {
                AssetBundleManifest desManifest = www.assetBundle.LoadAsset("AssetBundleManifest") as AssetBundleManifest;
                www.assetBundle.Unload(false);

                string[] srcAssetBundles = srcManifest.GetAllAssetBundles();
                for (int i = 0; i < srcAssetBundles.Length; ++i)
                {
                    string srcAssetBundle = srcAssetBundles[i];
                    if (!File.Exists(desPath + srcAssetBundle))
                    {
                        downloadAssetBundleList.Add(srcAssetBundle);
                    }
                    else
                    {
                        Hash128 desAssetBundleHash = desManifest.GetAssetBundleHash(srcAssetBundle);
                        Hash128 srcAssetBundleHash = srcManifest.GetAssetBundleHash(srcAssetBundle);
                        if (!desAssetBundleHash.Equals(srcAssetBundleHash))
                        {
                            downloadAssetBundleList.Add(srcAssetBundle);
                        }
                    }
                }
            }

            string assetbundlePath;

            for (int i = 0; i < downloadAssetBundleList.Count; ++i)
            {
                string assetbundle = downloadAssetBundleList[i];

                float progress = (i / (float)downloadAssetBundleList.Count);
                onProgressAction(progress, assetbundle);

                srcAssetBundleURL = string.Format("{0}/{1}", srcURL, assetbundle);
                www = new WWW(srcAssetBundleURL);
                yield return(www);

                assetbundlePath = string.Format("{0}/{1}", desPath, assetbundle);
                FileManager.CreateFileWithBytes(assetbundlePath, www.bytes, www.bytes.Length);

                www = new WWW(string.Format("{0}/{1}.manifest", srcURL, assetbundle));
                yield return(www);

                string manifestPath = string.Format("{0}/{1}.manifest", desPath, assetbundle);
                FileManager.CreateFileWithBytes(manifestPath, www.bytes, www.bytes.Length);
            }

            assetbundlePath = string.Format("{0}/{1}", desPath, platformName);
            FileManager.CreateFileWithBytes(assetbundlePath, srcAssetBundleContent, srcAssetBundleContent.Length);

            string assetbundleManifestPath = string.Format("{0}/{1}.manifest", desPath, platformName);

            FileManager.CreateFileWithBytes(assetbundleManifestPath, srcAssetBundleManifestContent, srcAssetBundleManifestContent.Length);

            www.Dispose();
            www = null;

            onSuccAction();

            yield return(Resources.UnloadUnusedAssets());

            yield return(new WaitForEndOfFrame());

            m_UIAutoUpdate.gameObject.SetActive(false);
        }