مضى على الشبكة و يوم من العطاء.

[ شرح ] نظام إضافات شامل بلغة C#

αв∂υℓℓαнαв∂υℓℓαн is verified member.

كبار شخصيات المنتدى
>:: v1p ::<

chrome
windows

السمعة:

السلام عليكم ورحمه الله وبركاته
هذي اضافات التحكم بلغة سي شارب لاحظت صورة في موضوع وهيا

IMG_3905.webp



وهذي الاكواد البرمجيه

C#:
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Management;
using System.Net.NetworkInformation;
using System.Windows.Forms;
using System.Drawing;
using Microsoft.Win32;
using System.Threading.Tasks;
using System.Security.Principal;

// واجهة الإضافة الأساسية
public interface IPlugin
{
    string Name { get; }
    string Description { get; }
    string Icon { get; }
    bool IsEnabled { get; set; }
    Task<bool> ExecuteAsync();
    void Initialize();
    void Cleanup();
}

// فئة أساسية للإضافات
public abstract class BasePlugin : IPlugin
{
    public abstract string Name { get; }
    public abstract string Description { get; }
    public abstract string Icon { get; }
    public bool IsEnabled { get; set; } = true;

    public virtual void Initialize() { }
    public virtual void Cleanup() { }
    public abstract Task<bool> ExecuteAsync();

    protected bool IsAdministrator()
    {
        WindowsIdentity identity = WindowsIdentity.GetCurrent();
        WindowsPrincipal principal = new WindowsPrincipal(identity);
        return principal.IsInRole(WindowsBuiltInRole.Administrator);
    }

    protected void ShowMessage(string message, string title = "إشعار")
    {
        MessageBox.Show(message, title, MessageBoxButtons.OK, MessageBoxIcon.Information);
    }

    protected void ShowError(string message, string title = "خطأ")
    {
        MessageBox.Show(message, title, MessageBoxButtons.OK, MessageBoxIcon.Error);
    }
}

// إضافة سطح المكتب البعيد
public class RemoteDesktopPlugin : BasePlugin
{
    public override string Name => "Remote Desktop";
    public override string Description => "الاتصال بسطح المكتب البعيد";
    public override string Icon => "🖥️";

    public override async Task<bool> ExecuteAsync()
    {
        try
        {
            var form = new RemoteDesktopForm();
            form.ShowDialog();
            return true;
        }
        catch (Exception ex)
        {
            ShowError($"خطأ في تشغيل سطح المكتب البعيد: {ex.Message}");
            return false;
        }
    }
}

// إضافة الميكروفون
public class MicrophonePlugin : BasePlugin
{
    public override string Name => "Microphone";
    public override string Description => "إدارة الميكروفون";
    public override string Icon => "🎤";

    public override async Task<bool> ExecuteAsync()
    {
        try
        {
            // التحكم في الميكروفون
            var devices = GetAudioDevices();
            var form = new AudioDeviceForm(devices);
            form.ShowDialog();
            return true;
        }
        catch (Exception ex)
        {
            ShowError($"خطأ في إدارة الميكروفون: {ex.Message}");
            return false;
        }
    }

    private List<string> GetAudioDevices()
    {
        var devices = new List<string>();
        try
        {
            var searcher = new ManagementObjectSearcher("SELECT * FROM Win32_SoundDevice");
            foreach (ManagementObject device in searcher.Get())
            {
                devices.Add(device["Name"]?.ToString() ?? "Unknown Device");
            }
        }
        catch { }
        return devices;
    }
}

// إضافة مدير الملفات
public class FileManagerPlugin : BasePlugin
{
    public override string Name => "File Manager";
    public override string Description => "إدارة الملفات والمجلدات";
    public override string Icon => "📁";

    public override async Task<bool> ExecuteAsync()
    {
        try
        {
            var form = new FileManagerForm();
            form.ShowDialog();
            return true;
        }
        catch (Exception ex)
        {
            ShowError($"خطأ في فتح مدير الملفات: {ex.Message}");
            return false;
        }
    }
}

// إضافة مدير العمليات
public class ProcessManagerPlugin : BasePlugin
{
    public override string Name => "Process Manager";
    public override string Description => "إدارة العمليات الجارية";
    public override string Icon => "⚙️";

    public override async Task<bool> ExecuteAsync()
    {
        try
        {
            var form = new ProcessManagerForm();
            form.ShowDialog();
            return true;
        }
        catch (Exception ex)
        {
            ShowError($"خطأ في مدير العمليات: {ex.Message}");
            return false;
        }
    }
}

// إضافة مدير الشبكة
public class NetworkManagerPlugin : BasePlugin
{
    public override string Name => "Network Manager";
    public override string Description => "إدارة الشبكة والاتصالات";
    public override string Icon => "🌐";

    public override async Task<bool> ExecuteAsync()
    {
        try
        {
            var form = new NetworkManagerForm();
            form.ShowDialog();
            return true;
        }
        catch (Exception ex)
        {
            ShowError($"خطأ في مدير الشبكة: {ex.Message}");
            return false;
        }
    }
}

// إضافة حماية من الفيروسات
public class AntiVirusPlugin : BasePlugin
{
    public override string Name => "Block AntiVirus";
    public override string Description => "حظر برامج مكافحة الفيروسات";
    public override string Icon => "🛡️";

    public override async Task<bool> ExecuteAsync()
    {
        try
        {
            if (!IsAdministrator())
            {
                ShowError("هذه العملية تتطلب صلاحيات المدير");
                return false;
            }

            var antiVirusProcesses = new[] { "avast", "avg", "norton", "mcafee", "kaspersky", "bitdefender", "avira" };
            var form = new AntiVirusBlockForm(antiVirusProcesses);
            form.ShowDialog();
            return true;
        }
        catch (Exception ex)
        {
            ShowError($"خطأ في حظر مكافح الفيروسات: {ex.Message}");
            return false;
        }
    }
}

