2024-02-05 23:08:37 -08:00
|
|
|
|
using System.Collections.Generic;
|
2024-07-24 19:59:06 -07:00
|
|
|
|
using CommunityToolkit.Mvvm.ComponentModel;
|
2024-02-05 23:08:37 -08:00
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
namespace SourceGit.ViewModels
|
|
|
|
|
{
|
2024-07-24 19:59:06 -07:00
|
|
|
|
public class RepositoryConfigure : ObservableObject
|
2024-03-17 18:37:06 -07:00
|
|
|
|
{
|
|
|
|
|
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-07-27 19:11:10 -07:00
|
|
|
|
get => _httpProxy;
|
|
|
|
|
set => SetProperty(ref _httpProxy, value);
|
2024-02-05 23:08:37 -08:00
|
|
|
|
}
|
|
|
|
|
|
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";
|
2024-06-18 19:21:36 -07:00
|
|
|
|
if (_cached.TryGetValue("tag.gpgsign", out var gpgTagSign))
|
2024-05-30 09:25:30 -07:00
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
|
2024-07-27 19:11:10 -07:00
|
|
|
|
public void ClearHttpProxy()
|
|
|
|
|
{
|
|
|
|
|
HttpProxy = string.Empty;
|
|
|
|
|
}
|
|
|
|
|
|
2024-07-24 19:59:06 -07:00
|
|
|
|
public void Save()
|
2024-03-17 18:37:06 -07:00
|
|
|
|
{
|
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");
|
2024-06-18 19:21:36 -07:00
|
|
|
|
SetIfChanged("tag.gpgsign", GPGTagSigningEnabled ? "true" : "false");
|
2024-02-05 23:08:37 -08:00
|
|
|
|
SetIfChanged("user.signingkey", GPGUserSigningKey);
|
|
|
|
|
SetIfChanged("http.proxy", HttpProxy);
|
|
|
|
|
}
|
|
|
|
|
|
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-07-27 19:11:10 -07:00
|
|
|
|
private string _httpProxy;
|
2024-02-05 23:08:37 -08:00
|
|
|
|
}
|
2024-03-31 01:54:29 -07:00
|
|
|
|
}
|