controller, backend: determine repo backend type in a cleaner way

This commit is contained in:
Hylke Bons 2011-05-28 19:29:16 +01:00
parent 1e8d7f04a6
commit c2cff43f46
2 changed files with 52 additions and 29 deletions

View file

@ -22,15 +22,7 @@ namespace SparkleLib {
public class SparkleBackend {
public static SparkleBackend DefaultBackend =
new SparkleBackend ("Git",
new string [4] {
"/opt/local/bin/git",
"/usr/bin/git",
"/usr/local/bin/git",
"/usr/local/git/bin/git"
}
);
public static SparkleBackend DefaultBackend = new SparkleBackendGit ();
public string Name;
public string Path;
@ -61,4 +53,44 @@ namespace SparkleLib {
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) { }
}
}

View file

@ -106,11 +106,10 @@ namespace SparkleShare {
if (File.Exists (old_global_config_file_path))
MigrateConfig ();
if (FirstRun) {
if (FirstRun)
SparkleConfig.DefaultConfig.SetConfigOption ("notifications", bool.TrueString);
} else {
else
AddKey ();
}
// Watch the SparkleShare folder
FileSystemWatcher watcher = new FileSystemWatcher (SparklePaths.SparklePath) {
@ -401,8 +400,7 @@ namespace SparkleShare {
event_log += day_entry.Replace ("<!-- $day-entry-content -->", event_entries);
}
string html = event_log_html.Replace ("<!-- $event-log-content -->", event_log);
return html;
return event_log_html.Replace ("<!-- $event-log-content -->", event_log);
}
@ -468,25 +466,17 @@ namespace SparkleShare {
if (backend == null)
return;
SparkleRepoBase repo = null;
if (backend.Equals ("Git")) {
repo = new SparkleRepoGit (folder_path, SparkleBackend.DefaultBackend);
if (backend.Equals ("Hg"))
repo = new SparkleRepoHg (folder_path, new SparkleBackendHg ());
} else if (backend.Equals ("Hg")) {
SparkleBackend hg_backend = new SparkleBackend ("Hg",
new string [] {
"/opt/local/bin/hg",
"/usr/bin/hg"
});
else if (backend.Equals ("Scp"))
repo = new SparkleRepoScp (folder_path, new SparkleBackendScp ());
repo = new SparkleRepoHg (folder_path, hg_backend);
} else if (backend.Equals ("Scp")) {
SparkleBackend scp_backend = new SparkleBackend ("Scp", new string [] {"/usr/bin/scp"});
repo = new SparkleRepoScp (folder_path, scp_backend);
}
else
repo = new SparkleRepoGit (folder_path, SparkleBackend.DefaultBackend);
repo.NewChangeSet += delegate (SparkleChangeSet change_set, string repository_path) {
@ -631,6 +621,7 @@ namespace SparkleShare {
if (changes_count > 0) {
string msg = Catalog.GetPluralString ("and {0} more", "and {0} more", changes_count);
message += " " + String.Format (msg, changes_count);
} else if (changes_count < 0) {
message += _("did something magical");
}