示例#1
0
        private void saveToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (sfdSave.ShowDialog() != DialogResult.OK)
            {
                return;
            }

            // Update values
            SaveData();

            // Update Checksum
            ChecksumCalculator.UpdateChecksum(_saveData);

            try
            {
                // Write save file
                File.WriteAllBytes(sfdSave.FileName, _saveData);

                // Inform the user
                MessageBox.Show("Saved successfully!", "Success!");
            }
            catch (Exception)
            {
                MessageBox.Show("An error occured while attempting to save!", "Error", MessageBoxButtons.OK,
                                MessageBoxIcon.Error);
            }
        }
示例#2
0
        public void Run(Options options)
        {
            if (options.UnrecognizedInput)
            {
                _console.WriteUnrecognizedInputMessage();
                return;
            }

            if (options.DisplayHelp)
            {
                _console.WriteHelpMessage();
                return;
            }

            if (string.IsNullOrWhiteSpace(options.FileName))
            {
                _console.WriteFileArgumentMissingMessage();
                return;
            }

            if (!_fileSystem.FileExists(options.FileName))
            {
                _console.WriteFileDoesNotExistMessage(options.FileName);
                return;
            }

            var fileLength = _fileSystem.GetFileLength(options.FileName);
            var file       = KnownFiles.IsKnownFile(fileLength);

            if (file.IsKnown == KnownState.Exact)
            {
                _console.WriteIdentifiedFileMessage(file.Description);
            }
            else if (file.IsKnown == KnownState.Probable)
            {
                _console.WriteProbableFileMessage(file.Description);
            }
            else
            {
                _console.WriteUnknownFileMessage();

                if (!ShouldProceed(options.Force))
                {
                    _console.WriteDidNotProceedWithUnknownFileMessage();
                    return;
                }
            }

            _checksumCalculator.UpdateChecksum(options.FileName);

            _console.WriteSuccessMessage();

            if (options.Pause)
            {
                _console.WritePauseMessage();
            }
        }