controller: Group new projects by domain name
This commit is contained in:
parent
fa5a5b5560
commit
aa380bbf8e
|
@ -327,65 +327,67 @@ namespace SparkleShare {
|
||||||
void CheckRepositories ()
|
void CheckRepositories ()
|
||||||
{
|
{
|
||||||
lock (this.check_repos_lock) {
|
lock (this.check_repos_lock) {
|
||||||
string path = Config.FoldersPath;
|
DetectRepositoryRenames ();
|
||||||
|
RemoveDeletedRepositories ();
|
||||||
// Detect any renames
|
}
|
||||||
foreach (string folder_path in Directory.GetDirectories (path)) {
|
|
||||||
|
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);
|
string folder_name = Path.GetFileName (folder_path);
|
||||||
|
|
||||||
if (folder_name.Equals (".tmp"))
|
if (Config.GetIdentifierForFolder (folder_name) != null)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (Config.GetIdentifierForFolder (folder_name) == null) {
|
string identifier_file_path = Path.Combine (folder_path, ".sparkleshare");
|
||||||
string identifier_file_path = Path.Combine (folder_path, ".sparkleshare");
|
|
||||||
|
if (!File.Exists (identifier_file_path))
|
||||||
if (!File.Exists (identifier_file_path))
|
continue;
|
||||||
continue;
|
|
||||||
|
string identifier = File.ReadAllText (identifier_file_path).Trim ();
|
||||||
string identifier = File.ReadAllText (identifier_file_path).Trim ();
|
|
||||||
|
if (!Config.IdentifierExists (identifier))
|
||||||
if (Config.IdentifierExists (identifier)) {
|
continue;
|
||||||
RemoveRepository (GetRepoByName (folder_name));
|
|
||||||
Config.RenameFolder (identifier, folder_name);
|
RemoveRepository (GetRepoByName (folder_name));
|
||||||
|
Config.RenameFolder (identifier, folder_name);
|
||||||
string new_folder_path = Path.Combine (path, folder_name);
|
|
||||||
AddRepository (new_folder_path);
|
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 + "'");
|
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)
|
void AddRepository (string folder_path)
|
||||||
{
|
{
|
||||||
BaseRepository repo = null;
|
BaseRepository repo = null;
|
||||||
|
@ -648,11 +650,16 @@ namespace SparkleShare {
|
||||||
}
|
}
|
||||||
|
|
||||||
string target_folder_name = canonical_name;
|
string target_folder_name = canonical_name;
|
||||||
|
|
||||||
if (suffix > 1)
|
if (suffix > 1)
|
||||||
target_folder_name += " (" + suffix + ")";
|
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 {
|
try {
|
||||||
Directory.Move (this.fetcher.TargetFolder, target_folder_path);
|
Directory.Move (this.fetcher.TargetFolder, target_folder_path);
|
||||||
|
|
|
@ -48,7 +48,7 @@ namespace SparkleShare {
|
||||||
|
|
||||||
Gdk.Color color = UserInterfaceHelpers.RGBAToColor (new Label().StyleContext.GetColor (StateFlags.Insensitive));
|
Gdk.Color color = UserInterfaceHelpers.RGBAToColor (new Label().StyleContext.GetColor (StateFlags.Insensitive));
|
||||||
SecondaryTextColor = UserInterfaceHelpers.ColorToHex (color);
|
SecondaryTextColor = UserInterfaceHelpers.ColorToHex (color);
|
||||||
|
|
||||||
color = UserInterfaceHelpers.MixColors (
|
color = UserInterfaceHelpers.MixColors (
|
||||||
UserInterfaceHelpers.RGBAToColor (new TreeView ().StyleContext.GetColor (StateFlags.Selected)),
|
UserInterfaceHelpers.RGBAToColor (new TreeView ().StyleContext.GetColor (StateFlags.Selected)),
|
||||||
UserInterfaceHelpers.RGBAToColor (new TreeView ().StyleContext.GetBackgroundColor (StateFlags.Selected)),
|
UserInterfaceHelpers.RGBAToColor (new TreeView ().StyleContext.GetBackgroundColor (StateFlags.Selected)),
|
||||||
|
|
|
@ -26,6 +26,7 @@ using MonoMac.AppKit;
|
||||||
|
|
||||||
using Sparkles;
|
using Sparkles;
|
||||||
using Sparkles.Git;
|
using Sparkles.Git;
|
||||||
|
using System.Linq;
|
||||||
|
|
||||||
namespace SparkleShare {
|
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;
|
SparkleMacWatcher watcher;
|
||||||
delegate void FileActivityTask ();
|
delegate void FileActivityTask ();
|
||||||
|
|
||||||
// We have to use our own custom made folder watcher, as
|
FileActivityTask MacFileActivityTask (BaseRepository repo, FileSystemEventArgs fse_args)
|
||||||
// System.IO.FileSystemWatcher fails watching subfolders on Mac
|
|
||||||
FileActivityTask MacActivityTask (BaseRepository repo, FileSystemEventArgs fse_args)
|
|
||||||
{
|
{
|
||||||
return delegate { new Thread (() => { repo.OnFileActivity (fse_args); }).Start (); };
|
return delegate { new Thread (() => { repo.OnFileActivity (fse_args); }).Start (); };
|
||||||
}
|
}
|
||||||
|
@ -193,30 +195,21 @@ namespace SparkleShare {
|
||||||
{
|
{
|
||||||
var triggered_repos = new List<string> ();
|
var triggered_repos = new List<string> ();
|
||||||
|
|
||||||
foreach (string file in changed_files_in_basedir) {
|
foreach (string file_path in changed_files_in_basedir) {
|
||||||
string repo_name;
|
string [] paths = file_path.Split (Path.DirectorySeparatorChar);
|
||||||
int path_sep_index = file.IndexOf (Path.DirectorySeparatorChar);
|
|
||||||
|
|
||||||
if (path_sep_index >= 0)
|
if (paths.Length < 2)
|
||||||
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)
|
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (!triggered_repos.Contains (repo_name)) {
|
BaseRepository repo = GetRepoByName (paths [1]);
|
||||||
triggered_repos.Add (repo_name);
|
|
||||||
|
|
||||||
FileActivityTask task = MacActivityTask (repo,
|
if (repo != null && !triggered_repos.Contains (repo.Name)) {
|
||||||
new FileSystemEventArgs (WatcherChangeTypes.Changed, file, "Unknown"));
|
FileActivityTask task = MacFileActivityTask (repo,
|
||||||
|
new FileSystemEventArgs (WatcherChangeTypes.Changed, file_path, "Unknown"));
|
||||||
|
|
||||||
task ();
|
task ();
|
||||||
|
triggered_repos.Add (repo.Name);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -63,7 +63,7 @@ namespace Sparkles {
|
||||||
|
|
||||||
public ChangeType Type;
|
public ChangeType Type;
|
||||||
public DateTime Timestamp;
|
public DateTime Timestamp;
|
||||||
public bool IsFolder = false;
|
public bool IsFolder;
|
||||||
|
|
||||||
public string Path;
|
public string Path;
|
||||||
public string MovedToPath;
|
public string MovedToPath;
|
||||||
|
@ -81,8 +81,10 @@ namespace Sparkles {
|
||||||
|
|
||||||
if (custom_path != null)
|
if (custom_path != null)
|
||||||
return Path.Combine (custom_path, Name);
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue