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.
This commit is contained in:
Jo Shields 2013-06-13 17:32:33 +01:00 committed by Hylke Bons
parent fd163a0c93
commit 0bb6e13d12
2 changed files with 16 additions and 3 deletions

View file

@ -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

View file

@ -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);
}
}