/// <summary> /// This method loads a .torrent file from the specified path. /// </summary> /// <param name="path">The path to load the .torrent file from</param> public static Torrent Load(string path) { Check.Path(path); using (Stream s = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read)) return(Load(s, path)); }
/// <summary> /// Loads a .torrent from the specificed path. A return value indicates /// whether the operation was successful. /// </summary> /// <param name="path">The path to load the .torrent file from</param> /// <param name="torrent">If the loading was succesful it is assigned the Torrent</param> /// <returns>True if successful</returns> public static bool TryLoad(string path, out Torrent torrent) { Check.Path(path); try { torrent = Load(path); } catch { torrent = null; } return(torrent != null); }
/// <summary> /// Called from either Load(stream) or Load(string). /// </summary> /// <param name="stream"></param> /// <param name="path"></param> /// <returns></returns> private static Torrent Load(Stream stream, string path) { Check.Stream(stream); Check.Path(path); try { var t = LoadCore((BEncodedDictionary)BEncodedValue.Decode(stream)); t.TorrentPath = path; return(t); } catch (BEncodingException ex) { throw new TorrentException("Invalid torrent file specified", ex); } }