Exemplo n.º 1
0
        private void btnUnlock_Click(object sender, EventArgs e)
        {
            // Sets progress bar to green
            ModifyProgressBarColor.SetState(pbUnlocker, 1);

            if (isAlreadyRunning)
            {
                return;
            }
            else
            {
                isAlreadyRunning = true;

                pbUnlocker.Value = 0;

                if (tbFilePath.Text == "No file selected")
                {
                    return;
                }
                ;


                Progress <int> progressBar = new Progress <int>();
                Progress <int> consoleProg = new Progress <int>();
                progressBar.ProgressChanged += (p, value) => pbUnlocker.Value = value;
                consoleProg.ProgressChanged += (p, value) => UpdateConsole(value);
                Task.Run(() => (UnlockClass.Unlock(tbFilePath.Text, cbOverwrite.Checked, cbUnlockVBA.Checked, progressBar, consoleProg)));


                rtbConsole.Text       = "";
                btnChooseFile.Enabled = false;
                cbOverwrite.Enabled   = false;
                bwProgress.RunWorkerAsync();
                bwProgress.WorkerReportsProgress = true;

                btnChooseFile.Enabled = true;
                cbOverwrite.Enabled   = true;
                ScrollToBottomOfMessages();
                isAlreadyRunning = false;
            }
        }
Exemplo n.º 2
0
        private void UpdateConsole(int code)
        {
            if (code == 0)
            {
                rtbConsole.AppendText("File unlocked successfully", Color.DarkGreen);
                rtbConsole.NewLine();

                if (cbOverwrite.Checked)
                {
                    rtbConsole.AppendText("Saved as \"", Color.Black);
                    rtbConsole.AppendText(Path.GetFileName(tbFilePath.Text), Color.DarkGoldenrod);
                    rtbConsole.AppendText("\"", Color.Black);
                    rtbConsole.NewLine();
                }
                else
                {
                    rtbConsole.AppendText("Saved as \"", Color.Black);
                    rtbConsole.AppendText("unlocked_" + Path.GetFileName(tbFilePath.Text), Color.DarkGoldenrod);
                    rtbConsole.AppendText("\"", Color.Black);
                    rtbConsole.NewLine();
                }

                rtbConsole.AppendText("In directory \"", Color.Black);
                rtbConsole.AppendText(Path.GetDirectoryName(tbFilePath.Text), Color.DarkGoldenrod);
                rtbConsole.AppendText("\"", Color.Black);
                rtbConsole.NewLine();
            }
            else
            {
                // Sets progress bar to red
                ModifyProgressBarColor.SetState(pbUnlocker, 2);
                rtbConsole.AppendText("File unlock failed", Color.DarkRed);
                rtbConsole.NewLine();
                rtbConsole.AppendText("Could not write to directory.", Color.Black);
                rtbConsole.NewLine();
                rtbConsole.AppendText("User does not have permission, file is currently open, or file\n\"", Color.Black);
                rtbConsole.AppendText("unlocked_" + Path.GetFileName(tbFilePath.Text), Color.DarkGoldenrod);
                rtbConsole.AppendText("\" already exists \nand overwrite directive not supplied", Color.Black);
                rtbConsole.NewLine();
            }
        }