Ejemplo n.º 1
0
 public static bool CleanCache()
 {
     TsCaching.SaveLastSpaceOccupied(0L);
     if (TsCaching.useCustomCacheOnly)
     {
         return(CustomCaching.CleanCache());
     }
     return(Caching.CleanCache());
 }
Ejemplo n.º 2
0
    private void OnDownload_PredownloadMarking(IDownloadedItem wItem, object obj)
    {
        if (!wItem.isSuccess || wItem.isCanceled)
        {
            TsLog.LogWarning("Failed~! OnDownload_PredownloadMarking() wItem= {0}", new object[]
            {
                wItem.assetPath
            });
            return;
        }
        bool flag = TsCaching.IsVersionCached(wItem.url, wItem.version, wItem.UseCustomCache);

        if (flag)
        {
            TsCaching.MarkAsUsed(wItem.url, wItem.version, wItem.UseCustomCache);
        }
    }
Ejemplo n.º 3
0
    public void SetPlatformPath()
    {
        string text = string.Empty;

        if (TsPlatform.IsEditor)
        {
            text = string.Format("{0}/Mobile/", NrTSingleton <NrGlobalReference> .Instance.basePath);
        }
        else if (TsPlatform.IsIPhone)
        {
            text = string.Format("{0}/at2/cacheroot/", TsPlatform.Operator.GetFileDir());
        }
        else if (TsPlatform.IsAndroid)
        {
            text = string.Format("{0}/at2/cacheroot/", TsPlatform.Operator.GetFileDir());
        }
        else
        {
            TsLog.Assert(false, "Unknown Platform", new object[0]);
        }
        this.m_strLocalFilePath = text;
        Option.SetProtocolRootPath(Protocol.FILE, text);
        UnityEngine.Debug.LogWarning("StageNPatchLauncher : " + text);
        this.m_strWebPath = Option.GetProtocolRootPath(Protocol.HTTP);
        TsLog.LogWarning("HttpPath[{0}] Cachepath[{1}]", new object[]
        {
            this.m_strWebPath,
            text
        });
        TsPlatform.FileLog("HttpPath = " + this.m_strWebPath + ", CacheDpath = " + text);
        NrTSingleton <NrGlobalReference> .Instance.localWWW = true;
        NrTSingleton <NrGlobalReference> .Instance.useCache = true;
        TsCaching.InitiailzeCustomCaching(this.m_strWebPath, text);
        Caching.maximumAvailableDiskSpace = (long)(1048576 * StageNPatchLauncher.UNITY_CACHE_SIZE);
        if (TsPlatform.IsAndroid)
        {
            NrTSingleton <NrGlobalReference> .Instance.STR_MOBILE_VER = TsPlatform.APP_VERSION_AND;
        }
        else if (TsPlatform.IsIPhone || TsPlatform.IsIPad())
        {
            NrTSingleton <NrGlobalReference> .Instance.STR_MOBILE_VER = TsPlatform.APP_VERSION_IOS;
        }
    }
Ejemplo n.º 4
0
    private void SetAuthorizeInfo()
    {
        switch (NrTSingleton <NrGlobalReference> .Instance.GetCurrentServiceArea())
        {
        case eSERVICE_AREA.SERVICE_WEBPLAYER_KORQA:
            Debug.Log("Cache Authorize Inner Domain - " + NrTSingleton <NrGlobalReference> .Instance.basePath);
            if (!TsCaching.Authorize("ndoorsat2_test_devkorea", "http://atlantica2.dn.nexoncdn.co.kr/", this.nCacheSize, -1, "9ed99fec890dc6ff08a55a1bb3a2ee35f230beea1978e8e35deaa9f43081ec73bcba689108e4299aff7bbb924471afed5603c143933d21162b581206058fb66850f9e421912f7c302aab9bdd99b5a71c7b238adffe9f7b027844c652ddd30ca4b822109cc41980c007de1c02559ae3c08837bf7507ad521ba3cc2ae7d1e2a58a"))
            {
                Debug.LogWarning("Cache Authorize [name = ndoorsat2_test_devkorea] Error!!");
            }
            break;

        case eSERVICE_AREA.SERVICE_WEBPLAYER_KORLIVE:
            Debug.Log("Cache Authorize Outer Domain - " + NrTSingleton <NrGlobalReference> .Instance.basePath);
            if (!TsCaching.Authorize("ndoorsat2_service_livekorea", "http://atlantica2.dn.nexoncdn.co.kr/", this.nCacheSize, -1, "5b180632c670ec79f15aa72bcca1218cae3b598d381a28dec47935a19144f299082dfcd9c33c2c6306ba26c8a7cf42c681a21bd48d8bc605424fcd022f6df5f0b36aa8d21231403dc1c65aa6efa49d4c2b351e9f67e3cebb589cc4ef39f18655170eebf16e9a38e315aa185f54db6062ba1d5a84e8a50b96a17227cc28c88f23"))
            {
                Debug.LogWarning("Cache Authorize [name = ndoorsat2_out_livetest] Error!!");
            }
            break;
        }
    }