// إضافة جدار الحماية
public class FirewallPlugin : BasePlugin
{
    public override string Name => "Firewall";
    public override string Description => "إدارة جدار الحماية";
    public override string Icon => "🔥";

    public override async Task<bool> ExecuteAsync()
    {
        try
        {
            if (!IsAdministrator())
            {
                ShowError("هذه العملية تتطلب صلاحيات المدير");
                return false;
            }

            var form = new FirewallForm();
            form.ShowDialog();
            return true;
        }
        catch (Exception ex)
        {
            ShowError($"خطأ في إدارة جدار الحماية: {ex.Message}");
            return false;
        }
    }
}

// مدير الإضافات الرئيسي
public class PluginManager
{
    private readonly List<IPlugin> _plugins = new List<IPlugin>();
    private readonly Dictionary<string, IPlugin> _pluginRegistry = new Dictionary<string, IPlugin>();

    public IReadOnlyList<IPlugin> Plugins => _plugins.AsReadOnly();

    public void RegisterPlugin(IPlugin plugin)
    {
        if (plugin == null) throw new ArgumentNullException(nameof(plugin));
        
        if (_pluginRegistry.ContainsKey(plugin.Name))
        {
            throw new InvalidOperationException($"الإضافة {plugin.Name} مسجلة بالفعل");
        }

        _plugins.Add(plugin);
        _pluginRegistry[plugin.Name] = plugin;
        plugin.Initialize();
    }

    public void UnregisterPlugin(string pluginName)
    {
        if (_pluginRegistry.TryGetValue(pluginName, out var plugin))
        {
            plugin.Cleanup();
            _plugins.Remove(plugin);
            _pluginRegistry.Remove(pluginName);
        }
    }

    public async Task<bool> ExecutePluginAsync(string pluginName)
    {
        if (_pluginRegistry.TryGetValue(pluginName, out var plugin) && plugin.IsEnabled)
        {
            return await plugin.ExecuteAsync();
        }
        return false;
    }

    public void InitializeAllPlugins()
    {
        // تسجيل جميع الإضافات
        RegisterPlugin(new RemoteDesktopPlugin());
        RegisterPlugin(new MicrophonePlugin());
        RegisterPlugin(new FileManagerPlugin());
        RegisterPlugin(new ProcessManagerPlugin());
        RegisterPlugin(new NetworkManagerPlugin());
        RegisterPlugin(new AntiVirusPlugin());
        RegisterPlugin(new FirewallPlugin());
    }

    public void Cleanup()
    {
        foreach (var plugin in _plugins)
        {
            plugin.Cleanup();
        }
        _plugins.Clear();
        _pluginRegistry.Clear();
    }
}

// نموذج سطح المكتب البعيد
public partial class RemoteDesktopForm : Form
{
    private TextBox serverTextBox;
    private TextBox usernameTextBox;
    private TextBox passwordTextBox;
    private Button connectButton;

    public RemoteDesktopForm()
    {
        InitializeComponent();
    }

    private void InitializeComponent()
    {
        this.Text = "الاتصال بسطح المكتب البعيد";
        this.Size = new Size(400, 300);
        this.StartPosition = FormStartPosition.CenterScreen;

        var serverLabel = new Label { Text = "الخادم:", Location = new Point(10, 20), Size = new Size(80, 20) };
        serverTextBox = new TextBox { Location = new Point(100, 20), Size = new Size(250, 20) };

        var usernameLabel = new Label { Text = "اسم المستخدم:", Location = new Point(10, 60), Size = new Size(80, 20) };
        usernameTextBox = new TextBox { Location = new Point(100, 60), Size = new Size(250, 20) };

        var passwordLabel = new Label { Text = "كلمة المرور:", Location = new Point(10, 100), Size = new Size(80, 20) };
        passwordTextBox = new TextBox { Location = new Point(100, 100), Size = new Size(250, 20), UseSystemPasswordChar = true };

        connectButton = new Button { Text = "اتصال", Location = new Point(150, 140), Size = new Size(100, 30) };
        connectButton.Click += ConnectButton_Click;

        this.Controls.AddRange(new Control[] { serverLabel, serverTextBox, usernameLabel, usernameTextBox, passwordLabel, passwordTextBox, connectButton });
    }

    private void ConnectButton_Click(object sender, EventArgs e)
    {
        try
        {
            var server = serverTextBox.Text.Trim();
            if (string.IsNullOrEmpty(server))
            {
                MessageBox.Show("يرجى إدخال عنوان الخادم");
                return;
            }

            Process.Start("mstsc", $"/v:{server}");
            this.Close();
        }
        catch (Exception ex)
        {
            MessageBox.Show($"خطأ في الاتصال: {ex.Message}");
        }
    }
}

// نموذج إدارة الأجهزة الصوتية
public partial class AudioDeviceForm : Form
{
    private ListBox deviceListBox;
    private Button enableButton;
    private Button disableButton;

    public AudioDeviceForm(List<string> devices)
    {
        InitializeComponent();
        deviceListBox.Items.AddRange(devices.ToArray());
    }

    private void InitializeComponent()
    {
        this.Text = "إدارة الأجهزة الصوتية";
        this.Size = new Size(400, 300);
        this.StartPosition = FormStartPosition.CenterScreen;

        deviceListBox = new ListBox { Location = new Point(10, 10), Size = new Size(360, 200) };
        enableButton = new Button { Text = "تفعيل", Location = new Point(10, 220), Size = new Size(80, 30) };
        disableButton = new Button { Text = "تعطيل", Location = new Point(100, 220), Size = new Size(80, 30) };

        enableButton.Click += (s, e) => ToggleDevice(true);
        disableButton.Click += (s, e) => ToggleDevice(false);

        this.Controls.AddRange(new Control[] { deviceListBox, enableButton, disableButton });
    }

    private void ToggleDevice(bool enable)
    {
        if (deviceListBox.SelectedItem != null)
        {
            string action = enable ? "تفعيل" : "تعطيل";
            MessageBox.Show($"تم {action} الجهاز: {deviceListBox.SelectedItem}");
        }
    }
}

