예제 #1
0
        private SaveResult SaveFile(SaveRequest saveAction = SaveRequest.Save)
        {
            try
            {
                if (_fs.IsNew || saveAction == SaveRequest.SaveAs)
                {
                    // Ask where to save new file
                    string filepath = String.Empty;
                    if (TryBrowseFileToOpen(true, ref filepath))
                    {
                        var pForm = new PasswordForm(false);
                        if (pForm.ShowDialog() == DialogResult.OK)
                        {
                            _io.Write(filepath, txtContent.Text, pForm.Password);
                            _fs.FilePath = filepath;
                            _fs.IsEdited = false;
                            return SaveResult.Saved;
                        }
                    }
                    return SaveResult.Cancelled;
                }

                // Save existing file
                if (_io.Write(txtContent.Text, saveAction == SaveRequest.ForceSave))
                {
                    _fs.IsEdited = false;
                    return SaveResult.Saved;
                }
                return SaveResult.NotChanged;
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message, e.ToString(), MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            return SaveResult.Failed;
        }
예제 #2
0
 private void OpenFile(string filepath)
 {
     try
     {
         var pForm = new PasswordForm(true);
         if (pForm.ShowDialog() == DialogResult.OK)
         {
             var content = _io.Read(filepath, pForm.Password);
             txtContent.Text = content;
             _fs.FilePath = filepath;
             _fs.IsEdited = false;
         }
     }
     catch (Exception e)
     {
         MessageBox.Show(e.Message, e.ToString(), MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }