Files
MicronSync/MicronSync/Components/MessageHandler.cs

162 lines
8.9 KiB
C#

using System.Windows.Forms;
namespace MicronSync
{
public class MessageHandler
{
// Call error messages by specifying an enum code
public enum msgCodes
{
_TestSample,
MainWindow_Warn_Purge,
MainWindow_Warn_Purge_Null,
MainWindow_Warn_OverwriteFile,
NewRegKeyUI_CorrectKey,
MainWindow_SaveChanges,
MainWindow_LoadIncompatible,
MainWindow_SZNotInstalled,
}
public enum errCodes
{
_TestSample,
WorkerUI_BadBackupPath,
WorkerUI_BadRestorePath,
MainWindow_RestrictedPath,
MainWindow_PathRootInvalid,
MainWindow_DstWithinSrc,
MainWindow_RestoreError,
MainWindow_BackupError,
Config_WriteError,
Config_ReadError,
MainWindow_ArchiveNotFound,
NewRegKeyUI_InvalidKey,
NewRegKeyUI_PirateKey,
MainWindow_BadConfigFile,
MainWindow_BadConfigFile_FromEXE,
MainWindow_DirectoryNotFound,
}
/// <summary>
/// Create an error message dialogue box.
/// </summary>
/// <param name="mc"></param>
/// <param name="info"></param>
internal static void errorMessage(errCodes mc, string info)
{
switch (mc)
{
case errCodes._TestSample:
MessageBox.Show("This is a sample error message", "Sample Error Message",
MessageBoxButtons.OK, MessageBoxIcon.Error);
break;
case errCodes.WorkerUI_BadBackupPath:
MessageBox.Show("The specified source path is inaccessible. Please ensure the path exists and you have read/write permission, then try again.", "MicronSync",
MessageBoxButtons.OK, MessageBoxIcon.Error);
break;
case errCodes.WorkerUI_BadRestorePath:
MessageBox.Show("The specified restore path is inaccessible. Please ensure the file exists and try again.", "MicronSync",
MessageBoxButtons.OK, MessageBoxIcon.Error);
break;
case errCodes.MainWindow_RestrictedPath:
MessageBox.Show($"The following path cannot be used:\n{info}", "MicronSync",
MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
break;
case errCodes.MainWindow_PathRootInvalid:
MessageBox.Show($"Drive roots cannot be used. Please select a valid sub-directory.", "MicronSync",
MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
break;
case errCodes.MainWindow_DstWithinSrc:
MessageBox.Show($"You cannot create a backup inside of the folder you're tying to backup. Please enter a valid path and try again.", "MicronSync",
MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
break;
case errCodes.MainWindow_RestoreError:
MessageBox.Show($"There was a problem restoring from the selected backup. Please ensure you have sufficient read/write access.", "MicronSync",
MessageBoxButtons.OK, MessageBoxIcon.Error);
break;
case errCodes.MainWindow_BackupError:
MessageBox.Show($"There was a problem backing up the selected directory, check you have entered the correct path. Additionally, ensure you have sufficient read/write access.", "MicronSync",
MessageBoxButtons.OK, MessageBoxIcon.Error);
break;
case errCodes.Config_WriteError:
MessageBox.Show($"Failed to write configuration file.", "MicronSync",
MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
break;
case errCodes.Config_ReadError:
MessageBox.Show($"The current directory is either write-protected or the configuration file is corrupt.", "MicronSync",
MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
break;
case errCodes.MainWindow_ArchiveNotFound:
MessageBox.Show($"The backup file specified does not exist.", "MicronSync",
MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
break;
case errCodes.MainWindow_DirectoryNotFound:
MessageBox.Show($"The backup directory specified does not exist.", "MicronSync",
MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
break;
case errCodes.NewRegKeyUI_InvalidKey:
MessageBox.Show($"The key you have entered is invalid. Please ensure you have typed it in the correct format.", "MicronSync",
MessageBoxButtons.OK, MessageBoxIcon.Error);
break;
case errCodes.NewRegKeyUI_PirateKey:
MessageBox.Show($"You have imported a bad key onto your system. Please delete it to continue using this software.", "MicronSync",
MessageBoxButtons.OK, MessageBoxIcon.Error);
break;
case errCodes.MainWindow_BadConfigFile:
MessageBox.Show($"Unsupported data.\nPlease only drop configs, directories or 7-Zip files!", "MicronSync",
MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
break;
case errCodes.MainWindow_BadConfigFile_FromEXE:
MessageBox.Show($"Unsupported data.\nOnly config files are supported when loaded directly from application!", "MicronSync",
MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
break;
}
}
/// <summary>
/// Create an informational message dialogue box.
/// </summary>
/// <param name="mc"></param>
/// <param name="info"></param>
/// <returns></returns>
internal static DialogResult stdMessage(msgCodes mc, string info)
{
DialogResult _dialogResult = DialogResult.None;
switch (mc)
{
case msgCodes.MainWindow_Warn_Purge:
_dialogResult = MessageBox.Show($"Purging will permanently delete ALL data within the following directory prior to attempting to restore:\n\"{info}\"\n\nBacking up is strongly recommended, continue enabling option?", "MicronSync - Dangerous operation",
MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
break;
case msgCodes.MainWindow_Warn_Purge_Null:
_dialogResult = MessageBox.Show($"Purging will permanently delete ALL data within the restore destintation directory prior to attempting to restore.\n\nBacking up is strongly recommended, continue enabling option?", "MicronSync - Dangerous operation",
MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
break;
case msgCodes.MainWindow_Warn_OverwriteFile:
_dialogResult = MessageBox.Show($"There is already a file with the same name in the specified directory:\n{info}\n\nWould you like to overwrite it?", "MicronSync - Confirm overwrite",
MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
break;
case msgCodes.NewRegKeyUI_CorrectKey:
_dialogResult = MessageBox.Show($"Thank you for registering MicronSync :-)", "MicronSync",
MessageBoxButtons.OK, MessageBoxIcon.Information);
break;
case msgCodes.MainWindow_SaveChanges:
_dialogResult = MessageBox.Show($"There are currently unsaved changes, would you like to save before exiting?\n\n{info}", "MicronSync",
MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question);
break;
case msgCodes.MainWindow_LoadIncompatible:
_dialogResult = MessageBox.Show($"You are trying load a legacy config file (v{info}) which is incompatible with this version of MicronSync. Please create a new config file, sorry for any inconvenience caused!", "MicronSync - Incompatible config",
MessageBoxButtons.OK, MessageBoxIcon.Warning);
break;
case msgCodes.MainWindow_SZNotInstalled:
_dialogResult = MessageBox.Show("7-Zip is not currently installed but is required for MicronSync to run. Would you like to be taken to the download page?", "MicronSync",
MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation);
break;
}
return _dialogResult;
}
}
}