/// <summary> /// Encrypts a text to a picture and saves it /// </summary> /// <param name="openFilePath">Path from were the picture gets loaded</param> /// <param name="encryptText">The text which gets hidden in the picture</param> /// <param name="seed"></param> /// <param name="bits"></param> public async Task Encrypt(string openFilePath, string encryptText, int seed, int bits) { await WaitDialogHelper.ExecuteThreadAsync("Encrypt Message", () => { string saveFilePath = RuntimeGlobals.ShowSaveFileDialog("PNG Image (*.png)|*.png", RuntimeGlobals.Settings.SavePath); if (string.IsNullOrEmpty(saveFilePath)) { return; } if (!InputOutput.CheckPathIsValidImage(saveFilePath)) { throw new FileFormatException(); } if (saveFilePath.Equals(openFilePath)) { throw new FileLoadException(); } var image = Interface.Encrypt((BitmapImage)ImageSource, ChannelUsage.Default, seed, encryptText); InputOutput.SaveImageToFile(saveFilePath, image); GC.Collect(); }, exception => { if (exception != null) { if (exception is OutOfMemoryException) { ErrorHelper.Add(6, exception.Message, exception.StackTrace); } else if (exception is FileFormatException) { ErrorHelper.Add(4); } else if (exception is FileLoadException) { ErrorHelper.Add(5); } else { ErrorHelper.Add(3, exception.GetType() + "\n" + exception.Message, exception.StackTrace); } } }); }
public void ExportTxt() { string path = RuntimeGlobals.ShowSaveFileDialog("Text-File (*.txt)|*.txt", RuntimeGlobals.Settings.SavePath); if (!string.IsNullOrEmpty(path)) { WaitDialogHelper.ExecuteThread("Save Text", () => { using (StreamWriter writer = new StreamWriter(path)) { writer.Write(DecryptText); } }, exception => { if (exception != null) { ErrorHelper.Add(3, exception.Message, exception.StackTrace); } }); } }