controller, backend: determine repo backend type in a cleaner way
This commit is contained in:
parent
7f65263da5
commit
ad0fa98e6b
|
@ -22,15 +22,7 @@ namespace SparkleLib {
|
||||||
|
|
||||||
public class SparkleBackend {
|
public class SparkleBackend {
|
||||||
|
|
||||||
public static SparkleBackend DefaultBackend =
|
public static SparkleBackend DefaultBackend = new SparkleBackendGit ();
|
||||||
new SparkleBackend ("Git",
|
|
||||||
new string [4] {
|
|
||||||
"/opt/local/bin/git",
|
|
||||||
"/usr/bin/git",
|
|
||||||
"/usr/local/bin/git",
|
|
||||||
"/usr/local/git/bin/git"
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
public string Name;
|
public string Name;
|
||||||
public string Path;
|
public string Path;
|
||||||
|
@ -61,4 +53,44 @@ namespace SparkleLib {
|
||||||
return (path.Length > 0);
|
return (path.Length > 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public class SparkleBackendGit : SparkleBackend {
|
||||||
|
|
||||||
|
private static string name = "Git";
|
||||||
|
private static string [] paths = new string [] {
|
||||||
|
"/opt/local/bin/git",
|
||||||
|
"/usr/bin/git",
|
||||||
|
"/usr/local/bin/git",
|
||||||
|
"/usr/local/git/bin/git"
|
||||||
|
};
|
||||||
|
|
||||||
|
public SparkleBackendGit () : base (name, paths) { }
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public class SparkleBackendHg : SparkleBackend {
|
||||||
|
|
||||||
|
private static string name = "Hg";
|
||||||
|
private static string [] paths = new string [] {
|
||||||
|
"/opt/local/bin/hg",
|
||||||
|
"/usr/bin/hg"
|
||||||
|
};
|
||||||
|
|
||||||
|
public SparkleBackendHg () : base (name, paths) { }
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public class SparkleBackendScp : SparkleBackend {
|
||||||
|
|
||||||
|
private static string name = "Scp";
|
||||||
|
private static string [] paths = new string [] {
|
||||||
|
"/usr/bin/scp"
|
||||||
|
};
|
||||||
|
|
||||||
|
public SparkleBackendScp () : base (name, paths) { }
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -106,11 +106,10 @@ namespace SparkleShare {
|
||||||
if (File.Exists (old_global_config_file_path))
|
if (File.Exists (old_global_config_file_path))
|
||||||
MigrateConfig ();
|
MigrateConfig ();
|
||||||
|
|
||||||
if (FirstRun) {
|
if (FirstRun)
|
||||||
SparkleConfig.DefaultConfig.SetConfigOption ("notifications", bool.TrueString);
|
SparkleConfig.DefaultConfig.SetConfigOption ("notifications", bool.TrueString);
|
||||||
} else {
|
else
|
||||||
AddKey ();
|
AddKey ();
|
||||||
}
|
|
||||||
|
|
||||||
// Watch the SparkleShare folder
|
// Watch the SparkleShare folder
|
||||||
FileSystemWatcher watcher = new FileSystemWatcher (SparklePaths.SparklePath) {
|
FileSystemWatcher watcher = new FileSystemWatcher (SparklePaths.SparklePath) {
|
||||||
|
@ -401,8 +400,7 @@ namespace SparkleShare {
|
||||||
event_log += day_entry.Replace ("<!-- $day-entry-content -->", event_entries);
|
event_log += day_entry.Replace ("<!-- $day-entry-content -->", event_entries);
|
||||||
}
|
}
|
||||||
|
|
||||||
string html = event_log_html.Replace ("<!-- $event-log-content -->", event_log);
|
return event_log_html.Replace ("<!-- $event-log-content -->", event_log);
|
||||||
return html;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -471,22 +469,14 @@ namespace SparkleShare {
|
||||||
|
|
||||||
SparkleRepoBase repo = null;
|
SparkleRepoBase repo = null;
|
||||||
|
|
||||||
if (backend.Equals ("Git")) {
|
if (backend.Equals ("Hg"))
|
||||||
repo = new SparkleRepoGit (folder_path, SparkleBackend.DefaultBackend);
|
repo = new SparkleRepoHg (folder_path, new SparkleBackendHg ());
|
||||||
|
|
||||||
} else if (backend.Equals ("Hg")) {
|
else if (backend.Equals ("Scp"))
|
||||||
SparkleBackend hg_backend = new SparkleBackend ("Hg",
|
repo = new SparkleRepoScp (folder_path, new SparkleBackendScp ());
|
||||||
new string [] {
|
|
||||||
"/opt/local/bin/hg",
|
|
||||||
"/usr/bin/hg"
|
|
||||||
});
|
|
||||||
|
|
||||||
repo = new SparkleRepoHg (folder_path, hg_backend);
|
else
|
||||||
|
repo = new SparkleRepoGit (folder_path, SparkleBackend.DefaultBackend);
|
||||||
} else if (backend.Equals ("Scp")) {
|
|
||||||
SparkleBackend scp_backend = new SparkleBackend ("Scp", new string [] {"/usr/bin/scp"});
|
|
||||||
repo = new SparkleRepoScp (folder_path, scp_backend);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
repo.NewChangeSet += delegate (SparkleChangeSet change_set, string repository_path) {
|
repo.NewChangeSet += delegate (SparkleChangeSet change_set, string repository_path) {
|
||||||
|
@ -631,6 +621,7 @@ namespace SparkleShare {
|
||||||
if (changes_count > 0) {
|
if (changes_count > 0) {
|
||||||
string msg = Catalog.GetPluralString ("and {0} more", "and {0} more", changes_count);
|
string msg = Catalog.GetPluralString ("and {0} more", "and {0} more", changes_count);
|
||||||
message += " " + String.Format (msg, changes_count);
|
message += " " + String.Format (msg, changes_count);
|
||||||
|
|
||||||
} else if (changes_count < 0) {
|
} else if (changes_count < 0) {
|
||||||
message += _("did something magical");
|
message += _("did something magical");
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue