-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathFormDeleteRepo.cs
80 lines (68 loc) · 2.53 KB
/
FormDeleteRepo.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
using System;
using System.IO;
using System.Windows.Forms;
namespace GitForce
{
public partial class FormDeleteRepo : Form
{
/// <summary>
/// Radio button selection mode
/// </summary>
private int radioSelection;
/// <summary>
/// Root directory to delete from
/// </summary>
private readonly string dir;
public FormDeleteRepo(string root)
{
InitializeComponent();
ClassWinGeometry.Restore(this);
dir = textPath.Text = root;
}
/// <summary>
/// Form is closing.
/// </summary>
private void FormDeleteRepoFormClosing(object sender, FormClosingEventArgs e)
{
ClassWinGeometry.Save(this);
}
/// <summary>
/// Remove directories and files if selected
/// </summary>
private void BtDeleteClick(object sender, EventArgs e)
{
// Move CWD away as it prevents Windows OS to cleanly delete directory
Directory.SetCurrentDirectory(App.AppHome);
bool ret = true;
// Depending on the selection, do the deletion:
// 0: dont delete anythng
// 1: delete only working files
// 2: delete only .git tree
// 3: delete complete repo folder
if (radioSelection == 1)
{
DirectoryInfo dirInfo = new DirectoryInfo(dir);
ret = ClassUtils.DeleteFolder(dirInfo, true, true); // Preserve .git, preserve root folder
}
if (radioSelection == 2)
{
DirectoryInfo dirInfo = new DirectoryInfo(dir + Path.DirectorySeparatorChar + ".git");
ret = ClassUtils.DeleteFolder(dirInfo, false, false); // Remove .git, remove root folder (.git)
}
if (radioSelection == 3)
{
DirectoryInfo dirInfo = new DirectoryInfo(dir);
ret = ClassUtils.DeleteFolder(dirInfo, false, false); // Remove .git, remove root folder
}
if (ret == false)
MessageBox.Show("Some files could not be removed!", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
/// <summary>
/// Any one of the 3 radio buttons are clicked. Store the selection.
/// </summary>
private void RadioButtonClicked(object sender, EventArgs e)
{
radioSelection = int.Parse((sender as RadioButton).Tag.ToString());
}
}
}