Esempio n. 1
0
    public string GetInterpretedDownloadUrl(BuildPlatform platform, bool bUseBackup = false)
    {
        if (bUseBackup)
        {
            return(BMUtility.InterpretPath(backupDownloadUrls[platform.ToString()], platform));
        }

        return(BMUtility.InterpretPath(downloadUrls[platform.ToString()], platform));
    }
Esempio n. 2
0
    private void CopyToDownloadPath()
    {
        var srcPath  = BuildConfiger.InterpretedOutputPath;
        var destPath = BMUtility.InterpretPath(BuildConfiger.CopyFolderStr, BuildConfiger.AutoBundleBuildtarget);

        if (Directory.Exists(destPath))
        {
            Directory.Delete(destPath, true);
        }
        BuildHelper.CopyFiles(srcPath, destPath);
    }
Esempio n. 3
0
    void initRootUrl()
    {
        TextAsset downloadUrlText = (TextAsset)Resources.Load("Urls");

        bmUrl = JsonMapper.ToObject <BMUrls>(downloadUrlText.text);

        if (Application.platform == RuntimePlatform.WindowsEditor ||
            Application.platform == RuntimePlatform.OSXEditor)
        {
#if UNITY_EDITOR
            switch (UnityEditor.EditorUserBuildSettings.activeBuildTarget)
            {
            case UnityEditor.BuildTarget.Android:
                curPlatform = BuildPlatform.Android;
                break;

            case UnityEditor.BuildTarget.iPhone:
                curPlatform = BuildPlatform.IOS;
                break;

            default:
                curPlatform = BuildPlatform.Standalones;
                break;
            }
#else
            curPlatform = bmUrl.bundleTarget;
#endif
        }
        else
        {
            curPlatform = getRuntimePlatform();
        }
        string downloadPathStr = string.Empty;
        if (manualUrl == "")
        {
            if (bmUrl.downloadFromOutput)
            {
                downloadPathStr = bmUrl.GetInterpretedOutputPath(curPlatform);
            }
            else
            {
                downloadPathStr = bmUrl.GetInterpretedDownloadUrl(curPlatform);
            }
        }
        else
        {
            downloadPathStr = BMUtility.InterpretPath(manualUrl, curPlatform);
        }
        if (!string.IsNullOrEmpty(downloadPathStr))
        {
            localRootUrl = new Uri(downloadPathStr).AbsoluteUri;
        }
    }
Esempio n. 4
0
    void initRootUrl()
    {
        TextAsset downloadUrlText = (TextAsset)Resources.Load("Urls");

        bmUrl = JsonMapper.ToObject <BMUrls>(downloadUrlText.text);

        if (Application.platform == RuntimePlatform.WindowsEditor ||
            Application.platform == RuntimePlatform.OSXEditor)
        {
            curPlatform = bmUrl.bundleTarget;
        }
        else
        {
            curPlatform = getRuntimePlatform();
        }

        if (manualUrl == "")
        {
            string downloadPathStr;
            if (bmUrl.downloadFromOutput)
            {
                downloadPathStr = bmUrl.GetInterpretedOutputPath(curPlatform);
            }
            else
            {
                downloadPathStr = bmUrl.GetInterpretedDownloadUrl(curPlatform);
            }

            Uri downloadUri = new Uri(downloadPathStr);
            downloadRootUrl = downloadUri.AbsoluteUri;
        }
        else
        {
            string downloadPathStr = BMUtility.InterpretPath(manualUrl, curPlatform);
            Uri    downloadUri     = new Uri(downloadPathStr);
            downloadRootUrl = downloadUri.AbsoluteUri;
        }

        downloadLoadRootUrl = Application.dataPath.Substring(0, Application.dataPath.LastIndexOf("/")) + "/" + "assetBundle";
    }
Esempio n. 5
0
 public string GetInterpretedOutputPath(BuildPlatform platform)
 {
     return(BMUtility.InterpretPath(outputs[platform.ToString()], platform));
 }
Esempio n. 6
0
 public string GetInterpretedDownloadUrl(BuildPlatform platform)
 {
     return(BMUtility.InterpretPath(downloadUrls[platform.ToString()], platform));
 }