Ejemplo n.º 5
0
        private void _CheckCaching()
        {
            this.m_cacheChecked             = true;
            this.isCacheHit                 = false;
            this.useLoadFromCacheOrDownload = false;
            if (this.m_protocol == Protocol.FILE)
            {
                return;
            }
            if (Option.localWWW)
            {
                this.m_protocol = Protocol.FILE;
                return;
            }
            if (!string.IsNullOrEmpty(this.anotherURL))
            {
                return;
            }
            if (!Option.useCache)
            {
                return;
            }
            if (this.m_kItem == null)
            {
                return;
            }
            if (!this.m_kItem.bUseCustomCache && !this.isUnityAsset)
            {
                return;
            }
            this.useLoadFromCacheOrDownload = true;
            string url = Option.GetProtocolRootPath(this.m_protocol) + this.assetPath;

            if (TsCaching.IsVersionCached(url, this.m_kItem.nVersion, this.m_kItem.bUseCustomCache))
            {
                this.isCacheHit = true;
            }
        }
Ejemplo n.º 6
0
        public static bool IsVersionCached(Protocol protocol, string path, bool markAsUsed)
        {
            path = path.ToLower();
            string        text          = Option.GetProtocolRootPath(protocol) + path;
            string        text2         = "/" + path;
            PatchFileInfo patchFileInfo = PatchFinalList.Instance.GetPatchFileInfo(text2);

            if (patchFileInfo == null)
            {
                TsLog.LogWarning("TsBundle.WWWItem.IsVersionCached Warning! - Key:{0}", new object[]
                {
                    text2.ToString()
                });
                return(false);
            }
            bool flag = TsCaching.IsVersionCached(text, patchFileInfo.nVersion, patchFileInfo.bUseCustomCache);

            if (flag && markAsUsed)
            {
                TsCaching.MarkAsUsed(text, patchFileInfo.nVersion, patchFileInfo.bUseCustomCache);
            }
            return(flag);
        }
 private static void CallbackSaveAssetBundle(IDownloadedItem wItem, object obj)
 {
     try
     {
         CustomCaching.CacheItem cacheItem = obj as CustomCaching.CacheItem;
         if (cacheItem == null)
         {
             TsLog.LogWarning("CacheItem not found. (assetPath=\"{0}\")", new object[]
             {
                 wItem.assetPath
             });
         }
         else if (!wItem.isCanceled && string.IsNullOrEmpty(wItem.errorString))
         {
             string   text  = string.Format("{0}{1}", CustomCaching._locRoot, wItem.assetPath);
             string[] array = text.Split(new char[]
             {
                 '/'
             });
             StringBuilder stringBuilder = new StringBuilder();
             for (int i = 0; i < array.Length - 1; i++)
             {
                 stringBuilder.AppendFormat("{0}{1}", array[i], '/');
                 string path = stringBuilder.ToString();
                 if (!Directory.Exists(path))
                 {
                     Directory.CreateDirectory(path);
                 }
             }
             try
             {
                 if (wItem.rawBytes == null)
                 {
                     throw new NullReferenceException(string.Format("[CustomCache] wItem.rawBytes is null. (path=\"{0}\")\n", wItem.assetPath));
                 }
                 cacheItem.isExistLocalFile = false;
                 if (File.Exists(text))
                 {
                     File.Delete(text);
                 }
                 using (FileStream fileStream = File.Create(text))
                 {
                     using (BinaryWriter binaryWriter = new BinaryWriter(fileStream, Encoding.UTF8))
                     {
                         byte[] rawBytes = wItem.rawBytes;
                         binaryWriter.Write(rawBytes, 0, rawBytes.Length);
                         long num = (long)rawBytes.Length;
                         CustomCaching._spaceOccupied += cacheItem.size;
                         if (num != cacheItem.size)
                         {
                             TsLog.LogError("Not Match File={0} OrgSize={1} DownSize={2}", new object[]
                             {
                                 wItem.assetPath,
                                 cacheItem.size,
                                 num
                             });
                             if (CustomCaching._cacheList.ContainsKey(cacheItem.url))
                             {
                                 CustomCaching._cacheList.Remove(cacheItem.url);
                             }
                             if (File.Exists(text))
                             {
                                 File.Delete(text);
                             }
                         }
                         else if (!CustomCaching._cacheList.ContainsKey(cacheItem.url))
                         {
                             CustomCaching._cacheList.Add(wItem.assetPath, cacheItem);
                         }
                         else
                         {
                             CustomCaching._cacheList.Remove(cacheItem.url);
                             CustomCaching._cacheList.Add(wItem.assetPath, cacheItem);
                         }
                     }
                 }
             }
             catch (Exception ex)
             {
                 CustomCaching._RemoveCacheItem(cacheItem.url);
                 TsLog.Assert(false, "Cache file save error! (Path=\"{1}\") : {0}", new object[]
                 {
                     ex,
                     text
                 });
             }
             cacheItem.wref = null;
         }
         else
         {
             CustomCaching._RemoveCacheItem(cacheItem.url);
             TsLog.LogError("CustomCaching. Error file saving (url=\"{0}\", error={1}, canceled={2})", new object[]
             {
                 cacheItem.url,
                 wItem.errorString,
                 wItem.isCanceled
             });
         }
         TsCaching.SaveCacheList();
     }
     catch (Exception obj2)
     {
         TsLog.LogWarning(obj2);
     }
 }
