Esempio n. 1
0
        private void UpdateConsole(int code, string path)
        {
            if (code == 0)
            {
                rtbConsole.AppendText("File unlocked successfully", Color.DarkGreen);
                rtbConsole.NewLine();

                rtbConsole.AppendText("Saved as \"", Color.Black);
                rtbConsole.AppendText(path, 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(path, Color.DarkGoldenrod);
                rtbConsole.AppendText("\" already exists \nand overwrite directive not supplied", Color.Black);
                rtbConsole.NewLine();
            }
        }
Esempio n. 2
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;
                }
                ;


                var saveDialog = new SaveFileDialog
                {
                    Title  = "Save unlocked file",
                    Filter = "Excel Workbook (*.xlsx)|*.xlsx|All files (*.*)|*.*"
                };
                saveDialog.ShowDialog();

                if (saveDialog.FileName == "")
                {
                    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, saveDialog.FileName);
                Task.Run(() => (UnlockClass.Unlock(saveDialog.FileName, tbFilePath.Text, cbOverwrite.Checked, cbUnlockVBA.Checked, cblRemoveVeryHidden.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;
            }
        }
Esempio n. 3
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;
            }
        }