// Removes a repository from the list of repositories and // updates the statusicon menu private void RemoveRepository(string folder_path) { string folder_name = Path.GetFileName(folder_path); for (int i = 0; i < Repositories.Count; i++) { SparkleRepo repo = Repositories [i]; if (repo.Name.Equals(folder_name)) { Repositories.Remove(repo); repo.Dispose(); repo = null; break; } } if (FolderListChanged != null) { FolderListChanged(); } FolderSize = GetFolderSize(); if (FolderSizeChanged != null) { FolderSizeChanged(FolderSize); } }
// Adds a repository to the list of repositories private void AddRepository(string folder_path) { // Check if the folder is a Git repository if (!SparkleRepo.IsRepo(folder_path)) { return; } SparkleRepo repo = new SparkleRepo(folder_path); repo.NewCommit += delegate(SparkleCommit commit, string repository_path) { string message = FormatMessage(commit); if (NotificationRaised != null) { NotificationRaised(commit.UserName, commit.UserEmail, message, repository_path); } }; repo.FetchingStarted += delegate { UpdateState(); }; repo.FetchingFinished += delegate { UpdateState(); }; repo.FetchingFailed += delegate { UpdateState(); }; repo.ChangesDetected += delegate { UpdateState(); }; repo.PushingStarted += delegate { UpdateState(); }; repo.PushingFinished += delegate { UpdateState(); }; repo.CommitEndedUpEmpty += delegate { UpdateState(); }; repo.PushingFailed += delegate { UpdateState(); }; repo.ConflictDetected += delegate { if (ConflictNotificationRaised != null) { ConflictNotificationRaised(); } }; Repositories.Add(repo); }
// Removes a repository from the list of repositories and // updates the statusicon menu private void RemoveRepository(string folder_path) { string folder_name = Path.GetFileName(folder_path); for (int i = 0; i < Repositories.Count; i++) { SparkleRepo repo = Repositories [i]; if (repo.Name.Equals(folder_name)) { Repositories.Remove(repo); repo.Dispose(); repo = null; break; } } }
public SparkleController() { // Remove temporary file if (Directory.Exists(SparklePaths.SparkleTmpPath)) { Directory.Delete(SparklePaths.SparkleTmpPath, true); } InstallLauncher(); EnableSystemAutostart(); // Create the SparkleShare folder and add it to the bookmarks if (CreateSparkleShareFolder()) { AddToBookmarks(); } FolderSize = GetFolderSize(); SparklePath = SparklePaths.SparklePath; string global_config_file_path = SparkleHelpers.CombineMore(SparklePaths.SparkleConfigPath, "config"); // Show the introduction screen if SparkleShare isn't configured if (!File.Exists(global_config_file_path)) { FirstRun = true; } else { FirstRun = false; AddKey(); } // Watch the SparkleShare folder FileSystemWatcher watcher = new FileSystemWatcher(SparklePaths.SparklePath) { IncludeSubdirectories = false, EnableRaisingEvents = true, Filter = "*" }; // Remove the repository when a delete event occurs watcher.Deleted += delegate(object o, FileSystemEventArgs args) { RemoveRepository(args.FullPath); if (FolderListChanged != null) { FolderListChanged(); } FolderSize = GetFolderSize(); if (FolderSizeChanged != null) { FolderSizeChanged(FolderSize); } }; // Add the repository when a create event occurs watcher.Created += delegate(object o, FileSystemEventArgs args) { // TODO: Needs to wait until the copying over is done // Handle invitations when the user saves an // invitation into the SparkleShare folder if (args.Name.EndsWith(".sparkle") && !FirstRun) { XmlDocument xml_doc = new XmlDocument(); xml_doc.Load(args.Name); string server = xml_doc.GetElementsByTagName("server") [0].InnerText; string folder = xml_doc.GetElementsByTagName("folder") [0].InnerText; string token = xml_doc.GetElementsByTagName("token") [0].InnerText; // FIXME: this is broken :\ if (OnInvitation != null) { OnInvitation(server, folder, token); } } else if (SparkleRepo.IsRepo(args.FullPath)) { AddRepository(args.FullPath); if (FolderListChanged != null) { FolderListChanged(); } FolderSize = GetFolderSize(); if (FolderSizeChanged != null) { FolderSizeChanged(FolderSize); } } }; CreateConfigurationFolders(); Thread thread = new Thread( new ThreadStart(PopulateRepositories) ); thread.Start(); }
// Adds a repository to the list of repositories private void AddRepository(string folder_path) { // Check if the folder is a Git repository if (!SparkleRepo.IsRepo(folder_path)) { return; } SparkleRepo repo = new SparkleRepo(folder_path); repo.NewCommit += delegate(SparkleCommit commit, string repository_path) { if (NotificationRaised != null) { NotificationRaised(commit, repository_path); } }; repo.FetchingStarted += delegate { UpdateState(); }; repo.FetchingFinished += delegate { UpdateState(); }; repo.FetchingFailed += delegate { UpdateState(); }; repo.ChangesDetected += delegate { UpdateState(); }; repo.PushingStarted += delegate { UpdateState(); }; repo.PushingFinished += delegate { UpdateState(); }; repo.CommitEndedUpEmpty += delegate { UpdateState(); }; repo.PushingFailed += delegate { UpdateState(); }; repo.ConflictDetected += delegate { if (ConflictNotificationRaised != null) { ConflictNotificationRaised(); } }; Repositories.Add(repo); if (FolderListChanged != null) { FolderListChanged(); } FolderSize = GetFolderSize(); if (FolderSizeChanged != null) { FolderSizeChanged(FolderSize); } }