/// <summary> /// Creates a text file containing the hash string of the pack file. /// </summary> /// <returns></returns> private async Task <bool> CreateHashFile() { if (File.Exists(Paths.GKPackFileFDir + Paths.GKPackHashName)) { File.Delete(Paths.GKPackFileFDir + Paths.GKPackHashName); } object Hash = await Task.Run(() => { return(SecurityTools.GetMD5OfFile(Paths.GKPackFileFullPath)); }); using (StreamWriter sw = File.CreateText(Paths.GKPackFileFDir + Paths.GKPackHashName)) { sw.Write(Hash); } return(true); }
/// <summary> /// Verifies directory structure, checks if pack file is present, then compares local and remote hashes of the pack file. /// /// Returns False if directory or file is missing, or if the hashes mismatch. /// </summary> /// <returns></returns> public async Task <bool> VerifyPackFile() { try { if (!Directory.Exists(Paths.GKPackFileFDir)) { return(false); } if (!Directory.Exists(Paths.GKExtractDir)) { return(false); } if (!File.Exists(Paths.GKPackFileFullPath)) { return(false); } else { string localHash = await Task.Run(() => { return(SecurityTools.GetMD5OfFile(Paths.GKPackFileFullPath)); }); string remoteHash = await Task.Run(() => { return(GetRemoteHash()); }); if (localHash == remoteHash) { return(true); } else { return(false); } } } catch (DirectoryNotFoundException dnfe) { Logging.Exception(dnfe); return(false); } catch (FileNotFoundException fnfe) { Logging.Exception(fnfe); return(false); } catch (Exception ex) { ErrorHandling.ErrHandle(ex, System.Reflection.MethodBase.GetCurrentMethod()); return(false); } }