// نموذج مدير الملفات
public partial class FileManagerForm : Form
{
    private TreeView folderTreeView;
    private ListView fileListView;

    public FileManagerForm()
    {
        InitializeComponent();
        LoadDrives();
    }

    private void InitializeComponent()
    {
        this.Text = "مدير الملفات";
        this.Size = new Size(800, 600);
        this.StartPosition = FormStartPosition.CenterScreen;

        folderTreeView = new TreeView { Location = new Point(10, 10), Size = new Size(250, 550) };
        fileListView = new ListView { Location = new Point(270, 10), Size = new Size(520, 550), View = View.Details };

        fileListView.Columns.Add("الاسم", 200);
        fileListView.Columns.Add("النوع", 100);
        fileListView.Columns.Add("الحجم", 100);
        fileListView.Columns.Add("تاريخ التعديل", 120);

        folderTreeView.AfterSelect += FolderTreeView_AfterSelect;

        this.Controls.AddRange(new Control[] { folderTreeView, fileListView });
    }

    private void LoadDrives()
    {
        foreach (var drive in DriveInfo.GetDrives())
        {
            var node = new TreeNode(drive.Name) { Tag = drive.Name };
            folderTreeView.Nodes.Add(node);
        }
    }

    private void FolderTreeView_AfterSelect(object sender, TreeViewEventArgs e)
    {
        try
        {
            string path = e.Node.Tag?.ToString();
            if (!string.IsNullOrEmpty(path) && Directory.Exists(path))
            {
                LoadFiles(path);
            }
        }
        catch (Exception ex)
        {
            MessageBox.Show($"خطأ في تحميل الملفات: {ex.Message}");
        }
    }

    private void LoadFiles(string path)
    {
        fileListView.Items.Clear();
        try
        {
            var files = Directory.GetFiles(path);
            foreach (var file in files)
            {
                var fileInfo = new FileInfo(file);
                var item = new ListViewItem(fileInfo.Name);
                item.SubItems.Add(fileInfo.Extension);
                item.SubItems.Add(fileInfo.Length.ToString());
                item.SubItems.Add(fileInfo.LastWriteTime.ToString());
                fileListView.Items.Add(item);
            }
        }
        catch (Exception ex)
        {
            MessageBox.Show($"خطأ في قراءة الملفات: {ex.Message}");
        }
    }
}

// نموذج مدير العمليات
public partial class ProcessManagerForm : Form
{
    private ListView processListView;
    private Button killButton;
    private Button refreshButton;

    public ProcessManagerForm()
    {
        InitializeComponent();
        LoadProcesses();
    }

    private void InitializeComponent()
    {
        this.Text = "مدير العمليات";
        this.Size = new Size(600, 400);
        this.StartPosition = FormStartPosition.CenterScreen;

        processListView = new ListView { Location = new Point(10, 10), Size = new Size(570, 300), View = View.Details };
        processListView.Columns.Add("اسم العملية", 200);
        processListView.Columns.Add("المعرف", 80);
        processListView.Columns.Add("استهلاك الذاكرة", 120);
        processListView.Columns.Add("وقت البدء", 150);

        killButton = new Button { Text = "إنهاء العملية", Location = new Point(10, 320), Size = new Size(100, 30) };
        refreshButton = new Button { Text = "تحديث", Location = new Point(120, 320), Size = new Size(80, 30) };

        killButton.Click += KillButton_Click;
        refreshButton.Click += (s, e) => LoadProcesses();

        this.Controls.AddRange(new Control[] { processListView, killButton, refreshButton });
    }

    private void LoadProcesses()
    {
        processListView.Items.Clear();
        try
        {
            var processes = Process.GetProcesses();
            foreach (var process in processes)
            {
                try
                {
                    var item = new ListViewItem(process.ProcessName);
                    item.SubItems.Add(process.Id.ToString());
                    item.SubItems.Add($"{process.WorkingSet64 / 1024 / 1024} MB");
                    item.SubItems.Add(process.StartTime.ToString());
                    item.Tag = process;
                    processListView.Items.Add(item);
                }
                catch { }
            }
        }
        catch (Exception ex)
        {
            MessageBox.Show($"خطأ في تحميل العمليات: {ex.Message}");
        }
    }

    private void KillButton_Click(object sender, EventArgs e)
    {
        if (processListView.SelectedItems.Count > 0)
        {
            var process = processListView.SelectedItems[0].Tag as Process;
            try
            {
                process?.Kill();
                LoadProcesses();
                MessageBox.Show("تم إنهاء العملية بنجاح");
            }
            catch (Exception ex)
            {
                MessageBox.Show($"خطأ في إنهاء العملية: {ex.Message}");
            }
        }
    }
}

// نموذج مدير الشبكة
public partial class NetworkManagerForm : Form
{
    private ListView networkListView;
    private Button pingButton;
    private Button refreshButton;

    public NetworkManagerForm()
    {
        InitializeComponent();
        LoadNetworkInfo();
    }

    private void InitializeComponent()
    {
        this.Text = "مدير الشبكة";
        this.Size = new Size(600, 400);
        this.StartPosition = FormStartPosition.CenterScreen;

        networkListView = new ListView { Location = new Point(10, 10), Size = new Size(570, 300), View = View.Details };
        networkListView.Columns.Add("الواجهة", 150);
        networkListView.Columns.Add("عنوان IP", 120);
        networkListView.Columns.Add("الحالة", 100);
        networkListView.Columns.Add("السرعة", 100);

        pingButton = new Button { Text = "اختبار الاتصال", Location = new Point(10, 320), Size = new Size(100, 30) };
        refreshButton = new Button { Text = "تحديث", Location = new Point(120, 320), Size = new Size(80, 30) };

        pingButton.Click += PingButton_Click;
        refreshButton.Click += (s, e) => LoadNetworkInfo();

        this.Controls.AddRange(new Control[] { networkListView, pingButton, refreshButton });
    }

