private void CheckRepositories ()
        {
            lock (this.check_repos_lock) {
                string path = this.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 (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 + "'");
                        }
                    }
                }
                
                // Remove any deleted folders
                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);
                    }
                }
                
                // Remove any duplicate folders
                string previous_name = "";
                foreach (string folder_name in this.config.Folders) {
                    if (!string.IsNullOrEmpty (previous_name) && folder_name.Equals (previous_name))
                        this.config.RemoveFolder (folder_name);
                    else
                        previous_name = folder_name;
                }

                FolderListChanged ();
            }
        }
Exemplo n.º 2
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);

                            SparkleHelpers.DebugInfo ("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);

                        SparkleHelpers.DebugInfo ("Controller",
                            "Removed folder '" + folder_name + "' from config");

                    } else {
                        AddRepository (folder_path);
                    }
                }

                FolderListChanged ();
            }
        }