private static void CompleteDownload(LocalStorageFileState state) { bool flag = true; LocalStorageAPI.s_log.LogDebug("Download completed for State={0}", new object[] { state }); HTTPHeader hTTPHeader = LocalStorageAPI.ParseHTTPHeader(state.FileData); if (hTTPHeader != null) { byte[] numArray = new byte[hTTPHeader.ContentLength]; Array.Copy(state.FileData, hTTPHeader.ContentStart, numArray, 0, hTTPHeader.ContentLength); if (LocalStorageAPI.ComputeSHA256(numArray) == state.CH.Sha256Digest) { flag = false; LocalStorageAPI.DecompressStateIfPossible(state, numArray); } else { LocalStorageAPI.s_log.LogWarning("Integrity check failed for State={0}", new object[] { state }); } } else { LocalStorageAPI.s_log.LogWarning("Parsinig of HTTP header failed for State={0}", new object[] { state }); } if (flag || state.FileData == null) { LocalStorageAPI.ExecuteFailedDownload(state); } else { LocalStorageAPI.ExecuteSucessfulDownload(state); } }
private bool LoadStateFromDrive(LocalStorageFileState state) { try { LocalStorageAPI.s_log.LogDebug("LoadState State={0}", new object[] { state }); string text = LocalStorageAPI.MakeFullPathFromState(state); LocalStorageAPI.s_log.LogDebug("Attempting to load {0}", new object[] { text }); if (!File.Exists(text)) { LocalStorageAPI.s_log.LogDebug("File does not exist, unable to load from disk."); bool result = false; return(result); } FileStream fileStream = File.OpenRead(text); byte[] array = new byte[fileStream.get_Length()]; fileStream.Read(array, 0, array.Length); fileStream.Close(); if (LocalStorageAPI.ComputeSHA256(array) != state.CH.Sha256Digest) { LocalStorageAPI.s_log.LogDebug("File was loaded but integrity check failed, attempting to delete ..."); File.Delete(text); bool result = false; return(result); } LocalStorageAPI.DecompressStateIfPossible(state, array); LocalStorageAPI.s_log.LogDebug("Loading completed"); LocalStorageAPI.FinalizeState(state); } catch (Exception ex) { LocalStorageAPI.s_log.LogWarning("EXCEPTION: {0}", new object[] { ex.get_Message() }); bool result = false; return(result); } return(true); }
private bool LoadStateFromDrive(LocalStorageFileState state) { bool flag; try { LocalStorageAPI.s_log.LogDebug("LoadState State={0}", new object[] { state }); string str = LocalStorageAPI.MakeFullPathFromState(state); LocalStorageAPI.s_log.LogDebug("Attempting to load {0}", new object[] { str }); if (File.Exists(str)) { FileStream fileStream = File.OpenRead(str); byte[] numArray = new byte[checked ((IntPtr)fileStream.Length)]; fileStream.Read(numArray, 0, (int)numArray.Length); fileStream.Close(); if (LocalStorageAPI.ComputeSHA256(numArray) == state.CH.Sha256Digest) { LocalStorageAPI.DecompressStateIfPossible(state, numArray); LocalStorageAPI.s_log.LogDebug("Loading completed"); LocalStorageAPI.FinalizeState(state); return(true); } else { LocalStorageAPI.s_log.LogDebug("File was loaded but integrity check failed, attempting to delete ..."); File.Delete(str); flag = false; } } else { LocalStorageAPI.s_log.LogDebug("File does not exist, unable to load from disk."); flag = false; } } catch (Exception exception1) { Exception exception = exception1; LocalStorageAPI.s_log.LogWarning("EXCEPTION: {0}", new object[] { exception.Message }); flag = false; } return(flag); }