Esempio n. 1
0
    private static void CompressFirstUPK()
    {
        // 版本路径
        string versionPath = GetVersionBundlePath();

        // 资源路径
        string firstUpkPath = Replace(string.Format("{0}{1}{2}", versionPath, Path.DirectorySeparatorChar, "first_upk"));

        //UPK资源路径
        string UPKPath = Replace(string.Format("{0}{1}{2}", firstUpkPath, Path.DirectorySeparatorChar, "first.upk"));

        //UPK资源路径
        string CompressUPKPah = Replace(string.Format("{0}{1}{2}", firstUpkPath, Path.DirectorySeparatorChar, "first.zupk"));

        RCompress.CompressFileLZMA(UPKPath, CompressUPKPah);

        // 替换之前文件
        if (File.Exists(UPKPath))
        {
            File.Delete(UPKPath);
        }

        File.Copy(CompressUPKPah, UPKPath);

        File.Delete(CompressUPKPah);
    }
Esempio n. 2
0
    // 压缩 streaming upk
    private static void CompressStreamingUPK()
    {
        // 资源路径
        string assetPath = Replace(string.Format("{0}{1}{2}", Application.dataPath, Path.DirectorySeparatorChar, "StreamingAssets"));

        // UPK资源路径
        string UPKPath = Replace(string.Format("{0}{1}{2}", assetPath, Path.DirectorySeparatorChar, "streaming.upk"));

        // UPK资源路径
        string CompressUPKPath = Replace(string.Format("{0}{1}{2}", assetPath, Path.DirectorySeparatorChar, "streaming.zupk"));

        RCompress.CompressFileLZMA(UPKPath, CompressUPKPath);

        //替换之前文件
        if (File.Exists(UPKPath))
        {
            File.Delete(UPKPath);
        }

        File.Copy(CompressUPKPath, UPKPath);

        File.Delete(CompressUPKPath);
    }
Esempio n. 3
0
    private IEnumerator UnpackStreamingAsync()
    {
        // 包信息
        if (Application.platform == RuntimePlatform.Android)
        {
            WWW www = new WWW(infoFilePath);
            yield return(www);

            if (!string.IsNullOrEmpty(www.error))
            {
                if (i_unpack != null)
                {
                    i_unpack.OnStreamingError("read streaming upk info www.error = " + www.error);
                }
                yield break;
            }
            else
            {
                infos = UPKInfo.Read(www.text);
            }
        }
        // UPK 文件读取
        if (Application.platform == RuntimePlatform.Android)
        {
            WWW www = new WWW(upkFilePath);
            yield return(www);

            if (!string.IsNullOrEmpty(www.error))
            {
                if (i_unpack != null)
                {
                    i_unpack.OnStreamingError("read streaming upk www.error = " + www.error);
                }
                yield break;
            }
            else
            {
                File.WriteAllBytes(tempUpkPath, www.bytes);
            }
        }
        else
        {
            File.Copy(upkFilePath, tempUpkPath);
        }
        yield return(0);

        // 解压
        if (i_unpack != null)
        {
            i_unpack.OnStreamingDecompression();
        }

        if (VersionInfo.IsCompression)
        {
            bool result = false;
            Timers.inst.StartCoroutine(WaitThreadRun(() =>
            {
                RCompress.DecompressFileLZMA(tempUpkPath, tempOutUpkPath);
                result = true;
            }));

            while (!result)
            {
                yield return(new WaitForSeconds(0.1f));
            }
        }
        else
        {
            tempOutUpkPath = upkFilePath;
        }

        FileStream upkOutStream = new FileStream(tempOutUpkPath, FileMode.Open);

        if (upkOutStream != null)
        {
            // 解包文件
            long offset = 0;
            for (int i = 0; i < infos.Length; i++)
            {
                var resPath = Path.Combine(outPath, infos[i].relativePath);
                var resLen  = infos[i].length;

                var resDir = Path.GetDirectoryName(resPath);
                if (!Directory.Exists(resDir))
                {
                    Directory.CreateDirectory(resDir);
                }

                if (File.Exists(resPath))
                {
                    File.Delete(resPath);
                }

                FileStream outStream = new FileStream(resPath, FileMode.Create);

                var outData = new byte[resLen];
                upkOutStream.Seek(offset, SeekOrigin.Begin);
                upkOutStream.Read(outData, 0, (int)resLen);

                outStream.Write(outData, 0, (int)resLen);
                outStream.Flush();
                outStream.Close();

                offset += resLen;

                if (i_unpack != null)
                {
                    i_unpack.OnStreamingProgress(upkOutStream.Length, offset);
                }
                yield return(0);
            }
            upkOutStream.Close();
        }
        else
        {
            if (i_unpack != null)
            {
                i_unpack.OnStreamingError("read streaming upk stream == null");
            }
        }
        if (i_unpack != null)
        {
            i_unpack.OnStreamingFinished();
        }

        // 删除临时文件
        if (File.Exists(tempUpkPath))
        {
            File.Delete(tempUpkPath);
        }

        if (File.Exists(tempOutUpkPath))
        {
            File.Delete(tempOutUpkPath);
        }
        yield break;
    }