Skip to content

Commit 990e9a9

Browse files
committed
Added the file change mode dialog.
1 parent 57f9634 commit 990e9a9

File tree

5 files changed

+525
-43
lines changed

5 files changed

+525
-43
lines changed

Sharp4Explorer/ChangeModeDialog.Designer.cs

Lines changed: 251 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Sharp4Explorer/ChangeModeDialog.cs

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.ComponentModel;
4+
using System.Data;
5+
using System.Drawing;
6+
using System.Linq;
7+
using System.Text;
8+
using System.Threading.Tasks;
9+
using System.Windows.Forms;
10+
11+
namespace SharpExt4Explorer
12+
{
13+
public partial class ChangeModeDialog : Form
14+
{
15+
public static string ModeToString(uint mode)
16+
{
17+
char fileType = '-';
18+
19+
if ((mode & 0xF000) == 0x4000) fileType = 'd'; // Directory
20+
else if ((mode & 0xF000) == 0x8000) fileType = '-'; // Regular file
21+
else if ((mode & 0xF000) == 0xA000) fileType = 'l'; // Symlink
22+
else if ((mode & 0xF000) == 0x6000) fileType = 'b'; // Block device
23+
else if ((mode & 0xF000) == 0x2000) fileType = 'c'; // Char device
24+
else if ((mode & 0xF000) == 0x1000) fileType = 'p'; // FIFO
25+
else if ((mode & 0xF000) == 0xC000) fileType = 's'; // Socket
26+
27+
string perms = "";
28+
29+
int[] shifts = { 6, 3, 0 }; // User, Group, Others
30+
foreach (int shift in shifts)
31+
{
32+
perms += ((mode >> shift) & 0b100) != 0 ? 'r' : '-';
33+
perms += ((mode >> shift) & 0b010) != 0 ? 'w' : '-';
34+
perms += ((mode >> shift) & 0b001) != 0 ? 'x' : '-';
35+
}
36+
37+
// Handle special bits
38+
if ((mode & 0x0800) != 0) // Setuid
39+
perms = perms.Substring(0, 2) + (perms[2] == 'x' ? 's' : 'S') + perms.Substring(3);
40+
if ((mode & 0x0400) != 0) // Setgid
41+
perms = perms.Substring(0, 5) + (perms[5] == 'x' ? 's' : 'S') + perms.Substring(6);
42+
if ((mode & 0x0200) != 0) // Sticky
43+
perms = perms.Substring(0, 8) + (perms[8] == 'x' ? 't' : 'T');
44+
45+
return fileType + perms;
46+
}
47+
48+
public static string ToSymbolic(int mode)
49+
{
50+
char[] result = new char[9];
51+
int[] masks = { 0x100, 0x80, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0x01 };
52+
char[] chars = { 'r', 'w', 'x' };
53+
54+
for (int i = 0; i < 9; i++)
55+
result[i] = (mode & masks[i]) != 0 ? chars[i % 3] : '-';
56+
57+
return new string(result);
58+
}
59+
60+
public uint FileMode { get; private set; }
61+
62+
public ChangeModeDialog(uint currentMode)
63+
{
64+
InitializeComponent();
65+
LoadMode(currentMode);
66+
}
67+
68+
private void LoadMode(uint mode)
69+
{
70+
// User permissions
71+
checkBoxUserRead.Checked = (mode & 0x100) != 0;
72+
checkBoxUserWrite.Checked = (mode & 0x80) != 0;
73+
checkBoxUserExecute.Checked = (mode & 0x40) != 0;
74+
75+
// Group permissions
76+
checkBoxGroupRead.Checked = (mode & 0x20) != 0;
77+
checkBoxGroupWrite.Checked = (mode & 0x10) != 0;
78+
checkBoxGroupExecute.Checked = (mode & 0x08) != 0;
79+
80+
// Other permissions
81+
checkBoxOtherRead.Checked = (mode & 0x04) != 0;
82+
checkBoxOtherWrite.Checked = (mode & 0x02) != 0;
83+
checkBoxOtherExecute.Checked = (mode & 0x01) != 0;
84+
}
85+
86+
private void btnOK_Click(object sender, EventArgs e)
87+
{
88+
FileMode = 0;
89+
90+
if (checkBoxUserRead.Checked) FileMode |= 0x100;
91+
if (checkBoxUserWrite.Checked) FileMode |= 0x80;
92+
if (checkBoxUserExecute.Checked) FileMode |= 0x40;
93+
94+
if (checkBoxGroupRead.Checked) FileMode |= 0x20;
95+
if (checkBoxGroupWrite.Checked) FileMode |= 0x10;
96+
if (checkBoxGroupExecute.Checked) FileMode |= 0x08;
97+
98+
if (checkBoxOtherRead.Checked) FileMode |= 0x04;
99+
if (checkBoxOtherWrite.Checked) FileMode |= 0x02;
100+
if (checkBoxOtherExecute.Checked) FileMode |= 0x01;
101+
102+
DialogResult = DialogResult.OK;
103+
Close();
104+
}
105+
}
106+
}

0 commit comments

Comments
 (0)