2024-02-05 23:08:37 -08:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
namespace SourceGit.ViewModels
|
|
|
|
|
{
|
|
|
|
|
public class RepositoryConfigure : Popup
|
|
|
|
|
{
|
|
|
|
|
public string UserName
|
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
|
get;
|
|
|
|
|
set;
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
public string UserEmail
|
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
|
get;
|
|
|
|
|
set;
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
public bool GPGSigningEnabled
|
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
|
get;
|
|
|
|
|
set;
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
public string GPGUserSigningKey
|
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
|
get;
|
|
|
|
|
set;
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
public string HttpProxy
|
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
|
get;
|
|
|
|
|
set;
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
public RepositoryConfigure(Repository repo)
|
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
|
_repo = repo;
|
|
|
|
|
|
|
|
|
|
_cached = new Commands.Config(repo.FullPath).ListAll();
|
|
|
|
|
if (_cached.ContainsKey("user.name")) UserName = _cached["user.name"];
|
|
|
|
|
if (_cached.ContainsKey("user.email")) UserEmail = _cached["user.email"];
|
|
|
|
|
if (_cached.ContainsKey("commit.gpgsign")) GPGSigningEnabled = _cached["commit.gpgsign"] == "true";
|
|
|
|
|
if (_cached.ContainsKey("user.signingkey")) GPGUserSigningKey = _cached["user.signingkey"];
|
|
|
|
|
if (_cached.ContainsKey("http.proxy")) HttpProxy = _cached["user.signingkey"];
|
|
|
|
|
|
|
|
|
|
View = new Views.RepositoryConfigure() { DataContext = this };
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
public override Task<bool> Sure()
|
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
|
SetIfChanged("user.name", UserName);
|
|
|
|
|
SetIfChanged("user.email", UserEmail);
|
|
|
|
|
SetIfChanged("commit.gpgsign", GPGSigningEnabled ? "true" : "false");
|
|
|
|
|
SetIfChanged("user.signingkey", GPGUserSigningKey);
|
|
|
|
|
SetIfChanged("http.proxy", HttpProxy);
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
private void SetIfChanged(string key, string value)
|
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
|
bool changed = false;
|
2024-03-17 18:37:06 -07:00
|
|
|
|
if (_cached.ContainsKey(key))
|
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
|
changed = value != _cached[key];
|
2024-03-17 18:37:06 -07:00
|
|
|
|
}
|
|
|
|
|
else if (!string.IsNullOrEmpty(value))
|
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
|
changed = true;
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
if (changed)
|
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
|
new Commands.Config(_repo.FullPath).Set(key, value);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
private readonly Repository _repo = null;
|
|
|
|
|
private readonly Dictionary<string, string> _cached = null;
|
2024-02-05 23:08:37 -08:00
|
|
|
|
}
|
2024-03-17 18:37:06 -07:00
|
|
|
|
}
|