Fix nullreference exception when adding new files before starting sparkleshare

This commit is contained in:
Hylke 2011-06-28 20:54:47 +01:00
parent d3e20e22d7
commit 138e8e744f
3 changed files with 23 additions and 29 deletions

View file

@ -37,24 +37,31 @@ namespace SparkleLib {
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));
@ -65,6 +72,7 @@ namespace SparkleLib {
break;
}
SparkleHelpers.DebugInfo ("ListenerFactory", "Issued new listener for " + announce_uri);
return (SparkleListenerIrc) listeners [listeners.Count - 1];
}
}

View file

@ -90,6 +90,7 @@ namespace SparkleLib {
CreateInitialChangeSet ();
CreateWatcher ();
CreateListener ();
this.local_timer.Elapsed += delegate (object o, ElapsedEventArgs args) {
CheckForChanges ();
@ -114,9 +115,6 @@ namespace SparkleLib {
}
};
this.remote_timer.Start ();
this.local_timer.Start ();
// Sync up everything that changed
// since we've been offline
if (AnyDifferences) {
@ -127,6 +125,9 @@ namespace SparkleLib {
SyncUpBase ();
EnableWatching ();
}
this.remote_timer.Start ();
this.local_timer.Start ();
}
@ -217,9 +218,9 @@ namespace SparkleLib {
}
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 {

View file

@ -542,21 +542,6 @@ namespace SparkleShare {
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);