Skip to content

Commit

Permalink
Fix nullreference exception when adding new files before starting spa…
Browse files Browse the repository at this point in the history
…rkleshare
  • Loading branch information
hbons committed Jun 28, 2011
1 parent f4c2a3e commit 6af7fdf
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 29 deletions.
26 changes: 17 additions & 9 deletions SparkleLib/SparkleListenerBase.cs
Expand Up @@ -37,24 +37,31 @@ public SparkleAnnouncement (string folder_identifier, string message)

public static class SparkleListenerFactory {

private static List<SparkleListenerBase> listeners;
private static List<SparkleListenerBase> listeners = new List<SparkleListenerBase> ();

public static SparkleListenerBase CreateListener (string uri, string folder_identifier)
public static SparkleListenerBase CreateListener (string folder_name, string folder_identifier)
{
if (listeners == null)
listeners = new List<SparkleListenerBase> ();
string announce_uri = SparkleConfig.DefaultConfig.GetAnnouncementUrlForFolder (folder_name);

if (announce_uri == null) {
// This is SparkleShare's centralized notification service.
// Don't worry, we only use this server as a backup if you
// don't have your own. All data needed to connect is hashed and
// we don't store any personal information ever

announce_uri = "irc://204.62.14.135/";
}

Uri listen_on = new Uri(uri);

foreach (SparkleListenerBase listener in listeners) {
if (listener.Server.Equals (uri)) {
SparkleHelpers.DebugInfo ("ListenerFactory", "Refered to existing listener for " + uri);
if (listener.Server.Equals (announce_uri)) {
SparkleHelpers.DebugInfo ("ListenerFactory", "Refered to existing listener for " + announce_uri);
listener.AlsoListenTo (folder_identifier);
return (SparkleListenerBase) listener;
}
}

SparkleHelpers.DebugInfo ("ListenerFactory", "Issued new listener for " + uri);
Uri listen_on = new Uri (announce_uri);

switch (listen_on.Scheme) {
case "tcp":
listeners.Add (new SparkleListenerTcp (listen_on, folder_identifier));
Expand All @@ -65,6 +72,7 @@ public static SparkleListenerBase CreateListener (string uri, string folder_iden
break;
}

SparkleHelpers.DebugInfo ("ListenerFactory", "Issued new listener for " + announce_uri);
return (SparkleListenerIrc) listeners [listeners.Count - 1];
}
}
Expand Down
11 changes: 6 additions & 5 deletions SparkleLib/SparkleRepoBase.cs
Expand Up @@ -90,6 +90,7 @@ public SparkleRepoBase (string path, SparkleBackend backend)
CreateInitialChangeSet ();

CreateWatcher ();
CreateListener ();

this.local_timer.Elapsed += delegate (object o, ElapsedEventArgs args) {
CheckForChanges ();
Expand All @@ -114,9 +115,6 @@ public SparkleRepoBase (string path, SparkleBackend backend)
}
};

this.remote_timer.Start ();
this.local_timer.Start ();

// Sync up everything that changed
// since we've been offline
if (AnyDifferences) {
Expand All @@ -127,6 +125,9 @@ public SparkleRepoBase (string path, SparkleBackend backend)
SyncUpBase ();
EnableWatching ();
}

this.remote_timer.Start ();
this.local_timer.Start ();
}


Expand Down Expand Up @@ -217,9 +218,9 @@ private void CreateWatcher ()
}


public void CreateListener (string uri, string folder_name)
public void CreateListener ()
{
this.listener = SparkleListenerFactory.CreateListener(uri, this.Identifier);
this.listener = SparkleListenerFactory.CreateListener (Name, Identifier);

// Stop polling when the connection to the irc channel is succesful
this.listener.Connected += delegate {
Expand Down
15 changes: 0 additions & 15 deletions SparkleShare/SparkleController.cs
Expand Up @@ -542,21 +542,6 @@ private void AddRepository (string folder_path)
else
repo = new SparkleRepoGit (folder_path, SparkleBackend.DefaultBackend);


string announce_uri = SparkleConfig.DefaultConfig.GetAnnouncementUrlForFolder (folder_name);
if (announce_uri == null) {
string announcements = SparkleConfig.DefaultConfig.GetAnnouncementsForFolder (folder_name);
if (announcements == null)
// This is SparkleShare's centralized notification service.
// Don't worry, we only use this server as a backup if you
// don't have your own. All data needed to connect is hashed and
// we don't store any personal information ever
announcements = "204.62.14.135";

announce_uri = String.Format("irc://{0}/", announcements);
}
repo.CreateListener(announce_uri, folder_name);

repo.NewChangeSet += delegate (SparkleChangeSet change_set, string repository_path) {
string message = FormatMessage (change_set);

Expand Down

0 comments on commit 6af7fdf

Please sign in to comment.