-
Notifications
You must be signed in to change notification settings - Fork 0
/
mainForm.cs
248 lines (194 loc) · 8.06 KB
/
mainForm.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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Windows.Forms;
namespace Hyria_MyFS
{
public partial class mainForm : Form
{
private int counter = 0;
public mainForm()
{
InitializeComponent();
}
private void mainForm_Load(object sender, EventArgs e)
{
}
private void addBtn_Click(object sender, EventArgs e)
{
// Get the values from the input controls
string fileInfo;
char hiddenChar = 'h';
char readOnlyChar = 'r';
string authorChar = "a";
string filename = filenameBoxInp.Text;
string extension = extnsBoxInp.Text;
int size;
int sectors;
string tagname;
//adjusting attributes depending on input
if (hiddnChkBx.Checked == true)
hiddenChar = 'H';
if (readonlyChkBx.Checked == true)
readOnlyChar = 'R';
if (authorChkBx.Checked == true)
authorChar = "RH";
// checking for only numerical input in size box
if (!int.TryParse(sizeBoxInp.Text, out size))
{
// The input is not a valid integer, so show an error message
MessageBox.Show("Please enter a valid integer for the file size.");
return;
}
// Calculate the number of sectors needed for the entry
sectors = (int)Math.Ceiling((double)size / 500);
// Combine the filename, extension, and size into a single string for Tag
tagname = filename + extension + size.ToString();
// checking to make sure the file doesn't already exist in the file system
foreach (ListViewItem existingItem in fileSystemBox.Items)
{
if (existingItem.Tag.ToString() == tagname)
{
MessageBox.Show("File already exists in the file system.");
return;
}
}
// string that will populate fileSystemBox
fileInfo = filename + ", " + extension + ", " + size + ", " + hiddenChar + ", " + readOnlyChar + ", " + (authorChar);
// Create a new ListViewItem for fileSystemBox
ListViewItem lbitem = new ListViewItem(fileInfo);
lbitem.SubItems.Add(sectors.ToString());
lbitem.Tag = tagname;
// Create a new ListViewItem for listofsectors
ListViewItem item = new ListViewItem(counter.ToString());
item.SubItems.Add(filename);
item.SubItems.Add(extension);
item.SubItems.Add(size.ToString());
item.SubItems.Add((hiddenChar.ToString()) + ", " + (readOnlyChar.ToString()) + ", " + (authorChar));
item.SubItems.Add(sectors.ToString());
item.Tag = tagname;
// Add the new entry's
fileSystemBox.Items.Add(lbitem);
// Adding to multiple sectors
if (sectors > 1)
{
for (int i = 1; i <= sectors; i++)
{
// Determine the size of the current sector
int sectorSize = size > 500 ? 500 : size; // if more than 500, max 500, else remaining val
// Add the new entry to the list
ListViewItem sitem = new ListViewItem(counter.ToString());
sitem.SubItems.Add(filename);
sitem.SubItems.Add(extension);
sitem.SubItems.Add(sectorSize.ToString());
sitem.SubItems.Add((hiddenChar.ToString()) + ", " + (readOnlyChar.ToString()) + ", " + (authorChar));
sitem.SubItems.Add(sectors.ToString());
sitem.Tag = tagname;
// Add the new entry to the list
listofSectors.Items.Add(sitem);
counter++;
size -= sectorSize; // deincrement the totsize by 500
}
}
// otherwise, it doesnt exceed the max sector size of 500, and only one entry is added
else
{
listofSectors.Items.Add(item);
// Increment the counter for the next entry
counter++;
}
// resetting text boxes after entry
listofSectors.Sort();
filenameBoxInp.Clear();
extnsBoxInp.Clear();
sizeBoxInp.Clear();
hiddnChkBx.Checked = false;
readonlyChkBx.Checked = false;
authorChkBx.Checked = false;
}
private void rmvBtn_Click(object sender, EventArgs e)
{
addBtn.Enabled = !addBtn.Enabled;
// Get the selected item's tagname
string selectedTag = fileSystemBox.SelectedItems[0].Tag.ToString();
// Remove the selected items from both lists
for (int i = listofSectors.Items.Count - 1; i >= 0; i--)
{
if (listofSectors.Items[i].Tag != null && listofSectors.Items[i].Tag.ToString() == selectedTag)// using the items tag
{ // we let the user know we are removing it from both lists
listofSectors.Items.RemoveAt(i);
}
}
MessageBox.Show("Removing all entries of: " + selectedTag, "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
fileSystemBox.Items.Remove(fileSystemBox.SelectedItems[0]);
// reset the counter
counter = listofSectors.Items.Count;
}
private void exitButton_Click(object sender, EventArgs e)
{
Application.Exit();
}
private void checkAddEnable()
{
if ((filenameBoxInp.TextLength > 0) && (extnsBoxInp.TextLength > 0) &&(sizeBoxInp.TextLength > 0))
addBtn.Enabled = true;
else
addBtn.Enabled = false;
}
private void filenameBoxInp_TextChanged(object sender, EventArgs e)
{
checkAddEnable();
}
private void extnsBoxInp_TextChanged(object sender, EventArgs e)
{
checkAddEnable();
}
private void sizeBoxInp_TextChanged(object sender, EventArgs e)
{
checkAddEnable();
}
private void hiddnChkBx_CheckedChanged(object sender, EventArgs e)
{
}
private void readonlyChkBx_CheckedChanged(object sender, EventArgs e)
{
}
private void authorChkBx_CheckedChanged(object sender, EventArgs e)
{
}
private void listofSectors_SelectedIndexChanged(object sender, EventArgs e)
{
// Clear the selected items in the ListView
listofSectors.SelectedItems.Clear();
// Set the ListView's HideSelection property to true
// to prevent the selection from appearing when the control loses focus
listofSectors.HideSelection = true;
}
private void fileSystemBox_SelectedIndexChanged(object sender, EventArgs e)
{
rmvBtn.Enabled = (fileSystemBox.SelectedItems.Count > 0);
}
private void sectorSizBox_TextChanged(object sender, EventArgs e)
{
sectorSizBox.ReadOnly = true;
}
private void sectorSizLabel_Click(object sender, EventArgs e)
{
}
private void listofSectors_ContextMenuStripChanged(object sender, EventArgs e)
{
}
private void listofSectors_ColumnWidthChanging(object sender, ColumnWidthChangingEventArgs e)
{
// Cancel the column width changing event
e.Cancel = true;
}
private void listofSectors_ColumnWidthChanged(object sender, ColumnWidthChangedEventArgs e)
{
}
private void listofSectors_Layout(object sender, LayoutEventArgs e)
{
}
}
}