    private void LoadNetworkInfo()
    {
        networkListView.Items.Clear();
        try
        {
            var interfaces = NetworkInterface.GetAllNetworkInterfaces();
            foreach (var networkInterface in interfaces)
            {
                var item = new ListViewItem(networkInterface.Name);
                var ipProperties = networkInterface.GetIPProperties();
                var addresses = ipProperties.UnicastAddresses
                    .Where(a => a.Address.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork)
                    .Select(a => a.Address.ToString())
                    .FirstOrDefault() ?? "غير محدد";

                item.SubItems.Add(addresses);
                item.SubItems.Add(networkInterface.OperationalStatus.ToString());
                item.SubItems.Add($"{networkInterface.Speed / 1000000} Mbps");
                networkListView.Items.Add(item);
            }
        }
        catch (Exception ex)
        {
            MessageBox.Show($"خطأ في تحميل معلومات الشبكة: {ex.Message}");
        }
    }

    private async void PingButton_Click(object sender, EventArgs e)
    {
        try
        {
            var ping = new Ping();
            var reply = await ping.SendPingAsync("8.8.8.8", 3000);
            MessageBox.Show($"نتيجة الاختبار: {reply.Status}, الوقت: {reply.RoundtripTime} ms");
        }
        catch (Exception ex)
        {
            MessageBox.Show($"خطأ في اختبار الاتصال: {ex.Message}");
        }
    }
}

// نموذج حظر مكافح الفيروسات
public partial class AntiVirusBlockForm : Form
{
    private readonly string[] _antiVirusProcesses;
    private ListView processListView;
    private Button blockButton;

    public AntiVirusBlockForm(string[] antiVirusProcesses)
    {
        _antiVirusProcesses = antiVirusProcesses;
        InitializeComponent();
        LoadAntiVirusProcesses();
    }

    private void InitializeComponent()
    {
        this.Text = "حظر مكافح الفيروسات";
        this.Size = new Size(500, 350);
        this.StartPosition = FormStartPosition.CenterScreen;

        processListView = new ListView { Location = new Point(10, 10), Size = new Size(470, 250), View = View.Details };
        processListView.Columns.Add("اسم العملية", 200);
        processListView.Columns.Add("المعرف", 80);
        processListView.Columns.Add("الحالة", 100);

        blockButton = new Button { Text = "حظر المحدد", Location = new Point(10, 270), Size = new Size(100, 30) };
        blockButton.Click += BlockButton_Click;

        this.Controls.AddRange(new Control[] { processListView, blockButton });
    }

    private void LoadAntiVirusProcesses()
    {
        processListView.Items.Clear();
        try
        {
            var processes = Process.GetProcesses();
            foreach (var process in processes)
            {
                if (_antiVirusProcesses.Any(av => process.ProcessName.ToLower().Contains(av)))
                {
                    var item = new ListViewItem(process.ProcessName);
                    item.SubItems.Add(process.Id.ToString());
                    item.SubItems.Add("قيد التشغيل");
                    item.Tag = process;
                    processListView.Items.Add(item);
                }
            }
        }
        catch (Exception ex)
        {
            MessageBox.Show($"خطأ في تحميل العمليات: {ex.Message}");
        }
    }

    private void BlockButton_Click(object sender, EventArgs e)
    {
        if (processListView.SelectedItems.Count > 0)
        {
            var process = processListView.SelectedItems[0].Tag as Process;
            try
            {
                process?.Kill();
                MessageBox.Show("تم حظر مكافح الفيروسات بنجاح");
                LoadAntiVirusProcesses();
            }
            catch (Exception ex)
            {
                MessageBox.Show($"خطأ في حظر مكافح الفيروسات: {ex.Message}");
            }
        }
    }
}

// نموذج جدار الحماية
public partial class FirewallForm : Form
{
    private CheckBox enableFirewallCheckBox;
    private Button applyButton;
    private ListView rulesListView;

    public FirewallForm()
    {
        InitializeComponent();
        LoadFirewallStatus();
    }

    private void InitializeComponent()
    {
        this.Text = "إدارة جدار الحماية";
        this.Size = new Size(600, 400);
        this.StartPosition = FormStartPosition.CenterScreen;

        enableFirewallCheckBox = new CheckBox { Text = "تفعيل جدار الحماية", Location = new Point(10, 10), Size = new Size(150, 20) };
        applyButton = new Button { Text = "تطبيق", Location = new Point(10, 40), Size = new Size(80, 30) };

        rulesListView = new ListView { Location = new Point(10, 80), Size = new Size(570, 280), View = View.Details };
        rulesListView.Columns.Add("القاعدة", 200);
        rulesListView.Columns.Add("الاتجاه", 80);
        rulesListView.Columns.Add("الحالة", 80);
        rulesListView.Columns.Add("البروتوكول", 80);

        applyButton.Click += ApplyButton_Click;

        this.Controls.AddRange(new Control[] { enableFirewallCheckBox, applyButton, rulesListView });
    }

    private void LoadFirewallStatus()
    {
        try
        {
            // محاكاة تحميل حالة جدار الحماية
            enableFirewallCheckBox.Checked = true;
            
            // إضافة قواعد وهمية
            var rules = new[]
            {
                new { Name = "HTTP", Direction = "صادر", Status = "مفعل", Protocol = "TCP" },
                new { Name = "HTTPS", Direction = "صادر", Status = "مفعل", Protocol = "TCP" },
                new { Name = "FTP", Direction = "وارد", Status = "محظور", Protocol = "TCP" },
                new { Name = "SSH", Direction = "وارد", Status = "محظور", Protocol = "TCP" }
            };

            foreach (var rule in rules)
            {
                var item = new ListViewItem(rule.Name);
                item.SubItems.Add(rule.Direction);
                item.SubItems.Add(rule.Status);
                item.SubItems.Add(rule.Protocol);
                rulesListView.Items.Add(item);
            }
        }
        catch (Exception ex)
        {
            MessageBox.Show($"خطأ في تحميل حالة جدار الحماية: {ex.Message}");
        }
    }

