using System; using System.IO; using System.Threading.Tasks; using System.Windows; using System.Windows.Controls; namespace SourceGit.UI { /// /// Clone dialog. /// public partial class Clone : UserControl { private PopupManager popup = null; private Action cb = null; /// /// Remote repository /// public string RemoteUri { get; set; } /// /// Parent folder. /// public string ParentFolder { get; set; } /// /// Local name. /// public string LocalName { get; set; } /// /// Remote name. /// public string RemoteName { get; set; } /// /// Constructor. /// public Clone(PopupManager mgr, Action success) { ParentFolder = App.Setting.Tools.GitDefaultCloneDir; popup = mgr; cb = success; InitializeComponent(); } /// /// Select parent folder. /// /// /// private void SelectParentFolder(object sender, RoutedEventArgs e) { FolderDailog.Open(App.Text("Clone.RemoteFolder.Placeholder"), path => { txtParentFolder.Text = path; }); } /// /// Start clone /// /// /// private async void Start(object sender, RoutedEventArgs e) { txtUrl.GetBindingExpression(TextBox.TextProperty).UpdateSource(); if (Validation.GetHasError(txtUrl)) return; txtParentFolder.GetBindingExpression(TextBox.TextProperty).UpdateSource(); if (Validation.GetHasError(txtParentFolder)) return; string repoName; if (string.IsNullOrWhiteSpace(LocalName)) { var from = RemoteUri.LastIndexOfAny(new char[] { '\\', '/' }); if (from <= 0) return; var name = RemoteUri.Substring(from + 1); repoName = name.Replace(".git", ""); } else { repoName = LocalName; } string rName; if (string.IsNullOrWhiteSpace(RemoteName)){ rName = null; } else { rName = RemoteName; } popup.Lock(); var succ = await Task.Run(() => { return Git.Repository.Clone(RemoteUri, ParentFolder, rName, repoName, popup.UpdateStatus); }); if (succ) { var path = new DirectoryInfo(ParentFolder + "/" + repoName).FullName; var repo = App.Setting.AddRepository(path, ""); App.Open(repo); cb?.Invoke(); popup.Close(true); } else { popup.Unlock(); } } /// /// Cancel. /// /// /// private void Cancel(object sender, RoutedEventArgs e) { popup.Close(); } } }