Ejemplo n.º 8
0
 public static void SaveLastSpaceOccupied()
 {
     TsCaching.SaveLastSpaceOccupied(Caching.spaceOccupied);
 }
Ejemplo n.º 9
0
        public void _InternalOnly_ChangeStateSuccess()
        {
            this.wiState       = WWWItem.StateWI.SUCCESS;
            this.safeBundle    = null;
            this.safeBytes     = null;
            this.safeString    = null;
            this.safeAudioClip = null;
            if (this.useLoadFromCacheOrDownload)
            {
                this.safeSize = ((this.m_kItem == null) ? 0 : this.m_kItem.nFileSize);
            }
            else
            {
                this.safeSize = ((this.m_www == null) ? 0 : this.m_www.size);
            }
            bool flag = !this.isCacheHit && this.itemType == ItemType.UNDEFINED && this.UseCustomCache;

            if (flag)
            {
                if (Option.EnableTrace)
                {
                    TsLog.LogWarning("[TsBundle] set RawBytes => Cache Hit[{0}], Use[{1}] (AssetPath=\"{2}\", Stack=\"{3}\", Type={4})", new object[]
                    {
                        this.isCacheHit,
                        this.useLoadFromCacheOrDownload,
                        this.assetPath,
                        this.stackName,
                        this.itemType
                    });
                }
                this.rawBytes = this.m_www.bytes;
            }
            try
            {
                if (this.itemType == ItemType.USER_STRING)
                {
                    this.safeString = this.m_www.text;
                    if (this.safeString == null)
                    {
                        this._InternalOnly_ChangeStateErrorOrRetry("fail to access www.text.");
                    }
                }
                else if (this.itemType == ItemType.USER_BYTESA)
                {
                    this.safeBytes = ((this.rawBytes == null) ? this.m_www.bytes : this.rawBytes);
                    if (this.safeBytes == null)
                    {
                        this._InternalOnly_ChangeStateErrorOrRetry("fail to access www.bytes.");
                    }
                }
                else if (this.itemType == ItemType.USER_AUDIO)
                {
                    this.safeAudioClip = this.m_www.GetAudioClip(false, true);
                    if (null == this.safeAudioClip)
                    {
                        this._InternalOnly_ChangeStateErrorOrRetry("fail to access www.AudioClip.");
                    }
                }
                else if (this.itemType == ItemType.UNDEFINED)
                {
                    if (this.refCnt == 1)
                    {
                        this.Dispose();
                    }
                    if (this.m_kItem != null)
                    {
                        TsCaching.MarkAsUsed(this.assetPath, this.m_kItem.nVersion, this.m_kItem.bUseCustomCache);
                    }
                }
                else
                {
                    this.safeBundle = this.m_www.assetBundle;
                    if (null == this.safeBundle)
                    {
                        this._InternalOnly_ChangeStateErrorOrRetry("fail to access www.assetBundle.");
                        throw new NullReferenceException();
                    }
                    this.mainAsset = this.safeBundle.mainAsset;
                    TsFix.AudioSourceWarning(this.mainAsset as GameObject);
                    if (this.loadAll)
                    {
                        this.subBundles = this.safeBundle.LoadAll();
                        UnityEngine.Object[] subBundles = this.subBundles;
                        for (int i = 0; i < subBundles.Length; i++)
                        {
                            UnityEngine.Object @object = subBundles[i];
                            TsFix.AudioSourceWarning(@object as GameObject);
                        }
                    }
                }
                if (Option.EnableTrace)
                {
                    bool flag2 = false;
                    int  num   = -1;
                    if (this.m_kItem != null)
                    {
                        string url = Helper.FullURL(this.assetPath);
                        num   = this.m_kItem.nVersion;
                        flag2 = TsCaching.IsVersionCached(url, num, this.m_kItem.bUseCustomCache);
                    }
                    TsLog.Log("[TsBundle] download => success (AssetPath=\"{0}\", Stack=\"{1}\", Type={2}, Version={3}, RefCnt={4}, LoadFromCacheOrDownload={5}, Disposed={6}), Cached => {7}\r\nCallStack={8}", new object[]
                    {
                        this.assetPath,
                        this.stackName,
                        this.itemType,
                        num,
                        this.refCnt,
                        this.useLoadFromCacheOrDownload,
                        this.m_www == null,
                        (string.IsNullOrEmpty(this.anotherURL) || this.useLoadFromCacheOrDownload) ? flag2.ToString() : "(ignore)"
                    });
                }
            }
            catch (Exception ex)
            {
                TsLog.LogError("[TsBundle] Unity Assetbundle access exception! (Protocol=\"{0}\", AssetPath=\"{1}\", Stack=\"{2}\", Type={3}) => {4}\r\nCallStack={5}", new object[]
                {
                    Option.GetProtocolRootPath(this.m_protocol),
                    this.assetPath,
                    this.stackName,
                    this.itemType,
                    ex.ToString(),
                    this.RequestCallStack
                });
                this._InternalOnly_ChangeStateErrorOrRetry("Exception! Unity Assetbundle access violation!");
            }
            if (!this.useLoadFromCacheOrDownload && !this.isCacheHit && 0 < this.safeSize)
            {
                Holder.DbgAddWWWItemStat(this.assetPath, this.safeSize);
                if (WWWItem.OnIncreaseSizeOfDownload != null)
                {
                    WWWItem.OnIncreaseSizeOfDownload(this.safeSize);
                }
            }
        }
