/// <summary> /// Compares the MD5 hash of the file on disk and the parameter. /// </summary> /// <param name="file"></param> /// <returns></returns> protected bool IsDiskFileEqual(PatchFile file) { // build expected path on disk string filePath = baseFilePath + file.Basepath + file.Filename; // not equal if not existant if (!File.Exists(filePath)) { return(false); } // create filestream FileStream fs = new FileStream(filePath, FileMode.Open, FileAccess.Read); // different length = not equal (no md5 needed) if (file.Length != fs.Length) { fs.Close(); fs.Dispose(); return(false); } // otherwise compute and compare sha256 byte[] sha256Fil = sha256.ComputeHash(fs); byte[] sha256Onl = StringToByteArray(file.MyHash); bool areEqual = sha256Fil.SequenceEqual <byte>(sha256Onl); // close filestream fs.Close(); fs.Dispose(); return(areEqual); }
/// <summary> /// Compares the MD5 hash of the file on disk and the parameter. /// </summary> /// <param name="file"></param> /// <returns></returns> protected bool IsDiskFileEqual(PatchFile file) { // build expected path on disk string filePath = baseFilePath + file.Basepath + file.Filename; // not equal if not existant if (!File.Exists(filePath)) { return(false); } // create filestream FileStream fs = new FileStream(filePath, FileMode.Open, FileAccess.Read); // compute and compare md5 byte[] md5Fil = md5.ComputeHash(fs); byte[] md5Onl = StringToByteArray(file.MyHash); bool areEqual = md5Fil.SequenceEqual <byte>(md5Onl); // close filestream fs.Close(); fs.Dispose(); return(areEqual); }
/// <summary> /// Raised by the WebClient object when download progresses. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void OnWebClientDownloadProgressChanged(object sender, DownloadProgressChangedEventArgs e) { if (e.UserState is PatchFile) { PatchFile f = (PatchFile)e.UserState; f.LengthDone = e.BytesReceived; } }
public void Enqueue(PatchFile Item) { lock (queue) { // enqueue item queue.Enqueue(Item); } }
/// <summary> /// Parses the entries from patchinfo.txt /// </summary> /// <returns></returns> private static void ReadJsonData(byte[] JsonData) { // clear current instances if any files.Clear(); // filestream on file MemoryStream fs = new MemoryStream(JsonData); // json reader DataContractJsonSerializer reader = new DataContractJsonSerializer(typeof(List <PatchFile>)); // deserialize list of PatchFile List <PatchFile> list = (List <PatchFile>)reader.ReadObject(fs); // cleanup filestream fs.Close(); fs.Dispose(); // remove unwanted entries for (int i = list.Count - 1; i >= 0; i--) { PatchFile f = list[i]; // remove files marked to be not downloaded if (!f.Download) { list.RemoveAt(i); } // look for hardcoded exclusions else { foreach (string s in EXCLUSIONS) { if (f.Filename.Equals(s)) { list.RemoveAt(i); break; } } } } // add them to the real list instance files.AddRange(list); }
/// <summary> /// Raised by the WebClient object when download completed (successful or not). /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void OnWebClientDownloadFileCompleted(object sender, AsyncCompletedEventArgs e) { isDownloading = false; if (e.UserState is PatchFile) { PatchFile f = (PatchFile)e.UserState; if (e.Error != null) { queueErrors.Enqueue(f); } else { queueFinished.Enqueue(f); } } }
public bool TryDequeue(out PatchFile Item) { bool returnValue = false; Item = default(PatchFile); lock (queue) { if (queue.Count > 0) { // dequeue item Item = queue.Dequeue(); // returnValue = true; } } return(returnValue); }
public EventArgs(PatchFile File) { this.File = File; }