Esempio n. 1
0
        private void ReadHosts()
        {
            HostFileManager.FileOperationResult readResult;
            this.hosts = HostFileManager.ReadHosts(out readResult);
            switch (readResult)
            {
            case HostFileManager.FileOperationResult.UnauthorizedAccess:
                MessageBox.Show(Resources.msg_error_unauthorized_user, Resources.error, MessageBoxButtons.OK, MessageBoxIcon.Error);
                break;

            case HostFileManager.FileOperationResult.FileNotFound:

                DialogResult userChoice = MessageBox.Show(Resources.msg_warning_host_file_not_found, Resources.warning, MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation);
                if (userChoice == DialogResult.Yes)
                {
                    HostFileManager.FileOperationResult createResult = HostFileManager.CreateDefaultHosts();
                    if (createResult == HostFileManager.FileOperationResult.UnauthorizedAccess)
                    {
                        MessageBox.Show(Resources.msg_error_unauthorized_user, Resources.error, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                    else if (createResult == HostFileManager.FileOperationResult.Failed)
                    {
                        MessageBox.Show(Resources.msg_error_writting, Resources.error, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }

                break;

            case HostFileManager.FileOperationResult.Failed:
                MessageBox.Show(Resources.msg_error_writting, Resources.error, MessageBoxButtons.OK, MessageBoxIcon.Error);
                break;
            }
        }
Esempio n. 2
0
        private void Save()
        {
            HostFileManager.FileOperationResult backupResult = HostFileManager.CreateBackup();

            bool backupFailed = false;

            switch (backupResult)
            {
            case HostFileManager.FileOperationResult.UnauthorizedAccess:
            case HostFileManager.FileOperationResult.BackupCreateFolderUnauthorizedAccess:
                backupFailed = true;
                break;

            case HostFileManager.FileOperationResult.Failed:
            case HostFileManager.FileOperationResult.BackupCreateFolderFailed:
                backupFailed = true;
                break;
            }

            // ------------------------------------------------------------
            if (backupFailed)
            {
                DialogResult userChoice = MessageBox.Show(Resources.msg_warning_backup_failed, Resources.warning, MessageBoxButtons.YesNo, MessageBoxIcon.Error);
                if (userChoice == DialogResult.No)
                {
                    return;
                }
            }

            // ------------------------------------------------------------

            HostFileManager.FileOperationResult writeResult = HostFileManager.WriteHosts(this.hosts);
            switch (writeResult)
            {
            case HostFileManager.FileOperationResult.UnauthorizedAccess:
                MessageBox.Show(Resources.msg_error_unauthorized_user, Resources.error, MessageBoxButtons.OK, MessageBoxIcon.Error);
                break;

            case HostFileManager.FileOperationResult.Failed:
                MessageBox.Show(Resources.msg_error_writting, Resources.error, MessageBoxButtons.OK, MessageBoxIcon.Error);
                break;

            case HostFileManager.FileOperationResult.Success:
                this.modifed = false;
                CheckSaveStatus();
                break;
            }
        }