private void RemoveSelectedItems() { try { foreach (var file in FilelistView.SelectedItems) { var item = (ListViewItem)file; var tet = item.SubItems[0].Text; var result = _nlockContainer.RemoveFile(tet); if ((_fileName != null) && !_isDirty && result) { _isDirty = true; } } if (FilelistView.Items.Count > 0) { UpdateListView(_nlockContainer.GetFileList()); } else { toolStripFileCountLabel.Text = "0"; _nlockContainer = null; } } catch (Exception ex) { MessageBox.Show(Resources.An_error_occurred + ex, Resources.Error, MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void MainFormClosed(object sender, FormClosedEventArgs e) { if (_nlockContainer != null) { _nlockContainer.Dispose(); } _nlockContainer = null; }
private void DragAdd(IEnumerable <string> files) { if (_nlockContainer == null) { _nlockContainer = new NLockContainerCommons(); } foreach (var file in files) { Logger.Debug("File dragged : " + file); _nlockContainer.AddFile(file); UpdateListView(_nlockContainer.GetFileList()); } }
private void ToolstripButtonAddFileClick(object sender, EventArgs e) { tssStatus.Text = string.Empty; if (Text != Resources.NLock) { Text = Resources.NLock; } if (_nlockContainer == null) { _nlockContainer = new NLockContainerCommons(); } try { Logger.Debug("Add"); if (openFileDialog.ShowDialog() == DialogResult.OK) { foreach (var file in openFileDialog.FileNames) { _nlockContainer.AddFile(file); } tsbLock.Enabled = true; if (_fileName != null) { _isDirty = true; } UpdateListView(_nlockContainer.GetFileList()); } } catch (OutOfMemoryException) { MessageBox.Show(Resources.Out_of_memory, Resources.Not_enough_memory, MessageBoxButtons.OK, MessageBoxIcon.Error); Logger.Error("OutOfMemoryException"); } }
private void ToolstrioButtonLockClick(object sender, EventArgs e) { tssStatus.ForeColor = Color.Blue; tssStatus.Text = Resources.Locking___; if (FilelistView.Items.Count > 0) { string predictedFileName = null; if (FilelistView.Items.Count == 1) { predictedFileName = FilelistView.Items[0].Text; } using (var lockForm = new LockForm()) { lockForm.ChangeSaveFileName(predictedFileName); lockForm.ShowDialog(); var result = lockForm.DialogResult; if (result == DialogResult.OK) { _nlockContainer.Template = lockForm.TemplateLoginForm; if (lockForm.AddPassword) { _nlockContainer.TemplateOperations = new NLockTemplateOperationsCommon(); _nlockContainer.Password = lockForm.Password; _nlockContainer.AddPassword = true; } else { _nlockContainer.AddPassword = false; _nlockContainer.Password = null; } _nlockContainer.Lock(); if (!lockForm.SaveFileName.EndsWith(".nlk")) { lockForm.SaveFileName = lockForm.SaveFileName + ".nlk"; } var status = _nlockContainer.Save(lockForm.SaveFileName); if (status == NLockContainerCommons.ContainerStatus.Empty) { MessageBox.Show(Resources.EmptyContainer, Resources.Locking, MessageBoxButtons.OK, MessageBoxIcon.Warning); Logger.Error("Failed...No files added. Empty container"); } else if (status == NLockContainerCommons.ContainerStatus.NullTemplate) { MessageBox.Show(Resources.BadFaceCaptured, Resources.Locking, MessageBoxButtons.OK, MessageBoxIcon.Error); Logger.Error("Failed...Bad image captured"); } else { FilelistView.Items.Clear(); tsbLock.Enabled = false; tsbExtract.Enabled = false; tssStatus.ForeColor = Color.Green; tssStatus.Text = Resources.Locking_Successful___; _saved = true; Text = Resources.NLock; _fileName = null; _isDirty = false; toolStripFileCountLabel.Text = string.Empty; _nlockContainer = null; } } else // result == DialogResult.Cancel { tssStatus.ForeColor = Color.Red; tssStatus.Text = Resources.Locking_Canceled___; } } } }
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"); } }
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"); } } }