Esempio n. 7
0
        private static void AndroidPackageProcess(string path)
        {
            #region 打开apk,装入bundles
            FileInfo bundle = new FileInfo(path);
            if (bundle.Length < MaxBundleSize || MaxBundleSize == 0)
            {
                using (var zipFile = new ZipFile(path))
                {
                    string basePath   = BMUtility.InterpretPath("$(Personal)/LTSites/", BuildPlatform.Android);
                    string outputPath = BuildConfiger.InterpretedOutputPath;
                    string shortPath  = "assets/AssetBundles/" + outputPath.Substring(basePath.Length);
                    if (zipFile.ContainsEntry(shortPath + "/" + "BundleShipInfo.json"))                     //已装过bundles
                    {
                        UnityEngine.Debug.LogWarning("AssetBundles already exists");
                    }
                    else
                    {
                        //获取要装入的bundles
                        // UnityEngine.Debug.LogError($"AndroidPackageProcess=====>max: {MaxBundleSize}==bundleLenght: {bundle.Length}");
                        var assets = MaxBundleSize > 0 ? BuildHelper.GetBundlesByPriority(MaxBundleSize - bundle.Length) : BMDataAccessor.BundleShipInfos;
                        zipFile.AddDirectoryByName(shortPath);
                        //装入准备好的bundles
                        foreach (var file in assets)
                        {
                            if (!GM.RemoteBundleManager.IsBuildBundle(file.BundleName))
                            {
                                continue;
                            }
                            var fullpath  = Path.Combine(outputPath, file.BundleName.ToLower() + ".cz");
                            var shortname = shortPath + "/" + file.BundleName.ToLower() + ".cz";
                            if (zipFile.ContainsEntry(shortname))
                            {
                                UnityEngine.Debug.LogWarningFormat("{0} already exists", shortname);
                            }
                            else
                            {
                                zipFile.AddFile(fullpath, shortPath);
                            }
                        }

                        //装入json等文件
                        if (MaxBundleSize == 0)
                        {
                            foreach (string s in Directory.GetFiles(outputPath, "*.json"))
                            {
                                string fileName  = System.IO.Path.GetFileName(s);
                                var    shortname = shortPath + "/" + fileName;
                                if (zipFile.ContainsEntry(shortname))
                                {
                                    UnityEngine.Debug.LogWarningFormat("{0} already exists", shortname);
                                }
                                else
                                {
                                    zipFile.AddFile(s, shortPath);
                                }
                            }

                            string sourcePath      = Path.GetDirectoryName(outputPath);
                            string destinationPath = Path.GetDirectoryName(shortPath);
                            foreach (string s in Directory.GetFiles(sourcePath))
                            {
                                string fileName  = System.IO.Path.GetFileName(s);
                                var    shortname = destinationPath + "/" + fileName;
                                if (zipFile.ContainsEntry(shortname))
                                {
                                    UnityEngine.Debug.LogWarningFormat("{0} already exists", shortname);
                                }
                                else
                                {
                                    zipFile.AddFile(s, destinationPath);
                                }
                            }
                        }
                        else
                        {
                            string shipInfoFile = shortPath + "/" + "BundleShipInfo.json";
                            if (zipFile.ContainsEntry(shipInfoFile))
                            {
                                zipFile.UpdateEntry(shipInfoFile, EB.Encoding.GetBytes(GM.JSON.ToJson(assets)));
                            }
                            else
                            {
                                zipFile.AddEntry(shipInfoFile, EB.Encoding.GetBytes(GM.JSON.ToJson(assets)));
                            }
                        }

                        //由于包体过大,压缩前需要设置这个
                        zipFile.UseZip64WhenSaving = Zip64Option.AsNecessary;
                        zipFile.Save();
                    }
                }
            }
            #endregion

            //重新签名
            ResignAPK(path);
        }
