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-05-30 09:25:30 -07:00
|
|
|
|
public bool GPGCommitSigningEnabled
|
|
|
|
|
{
|
|
|
|
|
get;
|
|
|
|
|
set;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool GPGTagSigningEnabled
|
2024-03-17 18:37:06 -07:00
|
|
|
|
{
|
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();
|
2024-03-31 01:54:29 -07:00
|
|
|
|
if (_cached.TryGetValue("user.name", out var name))
|
|
|
|
|
UserName = name;
|
|
|
|
|
if (_cached.TryGetValue("user.email", out var email))
|
|
|
|
|
UserEmail = email;
|
2024-05-30 09:25:30 -07:00
|
|
|
|
if (_cached.TryGetValue("commit.gpgsign", out var gpgCommitSign))
|
|
|
|
|
GPGCommitSigningEnabled = gpgCommitSign == "true";
|
|
|
|
|
if (_cached.TryGetValue("tag.gpgSign", out var gpgTagSign))
|
|
|
|
|
GPGTagSigningEnabled = gpgTagSign == "true";
|
2024-03-31 01:54:29 -07:00
|
|
|
|
if (_cached.TryGetValue("user.signingkey", out var signingKey))
|
|
|
|
|
GPGUserSigningKey = signingKey;
|
|
|
|
|
if (_cached.TryGetValue("http.proxy", out var proxy))
|
|
|
|
|
HttpProxy = proxy;
|
2024-02-05 23:08:37 -08:00
|
|
|
|
|
|
|
|
|
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);
|
2024-05-30 09:25:30 -07:00
|
|
|
|
SetIfChanged("commit.gpgsign", GPGCommitSigningEnabled ? "true" : "false");
|
|
|
|
|
SetIfChanged("tag.gpgSign", GPGTagSigningEnabled ? "true" : "false");
|
2024-02-05 23:08:37 -08:00
|
|
|
|
SetIfChanged("user.signingkey", GPGUserSigningKey);
|
|
|
|
|
SetIfChanged("http.proxy", HttpProxy);
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2024-06-03 19:20:31 -07:00
|
|
|
|
private void SetIfChanged(string key, string value)
|
2024-03-17 18:37:06 -07:00
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
|
bool changed = false;
|
2024-03-31 01:54:29 -07:00
|
|
|
|
if (_cached.TryGetValue(key, out var old))
|
2024-03-17 18:37:06 -07:00
|
|
|
|
{
|
2024-03-31 01:54:29 -07:00
|
|
|
|
changed = old != value;
|
2024-03-17 18:37:06 -07:00
|
|
|
|
}
|
2024-06-03 19:20:31 -07:00
|
|
|
|
else if (!string.IsNullOrEmpty(value))
|
2024-03-17 18:37:06 -07:00
|
|
|
|
{
|
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-31 01:54:29 -07:00
|
|
|
|
}
|