Ejemplo n.º 1
0
        private void CheckRepositories()
        {
            lock (this.check_repos_lock) {
                string path = this.config.FoldersPath;

                foreach (string folder_path in Directory.GetDirectories(path))
                {
                    string folder_name = Path.GetFileName(folder_path);

                    if (folder_name.Equals(".tmp"))
                    {
                        continue;
                    }

                    if (this.config.GetIdentifierForFolder(folder_name) == null)
                    {
                        string identifier_file_path = Path.Combine(folder_path, ".sparkleshare");

                        if (!File.Exists(identifier_file_path))
                        {
                            continue;
                        }

                        string identifier = File.ReadAllText(identifier_file_path).Trim();

                        if (this.config.IdentifierExists(identifier))
                        {
                            RemoveRepository(folder_path);
                            this.config.RenameFolder(identifier, folder_name);

                            string new_folder_path = Path.Combine(path, folder_name);
                            AddRepository(new_folder_path);

                            SparkleLogger.LogInfo("Controller",
                                                  "Renamed folder with identifier " + identifier + " to '" + folder_name + "'");
                        }
                    }
                }

                foreach (string folder_name in this.config.Folders)
                {
                    string folder_path = new SparkleFolder(folder_name).FullPath;

                    if (!Directory.Exists(folder_path))
                    {
                        this.config.RemoveFolder(folder_name);
                        RemoveRepository(folder_path);

                        SparkleLogger.LogInfo("Controller",
                                              "Removed folder '" + folder_name + "' from config");
                    }
                    else
                    {
                        AddRepository(folder_path);
                    }
                }

                FolderListChanged();
            }
        }
Ejemplo n.º 2
0
        // Updates the list of repositories with all the
        // folders in the SparkleShare folder
        private void PopulateRepositories()
        {
            lock (this.repo_lock) {
                foreach (string folder_name in SparkleConfig.DefaultConfig.Folders)
                {
                    string folder_path = new SparkleFolder(folder_name).FullPath;

                    if (Directory.Exists(folder_path))
                    {
                        AddRepository(folder_path);
                    }
                    else
                    {
                        SparkleConfig.DefaultConfig.RemoveFolder(folder_name);
                    }
                }
            }

            RepositoriesLoaded = true;

            if (FolderListChanged != null)
            {
                FolderListChanged();
            }
        }
Ejemplo n.º 3
0
        void RemoveDeletedRepositories()
        {
            foreach (string folder_name in Config.Folders)
            {
                string folder_path = new SparkleFolder(folder_name).FullPath;

                if (!Directory.Exists(folder_path))
                {
                    Config.RemoveFolder(folder_name);
                    RemoveRepository(GetRepoByName(folder_name));

                    Logger.LogInfo("Controller", "Removed folder '" + folder_name + "' from config");
                }
                else
                {
                    AddRepository(folder_path);
                }
            }
        }
Ejemplo n.º 4
0
        public List <SparkleChangeSet> GetLog(string name)
        {
            if (name == null)
            {
                return(GetLog());
            }

            string path = new SparkleFolder(name).FullPath;

            lock (this.repo_lock) {
                foreach (SparkleRepoBase repo in Repositories)
                {
                    if (repo.LocalPath.Equals(path))
                    {
                        return(repo.ChangeSets);
                    }
                }
            }

            return(null);
        }
        // Updates the list of repositories with all the
        // folders in the SparkleShare folder
        private void PopulateRepositories()
        {
            Repositories = new List <SparkleRepoBase> ();

            foreach (string folder_name in SparkleConfig.DefaultConfig.Folders)
            {
                string folder_path = new SparkleFolder(folder_name).FullPath;

                if (Directory.Exists(folder_path))
                {
                    AddRepository(folder_path);
                }
                else
                {
                    SparkleConfig.DefaultConfig.RemoveFolder(folder_name);
                }
            }

            if (FolderListChanged != null)
            {
                FolderListChanged();
            }
        }
Ejemplo n.º 6
0
        private void CheckRepositories()
        {
            lock (this.check_repos_lock) {
                string path = Config.FoldersPath;

                // Detect any renames
                foreach (string folder_path in Directory.GetDirectories(path))
                {
                    string folder_name = Path.GetFileName(folder_path);

                    if (folder_name.Equals(".tmp"))
                    {
                        continue;
                    }

                    if (Config.GetIdentifierForFolder(folder_name) == null)
                    {
                        string identifier_file_path = Path.Combine(folder_path, ".sparkleshare");

                        if (!File.Exists(identifier_file_path))
                        {
                            continue;
                        }

                        string identifier = File.ReadAllText(identifier_file_path).Trim();

                        if (Config.IdentifierExists(identifier))
                        {
                            RemoveRepository(GetRepoByName(folder_name));
                            Config.RenameFolder(identifier, folder_name);

                            string new_folder_path = Path.Combine(path, folder_name);
                            AddRepository(new_folder_path);

                            SparkleLogger.LogInfo("Controller",
                                                  "Renamed folder with identifier " + identifier + " to '" + folder_name + "'");
                        }
                    }
                }

                // Remove any deleted folders
                foreach (string folder_name in Config.Folders)
                {
                    string folder_path = new SparkleFolder(folder_name).FullPath;

                    if (!Directory.Exists(folder_path))
                    {
                        Config.RemoveFolder(folder_name);
                        RemoveRepository(GetRepoByName(folder_name));

                        SparkleLogger.LogInfo("Controller", "Removed folder '" + folder_name + "' from config");
                    }
                    else
                    {
                        AddRepository(folder_path);
                    }
                }

                // Remove any duplicate folders
                string previous_name = "";
                foreach (string folder_name in Config.Folders)
                {
                    if (!string.IsNullOrEmpty(previous_name) && folder_name.Equals(previous_name))
                    {
                        Config.RemoveFolder(folder_name);
                    }
                    else
                    {
                        previous_name = folder_name;
                    }
                }

                FolderListChanged();
            }
        }
Ejemplo n.º 7
0
        void RemoveDeletedRepositories ()
        {
            foreach (string folder_name in Config.Folders) {
                string folder_path = new SparkleFolder (folder_name).FullPath;

                if (!Directory.Exists (folder_path)) {
                    Config.RemoveFolder (folder_name);
                    RemoveRepository (GetRepoByName (folder_name));

                    Logger.LogInfo ("Controller", "Removed folder '" + folder_name + "' from config");

                } else {
                    AddRepository (folder_path);
                }
            }
        }
Ejemplo n.º 8
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);
                    }
                }
            };
        }