/// <summary> /// Load previously persisted cookie library from the file. /// </summary> internal static void Load() { #if !BESTHTTP_DISABLE_COOKIE_SAVE if (!IsSavingSupported) { return; } lock (Locker) { if (Loaded) { return; } SetupFolder(); try { Cookies.Clear(); if (!Directory.Exists(CookieFolder)) { Directory.CreateDirectory(CookieFolder); } if (!File.Exists(LibraryPath)) { return; } using (var fs = new FileStream(LibraryPath, FileMode.Open)) using (var br = new System.IO.BinaryReader(fs)) { /*int version = */ br.ReadInt32(); int cookieCount = br.ReadInt32(); for (int i = 0; i < cookieCount; ++i) { Cookie cookie = new Cookie(); cookie.LoadFrom(br); if (cookie.WillExpireInTheFuture()) { Cookies.Add(cookie); } } } } catch { Cookies.Clear(); } finally { Loaded = true; } } #endif }
/// <summary> /// Load previously persisted cookie library from the file. /// </summary> internal static void Load() { #if !BESTHTTP_DISABLE_COOKIE_SAVE if (!IsSavingSupported) { return; } if (Loaded) { return; } SetupFolder(); rwLock.EnterWriteLock(); try { Cookies.Clear(); if (!HTTPManager.IOService.DirectoryExists(CookieFolder)) { HTTPManager.IOService.DirectoryCreate(CookieFolder); } if (!HTTPManager.IOService.FileExists(LibraryPath)) { return; } using (var fs = HTTPManager.IOService.CreateFileStream(LibraryPath, FileStreamModes.Open)) using (var br = new System.IO.BinaryReader(fs)) { /*int version = */ br.ReadInt32(); int cookieCount = br.ReadInt32(); for (int i = 0; i < cookieCount; ++i) { Cookie cookie = new Cookie(); cookie.LoadFrom(br); if (cookie.WillExpireInTheFuture()) { Cookies.Add(cookie); } } } } catch { Cookies.Clear(); } finally { Loaded = true; rwLock.ExitWriteLock(); } #endif }
/// <summary> /// Load previously persisted cooki library from the file. /// </summary> internal static void Load() { #if !UNITY_WEBPLAYER lock (Locker) { try { Cookies.Clear(); if (!Directory.Exists(CookieFolder)) { Directory.CreateDirectory(CookieFolder); } if (!File.Exists(LibraryPath)) { return; } using (var fs = new FileStream(LibraryPath, FileMode.Open)) using (var br = new System.IO.BinaryReader(fs)) { /*int version = */ br.ReadInt32(); int cookieCount = br.ReadInt32(); for (int i = 0; i < cookieCount; ++i) { Cookie cookie = new Cookie(); cookie.LoadFrom(br); if (cookie.WillExpireInTheFuture()) { Cookies.Add(cookie); } } } } catch { Cookies.Clear(); } } #endif }
internal static void Load() { object locker = CookieJar.Locker; lock (locker) { try { CookieJar.Cookies.Clear(); if (!Directory.Exists(CookieJar.CookieFolder)) { Directory.CreateDirectory(CookieJar.CookieFolder); } if (File.Exists(CookieJar.LibraryPath)) { using (FileStream fileStream = new FileStream(CookieJar.LibraryPath, FileMode.Open)) { using (BinaryReader binaryReader = new BinaryReader(fileStream)) { binaryReader.ReadInt32(); int num = binaryReader.ReadInt32(); for (int i = 0; i < num; i++) { Cookie cookie = new Cookie(); cookie.LoadFrom(binaryReader); if (cookie.WillExpireInTheFuture()) { CookieJar.Cookies.Add(cookie); } } } } } } catch { CookieJar.Cookies.Clear(); } } }