Ejemplo n.º 10
0
 public void _InternalOnly_ChangeStateRequest()
 {
     if (this.wiState != WWWItem.StateWI.UNLOADED)
     {
         if (this.wiState != WWWItem.StateWI.DESTROIED)
         {
             this.retryRequested = false;
             this.wiState        = WWWItem.StateWI.REQUESTED;
             string text;
             if (string.IsNullOrEmpty(this.anotherURL))
             {
                 if (Option.usePatchDir && this.m_protocol == Protocol.HTTP && this.m_kItem != null)
                 {
                     string protocolRootPath = Option.GetProtocolRootPath(this.m_protocol);
                     string format           = string.Empty;
                     if (protocolRootPath[protocolRootPath.Length - 1] == '/')
                     {
                         if (this.assetPath[0] == '/')
                         {
                             format = "{0}{1}{2}";
                         }
                         else
                         {
                             format = "{0}{1}/{2}";
                         }
                     }
                     else if (this.assetPath[0] == '/')
                     {
                         format = "{0}/{1}{2}";
                     }
                     else
                     {
                         format = "{0}/{1}/{2}";
                     }
                     text = string.Format(format, protocolRootPath, this.m_kItem.VersionDir, this.assetPath);
                 }
                 else
                 {
                     text = Option.GetProtocolRootPath(this.m_protocol) + this.assetPath;
                 }
             }
             else
             {
                 text = this.anotherURL;
             }
             if (this.m_protocol == Protocol.HTTP && 0 < this.retryCnt)
             {
                 if (text.Contains("?r="))
                 {
                     text = string.Format("{0}{1}", text, this.retryCnt);
                 }
                 else
                 {
                     text = string.Format("{0}?r={1}{2}", text, (int)(UnityEngine.Random.value * 1000000f), this.retryCnt);
                 }
                 TsLog.Log("[TsBundle] TsBundle:Retry = \"{0}\"", new object[]
                 {
                     text
                 });
             }
             if (Option.EnableTrace)
             {
                 TsLog.Log("[TsBundle] www loading (AssetPath=\"{0}\", Stack=\"{1}\", Type={2}, Size={3:#,###,###,###}, UnloadReserved={4}, RefCount={5} ) {6}", new object[]
                 {
                     this.assetPath,
                     this.stackName,
                     this.itemType,
                     (this.m_kItem != null) ? this.m_kItem.nFileSize : 0,
                     this.DebugUnloadReserved,
                     this.refCnt,
                     (this.m_kItem != null) ? ((!TsCaching.IsVersionCached(text, this.m_kItem.nVersion, this.m_kItem.bUseCustomCache)) ? "<<will download>>" : "<<Cached>>") : "<<not listed>>"
                 });
             }
             if (string.IsNullOrEmpty(this.anotherURL))
             {
                 UsingAssetRecorder.RecordFile(this.assetPath);
             }
             this._ReleaseLoadedAsset();
             if (this.useLoadFromCacheOrDownload)
             {
                 if (!this.inUndefinedStack)
                 {
                     this.m_www = Holder.CancelPreDownload(this.assetPath);
                 }
                 if (this.m_www == null)
                 {
                     this.m_www = TsCaching.LoadFromCacheOrDownload(text, this.m_kItem.nVersion, (long)this.m_kItem.nFileSize, this.m_kItem.bUseCustomCache, this);
                 }
                 if (!this.isCacheHit)
                 {
                     Holder.DbgAddWWWItemStat(this.assetPath, this.m_kItem.nFileSize);
                     if (0 < this.m_kItem.nFileSize && WWWItem.OnIncreaseSizeOfDownload != null)
                     {
                         WWWItem.OnIncreaseSizeOfDownload(this.m_kItem.nFileSize);
                     }
                 }
             }
             else
             {
                 Holder.DbgAddWWWItemStat(this.assetPath, 0);
                 this.m_www = new WWW(text);
             }
             this.retryCnt++;
             return;
         }
     }
     try
     {
         if (Option.EnableTrace)
         {
             TsLog.Log("[TsBundle] cannot request download, already unloaded bundle (AssetPath=\"{0}\", Stack=\"{1}\", Type={2}, SIze={3:#,###,###,###})\n\rCallStack={4}", new object[]
             {
                 this.assetPath,
                 this.stackName,
                 this.itemType,
                 (this.m_kItem != null) ? this.m_kItem.nFileSize : 0,
                 this.RequestCallStack
             });
         }
     }
     catch (Exception arg)
     {
         TsLog.Log("[TsBundle] " + arg, new object[0]);
     }
 }