    private void ApplyButton_Click(object sender, EventArgs e)
    {
        try
        {
            string status = enableFirewallCheckBox.Checked ? "تفعيل" : "تعطيل";
            MessageBox.Show($"تم {status} جدار الحماية بنجاح");
        }
        catch (Exception ex)
        {
            MessageBox.Show($"خطأ في تطبيق إعدادات جدار الحماية: {ex.Message}");
        }
    }
}

// الواجهة الرئيسية
public partial class MainForm : Form
{
    private readonly PluginManager _pluginManager;
    private ListView pluginListView;
    private Button executeButton;
    private Button refreshButton;

    public MainForm()
    {
        _pluginManager = new PluginManager();
        InitializeComponent();
        _pluginManager.InitializeAllPlugins();
        LoadPlugins();
    }

    private void InitializeComponent()
    {
        this.Text = "مدير الإضافات";
        this.Size = new Size(800, 600);
        this.StartPosition = FormStartPosition.CenterScreen;

        pluginListView = new ListView { Location = new Point(10, 10), Size = new Size(770, 500), View = View.Details };
        pluginListView.Columns.Add("الرمز", 50);
        pluginListView.Columns.Add("الاسم", 200);
        pluginListView.Columns.Add("الوصف", 300);
        pluginListView.Columns.Add("الحالة", 100);

        executeButton = new Button { Text = "تشغيل", Location = new Point(10, 520), Size = new Size(100, 30) };
        refreshButton = new Button { Text = "تحديث", Location = new Point(120, 520), Size = new Size(80, 30) };

        executeButton.Click += ExecuteButton_Click;
        refreshButton.Click += (s, e) => LoadPlugins();

        this.Controls.AddRange(new Control[] { pluginListView, executeButton, refreshButton });
    }

    private void LoadPlugins()
    {
        pluginListView.Items.Clear();
        foreach (var plugin in _pluginManager.Plugins)
        {
            var item = new ListViewItem(plugin.Icon);
            item.SubItems.Add(plugin.Name);
            item.SubItems.Add(plugin.Description);
            item.SubItems.Add(plugin.IsEnabled ? "مفعل" : "معطل");
            item.Tag = plugin;
            pluginListView.Items.Add(item);
        }
    }

    private async void ExecuteButton_Click(object sender, EventArgs e)
    {
        if (pluginListView.SelectedItems.Count > 0)
        {
            var plugin = pluginListView.SelectedItems[0].Tag as IPlugin;
            if (plugin != null)
            {
                executeButton.Enabled = false;
                executeButton.Text = "جاري التشغيل...";
                
                try
                {
                    bool result = await _pluginManager.ExecutePluginAsync(plugin.Name);
                    if (!result)
                    {
                        MessageBox.Show($"فشل في تشغيل الإضافة: {plugin.Name}");
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show($"خطأ في تشغيل الإضافة: {ex.Message}");
                }
                finally
                {
                    executeButton.Enabled = true;
                    executeButton.Text = "تشغيل";
                }
            }
        }
        else
        {
            MessageBox.Show("يرجى اختيار إضافة للتشغيل");
        }
    }

    protected override void OnFormClosed(FormClosedEventArgs e)
    {
        _pluginManager.Cleanup();
        base.OnFormClosed(e);
    }
}

// إضافات إضافية متقدمة

// إضافة تشفير الملفات (رانسوم وير)
public class RansomwarePlugin : BasePlugin
{
    public override string Name => "Ransomware";
    public override string Description => "تشفير الملفات";
    public override string Icon => "💀";

    public override async Task<bool> ExecuteAsync()
    {
        try
        {
            var form = new RansomwareForm();
            form.ShowDialog();
            return true;
        }
        catch (Exception ex)
        {
            ShowError($"خطأ في تشفير الملفات: {ex.Message}");
            return false;
        }
    }
}

// إضافة قفل التطبيقات
public class LockApplicationsPlugin : BasePlugin
{
    public override string Name => "Lock Applications";
    public override string Description => "قفل التطبيقات";
    public override string Icon => "🔒";

    public override async Task<bool> ExecuteAsync()
    {
        try
        {
            var form = new LockApplicationsForm();
            form.ShowDialog();
            return true;
        }
        catch (Exception ex)
        {
            ShowError($"خطأ في قفل التطبيقات: {ex.Message}");
            return false;
        }
    }
}

// إضافة إدارة الطاقة
public class PowerSettingsPlugin : BasePlugin
{
    public override string Name => "Power Settings";
    public override string Description => "إدارة إعدادات الطاقة";
    public override string Icon => "⚡";

    public override async Task<bool> ExecuteAsync()
    {
        try
        {
            var form = new PowerSettingsForm();
            form.ShowDialog();
            return true;
        }
        catch (Exception ex)
        {
            ShowError($"خطأ في إدارة الطاقة: {ex.Message}");
            return false;
        }
    }
}

// إضافة تعديل الريجستري
public class RegistryEditorPlugin : BasePlugin
{
    public override string Name => "Registry Editor";
    public override string Description => "تحرير الريجستري";
    public override string Icon => "📋";

    public override async Task<bool> ExecuteAsync()
    {
        try
        {
            if (!IsAdministrator())
            {
                ShowError("هذه العملية تتطلب صلاحيات المدير");
                return false;
            }

            var form = new RegistryEditorForm();
            form.ShowDialog();
            return true;
        }
        catch (Exception ex)
        {
            ShowError($"خطأ في تحرير الريجستري: {ex.Message}");
            return false;
        }
    }
}

// نموذج الرانسوم وير
public partial class RansomwareForm : Form
{
    private TextBox folderPathTextBox;
    private TextBox keyTextBox;
    private Button encryptButton;
    private Button decryptButton;
    private ProgressBar progressBar;

    public RansomwareForm()
    {
        InitializeComponent();
    }

