Esempio n. 1
0
        private void ToolstripButtonOpenClick(object sender, EventArgs e)
        {
            tssStatus.ForeColor = Color.Blue;
            tssStatus.Text      = Resources.Opening___;
            try
            {
                if (openFileDialog.ShowDialog() == DialogResult.OK)
                {
                    FilelistView.Items.Clear();
                    Text = Resources.NLock;
                    toolStripFileCountLabel.Text = string.Empty;
                    tssStatus.ForeColor          = Color.Blue;
                    tssStatus.Text = Resources.Unlocking___;
                    if (NLockTemplateOperations.IsNLock(openFileDialog.FileName) > 0)
                    {
                        if (_nlockContainer != null)
                        {
                            _nlockContainer.Dispose();
                        }
                        _nlockContainer = new NLockContainerCommons();
                        _isDirty        = false;
                        _fileName       = openFileDialog.FileName;

                        _nlockContainer.LoadFromFile(_fileName);
                        if (!_nlockContainer.IsLocked)
                        {
                            Text = Resources.NLock + _fileName;
                            UpdateListView(_nlockContainer.GetFileList());

                            tsbExtract.Enabled = true;

                            tssStatus.ForeColor = Color.Green;
                            tssStatus.Text      = Resources.UnlockedUserIdentified;
                        }
                        else
                        {
                            _fileName = null;
                        }
                    }
                    else
                    {
                        MessageBox.Show(
                            Resources.FileCorrupted + Path.GetFileName(openFileDialog.FileName),
                            Resources.FileOpeningFailed, MessageBoxButtons.OK, MessageBoxIcon.Error);
                        tssStatus.ForeColor = Color.Red;
                        tssStatus.Text      = Resources.Unlocking___ + Resources.Failed;
                    }
                }
                else
                {
                    tssStatus.ForeColor = Color.Blue;
                    tssStatus.Text      = Resources.Canceled___;
                }
            }
            catch (Exception)
            {
                _fileName           = null;
                tssStatus.ForeColor = Color.Red;
                tssStatus.Text      = Resources.UnlockingFailed;
                Logger.Info("Unlocking... Failed");
            }
        }
