controller: Group new projects by domain name

This commit is contained in:
Hylke Bons 2016-04-01 23:17:29 +01:00
parent fa5a5b5560
commit aa380bbf8e
4 changed files with 83 additions and 81 deletions

View file

@ -327,65 +327,67 @@ namespace SparkleShare {
void CheckRepositories ()
{
lock (this.check_repos_lock) {
string path = Config.FoldersPath;
// Detect any renames
foreach (string folder_path in Directory.GetDirectories (path)) {
DetectRepositoryRenames ();
RemoveDeletedRepositories ();
}
FolderListChanged ();
}
void DetectRepositoryRenames ()
{
foreach (string group_path in Directory.GetDirectories (Config.FoldersPath)) {
if (group_path.EndsWith (".tmp"))
continue;
foreach (string folder_path in Directory.GetDirectories (group_path)) {
string folder_name = Path.GetFileName (folder_path);
if (folder_name.Equals (".tmp"))
if (Config.GetIdentifierForFolder (folder_name) != null)
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);
Logger.LogInfo ("Controller",
"Renamed folder with identifier " + identifier + " to '" + folder_name + "'");
}
}
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))
continue;
RemoveRepository (GetRepoByName (folder_name));
Config.RenameFolder (identifier, folder_name);
string new_folder_path = Path.Combine (group_path, folder_name);
AddRepository (new_folder_path);
Logger.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));
Logger.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 ();
}
}
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);
}
}
}
void AddRepository (string folder_path)
{
BaseRepository repo = null;
@ -648,11 +650,16 @@ namespace SparkleShare {
}
string target_folder_name = canonical_name;
if (suffix > 1)
target_folder_name += " (" + suffix + ")";
string target_folder_path = Path.Combine (Config.FoldersPath, target_folder_name);
string group_folder_path = Path.Combine (Config.FoldersPath, this.fetcher.RemoteUrl.Host);
if (!Directory.Exists (group_folder_path))
Directory.CreateDirectory (group_folder_path);
string target_folder_path = Path.Combine (group_folder_path, target_folder_name);
try {
Directory.Move (this.fetcher.TargetFolder, target_folder_path);

View file

@ -48,7 +48,7 @@ namespace SparkleShare {
Gdk.Color color = UserInterfaceHelpers.RGBAToColor (new Label().StyleContext.GetColor (StateFlags.Insensitive));
SecondaryTextColor = UserInterfaceHelpers.ColorToHex (color);
color = UserInterfaceHelpers.MixColors (
UserInterfaceHelpers.RGBAToColor (new TreeView ().StyleContext.GetColor (StateFlags.Selected)),
UserInterfaceHelpers.RGBAToColor (new TreeView ().StyleContext.GetBackgroundColor (StateFlags.Selected)),

View file

@ -26,6 +26,7 @@ using MonoMac.AppKit;
using Sparkles;
using Sparkles.Git;
using System.Linq;
namespace SparkleShare {
@ -179,12 +180,13 @@ namespace SparkleShare {
}
// We have to use our own custom made folder watcher, as
// System.IO.FileSystemWatcher fails watching subfolders on Mac
SparkleMacWatcher watcher;
delegate void FileActivityTask ();
// We have to use our own custom made folder watcher, as
// System.IO.FileSystemWatcher fails watching subfolders on Mac
FileActivityTask MacActivityTask (BaseRepository repo, FileSystemEventArgs fse_args)
FileActivityTask MacFileActivityTask (BaseRepository repo, FileSystemEventArgs fse_args)
{
return delegate { new Thread (() => { repo.OnFileActivity (fse_args); }).Start (); };
}
@ -193,30 +195,21 @@ namespace SparkleShare {
{
var triggered_repos = new List<string> ();
foreach (string file in changed_files_in_basedir) {
string repo_name;
int path_sep_index = file.IndexOf (Path.DirectorySeparatorChar);
foreach (string file_path in changed_files_in_basedir) {
string [] paths = file_path.Split (Path.DirectorySeparatorChar);
if (path_sep_index >= 0)
repo_name = file.Substring (0, path_sep_index);
else
repo_name = file;
repo_name = Path.GetFileNameWithoutExtension (repo_name);
BaseRepository repo = GetRepoByName (repo_name);
if (repo == null)
if (paths.Length < 2)
continue;
if (!triggered_repos.Contains (repo_name)) {
triggered_repos.Add (repo_name);
BaseRepository repo = GetRepoByName (paths [1]);
FileActivityTask task = MacActivityTask (repo,
new FileSystemEventArgs (WatcherChangeTypes.Changed, file, "Unknown"));
if (repo != null && !triggered_repos.Contains (repo.Name)) {
FileActivityTask task = MacFileActivityTask (repo,
new FileSystemEventArgs (WatcherChangeTypes.Changed, file_path, "Unknown"));
task ();
triggered_repos.Add (repo.Name);
}
}
}

View file

@ -63,7 +63,7 @@ namespace Sparkles {
public ChangeType Type;
public DateTime Timestamp;
public bool IsFolder = false;
public bool IsFolder;
public string Path;
public string MovedToPath;
@ -81,8 +81,10 @@ namespace Sparkles {
if (custom_path != null)
return Path.Combine (custom_path, Name);
else
return Path.Combine (Configuration.DefaultConfig.FoldersPath, Name);
return Path.Combine (Configuration.DefaultConfig.FoldersPath,
new Uri (Configuration.DefaultConfig.GetUrlForFolder (Name)).Host,
Name);
}
}