From 0bb6e13d12139dd3a47f3b97c10eaa80295999b4 Mon Sep 17 00:00:00 2001 From: Jo Shields Date: Thu, 13 Jun 2013 17:32:33 +0100 Subject: [PATCH] Add support for startup scanning of invites. This commit makes SparkleShare check its config directory for invite XML files on startup, rather than only when the Filesystem watcher is alerted to a new file being created. --- SparkleShare/Linux/sparkleshare.in | 1 + SparkleShare/SparkleControllerBase.cs | 18 +++++++++++++++--- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/SparkleShare/Linux/sparkleshare.in b/SparkleShare/Linux/sparkleshare.in index 46d5e7e3..a075609d 100755 --- a/SparkleShare/Linux/sparkleshare.in +++ b/SparkleShare/Linux/sparkleshare.in @@ -65,6 +65,7 @@ case $1 in invite=`date -u +%N` open=`echo $2 | sed 's/sparkleshare:\/\/addProject\///'` curl --insecure --output ~/SparkleShare/.$invite.xml $open + start ;; *) mono "@expanded_libdir@/@PACKAGE@/SparkleShare.exe" --help diff --git a/SparkleShare/SparkleControllerBase.cs b/SparkleShare/SparkleControllerBase.cs index 2925286a..6ac1fba9 100644 --- a/SparkleShare/SparkleControllerBase.cs +++ b/SparkleShare/SparkleControllerBase.cs @@ -251,6 +251,7 @@ namespace SparkleShare { } else { new Thread (() => { + StartupInviteScan (); CheckRepositories (); RepositoriesLoaded = true; UpdateState (); @@ -440,6 +441,12 @@ namespace SparkleShare { } } + private void StartupInviteScan () + { + foreach (string invite in Directory.GetFiles (FoldersPath, "*.xml")) { + HandleInvite (invite); + } + } private void OnFolderActivity (object o, FileSystemEventArgs args) { @@ -461,6 +468,11 @@ namespace SparkleShare { private void HandleInvite (FileSystemEventArgs args) + { + HandleInvite (args.FullPath); + } + + private void HandleInvite (string path) { if (this.fetcher != null && this.fetcher.IsActive) { @@ -468,14 +480,14 @@ namespace SparkleShare { AlertNotificationRaised ("SparkleShare Setup seems busy", "Please wait for it to finish"); } else { - SparkleInvite invite = new SparkleInvite (args.FullPath); + SparkleInvite invite = new SparkleInvite (path); // It may be that the invite we received a path to isn't // fully downloaded yet, so we try to read it several times int tries = 0; while (!invite.IsValid) { Thread.Sleep (100); - invite = new SparkleInvite (args.FullPath); + invite = new SparkleInvite (path); tries++; if (tries > 10) { @@ -487,7 +499,7 @@ namespace SparkleShare { if (invite.IsValid) InviteReceived (invite); - File.Delete (args.FullPath); + File.Delete (path); } }