public string GetAvatar(string email, int size) { string avatar_file_path = SparkleHelpers.CombineMore( Path.GetDirectoryName(SparkleConfig.DefaultConfig.FullPath), "icons", size + "x" + size, "status", "avatar-" + email); if (File.Exists(avatar_file_path)) { return(avatar_file_path); } else { FetchAvatars(email, size); if (File.Exists(avatar_file_path)) { return(avatar_file_path); } else { return(null); } } }
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(); }
public string GetHTMLLog(string name) { List <SparkleCommit> commits = GetLog(name); List <ActivityDay> activity_days = new List <ActivityDay> (); if (commits.Count == 0) { return(null); } foreach (SparkleCommit commit in commits) { GetAvatar(commit.UserEmail, 36); bool commit_inserted = false; foreach (ActivityDay stored_activity_day in activity_days) { if (stored_activity_day.DateTime.Year == commit.DateTime.Year && stored_activity_day.DateTime.Month == commit.DateTime.Month && stored_activity_day.DateTime.Day == commit.DateTime.Day) { stored_activity_day.Add(commit); commit_inserted = true; break; } } if (!commit_inserted) { ActivityDay activity_day = new ActivityDay(commit.DateTime); activity_day.Add(commit); activity_days.Add(activity_day); } } string event_log_html = EventLogHTML; string day_entry_html = DayEntryHTML; string event_entry_html = EventEntryHTML; string event_log = ""; foreach (ActivityDay activity_day in activity_days) { string event_entries = ""; foreach (SparkleCommit change_set in activity_day) { string event_entry = "<dl>"; if (change_set.IsMerge) { event_entry += "<dt>Merged a branch</dt>"; } else { if (change_set.Edited.Count > 0) { event_entry += "<dt>Edited</dt>"; foreach (string file_path in change_set.Edited) { string absolute_file_path = SparkleHelpers.CombineMore(SparklePaths.SparklePath, name, file_path); if (File.Exists(absolute_file_path)) { event_entry += "<dd><a href='" + absolute_file_path + "'>" + file_path + "</a></dd>"; } else { event_entry += "<dd>" + file_path + "</dd>"; } } } if (change_set.Added.Count > 0) { event_entry += "<dt>Added</dt>"; foreach (string file_path in change_set.Added) { string absolute_file_path = SparkleHelpers.CombineMore(SparklePaths.SparklePath, name, file_path); if (File.Exists(absolute_file_path)) { event_entry += "<dd><a href='" + absolute_file_path + "'>" + file_path + "</a></dd>"; } else { event_entry += "<dd>" + file_path + "</dd>"; } } } if (change_set.Deleted.Count > 0) { event_entry += "<dt>Deleted</dt>"; foreach (string file_path in change_set.Deleted) { string absolute_file_path = SparkleHelpers.CombineMore(SparklePaths.SparklePath, name, file_path); if (File.Exists(absolute_file_path)) { event_entry += "<dd><a href='" + absolute_file_path + "'>" + file_path + "</a></dd>"; } else { event_entry += "<dd>" + file_path + "</dd>"; } } } } event_entry += "</dl>"; event_entries += event_entry_html.Replace("<!-- $event-entry-content -->", event_entry) .Replace("<!-- $event-user-name -->", change_set.UserName) .Replace("<!-- $event-avatar-url -->", "file://" + GetAvatar(change_set.UserEmail, 36)) .Replace("<!-- $event-time -->", change_set.DateTime.ToString("H:mm")); } string day_entry = ""; DateTime today = DateTime.Now; DateTime yesterday = DateTime.Now.AddDays(-1); if (today.Day == activity_day.DateTime.Day && today.Month == activity_day.DateTime.Month && today.Year == activity_day.DateTime.Year) { day_entry = day_entry_html.Replace("<!-- $day-entry-header -->", "<b>Today</b>"); } else if (yesterday.Day == activity_day.DateTime.Day && yesterday.Month == activity_day.DateTime.Month && yesterday.Year == activity_day.DateTime.Year) { day_entry = day_entry_html.Replace("<!-- $day-entry-header -->", "<b>Yesterday</b>"); } else { if (activity_day.DateTime.Year != DateTime.Now.Year) { // TRANSLATORS: This is the date in the event logs day_entry = day_entry_html.Replace("<!-- $day-entry-header -->", "<b>" + activity_day.DateTime.ToString(_("ddd MMM d, yyyy")) + "</b>"); } else { // TRANSLATORS: This is the date in the event logs, without the year day_entry = day_entry_html.Replace("<!-- $day-entry-header -->", "<b>" + activity_day.DateTime.ToString(_("ddd MMM d")) + "</b>"); } } event_log += day_entry.Replace("<!-- $day-entry-content -->", event_entries); } string html = event_log_html.Replace("<!-- $event-log-content -->", event_log); return(html); }
public void FetchFolder(string url, string name) { SparkleHelpers.DebugInfo("Controller", "Formed URL: " + url); string host = url.Substring(url.IndexOf("@") + 1); if (host.Contains(":")) { host = host.Substring(0, host.IndexOf(":")); } else { host = host.Substring(0, host.IndexOf("/")); } DisableHostKeyCheckingForHost(host); // Strip the '.git' from the name string canonical_name = System.IO.Path.GetFileNameWithoutExtension(name); string tmp_folder = SparkleHelpers.CombineMore(SparklePaths.SparkleTmpPath, canonical_name); SparkleFetcher fetcher = new SparkleFetcher(url, tmp_folder); bool folder_exists = Directory.Exists( SparkleHelpers.CombineMore(SparklePaths.SparklePath, canonical_name)); // Add a numbered suffix to the nameif a folder with the same name // already exists. Example: "Folder (2)" int i = 1; while (folder_exists) { i++; folder_exists = Directory.Exists( SparkleHelpers.CombineMore(SparklePaths.SparklePath, canonical_name + " (" + i + ")")); } string target_folder_name = canonical_name; if (i > 1) { target_folder_name += " (" + i + ")"; } fetcher.CloningFinished += delegate { EnableHostKeyCheckingForHost(host); SparkleHelpers.ClearAttributes(tmp_folder); try { string target_folder_path = SparkleHelpers.CombineMore(SparklePaths.SparklePath, target_folder_name); Directory.Move(tmp_folder, target_folder_path); } catch (Exception e) { SparkleHelpers.DebugInfo("Controller", "Error moving folder: " + e.Message); } if (FolderFetched != null) { FolderFetched(); } if (FolderListChanged != null) { FolderListChanged(); } }; fetcher.CloningFailed += delegate { EnableHostKeyCheckingForHost(host); if (Directory.Exists(tmp_folder)) { SparkleHelpers.ClearAttributes(tmp_folder); Directory.Delete(tmp_folder, true); SparkleHelpers.DebugInfo("Config", "Deleted temporary directory: " + tmp_folder); } if (FolderFetchError != null) { FolderFetchError(); } }; fetcher.Start(); }
// Gets the avatar for a specific email address and size public string GetAvatar(string email, int size) { string avatar_path = SparkleHelpers.CombineMore(SparklePaths.SparkleLocalIconPath, size + "x" + size, "status"); if (!Directory.Exists(avatar_path)) { Directory.CreateDirectory(avatar_path); SparkleHelpers.DebugInfo("Config", "Created '" + avatar_path + "'"); } string avatar_file_path = SparkleHelpers.CombineMore(avatar_path, "avatar-" + email); if (File.Exists(avatar_file_path)) { return(avatar_file_path); } else { // Let's try to get the person's gravatar for next time WebClient web_client = new WebClient(); Uri uri = new Uri("http://www.gravatar.com/avatar/" + GetMD5(email) + ".jpg?s=" + size + "&d=404"); string tmp_file_path = SparkleHelpers.CombineMore(SparklePaths.SparkleTmpPath, email + size); if (!File.Exists(tmp_file_path)) { web_client.DownloadFileAsync(uri, tmp_file_path); web_client.DownloadFileCompleted += delegate { if (File.Exists(avatar_file_path)) { File.Delete(avatar_file_path); } FileInfo tmp_file_info = new FileInfo(tmp_file_path); if (tmp_file_info.Length > 255) { File.Move(tmp_file_path, avatar_file_path); } if (AvatarFetched != null) { AvatarFetched(); } }; } // Fall back to a generic icon if there is no gravatar if (File.Exists(avatar_file_path)) { return(avatar_file_path); } else { return(null); } } }
// Add a .gitignore file to the repo private void InstallExcludeRules() { DirectoryInfo info = Directory.CreateDirectory( SparkleHelpers.CombineMore(TargetFolder, ".git", "info")); // File that lists the files we want git to ignore string exclude_rules_file_path = Path.Combine(info.FullName, "exclude"); TextWriter writer = new StreamWriter(exclude_rules_file_path); foreach (string exclude_rule in ExcludeRules) { writer.WriteLine(exclude_rule); } 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(); }