2024-02-05 23:08:37 -08:00
|
|
|
|
using System.ComponentModel.DataAnnotations;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
namespace SourceGit.ViewModels
|
|
|
|
|
{
|
|
|
|
|
public class Archive : Popup
|
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
|
|
|
|
|
|
[Required(ErrorMessage = "Output file name is required")]
|
2024-03-17 18:37:06 -07:00
|
|
|
|
public string SaveFile
|
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
|
get => _saveFile;
|
|
|
|
|
set => SetProperty(ref _saveFile, value, true);
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
public object BasedOn
|
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
|
get;
|
|
|
|
|
private set;
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
public Archive(Repository repo, Models.Branch branch)
|
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
|
_repo = repo;
|
|
|
|
|
_revision = branch.Head;
|
|
|
|
|
_saveFile = $"archive-{Path.GetFileNameWithoutExtension(branch.Name)}.zip";
|
|
|
|
|
BasedOn = branch;
|
|
|
|
|
View = new Views.Archive() { DataContext = this };
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
public Archive(Repository repo, Models.Commit commit)
|
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
|
_repo = repo;
|
|
|
|
|
_revision = commit.SHA;
|
2024-03-17 18:37:06 -07:00
|
|
|
|
_saveFile = $"archive-{commit.SHA.Substring(0, 10)}.zip";
|
2024-02-05 23:08:37 -08:00
|
|
|
|
BasedOn = commit;
|
|
|
|
|
View = new Views.Archive() { DataContext = this };
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
public Archive(Repository repo, Models.Tag tag)
|
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
|
_repo = repo;
|
|
|
|
|
_revision = tag.SHA;
|
|
|
|
|
_saveFile = $"archive-{tag.Name}.zip";
|
|
|
|
|
BasedOn = tag;
|
|
|
|
|
View = new Views.Archive() { DataContext = this };
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
public override Task<bool> Sure()
|
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
|
_repo.SetWatcherEnabled(false);
|
2024-02-25 19:29:57 -08:00
|
|
|
|
ProgressDescription = "Archiving ...";
|
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
return Task.Run(() =>
|
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
|
var succ = new Commands.Archive(_repo.FullPath, _revision, _saveFile, SetProgressDescription).Exec();
|
2024-03-17 18:37:06 -07:00
|
|
|
|
CallUIThread(() =>
|
|
|
|
|
{
|
2024-02-25 19:29:57 -08:00
|
|
|
|
_repo.SetWatcherEnabled(true);
|
|
|
|
|
if (succ) App.SendNotification(_repo.FullPath, $"Save archive to : {_saveFile}");
|
|
|
|
|
});
|
|
|
|
|
|
2024-02-05 23:08:37 -08:00
|
|
|
|
return succ;
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
private readonly Repository _repo = null;
|
2024-02-05 23:08:37 -08:00
|
|
|
|
private string _saveFile = string.Empty;
|
2024-03-17 18:37:06 -07:00
|
|
|
|
private readonly string _revision = string.Empty;
|
2024-02-05 23:08:37 -08:00
|
|
|
|
}
|
2024-03-17 18:37:06 -07:00
|
|
|
|
}
|