Esempio n. 8
0
    // Privats
    IEnumerator Start()
    {
        // Initial download urls
        initRootUrl();

        // Try to get Url redirect file
        WWW redirectWWW = new WWW(formatUrl("BMRedirect.txt"));

        yield return(redirectWWW);

        if (redirectWWW.error == null)
        {
            // Redirect download
            string downloadPathStr = BMUtility.InterpretPath(redirectWWW.text, curPlatform);
            Uri    downloadUri     = new Uri(downloadPathStr);
            downloadRootUrl = downloadUri.AbsoluteUri;
        }

        redirectWWW.Dispose();


        // Download the initial data bundle
        const string verNumKey         = "BMDataVersion";
        string       bmDataUrl         = formatUrl("BM.data");
        int          lastBMDataVersion = 0;

        if (PlayerPrefs.HasKey(verNumKey))
        {
            lastBMDataVersion = PlayerPrefs.GetInt(verNumKey);
        }

        // Download and cache new data version
        WWW initDataWWW;

        if (bmUrl.offlineCache)
        {
            initDataWWW = WWW.LoadFromCacheOrDownload(bmDataUrl, lastBMDataVersion + 1);

            yield return(initDataWWW);

            if (initDataWWW.error != null)
            {
                initDataWWW.Dispose();
                Debug.Log("Cannot load BMData from target url. Try load it from cache.");

                initDataWWW = WWW.LoadFromCacheOrDownload(bmDataUrl, lastBMDataVersion);
                yield return(initDataWWW);

                if (initDataWWW.error != null)
                {
                    Debug.LogError("Download BMData failed.\nError: " + initDataWWW.error);
                    yield break;
                }
            }
            else
            {
                // Update cache version number
                PlayerPrefs.SetInt(verNumKey, lastBMDataVersion + 1);
            }
        }
        else
        {
            initDataWWW = new WWW(bmDataUrl);

            yield return(initDataWWW);

            if (initDataWWW.error != null)
            {
                Debug.LogError("Download BMData failed.\nError: " + initDataWWW.error);
                yield break;
            }
        }

        // Init datas
        //
        // Bundle Data
#if UNITY_5
        TextAsset ta = initDataWWW.assetBundle.LoadAsset <TextAsset>("BundleData");
#else
        TextAsset ta = initDataWWW.assetBundle.Load("BundleData") as TextAsset;
#endif
        bundles = JsonMapper.ToObject <List <BundleData> >(ta.text);
        foreach (var bundle in bundles)
        {
            bundleDict.Add(bundle.name, bundle);
        }

        // Build States
#if UNITY_5
        ta = initDataWWW.assetBundle.LoadAsset <TextAsset>("BuildStates");
#else
        ta = initDataWWW.assetBundle.Load("BuildStates") as TextAsset;
#endif
        buildStates = JsonMapper.ToObject <List <BundleBuildState> >(ta.text);
        foreach (var buildState in buildStates)
        {
            buildStatesDict.Add(buildState.bundleName, buildState);
        }

        // BMConfiger
#if UNITY_5
        ta = initDataWWW.assetBundle.LoadAsset <TextAsset>("BMConfiger");
#else
        ta = initDataWWW.assetBundle.Load("BMConfiger") as TextAsset;
#endif
        bmConfiger = JsonMapper.ToObject <BMConfiger>(ta.text);

        initDataWWW.assetBundle.Unload(true);
        initDataWWW.Dispose();


        // Start download for requests before init
        foreach (WWWRequest request in requestedBeforeInit)
        {
            download(request);
        }
    }
Esempio n. 9
0
    public IEnumerator CheckUpdate(string downloadPath)
    {
        while (!ConfigLoaded)
        {
            yield return(null);
        }

        var downloadPathStr = BMUtility.InterpretPath(downloadPath, curPlatform);

        if (string.IsNullOrEmpty(downloadPathStr))
        {
            CheckUpdateError = "{BM} Invalid update download path" + downloadPathStr;
            yield break;
        }

        remoteRootUrl = new Uri(downloadPathStr).AbsoluteUri;

        //Try to get Url redirect file
        var redirectUrl = formatUrl(remoteRootUrl, "BMRedirect.txt");

        if (!string.IsNullOrEmpty(redirectUrl))
        {
            WWW redirectWWW = new WWW(redirectUrl);
            yield return(redirectWWW);

            if (redirectWWW.error == null)
            {
                //Redirect download
                var redirectedDownloadPath = redirectWWW.text;
                downloadPathStr = BMUtility.InterpretPath(redirectedDownloadPath, curPlatform);
                if (string.IsNullOrEmpty(downloadPathStr))
                {
                    Debug.LogError("{BM} Invalid redirected download Path :" + downloadPathStr + "(Retrived from url:" + redirectUrl + ")." +
                                   "Using the original download path" + remoteRootUrl);
                }
                else
                {
                    remoteRootUrl = new Uri(downloadPathStr).AbsoluteUri;
                }
            }
            redirectWWW.Dispose();
        }

        var versionInfo = new VersionInfo(remoteRootUrl);

        yield return(StartCoroutine(downloadVersionInfoCo(versionInfo)));

        CheckUpdateError = versionInfo.error;

        if (versionInfo.isValue)
        {
            UpdateTotalSize = 0;
            UpdateVersion   = versionInfo.listVersion;

            mergeVersion(versionInfo);
            refreshBundleDict();
        }

        updateList = new List <BundleDownloadInfo>();
        foreach (var bundleDownloadInfo in bundles)
        {
            if (bundleDownloadInfo.needDownload)
            {
                if (!updateList.Contains(bundleDownloadInfo))
                {
                    updateList.Add(bundleDownloadInfo);
                    UpdateTotalSize += bundleDownloadInfo.versionInfo.size;
                }
            }
        }
    }