-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFoundCollectionControl.cs
130 lines (95 loc) · 4.07 KB
/
FoundCollectionControl.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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
using SUP.P2FK;
using System;
using System.IO;
using System.Windows.Forms;
namespace SUP
{
public partial class FoundCollectionControl : UserControl
{
private bool _testnet = true;
private string mainnetURL = @"http://127.0.0.1:18332";
private string mainnetLogin = "good-user";
private string mainnetPassword = "better-password";
private string mainnetVersionByte = "111";
public FoundCollectionControl(bool testnet = true)
{
InitializeComponent();
if (!testnet )
{
mainnetURL = @"http://127.0.0.1:8332";
mainnetLogin = "good-user";
mainnetPassword = "better-password";
mainnetVersionByte = "0";
_testnet = testnet;
}
}
private void foundObjectControl_Click(object sender, EventArgs e)
{
Form parentForm = this.FindForm();
ObjectBrowser childForm = new ObjectBrowser(ObjectAddress.Text,false, _testnet);
childForm.Owner = parentForm;
childForm.Show();
}
private void ObjectAddress_Click(object sender, EventArgs e)
{
Clipboard.SetText(ObjectAddress.Text);
}
private void lblTrash_Click(object sender, EventArgs e)
{
// Get the file name from the label
string fileName = ObjectName.Text;
// Prompt the user to confirm whether they want to delete the file
DialogResult result = MessageBox.Show($"Are you sure you want to delete {fileName}?", "Confirm Deletion", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
if (result == DialogResult.Yes)
{
// Delete the file
try
{
if (ObjectImage.ImageLocation != null && !ObjectImage.ImageLocation.StartsWith("includes"))
{
try
{
string directoryPath = Path.GetDirectoryName(ObjectImage.ImageLocation.Replace(@"/",@"\"));
Directory.Delete(directoryPath, true);
}
catch
{
// Handle any exceptions thrown during directory deletion
}
}
Root[] root = Root.GetRootsByAddress(ObjectAddress.Text,mainnetLogin,mainnetPassword,mainnetURL,0,-1,mainnetVersionByte);
foreach (Root rootItem in root)
{
try
{
Directory.Delete(@"root\" + rootItem.TransactionId, true);
}
catch { }
foreach (string key in rootItem.Keyword.Keys)
{
try { File.Delete(@"root\" + key + @"\GetObjectsCollectionsByAddress.json"); }catch { }
}
}
try
{
try { Directory.Delete(@"root\" + ObjectAddress.Text, true); } catch { }
try { Directory.CreateDirectory(@"root\" + ObjectAddress.Text); } catch { }
using (FileStream fs = File.Create(@"root\" + ObjectAddress.Text + @"\BLOCK"))
{
}
}
catch { }
}
catch (IOException ex)
{
// Handle the exception if the file cannot be deleted
MessageBox.Show($"Error deleting file: {ex.Message}", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
// Remove the user control from its parent flow panel
this.Parent.Controls.Remove(this);
}
}
}
}