Skip to content

Commit ec404de

Browse files
committed
Version 0.7.3
1 parent 4fdd67d commit ec404de

File tree

12 files changed

+407
-332
lines changed

12 files changed

+407
-332
lines changed

Controls/ServersTreeNodes/DirectoryNode.cs

Lines changed: 41 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,29 @@
22
using System.Windows.Forms;
33
using System.IO;
44
using System.Collections.Generic;
5+
using Microsoft.VisualBasic.Devices;
6+
using Microsoft.VisualBasic.FileIO;
57

68
namespace MinecraftServerManager.Controls.ServersTreeNodes
79
{
810
public class DirectoryNode : TreeNode
911
{
10-
private DirectoryInfo directory;
12+
public bool Delete = false;
13+
private DirectoryInfo Directory;
1114
protected List<string> names = new List<string>();
1215
protected Timer timer = new Timer();
1316

1417
public DirectoryNode(DirectoryNode parent, DirectoryInfo directoryInfo)
1518
: base(directoryInfo.Name)
1619
{
17-
this.directory = directoryInfo;
20+
Directory = directoryInfo;
1821

19-
this.ImageIndex = ServersTreeView.FolderCloseIcon;
20-
this.SelectedImageIndex = this.ImageIndex;
22+
ImageIndex = ServersTreeView.FolderCloseIcon;
23+
SelectedImageIndex = ImageIndex;
2124

22-
this.timer.Tick += new EventHandler(timer_tick);
23-
this.timer.Interval = 100;
24-
this.timer.Start();
25+
timer.Tick += new EventHandler(timer_tick);
26+
timer.Interval = 100;
27+
timer.Start();
2528

2629
parent.Nodes.Add(this);
2730

@@ -31,11 +34,11 @@ public DirectoryNode(DirectoryNode parent, DirectoryInfo directoryInfo)
3134
public DirectoryNode(ServersTreeView treeView, DirectoryInfo directoryInfo, string name)
3235
: base(name)
3336
{
34-
this.directory = directoryInfo;
37+
Directory = directoryInfo;
3538

36-
this.timer.Tick += new EventHandler(timer_tick);
37-
this.timer.Interval = 100;
38-
this.timer.Start();
39+
timer.Tick += new EventHandler(timer_tick);
40+
timer.Interval = 100;
41+
timer.Start();
3942

4043
treeView.Nodes.Add(this);
4144

@@ -46,18 +49,30 @@ private void timer_tick(object sender, EventArgs e)
4649
{
4750
try
4851
{
49-
if (this.IsExpanded)
50-
Refresh();
52+
Refresh();
5153
}
5254
catch (Exception) { }
5355
}
5456

5557
public virtual void Refresh()
5658
{
59+
if (Delete)
60+
{
61+
try
62+
{
63+
if (Directory.Exists)
64+
new Computer().FileSystem.DeleteDirectory(Directory.FullName, UIOption.AllDialogs, RecycleOption.SendToRecycleBin);
65+
if (this is ServerNode && ((ServerNode)this).GetServerData().isImported)
66+
File.Delete(((ServerNode)this).GetServerData().GetFile());
67+
Destroy();
68+
}
69+
catch (OperationCanceledException) { }
70+
return;
71+
}
5772
List<string> newNames = new List<string>();
58-
foreach (DirectoryInfo directoryInfo in directory.GetDirectories())
73+
foreach (DirectoryInfo directoryInfo in Directory.GetDirectories())
5974
newNames.Add(directoryInfo.FullName);
60-
foreach (FileInfo fileInfo in directory.GetFiles())
75+
foreach (FileInfo fileInfo in Directory.GetFiles())
6176
newNames.Add(fileInfo.FullName);
6277
bool equals = true;
6378
if (newNames.Count != names.Count)
@@ -77,17 +92,17 @@ public virtual void Refresh()
7792
}
7893
if (!equals)
7994
{
80-
this.names.Clear();
81-
this.Nodes.Clear();
82-
foreach (DirectoryInfo directoryInfo in directory.GetDirectories())
95+
names.Clear();
96+
Nodes.Clear();
97+
foreach (DirectoryInfo directoryInfo in Directory.GetDirectories())
8398
{
8499
new DirectoryNode(this, directoryInfo);
85-
this.names.Add(directoryInfo.FullName);
100+
names.Add(directoryInfo.FullName);
86101
}
87-
foreach (FileInfo fileInfo in directory.GetFiles())
102+
foreach (FileInfo fileInfo in Directory.GetFiles())
88103
{
89104
new FileNode(this, fileInfo);
90-
this.names.Add(fileInfo.FullName);
105+
names.Add(fileInfo.FullName);
91106
}
92107
}
93108
}
@@ -96,14 +111,14 @@ private void Virtualize()
96111
{
97112
int fileCount = 0;
98113

99-
fileCount = this.directory.GetFiles().Length;
100-
if ((fileCount + this.directory.GetDirectories().Length) > 0)
114+
fileCount = Directory.GetFiles().Length;
115+
if ((fileCount + Directory.GetDirectories().Length) > 0)
101116
new FakeChildNode(this);
102117
}
103118

104119
public DirectoryInfo GetDirectory()
105120
{
106-
return directory;
121+
return Directory;
107122
}
108123

109124
public new ServersTreeView TreeView
@@ -113,8 +128,8 @@ public DirectoryInfo GetDirectory()
113128

114129
public void Destroy()
115130
{
116-
this.Remove();
117-
this.timer.Stop();
131+
Remove();
132+
timer.Stop();
118133
}
119134
}
120135
}

0 commit comments

Comments
 (0)