Esempio n. 2
0
        private void MainFormLoad(object sender, EventArgs e)
        {
            InitializeForm();
            Logger.Debug("---------------(----------- Starting NLock -----------)-----------------------");
            FilelistView.Columns[FilelistView.Columns.Count - 1].Width = -2;
            _nlockContainer = new NLockContainerCommons();

            if (_opMode == OperationModes.Opennlock)
            {
                Logger.Debug("Open NLock Operation");
                if (_fileName != null)
                {
                    try
                    {
                        Text = Resources.NLock + _fileName;
                        _nlockContainer.LoadFromFile(_fileName);
                        UpdateListView(_nlockContainer.GetFileList());
                        tsbLock.Enabled    = true;
                        tsbExtract.Enabled = true;
                        Focus();
                    }
                    catch (Exception)
                    {
                        using (var form = new Form {
                            WindowState = FormWindowState.Maximized, TopMost = true
                        })
                        {
                            MessageBox.Show(Resources.OpeningFile, Resources.Alert, MessageBoxButtons.OK,
                                            MessageBoxIcon.Stop);
                        }
                        Close();
                    }
                }
                else
                {
                    MessageBox.Show(Resources.InvalidFile, Resources.Alert, MessageBoxButtons.OK, MessageBoxIcon.Stop);
                    Logger.Info("OperationModes.OPENNLOCK Null File Name");
                    Close();
                }
            }
            else if (_opMode == OperationModes.Unlockhere)
            {
                Logger.Debug("Unlock here Operation");
                if (_fileName != null)
                {
                    try
                    {
                        _nlockContainer.LoadFromFile(_fileName);

                        var          currentPath = string.Concat(Path.GetDirectoryName(_fileName), "\\");
                        DialogResult result;
                        if (_nlockContainer.ExtractToFolder(currentPath))
                        {
                            using (var form = new Form {
                                WindowState = FormWindowState.Maximized, TopMost = true
                            })
                            {
                                result = MessageBox.Show(form,
                                                         Resources.SuccessExtractedTo + currentPath + "\n" + Resources.ExitQ,
                                                         Resources.Unlocking,
                                                         MessageBoxButtons.YesNo, MessageBoxIcon.Information);
                            }
                        }
                        else
                        {
                            using (var form = new Form {
                                WindowState = FormWindowState.Maximized, TopMost = true
                            })
                            {
                                result = MessageBox.Show(form,
                                                         Resources.FailedExtractTo + currentPath + "\n" + Resources.ExitQ,
                                                         Resources.UnlockingFailed,
                                                         MessageBoxButtons.YesNo, MessageBoxIcon.Error);
                            }
                        }

                        if (result == DialogResult.Yes)
                        {
                            Close();
                        }
                        else
                        {
                            Focus();
                            tsbExtract.Enabled = true;
                            folderBrowserDialog.SelectedPath = currentPath;
                            UpdateListView(_nlockContainer.GetFileList());
                        }
                    }
                    catch (InvalidOperationException)
                    {
                        MessageBox.Show(Resources.InvalidUser, Resources.Alert, MessageBoxButtons.OK,
                                        MessageBoxIcon.Stop);
                    }
                    catch (Exception)
                    {
                        MessageBox.Show(Resources.UnlockingFailed, Resources.Alert, MessageBoxButtons.OK,
                                        MessageBoxIcon.Stop);
                    }
                }
                else
                {
                    Logger.Info("OperationModes.UNLOCKHERE Null File Name");
                }
            }
            else if (_opMode == OperationModes.Unlockto)
            {
                Logger.Debug("Unlock to Operation");
                if (_fileName != null)
                {
                    try
                    {
                        _nlockContainer.LoadFromFile(_fileName);
                        tsbExtract.Enabled = true;
                        var unlockingPath = string.Concat(Path.GetDirectoryName(_fileName), "\\");
                        folderBrowserDialog.SelectedPath = unlockingPath;
                        Extract();

                        var result = DialogResult.None;

                        if (_status == Status.Sucessfullyextracted)
                        {
                            tsbExtract.Enabled = false;
                            using (var form = new Form {
                                WindowState = FormWindowState.Maximized, TopMost = true
                            })
                            {
                                result = MessageBox.Show(form,
                                                         Resources.SuccessExtractedTo + unlockingPath + "\n" + Resources.ExitQ,
                                                         Resources.Unlocking,
                                                         MessageBoxButtons.YesNo, MessageBoxIcon.Information);
                            }
                        }
                        else if (_status == Status.Extractionfailed)
                        {
                            using (var form = new Form {
                                WindowState = FormWindowState.Maximized, TopMost = true
                            })
                            {
                                result = MessageBox.Show(form, Resources.Failed + "\n" + Resources.ExitQ,
                                                         Resources.Unlocking,
                                                         MessageBoxButtons.YesNo, MessageBoxIcon.Error);
                            }
                        }
                        else // status == Status.EXTRACTIONCANCELLED)
                        {
                            Close();
                        }

                        if (result == DialogResult.Yes)
                        {
                            Close();
                        }
                        else // result == DialogResult.No
                        {
                            Focus();
                        }
                    }
                    catch (InvalidOperationException)
                    {
                        using (var form = new Form {
                            WindowState = FormWindowState.Maximized, TopMost = true
                        })
                        {
                            MessageBox.Show(form, Resources.InvalidUser, Resources.Alert, MessageBoxButtons.OK,
                                            MessageBoxIcon.Stop);
                        }
                    }
                    catch (Exception)
                    {
                        using (var form = new Form {
                            WindowState = FormWindowState.Maximized, TopMost = true
                        })
                        {
                            MessageBox.Show(Resources.UnlockingFailed, Resources.Alert, MessageBoxButtons.OK,
                                            MessageBoxIcon.Stop);
                        }
                    }
                }
                else
                {
                    Logger.Info("OperationModes.UNLOCKTO Null File Name");
                }
            }
            else if (_opMode == OperationModes.Lockfolder)
            {
                try
                {
                    Logger.Debug("Lock folder Operation");
                    if (_fileName != null)
                    {
                        Logger.Debug("File name : " + _fileName);
                        var copiedName = _fileName;
                        _nlockContainer.AddDirectory(_fileName, true);
                        UpdateListView(_nlockContainer.GetFileList());
                        tsbLock.Enabled = true;
                        saveFileDialog.InitialDirectory = Path.GetDirectoryName(_fileName);
                        Logger.Debug("Perform button lock");
                        tsbLock.PerformClick();

                        if (_saved)
                        {
                            using (var form = new Form {
                                WindowState = FormWindowState.Maximized, TopMost = true
                            })
                            {
                                var result = MessageBox.Show(form,
                                                             Resources.SuccessfullyLockedFilesTo + copiedName + "\n" + Resources.ExitQ,
                                                             Resources.Successful,
                                                             MessageBoxButtons.YesNo, MessageBoxIcon.Information);

                                if (result == DialogResult.Yes)
                                {
                                    Close();
                                }
                            }
                        }
                        else
                        {
                            Close();
                        }
                    }
                    else
                    {
                        Logger.Info("OperationModes.LOCKFOLDER Null File Name");
                    }
                }
                catch (Exception)
                {
                    MessageBox.Show(Resources.EmptyFolderNoFilesAdded, Resources.Failed, MessageBoxButtons.OK,
                                    MessageBoxIcon.Warning);
                }
            }
            else // _opMode == OperationModes.NLOCKTHISFILE
            {
                Logger.Debug(" Lock NLock this file Operation");
                if (_fileName != null)
                {
                    Logger.Debug("File name : " + _fileName);
                    _nlockContainer.AddFile(_fileName);
                    UpdateListView(_nlockContainer.GetFileList());

                    Logger.Debug("Perform button lock");
                    tsbLock.Enabled = true;
                    tsbLock.PerformClick();

                    using (var form = new Form {
                        WindowState = FormWindowState.Maximized, TopMost = true
                    })
                    {
                        var result = MessageBox.Show(form, Resources.WantToExitNLock, Resources.Locking,
                                                     MessageBoxButtons.YesNo, MessageBoxIcon.Information);

                        saveFileDialog.InitialDirectory = Path.GetDirectoryName(_fileName);

                        if (result == DialogResult.Yes)
                        {
                            Close();
                        }
                        else // result == DialogResult.No
                        {
                            InitializeForm();
                        }
                    }
                }
                else
                {
                    Logger.Info("OperationModes.NLOCKTHISFILE Null File Name");
                }
            }
        }