Beispiel #1
0
    public void RepleaceWith(XManifestInfo newManifest)
    {
        foreach (var pack in newManifest.packs)
        {
            if (System.IO.File.Exists(Path.Combine(AssetBundleManager.dataBasePath, string.Format("{0}.{1}", pack.name, pack.checksum))))
            {
                pack.location = Location.Data;
            }
            else
            {
                pack.location = Location.Streaming;
            }
        }

        foreach (var file in newManifest.files)
        {
            if (System.IO.File.Exists(Path.Combine(LuaFilePicker.dataBasePath, string.Format("{0}.{1}", file.name, file.checksum))))
            {
                file.location = Location.Data;
            }
            else
            {
                file.location = Location.Streaming;
            }
        }

        Clear();
        _ParseContent(newManifest);
        XManifest.Instance.SaveToPersistentDataPath();
    }
Beispiel #2
0
    public void Load(string path)
    {
        Clear();
        System.IO.StreamReader sr = new System.IO.StreamReader(path);
        string data = sr.ReadToEnd();

        sr.Close();
        XManifestInfo info = XManifestInfo.Parse(data);

        _ParseContent(info);
    }
Beispiel #3
0
    public void Initialize(bool useExternalFolder) // useExternalFolder:是否允许从外部储存目录读取
    {
        Clear();
        isExternal = false;

        string data    = string.Empty;
        string extPath = System.IO.Path.Combine(Application.persistentDataPath, name);

        if (useExternalFolder && System.IO.File.Exists(extPath))
        {
            System.IO.StreamReader sr = new System.IO.StreamReader(extPath);
            data = sr.ReadToEnd();
            sr.Close();

            Debug.LogFormat("...Load Manifest in ext path: {0}...", extPath);

            if (string.IsNullOrEmpty(data))
            {
                Debug.LogFormat("...ext Manifest damaged, delete now: {0}...", extPath);
                System.IO.File.Delete(extPath);
            }
            else
            {
                isExternal = true;
            }
        }
        else
        {
            data = ResHelper.LoadTextFromStreamingAssets(System.IO.Path.Combine(Application.streamingAssetsPath, name));
        }

        if (string.IsNullOrEmpty(data))
        {
            Debug.LogFormat("...Manifest not exist...", extPath);
            return;
        }

        XManifestInfo info = XManifestInfo.Parse(data);

        if (info != null)
        {
            _ParseContent(info);
        }
        else
        {
            Debug.LogError("...Parse Manifest info failed...");
        }
    }
Beispiel #4
0
    private void _ParseContent(XManifestInfo info)
    {
        if (info.files != null)
        {
            for (int i = 0; i < info.files.Count; i++)
            {
                Add(info.files[i]);
            }
        }

        if (info.packs != null)
        {
            for (int i = 0; i < info.packs.Count; i++)
            {
                Add(info.packs[i]);
            }
        }

        if (info.scenes != null)
        {
            for (int i = 0; i < info.scenes.Count; i++)
            {
                Add(info.scenes[i]);
            }
        }

        if (info.spritePacks != null)
        {
            for (int i = 0; i < info.spritePacks.Count; i++)
            {
                Add(info.spritePacks[i]);
            }
        }
        if (info.bundleRules != null)
        {
            for (int i = 0; i < info.bundleRules.Count; i++)
            {
                AddBundleRule(info.bundleRules[i]);
            }
        }
    }
Beispiel #5
0
    public Queue <EntryDiff> GenerateManifestDiff(XManifestInfo newManifest)
    {
        Queue <EntryDiff> diffManifest = new Queue <EntryDiff>();

        // pack diff
        for (int i = 0; i < newManifest.packs.Count; i++)
        {
            bool diff = true;
            Pack pack = newManifest.packs[i];
            Pack localPack;
            if (_packs.TryGetValue(pack.name, out localPack))
            {
                if (localPack.checksum == pack.checksum)
                {
                    diff = false;
                }
            }

            if (diff)
            {
                diffManifest.Enqueue(new EntryDiff()
                {
                    type = EntryType.Pack, local = localPack, remote = pack
                });
            }
        }

        // file diff
        for (int i = 0; i < newManifest.files.Count; i++)
        {
            bool diff = true;
            File file = newManifest.files[i];
            File localFile;
            if (_files.TryGetValue(file.name, out localFile))
            {
                if (localFile.checksum == file.checksum)
                {
                    diff = false;
                }
            }

            if (diff)
            {
                diffManifest.Enqueue(new EntryDiff()
                {
                    type = EntryType.File, local = localFile, remote = file
                });
            }
        }

        // scene diff
        for (int i = 0; i < newManifest.scenes.Count; i++)
        {
            bool  diff  = true;
            Scene scene = newManifest.scenes[i];
            Scene localScene;
            if (_scenes.TryGetValue(scene.name, out localScene))
            {
                if (localScene.bundle == scene.bundle)
                {
                    diff = false;
                }
            }

            if (diff)
            {
                diffManifest.Enqueue(new EntryDiff()
                {
                    type = EntryType.Scene, local = localScene, remote = scene
                });
            }
        }

        // spritepack diff
        for (int i = 0; i < newManifest.spritePacks.Count; i++)
        {
            bool       diff       = true;
            SpritePack spritePack = newManifest.spritePacks[i];
            SpritePack localSpritePack;
            if (_spritePacks.TryGetValue(spritePack.name, out localSpritePack))
            {
                if (localSpritePack.realName == spritePack.realName)
                {
                    diff = false;
                }
            }

            if (diff)
            {
                diffManifest.Enqueue(new EntryDiff()
                {
                    type = EntryType.SpritePack, local = localSpritePack, remote = spritePack
                });
            }
        }

        return(diffManifest);
    }
