// Add a .gitignore file to the repo private void InstallExcludeRules() { string exlude_rules_file_path = SparkleHelpers.CombineMore( TargetFolder, ".git", "info", "exclude"); TextWriter writer = new StreamWriter(exlude_rules_file_path); // gedit and emacs writer.WriteLine("*~"); // vi(m) writer.WriteLine(".*.sw[a-z]"); writer.WriteLine("*.un~"); writer.WriteLine("*.swp"); writer.WriteLine("*.swo"); // KDE writer.WriteLine(".directory"); // Mac OSX writer.WriteLine(".DS_Store"); writer.WriteLine("Icon?"); writer.WriteLine("._*"); writer.WriteLine(".Spotlight-V100"); writer.WriteLine(".Trashes"); // Mac OSX writer.WriteLine("*(Autosaved).graffle"); // Windows writer.WriteLine("Thumbs.db"); writer.WriteLine("Desktop.ini"); // CVS writer.WriteLine("*/CVS/*"); writer.WriteLine(".cvsignore"); writer.WriteLine("*/.cvsignore"); // Subversion writer.WriteLine("/.svn/*"); writer.WriteLine("*/.svn/*"); writer.Close(); }
// Gets the repository's description private string GetDescription() { string description_file_path = SparkleHelpers.CombineMore(LocalPath, ".git", "description"); if (!File.Exists(description_file_path)) { return(null); } StreamReader reader = new StreamReader(description_file_path); string description = reader.ReadToEnd(); reader.Close(); if (description.StartsWith("Unnamed")) { description = null; } return(description); }
private string GetCurrentHash() { // Remove stale rebase-apply files because it // makes the method return the wrong hashes. string rebase_apply_file = SparkleHelpers.CombineMore(LocalPath, ".git", "rebase-apply"); if (File.Exists(rebase_apply_file)) { File.Delete(rebase_apply_file); } SparkleGit git = new SparkleGit(LocalPath, "log -1 --format=%H"); git.Start(); git.WaitForExit(); string output = git.StandardOutput.ReadToEnd(); string hash = output.Trim(); return(hash); }
private void DisableHostKeyCheckingForHost(string host) { string path = SparkleConfig.DefaultConfig.HomePath; if (!(SparkleBackend.Platform == PlatformID.Unix || SparkleBackend.Platform == PlatformID.MacOSX)) { path = Environment.ExpandEnvironmentVariables("%HOMEDRIVE%%HOMEPATH%"); } string ssh_config_path = Path.Combine(path, ".ssh"); string ssh_config_file_path = SparkleHelpers.CombineMore(path, ".ssh", "config"); string ssh_config = "\n# <SparkleShare>" + "\nHost " + host + "\n\tStrictHostKeyChecking no" + "\n# </SparkleShare>"; if (!Directory.Exists(ssh_config_path)) { Directory.CreateDirectory(ssh_config_path); } if (File.Exists(ssh_config_file_path)) { TextWriter writer = File.AppendText(ssh_config_file_path); writer.Write(ssh_config); writer.Close(); } else { File.WriteAllText(ssh_config_file_path, ssh_config); } //UnixFileSystemInfo file_info = new UnixFileInfo (ssh_config_file_path); //file_info.FileAccessPermissions = (FileAccessPermissions.UserRead | // FileAccessPermissions.UserWrite); TODO SparkleHelpers.DebugInfo("Fetcher", "Disabled host key checking " + host); }
// Install the user's name and email and some config into // the newly cloned repository private void InstallConfiguration() { string global_config_file_path = SparkleHelpers.CombineMore(SparklePaths.SparkleConfigPath, "config"); if (File.Exists(global_config_file_path)) { StreamReader reader = new StreamReader(global_config_file_path); string user_info = reader.ReadToEnd(); reader.Close(); string repo_config_file_path = SparkleHelpers.CombineMore(TargetFolder, ".git", "config"); string config = String.Join("\n", File.ReadAllLines(repo_config_file_path)); config = config.Replace("ignorecase = true", "ignorecase = false"); config += Environment.NewLine + user_info; TextWriter writer = new StreamWriter(repo_config_file_path); writer.WriteLine(config); writer.Close(); SparkleHelpers.DebugInfo("Config", "Added configuration to '" + repo_config_file_path + "'"); } }
// Pushes the changes to the remote repo public void Push() { _IsSyncing = true; _IsPushing = true; SparkleHelpers.DebugInfo("Git", "[" + Name + "] Pushing changes..."); SparkleGit git = new SparkleGit(LocalPath, "push origin master"); SparkleEventArgs args = new SparkleEventArgs("PushingStarted"); if (PushingStarted != null) { PushingStarted(this, args); } git.Exited += delegate { _IsSyncing = false; _IsPushing = false; if (git.ExitCode != 0) { SparkleHelpers.DebugInfo("Git", "[" + Name + "] Pushing failed."); string unsynced_file_path = SparkleHelpers.CombineMore(LocalPath, ".git", "has_unsynced_changes"); if (!File.Exists(unsynced_file_path)) { File.Create(unsynced_file_path); } _HasUnsyncedChanges = true; args = new SparkleEventArgs("PushingFailed"); if (PushingFailed != null) { PushingFailed(this, args); } FetchRebaseAndPush(); } else { SparkleHelpers.DebugInfo("Git", "[" + Name + "] Changes pushed."); args = new SparkleEventArgs("PushingFinished"); string unsynced_file_path = SparkleHelpers.CombineMore(LocalPath, ".git", "has_unsynced_changes"); if (File.Exists(unsynced_file_path)) { File.Delete(unsynced_file_path); } _HasUnsyncedChanges = false; if (PushingFinished != null) { PushingFinished(this, args); } if (Listener.Client.IsConnected) { Listener.Announce(_CurrentHash); } else { AnnounceQueue++; SparkleHelpers.DebugInfo("Irc", "[" + Name + "] Could not deliver notification, added it to the queue"); } } }; git.Start(); git.WaitForExit(); }
public SparkleRepo(string path) { LocalPath = path; Name = Path.GetFileName(LocalPath); RemoteOriginUrl = GetRemoteOriginUrl(); RemoteName = Path.GetFileNameWithoutExtension(RemoteOriginUrl); Domain = GetDomain(RemoteOriginUrl); Description = GetDescription(); UserName = GetUserName(); UserEmail = GetUserEmail(); _IsSyncing = false; _IsBuffering = false; _IsPolling = true; _IsFetching = false; _IsPushing = false; _ServerOnline = true; HasChanged = false; ChangeLock = new Object(); FetchQueue = 0; AnnounceQueue = 0; if (IsEmpty) { _CurrentHash = null; } else { _CurrentHash = GetCurrentHash(); } string unsynced_file_path = SparkleHelpers.CombineMore(LocalPath, ".git", "has_unsynced_changes"); if (File.Exists(unsynced_file_path)) { _HasUnsyncedChanges = true; } else { _HasUnsyncedChanges = false; } if (_CurrentHash == null) { CreateInitialCommit(); } // Watch the repository's folder Watcher = new FileSystemWatcher(LocalPath) { IncludeSubdirectories = true, EnableRaisingEvents = true, Filter = "*" }; Watcher.Changed += new FileSystemEventHandler(OnFileActivity); Watcher.Created += new FileSystemEventHandler(OnFileActivity); Watcher.Deleted += new FileSystemEventHandler(OnFileActivity); Watcher.Renamed += new RenamedEventHandler(OnFileActivity); // Listen to the irc channel on the server... if (UsesNotificationCenter) { Listener = new SparkleListener(Domain, RemoteName, UserEmail, NotificationServerType.Central); } else { Listener = new SparkleListener(Domain, RemoteName, UserEmail, NotificationServerType.Own); } // ...fetch remote changes every 60 seconds if that fails RemoteTimer = new Timer() { Interval = 60000 }; RemoteTimer.Elapsed += delegate { if (_IsPolling) { CheckForRemoteChanges(); if (!Listener.Client.IsConnected) { SparkleHelpers.DebugInfo("Irc", "[" + Name + "] Trying to reconnect..."); Listener.Listen(); } } if (_HasUnsyncedChanges) { FetchRebaseAndPush(); } }; // Stop polling when the connection to the irc channel is succesful Listener.Client.OnConnected += delegate { _IsPolling = false; // Check for changes manually one more time CheckForRemoteChanges(); // Push changes that were made since the last disconnect if (_HasUnsyncedChanges) { Push(); } SparkleHelpers.DebugInfo("Irc", "[" + Name + "] Connected. Now listening... (" + Listener.Server + ")"); if (AnnounceQueue > 0) { Listener.Announce(_CurrentHash); AnnounceQueue = 0; SparkleHelpers.DebugInfo("Irc", "[" + Name + "] Queued messages delivered. (" + Listener.Server + ")"); } }; // Start polling when the connection to the irc channel is lost Listener.Client.OnConnectionError += delegate { SparkleHelpers.DebugInfo("Irc", "[" + Name + "] Lost connection. Falling back to polling..."); _IsPolling = true; }; // Start polling when the connection to the irc channel is lost Listener.Client.OnDisconnected += delegate { SparkleHelpers.DebugInfo("Irc", "[" + Name + "] Lost connection. Falling back to polling..."); _IsPolling = true; }; // Fetch changes when there is a message in the irc channel Listener.Client.OnChannelMessage += delegate(object o, IrcEventArgs args) { SparkleHelpers.DebugInfo("Irc", "[" + Name + "] Was notified of a remote change..."); string message = args.Data.Message.Trim(); if (!message.Equals(_CurrentHash) && message.Length == 40) { FetchQueue++; if (_IsBuffering) { SparkleHelpers.DebugInfo("Irc", "[" + Name + "] ...but we're busy adding files. We'll fetch them later."); } else if (!_IsFetching) { while (FetchQueue > 0) { Fetch(); FetchQueue--; } Watcher.EnableRaisingEvents = false; Rebase(); Watcher.EnableRaisingEvents = true; } } else { // Not really needed as we won't be notified about our own messages SparkleHelpers.DebugInfo("Irc", "[" + Name + "] False alarm, already up to date. (" + _CurrentHash + ")"); } }; // Start listening Listener.Listen(); SizeBuffer = new List <double> (); // Keep a timer that checks if there are changes and // whether they have settled LocalTimer = new Timer() { Interval = 250 }; LocalTimer.Elapsed += delegate(object o, ElapsedEventArgs args) { CheckForChanges(); }; RemoteTimer.Start(); LocalTimer.Start(); // Add everything that changed // since SparkleShare was stopped AddCommitAndPush(); if (_CurrentHash == null) { _CurrentHash = GetCurrentHash(); } }
// Add a .gitignore file to the repo private void InstallExcludeRules() { DirectoryInfo info = Directory.CreateDirectory( SparkleHelpers.CombineMore(this.target_folder, ".git", "info")); // File that lists the files we want git to ignore string exlude_rules_file_path = Path.Combine(info.FullName, "exclude"); TextWriter writer = new StreamWriter(exlude_rules_file_path); // gedit and emacs writer.WriteLine("*~"); // Firefox and Chromium temporary download files writer.WriteLine("*.part"); writer.WriteLine("*.crdownload"); // vi(m) writer.WriteLine(".*.sw[a-z]"); writer.WriteLine("*.un~"); writer.WriteLine("*.swp"); writer.WriteLine("*.swo"); // KDE writer.WriteLine(".directory"); // Mac OS X writer.WriteLine(".DS_Store"); writer.WriteLine("Icon?"); writer.WriteLine("._*"); writer.WriteLine(".Spotlight-V100"); writer.WriteLine(".Trashes"); // Omnigraffle writer.WriteLine("*(Autosaved).graffle"); // Windows writer.WriteLine("Thumbs.db"); writer.WriteLine("Desktop.ini"); // MS Office writer.WriteLine("~*.tmp"); writer.WriteLine("~*.TMP"); writer.WriteLine("*~*.tmp"); writer.WriteLine("*~*.TMP"); writer.WriteLine("~*.ppt"); writer.WriteLine("~*.PPT"); writer.WriteLine("~*.pptx"); writer.WriteLine("~*.PPTX"); writer.WriteLine("~*.xls"); writer.WriteLine("~*.XLS"); writer.WriteLine("~*.xlsx"); writer.WriteLine("~*.XLSX"); writer.WriteLine("~*.doc"); writer.WriteLine("~*.DOC"); writer.WriteLine("~*.docx"); writer.WriteLine("~*.DOCX"); // CVS writer.WriteLine("*/CVS/*"); writer.WriteLine(".cvsignore"); writer.WriteLine("*/.cvsignore"); // Subversion writer.WriteLine("/.svn/*"); writer.WriteLine("*/.svn/*"); writer.Close(); // File that lists the files we want don't want git to compress. // Not compressing the already compressed files saves us memory // usage and increases speed string no_compression_rules_file_path = Path.Combine(info.FullName, "attributes"); writer = new StreamWriter(no_compression_rules_file_path); // Images writer.WriteLine("*.jpg -delta"); writer.WriteLine("*.jpeg -delta"); writer.WriteLine("*.JPG -delta"); writer.WriteLine("*.JPEG -delta"); writer.WriteLine("*.png -delta"); writer.WriteLine("*.PNG -delta"); writer.WriteLine("*.tiff -delta"); writer.WriteLine("*.TIFF -delta"); // Audio writer.WriteLine("*.flac -delta"); writer.WriteLine("*.FLAC -delta"); writer.WriteLine("*.mp3 -delta"); writer.WriteLine("*.MP3 -delta"); writer.WriteLine("*.ogg -delta"); writer.WriteLine("*.OGG -delta"); writer.WriteLine("*.oga -delta"); writer.WriteLine("*.OGA -delta"); // Video writer.WriteLine("*.avi -delta"); writer.WriteLine("*.AVI -delta"); writer.WriteLine("*.mov -delta"); writer.WriteLine("*.MOV -delta"); writer.WriteLine("*.mpg -delta"); writer.WriteLine("*.MPG -delta"); writer.WriteLine("*.mpeg -delta"); writer.WriteLine("*.MPEG -delta"); writer.WriteLine("*.mkv -delta"); writer.WriteLine("*.MKV -delta"); writer.WriteLine("*.ogv -delta"); writer.WriteLine("*.OGV -delta"); writer.WriteLine("*.ogx -delta"); writer.WriteLine("*.OGX -delta"); writer.WriteLine("*.webm -delta"); writer.WriteLine("*.WEBM -delta"); // Archives writer.WriteLine("*.zip -delta"); writer.WriteLine("*.ZIP -delta"); writer.WriteLine("*.gz -delta"); writer.WriteLine("*.GZ -delta"); writer.WriteLine("*.bz -delta"); writer.WriteLine("*.BZ -delta"); writer.WriteLine("*.bz2 -delta"); writer.WriteLine("*.BZ2 -delta"); writer.WriteLine("*.rpm -delta"); writer.WriteLine("*.RPM -delta"); writer.WriteLine("*.deb -delta"); writer.WriteLine("*.DEB -delta"); writer.WriteLine("*.tgz -delta"); writer.WriteLine("*.TGZ -delta"); writer.WriteLine("*.rar -delta"); writer.WriteLine("*.RAR -delta"); writer.WriteLine("*.ace -delta"); writer.WriteLine("*.ACE -delta"); writer.WriteLine("*.7z -delta"); writer.WriteLine("*.7Z -delta"); writer.WriteLine("*.pak -delta"); writer.WriteLine("*.PAK -delta"); writer.WriteLine("*.tar -delta"); writer.WriteLine("*.TAR -delta"); writer.Close(); }
// Add a .gitignore file to the repo private void InstallExcludeRules() { DirectoryInfo info = Directory.CreateDirectory(SparkleHelpers.CombineMore( this.target_folder, ".git", "info")); string exlude_rules_file_path = Path.Combine(info.FullName, "exclude"); TextWriter writer = new StreamWriter(exlude_rules_file_path); // gedit and emacs writer.WriteLine("*~"); // Firefox and Chromium temporary download files writer.WriteLine("*.part"); writer.WriteLine("*.crdownload"); // vi(m) writer.WriteLine(".*.sw[a-z]"); writer.WriteLine("*.un~"); writer.WriteLine("*.swp"); writer.WriteLine("*.swo"); // KDE writer.WriteLine(".directory"); // Mac OSX writer.WriteLine(".DS_Store"); writer.WriteLine("Icon?"); writer.WriteLine("._*"); writer.WriteLine(".Spotlight-V100"); writer.WriteLine(".Trashes"); // Mac OSX writer.WriteLine("*(Autosaved).graffle"); // Windows writer.WriteLine("Thumbs.db"); writer.WriteLine("Desktop.ini"); // MS Office writer.WriteLine("~*.tmp"); writer.WriteLine("~*.TMP"); writer.WriteLine("*~*.tmp"); writer.WriteLine("*~*.TMP"); writer.WriteLine("~*.ppt"); writer.WriteLine("~*.pptx"); writer.WriteLine("~*.PPT"); writer.WriteLine("~*.PPTX"); writer.WriteLine("~*.xls"); writer.WriteLine("~*.xlsx"); writer.WriteLine("~*.XLS"); writer.WriteLine("~*.XLSX"); writer.WriteLine("~*.doc"); writer.WriteLine("~*.docx"); writer.WriteLine("~*.DOC"); writer.WriteLine("~*.DOCX"); // CVS writer.WriteLine("*/CVS/*"); writer.WriteLine(".cvsignore"); writer.WriteLine("*/.cvsignore"); // Subversion writer.WriteLine("/.svn/*"); writer.WriteLine("*/.svn/*"); writer.Close(); }
// Pushes the changes to the remote repo public void Push() { _IsSyncing = true; _IsPushing = true; SparkleGit git = new SparkleGit(LocalPath, "push origin master"); SparkleHelpers.DebugInfo("Git", "[" + Name + "] Pushing changes..."); SparkleEventArgs args = new SparkleEventArgs("PushingStarted"); if (PushingStarted != null) { PushingStarted(this, args); } git.Exited += delegate { _IsSyncing = false; _IsPushing = false; if (git.ExitCode != 0) { SparkleHelpers.DebugInfo("Git", "[" + Name + "] Pushing failed."); string unsynced_file_path = SparkleHelpers.CombineMore(LocalPath, ".git", "has_unsynced_changes"); if (!File.Exists(unsynced_file_path)) { File.Create(unsynced_file_path); } _HasUnsyncedChanges = true; args = new SparkleEventArgs("PushingFailed"); if (PushingFailed != null) { PushingFailed(this, args); } CheckForRemoteChanges(); Push(); } else { SparkleHelpers.DebugInfo("Git", "[" + Name + "] Changes pushed."); args = new SparkleEventArgs("PushingFinished"); string unsynced_file_path = SparkleHelpers.CombineMore(LocalPath, ".git", "has_unsynced_changes"); if (File.Exists(unsynced_file_path)) { File.Delete(unsynced_file_path); } _HasUnsyncedChanges = false; if (PushingFinished != null) { PushingFinished(this, args); } if (!_IsPolling) { Listener.Announce(_CurrentHash); } } }; git.Start(); git.WaitForExit(); }