Permalink
Browse files

[EditableTorrent] Don't hardcode metadata access strings throughout t…

…he class
  • Loading branch information...
1 parent e9562eb commit ade8173770698e851d627ddebbb2ac536312f92d @alanmcgovern alanmcgovern committed Oct 9, 2010
Showing with 31 additions and 22 deletions.
  1. +31 −22 src/MonoTorrent/MonoTorrent.Common/EditableTorrent.cs
View
53 src/MonoTorrent/MonoTorrent.Common/EditableTorrent.cs
@@ -7,10 +7,20 @@ namespace MonoTorrent
{
public abstract class EditableTorrent
{
+ static readonly BEncodedString AnnounceKey = "announce";
+ static readonly BEncodedString AnnounceListKey = "announce-list";
+ static readonly BEncodedString CommentKey = "comment";
+ static readonly BEncodedString CreatedByKey = "created by";
+ static readonly BEncodedString EncodingKey = "encoding";
+ static readonly BEncodedString InfoKey = "info";
+ static readonly BEncodedString PieceLengthKey = "piece length";
+ static readonly BEncodedString PrivateKey = "private";
+ static readonly BEncodedString PublisherKey = "publisher";
+ static readonly BEncodedString PublisherUrlKey = "publisher-url";
public string Announce {
- get { return GetString (Metadata, "announce"); }
- set { SetString (Metadata, "announce", value); }
+ get { return GetString (Metadata, AnnounceKey); }
+ set { SetString (Metadata, AnnounceKey, value); }
}
public RawTrackerTiers Announces {
@@ -22,47 +32,47 @@ public abstract class EditableTorrent
}
public string Comment {
- get { return GetString (Metadata, "comment"); }
- set { SetString (Metadata, "comment", value); }
+ get { return GetString (Metadata, CommentKey); }
+ set { SetString (Metadata, CommentKey, value); }
}
public string CreatedBy {
- get { return GetString (Metadata, "created by"); }
- set { SetString (Metadata, "created by", value); }
+ get { return GetString (Metadata, CreatedByKey); }
+ set { SetString (Metadata, CreatedByKey, value); }
}
public string Encoding {
- get { return GetString (Metadata, "encoding"); }
- private set { SetString (Metadata, "encoding", value); }
+ get { return GetString (Metadata, EncodingKey); }
+ private set { SetString (Metadata, EncodingKey, value); }
}
protected BEncodedDictionary InfoDict {
- get { return GetDictionary (Metadata, "info"); }
- private set { SetDictionary (Metadata, "info", new BEncodedDictionary ()); }
+ get { return GetDictionary (Metadata, InfoKey); }
+ private set { SetDictionary (Metadata, InfoKey, value); }
}
protected BEncodedDictionary Metadata {
get; private set;
}
public long PieceLength {
- get { return GetLong (InfoDict, "piece length"); }
- set { SetLong (InfoDict, "piece length", value); }
+ get { return GetLong (InfoDict, PieceLengthKey); }
+ set { SetLong (InfoDict, PieceLengthKey, value); }
}
public bool Private {
- get { return GetLong (InfoDict, "private") == 1; }
- set { SetLong (InfoDict, "private", value ? 1 : 0); }
+ get { return GetLong (InfoDict, PrivateKey) == 1; }
+ set { SetLong (InfoDict, PrivateKey, value ? 1 : 0); }
}
public string Publisher {
- get { return GetString (InfoDict, "publisher"); }
- set { SetString (InfoDict, "publisher", value); }
+ get { return GetString (InfoDict, PublisherKey); }
+ set { SetString (InfoDict, PublisherKey, value); }
}
public string PublisherUrl {
- get { return GetString (InfoDict, "publisher-url"); }
- set { SetString (InfoDict, "publisher-url", value); }
+ get { return GetString (InfoDict, PublisherUrlKey); }
+ set { SetString (InfoDict, PublisherUrlKey, value); }
}
public EditableTorrent ()
@@ -88,18 +98,17 @@ void Initialise (BEncodedDictionary metadata)
Metadata = metadata;
BEncodedValue value;
- if (!Metadata.TryGetValue ("announce-list", out value)) {
+ if (!Metadata.TryGetValue (AnnounceListKey, out value)) {
value = new BEncodedList ();
- Metadata.Add ("announce-list", value);
+ Metadata.Add (AnnounceListKey, value);
}
+ Announces = new RawTrackerTiers ((BEncodedList) value);
if (string.IsNullOrEmpty (Encoding))
Encoding = "UTF-8";
if (InfoDict == null)
InfoDict = new BEncodedDictionary ();
-
- Announces = new RawTrackerTiers ((BEncodedList) value);
}
public void AddCustom (BEncodedString key, BEncodedValue value)

0 comments on commit ade8173

Please sign in to comment.