Beispiel #6
0
    public void Save(string path, bool pretty = true, int MainVersion = 0, int SubVersion = 0)
    {
        List <Pack> packs = new List <Pack>();

        foreach (Pack pack in _packs.Values)
        {
            packs.Add(pack);
        }

        List <File> files = new List <File>();

        foreach (File file in _files.Values)
        {
            files.Add(file);
        }

        List <Scene> scenes = new List <Scene>();

        foreach (Scene scene in _scenes.Values)
        {
            scenes.Add(scene);
        }

        List <SpritePack> spritePacks = new List <SpritePack>();

        foreach (SpritePack spritePack in _spritePacks.Values)
        {
            spritePacks.Add(spritePack);
        }

        List <BundlePackRule> bundleRules = new List <BundlePackRule>();

        foreach (BundlePackRule bundleRule in _bundleRules)
        {
            bundleRules.Add(bundleRule);
        }

#if UNITY_EDITOR
        #region CACHE
        BundleExtraCacheInfo cacheInfo    = null;
        List <string>        cacheInScene = null;
        List <string>        cacheAllTime = null;
        List <string>        notCache     = null;
        string infoText = BundleExtraInfoUtils.GetBundleExtraCacheInfoText();
        if (!string.IsNullOrEmpty(infoText))
        {
            cacheInfo = LitJson.JsonMapper.ToObject <BundleExtraCacheInfo>(infoText);
            if (cacheInfo != null)
            {
                cacheInScene = BundleExtraInfoUtils.ArrayToList <string>(cacheInfo.CacheInScene);
                if (cacheInScene == null)
                {
                    cacheInScene = new List <string>();
                }
                cacheAllTime = BundleExtraInfoUtils.ArrayToList <string>(cacheInfo.CacheAllTime);
                if (cacheAllTime == null)
                {
                    cacheAllTime = new List <string>();
                }

                notCache = BundleExtraInfoUtils.ArrayToList <string>(cacheInfo.NotCache);
                if (notCache == null)
                {
                    notCache = new List <string>();
                }

                foreach (Pack pack in packs)
                {
                    SetupBundleCacheType(pack, notCache, cacheInScene, cacheAllTime);
                }

                foreach (Scene scene in scenes)
                {
                    SetupBundleCacheType(scene, notCache, cacheInScene, cacheAllTime);
                }
            }
        }
        else
        {
            Debug.LogError("NOT FOUND BUNDLE EXTRA INFO TEXT!!!!!!!!!!!!");
        }

        #endregion      //CACHE
#endif

        XManifestInfo manifest = new XManifestInfo();
        manifest.packs       = packs;
        manifest.files       = files;
        manifest.scenes      = scenes;
        manifest.spritePacks = spritePacks;
        manifest.bundleRules = bundleRules;
        manifest.MainVersion = MainVersion;
        manifest.SubVersion  = SubVersion;

        Debug.LogFormat("Mainfest_Save {0}, {1}", MainVersion, SubVersion);

        System.IO.FileStream fs = new System.IO.FileStream(path, System.IO.FileMode.Create, System.IO.FileAccess.Write);
        if (fs != null)
        {
            StringBuilder          sb     = new StringBuilder();
            System.IO.StringWriter writer = new System.IO.StringWriter(sb);
            LitJson.JsonMapper.ToJson(manifest,
                                      new LitJson.JsonWriter(writer)
            {
                PrettyPrint = pretty
            });

            byte[] buff = Encoding.UTF8.GetBytes(sb.ToString());

            fs.Write(buff, 0, buff.Length);
            fs.Close();
        }
    }