示例#1
0
        static void Main()
        {
            #region Request admin acess
            WindowsPrincipal pricipal = new WindowsPrincipal(WindowsIdentity.GetCurrent());
            bool             hasAdministrativeRight = pricipal.IsInRole(WindowsBuiltInRole.Administrator);
            if (!hasAdministrativeRight)
            {
                // relaunch the application with admin rights
                string           fileName    = Assembly.GetExecutingAssembly().Location;
                ProcessStartInfo processInfo = new ProcessStartInfo();
                processInfo.Verb     = "runas";
                processInfo.FileName = fileName;

                try
                {
                    Process.Start(processInfo);
                }
                catch (Win32Exception)
                {
                    // This will be thrown if the user cancels the prompt
                }

                return;
            }
            #endregion
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new Form1());
            FileSystemExplorer sys = new FileSystemExplorer();
        }
示例#2
0
        public string ShowTextReplacer(string text, FileSystemExplorer FileSys)
        {
            Form prompt = new Form()
            {
                Width           = 500,
                Height          = 250,
                FormBorderStyle = FormBorderStyle.FixedDialog,
                Text            = "Find and replace text",
                StartPosition   = FormStartPosition.CenterScreen
            };
            Label textLabel = new Label()
            {
                Left = 50, Top = 20, Text = "Search text:"
            };
            TextBox textBox = new TextBox()
            {
                Left = 50, Top = 50, Width = 300
            };
            Label textLabe2 = new Label()
            {
                Left = 50, Top = 95, Text = "And replace with"
            };
            TextBox textBox2 = new TextBox()
            {
                Left = 50, Top = 125, Width = 300
            };
            Button confirmation = new Button()
            {
                Text = "Replace", Left = 300, Width = 100, Top = 175, DialogResult = DialogResult.OK
            };

            confirmation.Click += (sender, e) => {
                prompt.Close();
                textBox.Text = FileSys.Operation.Replace(text, textBox.Text, textBox2.Text);
            };
            prompt.Controls.Add(textBox);
            prompt.Controls.Add(textBox2);
            prompt.Controls.Add(confirmation);
            prompt.Controls.Add(textLabel);
            prompt.Controls.Add(textLabe2);
            prompt.AcceptButton = confirmation;

            return(prompt.ShowDialog() == DialogResult.OK ? textBox.Text : "");
        }
示例#3
0
        public string ShowFilePicker(FileSystemExplorer FileSys)
        {
            string text    = "File name:";
            string caption = "Choose fille scearch options";

            Form prompt = new Form()
            {
                Width           = 500,
                Height          = 500,
                FormBorderStyle = FormBorderStyle.FixedDialog,
                Text            = caption,
                MinimizeBox     = false,
                MaximizeBox     = false,
                StartPosition   = FormStartPosition.CenterScreen
            };
            Label textLabel = new Label()
            {
                Left = 50, Top = 20, Text = text
            };
            TextBox textBox = new TextBox()
            {
                Left = 50, Top = 50, Width = 200
            };
            DateTimePicker timePicker = new DateTimePicker()
            {
                Left = 50, Top = 150
            };
            Label textLabe2 = new Label()
            {
                Left = 50, Top = 125, Text = "File last changed:"
            };
            NumericUpDown textBox2 = new NumericUpDown()
            {
                Left = 50, Top = 225, Width = 200
            };
            Label textLabe3 = new Label()
            {
                Left = 50, Top = 200, Text = "File size, B:"
            };
            Button confirmation = new Button()
            {
                Text         = "Find!",
                Height       = 50,
                Left         = 175,
                Width        = 150,
                Top          = 400,
                DialogResult = DialogResult.OK
            };
            ComboBox ListBox1 = new ComboBox()
            {
                Width         = 150,
                Left          = 300,
                Top           = 50,
                BackColor     = prompt.BackColor,
                DropDownStyle = ComboBoxStyle.DropDownList,
                ImeMode       = ImeMode.Off
                ,
                Font = new Font("Bradley Hand ITC", 8)
            };

            confirmation.Click += (sender, e) =>
            {
                if (ListBox1.SelectedIndex != -1)
                {
                    switch (ListBox1.SelectedIndex)
                    {
                    case (0):
                        FileSys.GetFiles(textBox.Text);
                        break;

                    case (2):
                        string theDate    = timePicker.Value.ToShortDateString();
                        string dateInput  = theDate;
                        var    parsedDate = DateTime.Parse(dateInput);
                        FileSys.GetFiles(parsedDate);
                        break;

                    case (1):
                        FileSys.GetFiles(textBox2.Value);
                        break;

                    default:
                        FileSys.GetFiles("*"); break;
                    }
                }
                prompt.Close();
            };
            prompt.Controls.Add(textBox);
            prompt.Controls.Add(textBox2);
            prompt.Controls.Add(confirmation);
            prompt.Controls.Add(textLabel);
            prompt.Controls.Add(textLabe2);
            prompt.Controls.Add(textLabe3);
            prompt.Controls.Add(ListBox1);
            prompt.Controls.Add(timePicker);
            textBox2.Maximum = 999999999;
            ListBox1.Items.Add("Search by name");
            ListBox1.Items.Add("Search by size");
            ListBox1.Items.Add("Search by date");
            prompt.AcceptButton = confirmation;

            return(prompt.ShowDialog() == DialogResult.OK ? textBox.Text : "");
        }