示例#1
0
        void HandleInvite(string path)
        {
            if (this.fetcher != null &&
                this.fetcher.IsActive)
            {
                AlertNotificationRaised("SparkleShare Setup seems busy", "Please wait for it to finish");
            }
            else
            {
                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(path);
                    tries++;

                    if (tries > 10)
                    {
                        AlertNotificationRaised("Oh noes!", "This invite seems screwed up...");
                        break;
                    }
                }

                if (invite.IsValid)
                {
                    InviteReceived(invite);
                }

                File.Delete(path);
            }
        }
        private void HandleInvite (FileSystemEventArgs args)
        {
            if (this.fetcher != null &&
                this.fetcher.IsActive) {

                AlertNotificationRaised ("SparkleShare Setup seems busy", "Please wait for it to finish");

            } else {
                SparkleInvite invite = new SparkleInvite (args.FullPath);

                // 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);
                    tries++;

                    if (tries > 10) {
                        AlertNotificationRaised ("Oh noes!", "This invite seems screwed up...");
                        break;
                    }
                }

                if (invite.IsValid)
                    InviteReceived (invite);

                File.Delete (args.FullPath);
            }
        }
        public SparkleSetupController()
        {
            TutorialPageNumber = 1;
            PreviousAddress    = "";
            PreviousPath       = "";
            PreviousUrl        = "";
            SyncingFolder      = "";

            string local_plugins_path = SparkleHelpers.CombineMore (
                Environment.GetFolderPath (Environment.SpecialFolder.ApplicationData),
                "sparkleshare", "plugins");

            if (Directory.Exists (local_plugins_path))
                foreach (string xml_file_path in Directory.GetFiles (local_plugins_path, "*.xml"))
                    Plugins.Add (new SparklePlugin (xml_file_path));

            if (Directory.Exists (Program.Controller.PluginsPath)) {
                foreach (string xml_file_path in Directory.GetFiles (Program.Controller.PluginsPath, "*.xml")) {
                    if (xml_file_path.EndsWith ("own-server.xml"))
                        Plugins.Insert (0, new SparklePlugin (xml_file_path));
                    else
                        Plugins.Add (new SparklePlugin (xml_file_path));
                }
            }

            SelectedPlugin = Plugins [0];

            Program.Controller.InviteReceived += delegate (SparkleInvite invite) {
                PendingInvite = invite;

                if (ChangePageEvent != null)
                    ChangePageEvent (PageType.Invite, null);

                if (ShowWindowEvent != null)
                    ShowWindowEvent ();
            };

            Program.Controller.ShowSetupWindowEvent += delegate (PageType page_type) {
                if (PendingInvite != null) {
                    if (ShowWindowEvent != null)
                        ShowWindowEvent ();

                    return;
                }

                if (ChangePageEvent != null)
                    ChangePageEvent (page_type, null);

                if (ShowWindowEvent != null)
                    ShowWindowEvent ();

                if (page_type == PageType.Add)
                    SelectedPluginChanged (SelectedPluginIndex);
            };
        }
        public void PageCancelled()
        {
            PendingInvite = null;

            if (HideWindowEvent != null)
                HideWindowEvent ();
        }
        public void InvitePageCompleted()
        {
            SyncingFolder   = Path.GetFileNameWithoutExtension (PendingInvite.RemotePath);
            PreviousAddress = PendingInvite.Address;
            // TODO: trailing slash should work
            PreviousPath    = PendingInvite.RemotePath;

            if (ChangePageEvent != null)
                ChangePageEvent (PageType.Syncing, null);

            if (!PendingInvite.Accept ()) {
                if (ChangePageEvent != null)
                    ChangePageEvent (PageType.Error, null);

                return;
            }

            // TODO: Remove events afterwards

            Program.Controller.FolderFetched += delegate (string [] warnings) {
                if (ChangePageEvent != null)
                    ChangePageEvent (PageType.Finished, warnings);

                PreviousAddress = "";
                SyncingFolder   = "";
                PreviousUrl     = "";
                SelectedPlugin  = Plugins [0];

                PendingInvite = null;
            };

            Program.Controller.FolderFetchError += delegate (string remote_url) {
                Thread.Sleep (1000);
                PreviousUrl = remote_url;

                if (ChangePageEvent != null)
                    ChangePageEvent (PageType.Error, null);

                SyncingFolder = "";
            };

            Program.Controller.FolderFetching += delegate (double percentage) {
                if (UpdateProgressBarEvent != null)
                    UpdateProgressBarEvent (percentage);
            };

            Program.Controller.FetchFolder (PendingInvite.Address, PendingInvite.RemotePath);
        }
示例#6
0
        public virtual void Initialize()
        {
            SparklePlugin.PluginsPath = PluginsPath;
            InstallProtocolHandler();

            // Create the SparkleShare folder and add it to the bookmarks
            if (CreateSparkleShareFolder())
            {
                AddToBookmarks();
            }

            if (FirstRun)
            {
                SparkleConfig.DefaultConfig.SetConfigOption("notifications", bool.TrueString);
            }
            else
            {
                ImportPrivateKey();
            }

            // Watch the SparkleShare folder
            FileSystemWatcher watcher = new FileSystemWatcher(SparkleConfig.DefaultConfig.FoldersPath)
            {
                IncludeSubdirectories = false,
                EnableRaisingEvents   = true,
                Filter = "*"
            };

            watcher.Deleted += delegate(object o, FileSystemEventArgs args) {
                lock (this.delete_watcher_lock) {
                    foreach (string folder_name in SparkleConfig.DefaultConfig.Folders)
                    {
                        string folder_path = new SparkleFolder(folder_name).FullPath;

                        if (!Directory.Exists(folder_path))
                        {
                            SparkleConfig.DefaultConfig.RemoveFolder(folder_name);
                            RemoveRepository(folder_path);
                        }
                    }

                    if (FolderListChanged != null)
                    {
                        FolderListChanged();
                    }
                }
            };

            watcher.Created += delegate(object o, FileSystemEventArgs args) {
                if (!args.FullPath.EndsWith(".xml"))
                {
                    return;
                }

                if (this.fetcher != null &&
                    this.fetcher.IsActive)
                {
                    if (AlertNotificationRaised != null)
                    {
                        AlertNotificationRaised("SparkleShare Setup seems busy",
                                                "Please wait for it to finish");
                    }
                }
                else
                {
                    if (InviteReceived != null)
                    {
                        SparkleInvite invite = new SparkleInvite(args.FullPath);

                        // 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(1 * 250);
                            invite = new SparkleInvite(args.FullPath);
                            tries++;
                            if (tries > 20)
                            {
                                break;
                            }
                        }

                        if (invite.IsValid)
                        {
                            InviteReceived(invite);
                        }
                        else
                        {
                            invite = null;

                            if (AlertNotificationRaised != null)
                            {
                                AlertNotificationRaised("Oh noes!",
                                                        "This invite seems screwed up...");
                            }
                        }

                        File.Delete(args.FullPath);
                    }
                }
            };
        }