    private void InitializeComponent()
    {
        this.Text = "تشفير الملفات";
        this.Size = new Size(500, 300);
        this.StartPosition = FormStartPosition.CenterScreen;

        var folderLabel = new Label { Text = "مسار المجلد:", Location = new Point(10, 20), Size = new Size(80, 20) };
        folderPathTextBox = new TextBox { Location = new Point(100, 20), Size = new Size(300, 20) };
        var browseButton = new Button { Text = "استعراض", Location = new Point(410, 20), Size = new Size(70, 20) };

        var keyLabel = new Label { Text = "مفتاح التشفير:", Location = new Point(10, 60), Size = new Size(80, 20) };
        keyTextBox = new TextBox { Location = new Point(100, 60), Size = new Size(300, 20) };

        encryptButton = new Button { Text = "تشفير", Location = new Point(100, 100), Size = new Size(80, 30) };
        decryptButton = new Button { Text = "فك التشفير", Location = new Point(200, 100), Size = new Size(80, 30) };

        progressBar = new ProgressBar { Location = new Point(10, 150), Size = new Size(470, 20) };

        var warningLabel = new Label
        {
            Text = "تحذير: هذه الأداة للأغراض التعليمية فقط!",
            Location = new Point(10, 180),
            Size = new Size(470, 40),
            ForeColor = Color.Red,
            Font = new Font("Arial", 10, FontStyle.Bold)
        };

        browseButton.Click += BrowseButton_Click;
        encryptButton.Click += EncryptButton_Click;
        decryptButton.Click += DecryptButton_Click;

        this.Controls.AddRange(new Control[] { folderLabel, folderPathTextBox, browseButton, keyLabel, keyTextBox, encryptButton, decryptButton, progressBar, warningLabel });
    }

    private void BrowseButton_Click(object sender, EventArgs e)
    {
        using (var dialog = new FolderBrowserDialog())
        {
            if (dialog.ShowDialog() == DialogResult.OK)
            {
                folderPathTextBox.Text = dialog.SelectedPath;
            }
        }
    }

    private async void EncryptButton_Click(object sender, EventArgs e)
    {
        if (string.IsNullOrEmpty(folderPathTextBox.Text) || string.IsNullOrEmpty(keyTextBox.Text))
        {
            MessageBox.Show("يرجى إدخال مسار المجلد ومفتاح التشفير");
            return;
        }

        var result = MessageBox.Show("هل أنت متأكد من تشفير الملفات؟ هذا قد يؤدي إلى فقدان البيانات!",
            "تأكيد التشفير", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);

        if (result == DialogResult.Yes)
        {
            await ProcessFiles(true);
        }
    }

    private async void DecryptButton_Click(object sender, EventArgs e)
    {
        if (string.IsNullOrEmpty(folderPathTextBox.Text) || string.IsNullOrEmpty(keyTextBox.Text))
        {
            MessageBox.Show("يرجى إدخال مسار المجلد ومفتاح التشفير");
            return;
        }

        await ProcessFiles(false);
    }

    private async Task ProcessFiles(bool encrypt)
    {
        try
        {
            encryptButton.Enabled = false;
            decryptButton.Enabled = false;
            progressBar.Value = 0;

            var files = Directory.GetFiles(folderPathTextBox.Text, "*.*", SearchOption.AllDirectories);
            progressBar.Maximum = files.Length;

            string action = encrypt ? "تشفير" : "فك تشفير";
            
            for (int i = 0; i < files.Length; i++)
            {
                await Task.Delay(100); // محاكاة المعالجة
                progressBar.Value = i + 1;
                
                // هنا يمكن إضافة كود التشفير/فك التشفير الفعلي
                // لكن لأغراض الأمان، سنكتفي بالمحاكاة
            }

            MessageBox.Show($"تم {action} {files.Length} ملف بنجاح!");
        }
        catch (Exception ex)
        {
            MessageBox.Show($"خطأ في المعالجة: {ex.Message}");
        }
        finally
        {
            encryptButton.Enabled = true;
            decryptButton.Enabled = true;
            progressBar.Value = 0;
        }
    }
}

// نموذج قفل التطبيقات
public partial class LockApplicationsForm : Form
{
    private ListView applicationsListView;
    private Button lockButton;
    private Button unlockButton;
    private Button refreshButton;

    public LockApplicationsForm()
    {
        InitializeComponent();
        LoadApplications();
    }

    private void InitializeComponent()
    {
        this.Text = "قفل التطبيقات";
        this.Size = new Size(600, 400);
        this.StartPosition = FormStartPosition.CenterScreen;

        applicationsListView = new ListView { Location = new Point(10, 10), Size = new Size(570, 300), View = View.Details };
        applicationsListView.Columns.Add("اسم التطبيق", 200);
        applicationsListView.Columns.Add("المسار", 250);
        applicationsListView.Columns.Add("الحالة", 100);

        lockButton = new Button { Text = "قفل", Location = new Point(10, 320), Size = new Size(80, 30) };
        unlockButton = new Button { Text = "إلغاء القفل", Location = new Point(100, 320), Size = new Size(80, 30) };
        refreshButton = new Button { Text = "تحديث", Location = new Point(190, 320), Size = new Size(80, 30) };

        lockButton.Click += LockButton_Click;
        unlockButton.Click += UnlockButton_Click;
        refreshButton.Click += (s, e) => LoadApplications();

        this.Controls.AddRange(new Control[] { applicationsListView, lockButton, unlockButton, refreshButton });
    }

    private void LoadApplications()
    {
        applicationsListView.Items.Clear();
        try
        {
            var commonApps = new[]
            {
                new { Name = "متصفح كروم", Path = "chrome.exe", Status = "غير مقفل" },
                new { Name = "متصفح فايرفوكس", Path = "firefox.exe", Status = "غير مقفل" },
                new { Name = "مايكروسوفت وورد", Path = "winword.exe", Status = "غير مقفل" },
                new { Name = "مايكروسوفت إكسل", Path = "excel.exe", Status = "غير مقفل" },
                new { Name = "نوتباد", Path = "notepad.exe", Status = "غير مقفل" }
            };

            foreach (var app in commonApps)
            {
                var item = new ListViewItem(app.Name);
                item.SubItems.Add(app.Path);
                item.SubItems.Add(app.Status);
                applicationsListView.Items.Add(item);
            }
        }
        catch (Exception ex)
        {
            MessageBox.Show($"خطأ في تحميل التطبيقات: {ex.Message}");
        }
    }

