public virtual async Task Save(string filename, IFileSystem provider) { PreSave(); var buffer = new byte[(int)Math.Ceiling(Bits.Count / (decimal)8) - 1]; using (var f = new GenericFile()) { f.CreateFile(buffer); for (int i = 0; i < buffer.Length; i++) { await f.WriteAsync(i, (byte)Bits.GetInt(i, 0, 8)); } await f.Save(filename, provider); } FileSaved?.Invoke(this, new EventArgs()); }
private void SaveButton_Click(object sender, RoutedEventArgs e) { var saveFileDialog = new SaveFileDialog(); saveFileDialog.ShowDialog(); saveFileDialog.InitialDirectory = Utility.getSteamPath(); //to-do clean that up + move messageboxes to encrypt/decrypt functions -.- if (saveFile != null && !saveFile.validChecksum) { if (MessageBox.Show("The checksum is invalid. Should it be fixed?", "Checksum", MessageBoxButton.YesNo) == MessageBoxResult.Yes) { if (MessageBox.Show("Encrypt the file?", "Save", MessageBoxButton.YesNo) == MessageBoxResult.Yes) { saveFile.Encrypt(); } saveFile.Save(saveFileDialog.FileName, true); } else { if (MessageBox.Show("Encrypt the file?", "Save", MessageBoxButton.YesNo) == MessageBoxResult.Yes) { saveFile.Encrypt(); } saveFile.Save(saveFileDialog.FileName, false); } } else if (saveFile != null) { if (MessageBox.Show("Encrypt the file?", "Save", MessageBoxButton.YesNo) == MessageBoxResult.Yes) { saveFile.Encrypt(); } saveFile.Save(saveFileDialog.FileName, false); } else { genericFile.Encrypt(); genericFile.Save(saveFileDialog.FileName); } MessageBox.Show("File saved.", "Save", MessageBoxButton.OK); }