Locker Code
Locker code:
namespace LiteLock
{
public partial class Locker : Form
{
[DllImport("user32.dll")]
static extern bool SetForegroundWindow(IntPtr hWnd);
private Thread cryptoThread;
private EncryptDecrypt cryptor;
public bool isClosing = false;
public bool isWorking = false;
public Locker()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
this.overwriteOriginal.Checked = Properties.Settings.Default.overwriteBox;
cryptor = new EncryptDecrypt(this);
this.encryptionProgress.Visible = false;
this.currentFileLabel.Visible = false;
this.Height = 254;
string[] args = Environment.GetCommandLineArgs();
if (args.Length > 1)
foreach (string a in args)
MessageBox.Show(a);
}
private void EncryptLabel_DragDrop(object sender, DragEventArgs e)
{
if (isWorking)
return;
SetForegroundWindow(this.Handle);
Password pass = new Password();
if (pass.ShowDialog(this) == DialogResult.OK)
{
string p = pass.textBox1.Text.ToString();
pass.Dispose();
Password pass2 = new Password();
pass2.Text = "Enter Again";
if (pass2.ShowDialog(this) == DialogResult.OK)
{
string p2 = pass2.textBox1.Text.ToString();
pass2.Dispose();
if (p.Equals(p2))
{
isWorking = true;
cryptoThread = new Thread(() => EncryptList(e,p));
cryptoThread.Start();
}
else
{
MessageBox.Show("Password Mismatch. Please try again.","LiteLock");
}
}
}
}
private void EncryptList(DragEventArgs e, string p)
{
List<string> filepaths = new List<string>();
this.Invoke((MethodInvoker)delegate
{
this.currentFileLabel.Visible = true;
this.Height = 347;
});
try
{
filepaths = getFilepaths((string[])(e.Data.GetData(DataFormats.FileDrop)));
}
catch (Exception) {}
int filesCrypted = 0;
this.Invoke((MethodInvoker)delegate
{
this.encryptionProgress.Maximum = filepaths.Count;
this.encryptionProgress.Value = filesCrypted;
this.encryptionProgress.Visible = true;
this.fileProgressBar.Visible = true;
});
foreach (string fileLoc in filepaths)
{
if (isClosing)
break;
this.Invoke((MethodInvoker)delegate
{
this.encryptionProgress.Value = filesCrypted;
this.currentFileLabel.Text = "Encrypting: " + fileLoc;
});
if (File.Exists(fileLoc))
{
if (cryptor.EncryptFile(fileLoc, fileLoc + ".locking", p)) //Encrypt the file
{
try
{
if (overwriteOriginal.Checked)
{
try
{
cryptor.EncryptFile(fileLoc + ".locking", fileLoc, p); //Overwrite the original with an encrypted version of the encrypted file.
}
catch (Exception exception)
{
MessageBox.Show(exception.Message.ToString());
}
}
File.Delete(fileLoc);
File.Move(fileLoc + ".locking", fileLoc);
}
catch { }
}
else
{
try
{
File.Delete(fileLoc + ".locking");
break;
}
catch { }
}
}
filesCrypted++;
}
this.Invoke((MethodInvoker)delegate
{
this.encryptionProgress.Value = filesCrypted;
this.encryptionProgress.Visible = false;
this.currentFileLabel.Visible = false;
this.fileProgressBar.Visible = false;
this.Height = 254;
if (isClosing)
{
isClosing = false;
this.Text = "LiteLock v2.0 - Created by DarkTussin";
//this.Close();
}
isWorking = false;
});
}
private void DecryptList(DragEventArgs e, string p)
{
List<string> filepaths = new List<string>();
this.Invoke((MethodInvoker)delegate
{
this.currentFileLabel.Visible = true;
this.Height = 347;
});
try
{
filepaths = getFilepaths((string[])(e.Data.GetData(DataFormats.FileDrop)));
}
catch (Exception) {}
int filesCrypted = 0;
this.Invoke((MethodInvoker)delegate
{
this.encryptionProgress.Maximum = filepaths.Count;
this.encryptionProgress.Value = filesCrypted;
this.encryptionProgress.Visible = true;
});
foreach (string fileLoc in filepaths)
{
if (isClosing)
break;
this.Invoke((MethodInvoker)delegate
{
this.encryptionProgress.Value = filesCrypted;
this.fileProgressBar.Visible = true;
this.currentFileLabel.Text = "Decrypting: " + fileLoc;
});
if (File.Exists(fileLoc))
{
if (cryptor.DecryptFile(fileLoc, fileLoc + ".unlocking", p))
{
try
{
File.Delete(fileLoc);
File.Move(fileLoc + ".unlocking", fileLoc);
}
catch { }
}
else
{
try
{
File.Delete(fileLoc + ".unlocking");
break;
}
catch { }
}
}
filesCrypted++;
}
this.Invoke((MethodInvoker)delegate
{
this.encryptionProgress.Value = filesCrypted;
this.encryptionProgress.Visible = false;
this.currentFileLabel.Visible = false;
this.fileProgressBar.Visible = false;
this.Height = 254;
if (isClosing)
{
isClosing = false;
this.Text = "LiteLock v2.0 - Created by DarkTussin";
//this.Close();
}
isWorking = false;
});
}
//continued in reply