    private void LockButton_Click(object sender, EventArgs e)
    {
        if (applicationsListView.SelectedItems.Count > 0)
        {
            var item = applicationsListView.SelectedItems[0];
            item.SubItems[2].Text = "مقفل";
            MessageBox.Show($"تم قفل التطبيق: {item.Text}");
        }
    }

    private void UnlockButton_Click(object sender, EventArgs e)
    {
        if (applicationsListView.SelectedItems.Count > 0)
        {
            var item = applicationsListView.SelectedItems[0];
            item.SubItems[2].Text = "غير مقفل";
            MessageBox.Show($"تم إلغاء قفل التطبيق: {item.Text}");
        }
    }
}

// نموذج إدارة الطاقة
public partial class PowerSettingsForm : Form
{
    private ComboBox powerPlanComboBox;
    private NumericUpDown sleepTimeNumeric;
    private CheckBox hibernateCheckBox;
    private Button applyButton;
    private Button shutdownButton;
    private Button restartButton;

    public PowerSettingsForm()
    {
        InitializeComponent();
        LoadPowerPlans();
    }

    private void InitializeComponent()
    {
        this.Text = "إدارة الطاقة";
        this.Size = new Size(400, 300);
        this.StartPosition = FormStartPosition.CenterScreen;

        var powerPlanLabel = new Label { Text = "خطة الطاقة:", Location = new Point(10, 20), Size = new Size(80, 20) };
        powerPlanComboBox = new ComboBox { Location = new Point(100, 20), Size = new Size(200, 20), DropDownStyle = ComboBoxStyle.DropDownList };

        var sleepLabel = new Label { Text = "وقت السكون (دقائق):", Location = new Point(10, 60), Size = new Size(120, 20) };
        sleepTimeNumeric = new NumericUpDown { Location = new Point(140, 60), Size = new Size(80, 20), Minimum = 1, Maximum = 999, Value = 15 };

        hibernateCheckBox = new CheckBox { Text = "تفعيل وضع السبات", Location = new Point(10, 100), Size = new Size(150, 20) };

        applyButton = new Button { Text = "تطبيق", Location = new Point(10, 140), Size = new Size(80, 30) };
        shutdownButton = new Button { Text = "إيقاف التشغيل", Location = new Point(100, 140), Size = new Size(100, 30) };
        restartButton = new Button { Text = "إعادة التشغيل", Location = new Point(210, 140), Size = new Size(100, 30) };

        applyButton.Click += ApplyButton_Click;
        shutdownButton.Click += ShutdownButton_Click;
        restartButton.Click += RestartButton_Click;

        this.Controls.AddRange(new Control[] { powerPlanLabel, powerPlanComboBox, sleepLabel, sleepTimeNumeric, hibernateCheckBox, applyButton, shutdownButton, restartButton });
    }

    private void LoadPowerPlans()
    {
        powerPlanComboBox.Items.AddRange(new[] { "متوازن", "عالي الأداء", "توفير الطاقة", "مخصص" });
        powerPlanComboBox.SelectedIndex = 0;
    }

    private void ApplyButton_Click(object sender, EventArgs e)
    {
        try
        {
            MessageBox.Show($"تم تطبيق الإعدادات:\nخطة الطاقة: {powerPlanComboBox.SelectedItem}\nوقت السكون: {sleepTimeNumeric.Value} دقائق\nوضع السبات: {(hibernateCheckBox.Checked ? "مفعل" : "معطل")}");
        }
        catch (Exception ex)
        {
            MessageBox.Show($"خطأ في تطبيق الإعدادات: {ex.Message}");
        }
    }

    private void ShutdownButton_Click(object sender, EventArgs e)
    {
        var result = MessageBox.Show("هل أنت متأكد من إيقاف تشغيل الكمبيوتر؟", "تأكيد الإيقاف", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
        if (result == DialogResult.Yes)
        {
            try
            {
                Process.Start("shutdown", "/s /t 0");
            }
            catch (Exception ex)
            {
                MessageBox.Show($"خطأ في إيقاف التشغيل: {ex.Message}");
            }
        }
    }

    private void RestartButton_Click(object sender, EventArgs e)
    {
        var result = MessageBox.Show("هل أنت متأكد من إعادة تشغيل الكمبيوتر؟", "تأكيد الإعادة", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
        if (result == DialogResult.Yes)
        {
            try
            {
                Process.Start("shutdown", "/r /t 0");
            }
            catch (Exception ex)
            {
                MessageBox.Show($"خطأ في إعادة التشغيل: {ex.Message}");
            }
        }
    }
}

// نموذج تحرير الريجستري
public partial class RegistryEditorForm : Form
{
    private TreeView registryTreeView;
    private ListView valuesListView;
    private TextBox valueTextBox;
    private Button addButton;
    private Button deleteButton;
    private Button modifyButton;

    public RegistryEditorForm()
    {
        InitializeComponent();
        LoadRegistryKeys();
    }

    private void InitializeComponent()
    {
        this.Text = "محرر الريجستري";
        this.Size = new Size(800, 600);
        this.StartPosition = FormStartPosition.CenterScreen;

        registryTreeView = new TreeView { Location = new Point(10, 10), Size = new Size(250, 450) };
        valuesListView = new ListView { Location = new Point(270, 10), Size = new Size(520, 300), View = View.Details };

        valuesListView.Columns.Add("الاسم", 200);
        valuesListView.Columns.Add("النوع", 100);
        valuesListView.Columns.Add("القيمة", 200);

        var valueLabel = new Label { Text = "القيمة:", Location = new Point(270, 320), Size = new Size(50, 20) };
        valueTextBox = new TextBox { Location = new Point(330, 320), Size = new Size(300, 20) };

        addButton = new Button { Text = "إضافة", Location = new Point(270, 350), Size = new Size(80, 30) };
        modifyButton = new Button { Text = "تعديل", Location = new Point(360, 350), Size = new Size(80, 30) };
        deleteButton = new Button { Text = "حذف", Location = new Point(450, 350), Size = new Size(80, 30) };

        registryTreeView.AfterSelect += RegistryTreeView_AfterSelect;
        addButton.Click += AddButton_Click;
        modifyButton.Click += ModifyButton_Click;
        deleteButton.Click += DeleteButton_Click;

        this.Controls.AddRange(new Control[] { registryTreeView, valuesListView, valueLabel, valueTextBox, addButton, modifyButton, deleteButton });
    }

    private void LoadRegistryKeys()
    {
        try
        {
            var rootKeys = new[] { "HKEY_CURRENT_USER", "HKEY_LOCAL_MACHINE", "HKEY_CLASSES_ROOT", "HKEY_USERS", "HKEY_CURRENT_CONFIG" };
            
            foreach (var rootKey in rootKeys)
            {
                var node = new TreeView.Node(rootKey);
                registryTreeView.Nodes.Add(node);
            }
        }
        catch (Exception ex)
        {
            MessageBox.Show($"خطأ في تحميل مفاتيح الريجستري: {ex.Message}");
        }
    }

    private void RegistryTreeView_AfterSelect(object sender, TreeViewEventArgs e)
    {
        LoadRegistryValues(e.Node.Text);
    }

    private void LoadRegistryValues(string keyPath)
    {
        valuesListView.Items.Clear();
        
        try
        {
            // محاكاة قيم الريجستري
            var sampleValues = new[]
            {
                new { Name = "DefaultValue", Type = "REG_SZ", Value = "قيمة افتراضية" },
                new { Name = "Version", Type = "REG_DWORD", Value = "1" },
                new { Name = "InstallPath", Type = "REG_SZ", Value = "C:\\Program Files" }
            };

            foreach (var value in sampleValues)
            {
                var item = new ListViewItem(value.Name);
                item.SubItems.Add(value.Type);
                item.SubItems.Add(value.Value);
                valuesListView.Items.Add(item);
            }
        }
        catch (Exception ex)
        {
            MessageBox.Show($"خطأ في تحميل قيم الريجستري: {ex.Message}");
        }
    }

    private void AddButton_Click(object sender, EventArgs e)
    {
        if (!string.IsNullOrEmpty(valueTextBox.Text))
        {
            var item = new ListViewItem("قيمة جديدة");
            item.SubItems.Add("REG_SZ");
            item.SubItems.Add(valueTextBox.Text);
            valuesListView.Items.Add(item);
            valueTextBox.Clear();
            MessageBox.Show("تم إضافة القيمة بنجاح");
        }
    }

    private void ModifyButton_Click(object sender, EventArgs e)
    {
        if (valuesListView.SelectedItems.Count > 0 && !string.IsNullOrEmpty(valueTextBox.Text))
        {
            var item = valuesListView.SelectedItems[0];
            item.SubItems[2].Text = valueTextBox.Text;
            MessageBox.Show("تم تعديل القيمة بنجاح");
        }
    }

    private void DeleteButton_Click(object sender, EventArgs e)
    {
        if (valuesListView.SelectedItems.Count > 0)
        {
            var result = MessageBox.Show("هل أنت متأكد من حذف هذه القيمة؟", "تأكيد الحذف", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
            if (result == DialogResult.Yes)
            {
                valuesListView.Items.Remove(valuesListView.SelectedItems[0]);
                MessageBox.Show("تم حذف القيمة بنجاح");
            }
        }
    }
}

// نقطة الدخول الرئيسية
public static class Program
{
    [STAThread]
    public static void Main()
    {
        Application.EnableVisualStyles();
        Application.SetCompatibleTextRenderingDefault(false);
        
        try
        {
            Application.Run(new MainForm());
        }
        catch (Exception ex)
        {
            MessageBox.Show($"خطأ في تشغيل التطبيق: {ex.Message}", "خطأ", MessageBoxButtons.OK, MessageBoxIcon.Error);
        }
    }
}

نظام إضافات شامل بلغة C# يحتوي على:
الميزات الرئيسية:
1. نظام الإضافات الأساسيواجهة IPlugin للإضافاتفئة BasePlugin كأساس للإضافات مدير الإضافات PluginManagerواجهة رئيسية لإدارة الإضافات
2. الإضافات المتوفره
سطح المكتب البعيد: الاتصال بأجهزة أخرى
إدارة الميكروفون: التحكم في الأجهزة الصوتية
مدير الملفات: تصفح وإدارة الملفاتمدير العمليات: عرض وإنهاء العمليات
مدير الشبكة: مراقبة الاتصالات حظر مكافح الفيروسات: إيقاف برامج الحماية
جدار الحماية: إدارة قواعد الحماية
تشفير الملفات: تشفير/فك تشفير الملفات
قفل التطبيقات: منع تشغيل برامج معينةإدارة الطاقة: التحكم في إعدادات الطاقة
محرر الريجستري: تعديل سجل النظام
3. الأمان والصلاحيات فحص صلاحيات المدير تحذيرات أمنيةتأكيد العمليات الحساسة

4. الواجهات التفاعليةنوافذ منفصلة لكل إضافةقوائم وجداول لعرض البيانات أزرار تفاعلية للعمليات

كيفية الاستخدام:

تجميع المشروع:

احفظ الكود في ملف .cs واستخدم Visual Studioتشغيل التطبيق: سيظهر قائمة بجميع الإضافات المتاحةاختيار الإضافة: اختر الإضافة المطلوبة واضغط "تشغيل"التفاعل: استخدم الواجهات المخصصة لكل إضافةالمتطلبات:.NET Framework 4.7.2 أو أحدثWindows Formsصلاحيات المدير لبعض الإضافات
تحذير: هذا الكود للأغراض التعليمية.
 

آخر المشاركات

عودة
أعلى