/// <summary>Displays a message box with the specified text, caption, buttons, icon, and default button.</summary>
        /// <param name="text">The text to display in the message box.</param>
        /// <param name="caption">The text to display in the title bar of the message box.</param>
        /// <param name="buttons">One of the <see cref="T:System.Windows.Forms.MessageBoxButtons" /> values that specifies which buttons to display in the message box.</param>
        /// <param name="icon">One of the <see cref="T:System.Windows.Forms.MessageBoxIcon" /> values that specifies which icon to display in the message box.</param>
        /// <param name="defaultButton">One of the <see cref="T:System.Windows.Forms.MessageBoxDefaultButton" /> values that specifies the default button for the message box.</param>
        /// <returns>One of the <see cref="T:System.Windows.Forms.DialogResult" /> values.</returns>
        public static DialogResult Show(string text, string caption = "", MessageBoxButtons buttons = MessageBoxButtons.OK, MessageBoxIcon icon = MessageBoxIcon.Information, MessageBoxDefaultButton defaultButton = MessageBoxDefaultButton.Button1)
        {
            MessageBoxForm form = new MessageBoxForm();

            form.StartPosition = FormStartPosition.CenterScreen;
            return(form.ShowForm(text, caption, buttons, icon, defaultButton));
        }
示例#2
0
        private void ResetToDefaultButton_Click(object sender, EventArgs e)
        {
            var game = CurrentItem;

            if (game == null)
            {
                return;
            }
            var program = _DefaultSettings;

            if (program == null)
            {
                return;
            }
            var form = new MessageBoxForm();

            form.StartPosition = FormStartPosition.CenterParent;
            var result = form.ShowForm("Reset current settings to default?", "Reset", MessageBoxButtons.OKCancel, MessageBoxIcon.Question);

            if (result != DialogResult.OK)
            {
                return;
            }
            // Reset to default all properties which affects checksum.
            game.XInputMask    = program.XInputMask;
            game.HookMask      = program.HookMask;
            game.AutoMapMask   = (int)MapToMask.None;
            game.EmulationType = (int)EmulationType.None;
            game.DInputMask    = program.DInputMask;
            game.DInputFile    = program.DInputFile ?? "";
            game.FakeVID       = program.FakeVID;
            game.FakePID       = program.FakePID;
            game.Timeout       = program.Timeout;
        }
示例#3
0
        private void SynchronizeSettingsButton_Click(object sender, EventArgs e)
        {
            MessageBoxForm form = new MessageBoxForm();

            form.StartPosition = FormStartPosition.CenterParent;
            var           status = GetGameStatus(CurrentGame, false);
            var           values = Enum.GetValues(typeof(GameRefreshStatus));
            List <string> errors = new List <string>();

            foreach (GameRefreshStatus value in values)
            {
                if (status.HasFlag(value))
                {
                    var description = JocysCom.ClassLibrary.ClassTools.EnumTools.GetDescription(value);
                    errors.Add(description);
                }
            }
            var message = "Synchronize current settings to game folder?";

            message += "\r\n\r\n\tIssues:\r\n\r\n\t - " + string.Join("\r\n\t - ", errors);
            var result = form.ShowForm(message, "Synchronize", MessageBoxButtons.OKCancel, MessageBoxIcon.Question);

            if (result == DialogResult.OK)
            {
                ApplySettings();
            }
        }
示例#4
0
        private void SettingsDeleteButton_Click(object sender, EventArgs e)
        {
            var grid  = SettingsDataGridView;
            var items = grid.SelectedRows.Cast <DataGridViewRow>().Select(x => (Setting)x.DataBoundItem).ToArray();
            var form  = new MessageBoxForm();

            form.StartPosition = FormStartPosition.CenterParent;
            var result = form.ShowForm("Do you want to delete selected settings?", "X360CE - Delete Settings", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question);

            if (result == DialogResult.Yes)
            {
                foreach (var item in items)
                {
                    SettingsManager.Settings.Items.Remove(item);
                }
                //		mainForm.LoadingCircle = true;
                //		var setting = (Setting)MyDevicesDataGridView.SelectedRows[0].DataBoundItem;
                //		var ws = new WebServiceClient();
                //		ws.Url = MainForm.Current.OptionsPanel.InternetDatabaseUrlComboBox.Text;
                //		ws.DeleteSettingCompleted += ws_DeleteSettingCompleted;
                //		ws.DeleteSettingAsync(setting);
            }
            form.Dispose();
            form = null;
        }
示例#5
0
        void DeleteSelectedGames()
        {
            var            grid      = GamesDataGridView;
            var            selection = JocysCom.ClassLibrary.Controls.ControlsHelper.GetSelection <string>(grid, "FileName");
            var            userGames = SettingsManager.UserGames.Items.Where(x => selection.Contains(x.FileName)).ToArray();
            MessageBoxForm form      = new MessageBoxForm();

            form.StartPosition = FormStartPosition.CenterParent;
            string message;

            if (userGames.Length == 1)
            {
                var item = userGames[0];
                message = string.Format("Are you sure you want to delete settings for?\r\n\r\n\tFile Name: {0}\r\n\tProduct Name: {1}",
                                        item.FileName,
                                        item.FileProductName);
            }
            else
            {
                message = string.Format("Delete {0} setting(s)?", userGames.Length);
            }
            var result = form.ShowForm(message, "Delete", MessageBoxButtons.OKCancel, MessageBoxIcon.Exclamation);

            if (result == DialogResult.OK)
            {
                foreach (var item in userGames)
                {
                    SettingsManager.UserGames.Items.Remove(item);
                }
                SettingsManager.Save();
                MainForm.Current.CloudPanel.Add(CloudAction.Delete, userGames, true);
            }
        }
        void LoadPreset()
        {
            mainForm.UpdateTimer.Stop();
            if (ControllerComboBox.SelectedItem == null)
            {
                return;
            }
            var name = ((KeyValuePair)ControllerComboBox.SelectedItem).Key;

            if (PresetsDataGridView.SelectedRows.Count == 0)
            {
                return;
            }
            var title   = "Load Preset Setting?";
            var preset  = (Preset)PresetsDataGridView.SelectedRows[0].DataBoundItem;
            var message = "Do you want to load Preset Setting:";

            message += "\r\n\r\n    " + preset.ProductName;
            message += "\r\n\r\nfor \"" + name + "\" controller?";
            MessageBoxForm form = new MessageBoxForm();

            form.StartPosition = FormStartPosition.CenterParent;
            var result = form.ShowForm(message, title, MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1);

            if (result == DialogResult.Yes)
            {
                LoadPreset(preset.ProductName);
            }
            else
            {
                mainForm.UpdateTimer.Start();
            }
        }
示例#7
0
        private void synchronizeToHidGuardianToolStripMenuItem_Click(object sender, EventArgs e)
        {
            // Get all devices which must be hidden.
            var devices = SettingsManager.UserDevices.Items.Where(x => x.IsHidden).ToList();
            // Get all Ids.
            var ids = new List <string>();

            foreach (var ud in devices)
            {
                var idsToBlock = GetIdsToBlock(ud.HidDeviceId, ud.HidHardwareIds);
                ids.AddRange(idsToBlock);
            }
            var canModify = ViGEm.HidGuardianHelper.CanModifyParameters(true);

            if (canModify)
            {
                var idsToBlock = ids.Distinct().ToArray();
                ViGEm.HidGuardianHelper.InsertToAffected(idsToBlock);
            }
            else
            {
                var form = new MessageBoxForm();
                form.StartPosition = FormStartPosition.CenterParent;
                form.ShowForm("Can't modify HID Guardian registry.\r\nPlease run this application as Administrator once in order to fix permissions.", "Permission Denied", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
        }
示例#8
0
        /// <summary>Displays a message box with the specified text, caption, buttons, icon, and default button.</summary>
        /// <param name="text">The text to display in the message box.</param>
        /// <param name="caption">The text to display in the title bar of the message box.</param>
        /// <param name="buttons">One of the <see cref="T:System.Windows.Forms.MessageBoxButtons" /> values that specifies which buttons to display in the message box.</param>
        /// <param name="icon">One of the <see cref="T:System.Windows.Forms.MessageBoxIcon" /> values that specifies which icon to display in the message box.</param>
        /// <param name="defaultButton">One of the <see cref="T:System.Windows.Forms.MessageBoxDefaultButton" /> values that specifies the default button for the message box.</param>
        /// <returns>One of the <see cref="T:System.Windows.Forms.DialogResult" /> values.</returns>
        public static System.Windows.Forms.DialogResult Show(string text, string caption, MessageBoxButtons buttons, MessageBoxIcon icon, MessageBoxDefaultButton defaultButton)
        {
            MessageBoxForm form = new MessageBoxForm();

            form.StartPosition = FormStartPosition.CenterScreen;
            return(form.ShowForm(text, caption, buttons, icon, defaultButton));
        }
示例#9
0
        private void DeleteButton_Click(object sender, System.Windows.RoutedEventArgs e)
        {
            var grid         = MainDataGrid;
            var userSettings = grid.SelectedItems.Cast <UserSetting>().ToArray();
            var form         = new MessageBoxForm();

            form.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
            var result = form.ShowForm("Do you want to delete selected settings?", "X360CE - Delete Settings",
                                       System.Windows.Forms.MessageBoxButtons.YesNoCancel, System.Windows.Forms.MessageBoxIcon.Question);

            if (result == System.Windows.Forms.DialogResult.Yes)
            {
                // Remove from local settings.
                foreach (var item in userSettings)
                {
                    SettingsManager.UserSettings.Items.Remove(item);
                }
                SettingsManager.Save();
                // Remove from cloud settings.
                Task.Run(new Action(() =>
                {
                    foreach (var item in userSettings)
                    {
                        Global.CloudClient.Add(CloudAction.Delete, new UserSetting[] { item });
                    }
                }));
            }
            form.Dispose();
            form = null;
        }
示例#10
0
 static void Main(string[] args)
 {
     // IMPORTANT: Make sure this class don't have any static references to x360ce.Engine library or
     // program tries to load x360ce.Engine.dll before AssemblyResolve event is available and fails.
     AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(CurrentDomain_AssemblyResolve);
     if (IsDebug)
     {
         StartApp(args);
         return;
     }
     try
     {
         StartApp(args);
     }
     catch (Exception ex)
     {
         var message = ExceptionToText(ex);
         var box     = new Controls.MessageBoxForm();
         if (message.Contains("Could not load file or assembly 'Microsoft.DirectX"))
         {
             message += "===============================================================\r\n";
             message += "You can click the link below to download Microsoft DirectX.";
             box.MainLinkLabel.Text    = "http://www.microsoft.com/en-us/download/details.aspx?id=35";
             box.MainLinkLabel.Visible = true;
         }
         var result = box.ShowForm(message, "Exception!", MessageBoxButtons.RetryCancel, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1);
         if (result == DialogResult.Cancel)
         {
             Application.Exit();
         }
     }
 }
示例#11
0
        void DeleteSelectedPrograms()
        {
            var            grid          = ProgramsDataGridView;
            var            selection     = JocysCom.ClassLibrary.Controls.ControlsHelper.GetSelection <string>(grid, "FileName");
            var            itemsToDelete = SettingsManager.Programs.Items.Where(x => selection.Contains(x.FileName)).ToArray();
            MessageBoxForm form          = new MessageBoxForm();

            form.StartPosition = FormStartPosition.CenterParent;
            string message;

            if (itemsToDelete.Length == 1)
            {
                var item = itemsToDelete[0];
                message = string.Format("Are you sure you want to delete default settings for?\r\n\r\n\tFile Name: {0}\r\n\tProduct Name: {1}",
                                        item.FileName,
                                        item.FileProductName);
            }
            else
            {
                message = string.Format("Delete {0} default setting(s)?", itemsToDelete.Length);
            }
            var result = form.ShowForm(message, "Delete", MessageBoxButtons.OKCancel, MessageBoxIcon.Exclamation);

            if (result == DialogResult.OK)
            {
                foreach (var item in itemsToDelete)
                {
                    SettingsManager.Programs.Items.Remove(item);
                }
                SettingsManager.Save();
            }
        }
示例#12
0
        /// <summary>
        /// Button must be available only if editing UserGame .
        /// </summary>
        private void SynchronizeSettingsButton_Click(object sender, EventArgs e)
        {
            var            game = CurrentItem as UserGame;
            MessageBoxForm form = new MessageBoxForm();

            form.StartPosition = FormStartPosition.CenterParent;
            var           status = SettingsManager.Current.GetDllAndIniStatus(game, false);
            var           values = ((GameRefreshStatus[])Enum.GetValues(typeof(GameRefreshStatus))).Except(new[] { GameRefreshStatus.OK }).ToArray();
            List <string> errors = new List <string>();

            foreach (GameRefreshStatus value in values)
            {
                if (status.HasFlag(value))
                {
                    var description = Attributes.GetDescription(value);
                    errors.Add(description);
                }
            }
            var message = "Synchronize current settings to game folder?";

            message += "\r\n\r\n\tIssues:\r\n\r\n\t - " + string.Join("\r\n\t - ", errors);
            var result = form.ShowForm(message, "Synchronize", MessageBoxButtons.OKCancel, MessageBoxIcon.Question);

            if (result == DialogResult.OK)
            {
                ApplySettings();
            }
        }
示例#13
0
 static void Main(string[] args)
 {
     if (IsDebug)
     {
         StartApp(args);
         return;
     }
     try
     {
         StartApp(args);
     }
     catch (Exception ex)
     {
         var message = AppHelper.ExceptionToText(ex);
         var box     = new Controls.MessageBoxForm();
         if (message.Contains("Could not load file or assembly 'Microsoft.DirectX"))
         {
             message += "===============================================================\r\n";
             message += "You can click the link below to download Microsoft DirectX.";
             box.MainLinkLabel.Text    = "http://www.microsoft.com/en-us/download/details.aspx?id=35";
             box.MainLinkLabel.Visible = true;
         }
         var result = box.ShowForm(message, "Exception!", MessageBoxButtons.RetryCancel, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1);
         if (result == DialogResult.Cancel)
         {
             Application.Exit();
         }
     }
 }
示例#14
0
        static void Main(string[] args)
        {
            // First: Set working folder to the path of executable.
            var fi = new FileInfo(Application.ExecutablePath);

            Directory.SetCurrentDirectory(fi.Directory.FullName);
            // Prevent brave users from running this app from Windows folder.
            var winFolder = Environment.GetFolderPath(Environment.SpecialFolder.Windows);

            if (fi.FullName.StartsWith(winFolder, StringComparison.OrdinalIgnoreCase))
            {
                MessageBox.Show("Running from Windows folder is not allowed!\r\nPlease run this program from another folder.", "Windows Folder", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }

            //var x = @"c:\Program Files\X360CE\x360ce.ini";
            //if (File.Exists(x))
            //{
            //    var rights = System.Security.AccessControl.FileSystemRights.Modify;
            //    var users = new SecurityIdentifier(WellKnownSidType.BuiltinUsersSid, null);
            //    // Check if users in non elevated mode have rights to modify the file.
            //    var hasRights = JocysCom.ClassLibrary.Security.PermissionHelper.HasRights(x, rights, users, false);
            //    if (!hasRights && JocysCom.ClassLibrary.Win32.WinAPI.IsElevated())
            //    {
            //        // Allow users to modify file when in non elevated mode.
            //        JocysCom.ClassLibrary.Security.PermissionHelper.SetRights(x, rights, users);
            //        hasRights = JocysCom.ClassLibrary.Security.PermissionHelper.HasRights(x, rights, users, false);
            //    }
            //}

            // IMPORTANT: Make sure this class don't have any static references to x360ce.Engine library or
            // program tries to load x360ce.Engine.dll before AssemblyResolve event is available and fails.
            AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(CurrentDomain_AssemblyResolve);
            if (IsDebug)
            {
                StartApp(args);
                return;
            }
            try
            {
                StartApp(args);
            }
            catch (Exception ex)
            {
                var message = ExceptionToText(ex);
                var box     = new Controls.MessageBoxForm();
                if (message.Contains("Could not load file or assembly 'Microsoft.DirectX"))
                {
                    message += "===============================================================\r\n";
                    message += "You can click the link below to download Microsoft DirectX.";
                    box.MainLinkLabel.Text    = "http://www.microsoft.com/en-us/download/details.aspx?id=35";
                    box.MainLinkLabel.Visible = true;
                }
                var result = box.ShowForm(message, "Exception!", MessageBoxButtons.RetryCancel, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1);
                if (result == DialogResult.Cancel)
                {
                    Application.Exit();
                }
            }
        }
示例#15
0
        private void synchronizeToHidGuardianToolStripMenuItem_Click(object sender, EventArgs e)
        {
            var canModify = AppHelper.SynchronizeToHidGuardian();

            if (!canModify)
            {
                var form = new MessageBoxForm();
                form.StartPosition = FormStartPosition.CenterParent;
                form.ShowForm("Can't modify HID Guardian registry.\r\nPlease run this application as Administrator once in order to fix permissions.", "Permission Denied", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
        }
示例#16
0
		static void Main(string[] args)
		{
			try
			{
				//var fi = new FileInfo(Application.ExecutablePath);
				//Directory.SetCurrentDirectory(fi.Directory.FullName);
				// IMPORTANT: Make sure this method don't have any static references to x360ce.Engine library or
				// program tries to load x360ce.Engine.dll before AssemblyResolve event is available and fails.
				AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(CurrentDomain_AssemblyResolve);
				if (!RuntimePolicyHelper.LegacyV2RuntimeEnabledSuccessfully)
				{
					// Failed to enable useLegacyV2RuntimeActivationPolicy at runtime.
				}
				Application.EnableVisualStyles();
				Application.SetCompatibleTextRenderingDefault(false);
				// Requires System.Configuration.Installl reference.
				var ic = new System.Configuration.Install.InstallContext(null, args);
				if (ic.Parameters.ContainsKey("Settings"))
				{
					OpenSettingsFolder(Application.UserAppDataPath);
					OpenSettingsFolder(Application.CommonAppDataPath);
					OpenSettingsFolder(Application.LocalUserAppDataPath);
					return;
				}
				if (!CheckSettings()) return;
				//Application.ThreadException += new System.Threading.ThreadExceptionEventHandler(Application_ThreadException);
				MainForm.Current = new MainForm();
				if (ic.Parameters.ContainsKey("Exit"))
				{
					MainForm.Current.BroadcastMessage(MainForm.wParam_Close);
					return;
				}
				if (!IsOneCopyRunningAlready())
				{
					Application.Run(MainForm.Current);
				}
			}
			catch (Exception ex)
			{
				var message = "";
				AddExceptionMessage(ex, ref message);
				if (ex.InnerException != null) AddExceptionMessage(ex.InnerException, ref message);
				var box = new Controls.MessageBoxForm();
				if (message.Contains("Could not load file or assembly 'Microsoft.DirectX"))
				{
					message += "===============================================================\r\n";
					message += "You can click the link below to download Microsoft DirectX.";
					box.MainLinkLabel.Text = "http://www.microsoft.com/en-us/download/details.aspx?id=35";
					box.MainLinkLabel.Visible = true;
				}
				var result = box.ShowForm(message, "Exception!", MessageBoxButtons.RetryCancel, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1);
				if (result == DialogResult.Cancel) Application.Exit();
			}
		}
		/// <summary>
		/// Scan for games
		/// </summary>
		/// <param name="sender"></param>
		/// <param name="e"></param>
		private void ScanButton_Click(object sender, EventArgs e)
		{
			MessageBoxForm form = new MessageBoxForm();
			form.StartPosition = FormStartPosition.CenterParent;
			var result = form.ShowForm("Scan for games on your computer?", "Scan", MessageBoxButtons.OKCancel, MessageBoxIcon.Question);
			if (result == DialogResult.OK)
			{
				var success = System.Threading.ThreadPool.QueueUserWorkItem(ScanGames);
				if (!success) ScanProgressLabel.Text = "Scan failed!";
			}
		}
示例#18
0
        private void ShowEnumeratedDevicesMenuItem_Click(object sender, EventArgs e)
        {
            var devices = ViGEm.HidGuardianHelper.GetEnumeratedDevices();
            var form    = new MessageBoxForm();

            form.StartPosition = FormStartPosition.CenterParent;
            var text = devices.Length == 0
                ? "None"
                : string.Join("\r\n", devices);

            form.ShowForm(text, "Enumerated Devices", MessageBoxButtons.OK, MessageBoxIcon.Information);
        }
示例#19
0
        void ResetPresetButton_Click(object sender, EventArgs e)
        {
            var text = string.Format("Do you really want to reset all Controller {0} settings?", ControllerIndex + 1);
            var form = new MessageBoxForm();

            form.StartPosition = FormStartPosition.CenterParent;
            var result = form.ShowForm(text, "Reset Controller Settings", MessageBoxButtons.YesNo, MessageBoxIcon.Question);

            if (result == DialogResult.Yes)
            {
                MainForm.Current.ReloadXinputSettings();
            }
        }
示例#20
0
        private void ShowEnumeratedDevicesMenuItem_Click(object sender, RoutedEventArgs e)
        {
            var devices = ViGEm.HidGuardianHelper.GetEnumeratedDevices();
            var form    = new MessageBoxForm();

            form.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
            var text = devices.Length == 0
                                ? "None"
                       // Join and make && visible.
                                : string.Join("\r\n", devices).Replace("&", "&&");

            form.ShowForm(text, "Enumerated Devices", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Information);
        }
示例#21
0
        private void ShowHiddenDevicesMenuItem_Click(object sender, EventArgs e)
        {
            var devices = ViGEm.HidGuardianHelper.GetAffected();
            var form    = new MessageBoxForm();

            form.StartPosition = FormStartPosition.CenterParent;
            var text = devices.Length == 0
                                ? "None"
                       // Join and make && visible.
                                : string.Join("\r\n", devices).Replace("&", "&&");

            form.ShowForm(text, "Affected Devices", MessageBoxButtons.OK, MessageBoxIcon.Information);
        }
示例#22
0
        private void DevicesDataGridView_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            if (e.RowIndex < 0 || e.ColumnIndex < 0)
            {
                return;
            }
            var grid   = (DataGridView)sender;
            var row    = grid.Rows[e.RowIndex];
            var column = grid.Columns[e.ColumnIndex];
            var ud     = (UserDevice)row.DataBoundItem;

            // If user clicked on the CheckBox column then...
            if (column == IsEnabledColumn)
            {
                // Changed check (enabled state) of the current item.
                ud.IsEnabled = !ud.IsEnabled;
            }
            else if (column == IsHiddenColumn)
            {
                if (ud.AllowHide)
                {
                    var canModify = ViGEm.HidGuardianHelper.CanModifyParameters(true);
                    if (canModify)
                    {
                        //var ids = AppHelper.GetIdsToAffect(ud.HidDeviceId, ud.HidHardwareIds);
                        var ids = new string[] { ud.DevDeviceId };
                        // If parent device ID is known then...
                        //if (!string.IsNullOrEmpty(parentDeviceId))
                        //{
                        ud.IsHidden = !ud.IsHidden;
                        if (ud.IsHidden)
                        {
                            ViGEm.HidGuardianHelper.InsertToAffected(ids);
                            //ViGEm.HidGuardianHelper.InsertToAffected(parentDeviceId, ud.HidDeviceId);
                        }
                        else
                        {
                            ViGEm.HidGuardianHelper.RemoveFromAffected(ids);
                            //ViGEm.HidGuardianHelper.RemoveFromAffected(parentDeviceId, ud.HidDeviceId);
                        }
                        //}
                    }
                    else
                    {
                        var form = new MessageBoxForm();
                        form.StartPosition = FormStartPosition.CenterParent;
                        form.ShowForm("Can't modify HID Guardian registry.\r\nPlease run this application as Administrator once in order to fix permissions.", "Permission Denied", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    }
                }
            }
        }
        private void ResetToDefaultButton_Click(object sender, EventArgs e)
        {
            MessageBoxForm form = new MessageBoxForm();

            form.StartPosition = FormStartPosition.CenterParent;
            var result = form.ShowForm("Reset current settings to default?", "Reset", MessageBoxButtons.OKCancel, MessageBoxIcon.Question);

            if (result == DialogResult.OK)
            {
                _CurrentGame.XInputMask = _DefaultSettings.XInputMask;
                _CurrentGame.HookMask   = _DefaultSettings.HookMask;
                UpdateInterface();
            }
        }
示例#24
0
        /// <summary>
        /// Scan for games
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ScanButton_Click(object sender, EventArgs e)
        {
            MessageBoxForm form = new MessageBoxForm();

            form.StartPosition = FormStartPosition.CenterParent;
            var result = form.ShowForm("Scan for games on your computer?", "Scan", MessageBoxButtons.OKCancel, MessageBoxIcon.Question);

            if (result == DialogResult.OK)
            {
                var success = System.Threading.ThreadPool.QueueUserWorkItem(ScanGames);
                if (!success)
                {
                    ScanProgressLabel.Text = "Scan failed!";
                }
            }
        }
        private void MySettingsDeleteButton_Click(object sender, EventArgs e)
        {
            var form = new MessageBoxForm();

            form.StartPosition = FormStartPosition.CenterParent;
            var result = form.ShowForm("Do you really want to delete selected setting from Internet Settings Database?", MainForm.Current.Text, MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question);

            if (result == DialogResult.Yes)
            {
                mainForm.LoadingCircle = true;
                var setting = (UserSetting)MyDevicesDataGridView.SelectedRows[0].DataBoundItem;
                var ws      = new WebServiceClient();
                ws.Url = MainForm.Current.OptionsPanel.InternetDatabaseUrlComboBox.Text;
                ws.DeleteSettingCompleted += ws_DeleteSettingCompleted;
                ws.DeleteSettingAsync(setting);
            }
        }
示例#26
0
		private void ResetToDefaultButton_Click(object sender, EventArgs e)
		{
			MessageBoxForm form = new MessageBoxForm();
			form.StartPosition = FormStartPosition.CenterParent;
			var result = form.ShowForm("Reset current settings to default?", "Reset", MessageBoxButtons.OKCancel, MessageBoxIcon.Question);
			if (result == DialogResult.OK)
			{
				// Reset to default all properties which affects checksum.
				_CurrentGame.XInputMask = _DefaultSettings.XInputMask;
				_CurrentGame.HookMask = _DefaultSettings.HookMask;
				_CurrentGame.DInputMask = _DefaultSettings.DInputMask;
				_CurrentGame.DInputFile = _DefaultSettings.DInputFile ?? "";
				_CurrentGame.FakeVID = _DefaultSettings.FakeVID;
				_CurrentGame.FakePID = _DefaultSettings.FakePID;
				_CurrentGame.Timeout = _DefaultSettings.Timeout;
				UpdateInterface();
			}
		}
示例#27
0
        private void DevicesDataGridView_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            if (e.RowIndex < 0)
            {
                return;
            }
            var grid = (DataGridView)sender;
            var row  = grid.Rows[e.RowIndex];
            var item = (Engine.Data.UserDevice)row.DataBoundItem;

            // If user clicked on the CheckBox column then...
            if (e.ColumnIndex == grid.Columns[IsEnabledColumn.Name].Index)
            {
                // Changed check (enabled state) of the current item.
                item.IsEnabled = !item.IsEnabled;
            }
            else if (e.ColumnIndex == grid.Columns[IsHiddenColumn.Name].Index)
            {
                //var guardianHardwareId = ViGEm.HidGuardianHelper.GetHardwareId(item.HidDevicePath);
                var guardianHardwareId = item.HidDeviceId;
                if (!string.IsNullOrEmpty(guardianHardwareId))
                {
                    var canModify = ViGEm.HidGuardianHelper.CanModifyParameters(true);
                    if (canModify)
                    {
                        item.IsHidden = !item.IsHidden;
                        if (item.IsHidden)
                        {
                            ViGEm.HidGuardianHelper.InsertToAffected(guardianHardwareId);
                        }
                        else
                        {
                            ViGEm.HidGuardianHelper.RemoveFromAffected(guardianHardwareId);
                        }
                    }
                    else
                    {
                        MessageBoxForm form = new MessageBoxForm();
                        form.StartPosition = FormStartPosition.CenterParent;
                        form.ShowForm("Can't modify HID Guardian registry.\r\nPlease run this application as Aministrator once in order to fix permissions.", "Permission Denied", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    }
                }
            }
        }
示例#28
0
        static void Main(string[] args)
        {
            // First: Set working folder to the path of executable.
            var fi = new FileInfo(Application.ExecutablePath);

            Directory.SetCurrentDirectory(fi.Directory.FullName);
            // Prevent brave users from running this application from Windows folder.
            var winFolder = Environment.GetFolderPath(Environment.SpecialFolder.Windows);

            if (fi.FullName.StartsWith(winFolder, StringComparison.OrdinalIgnoreCase))
            {
                MessageBox.Show("Running from Windows folder is not allowed!\r\nPlease run this program from another folder.", "Windows Folder", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
            // IMPORTANT: Make sure this class don't have any static references to x360ce.Engine library or
            // program tries to load x360ce.Engine.dll before AssemblyResolve event is available and fails.
            AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(CurrentDomain_AssemblyResolve);
            if (IsDebug)
            {
                StartApp(args);
                return;
            }
            try
            {
                StartApp(args);
            }
            catch (Exception ex)
            {
                var message = ExceptionToText(ex);
                var box     = new Controls.MessageBoxForm();
                if (message.Contains("Could not load file or assembly 'Microsoft.DirectX"))
                {
                    message += "===============================================================\r\n";
                    message += "You can click the link below to download Microsoft DirectX.";
                    box.MainLinkLabel.Text    = "http://www.microsoft.com/en-us/download/details.aspx?id=35";
                    box.MainLinkLabel.Visible = true;
                }
                var result = box.ShowForm(message, "Exception!", MessageBoxButtons.RetryCancel, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1);
                if (result == DialogResult.Cancel)
                {
                    Application.Exit();
                }
            }
        }
示例#29
0
        private void DevicesDataGridView_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            if (e.RowIndex < 0 || e.ColumnIndex < 0)
            {
                return;
            }
            var grid   = (DataGridView)sender;
            var row    = grid.Rows[e.RowIndex];
            var column = grid.Columns[e.ColumnIndex];
            var ud     = (UserDevice)row.DataBoundItem;

            // If user clicked on the CheckBox column then...
            if (column == IsEnabledColumn)
            {
                // Changed check (enabled state) of the current item.
                ud.IsEnabled = !ud.IsEnabled;
            }
            else if (column == IsHiddenColumn)
            {
                if (ud.AllowHide)
                {
                    var canModify = ViGEm.HidGuardianHelper.CanModifyParameters(true);
                    if (canModify)
                    {
                        //var ids = AppHelper.GetIdsToAffect(ud.HidDeviceId, ud.HidHardwareIds);
                        var ids = new string[] { ud.DevDeviceId };
                        ud.IsHidden = !ud.IsHidden;
                        // Use begin invoke which will prevent mouse multi-select rows.
                        ControlsHelper.BeginInvoke(() =>
                        {
                            AppHelper.SynchronizeToHidGuardian(ud.InstanceGuid);
                        });
                    }
                    else
                    {
                        var form = new MessageBoxForm();
                        form.StartPosition = FormStartPosition.CenterParent;
                        form.ShowForm("Can't modify HID Guardian registry.\r\nPlease run this application as Administrator once in order to fix permissions.", "Permission Denied", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    }
                }
            }
        }
        void LoadMySetting()
        {
            mainForm.UpdateTimer.Stop();
            if (ControllerComboBox.SelectedItem == null)
            {
                return;
            }
            var name = ((KeyValuePair)ControllerComboBox.SelectedItem).Key;

            if (MyDevicesDataGridView.SelectedRows.Count == 0)
            {
                return;
            }
            var title   = "Load My Setting?";
            var setting = (UserSetting)MyDevicesDataGridView.SelectedRows[0].DataBoundItem;
            var message = "Do you want to load My Setting:";

            message += "\r\n\r\n    " + setting.ProductName;
            if (!string.IsNullOrEmpty(setting.FileName))
            {
                message += " | " + setting.FileName;
            }
            if (!string.IsNullOrEmpty(setting.FileProductName))
            {
                message += " | " + setting.FileProductName;
            }
            message += "\r\n\r\nfor \"" + name + "\" controller?";
            MessageBoxForm form = new MessageBoxForm();

            form.StartPosition = FormStartPosition.CenterParent;
            var result = form.ShowForm(message, title, MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1);

            if (result == DialogResult.Yes)
            {
                LoadSetting(setting.PadSettingChecksum);
            }
            else
            {
                mainForm.UpdateTimer.Start();
            }
        }
        private void SettingsDeleteButton_Click(object sender, EventArgs e)
        {
            var grid         = SettingsDataGridView;
            var userSettings = grid.SelectedRows.Cast <DataGridViewRow>().Select(x => (Setting)x.DataBoundItem).ToArray();
            var form         = new MessageBoxForm();

            form.StartPosition = FormStartPosition.CenterParent;
            var result = form.ShowForm("Do you want to delete selected settings?", "X360CE - Delete Settings", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question);

            if (result == DialogResult.Yes)
            {
                foreach (var item in userSettings)
                {
                    SettingsManager.Settings.Items.Remove(item);
                }
                SettingsManager.Save();
                MainForm.Current.CloudPanel.Add(CloudAction.Delete, userSettings, true);
            }
            form.Dispose();
            form = null;
        }
示例#32
0
 public bool CreateFile(string resourceName, string destinationFileName, ProcessorArchitecture oldArchitecture, ProcessorArchitecture newArchitecture)
 {
     if (destinationFileName == null) destinationFileName = resourceName;
     DialogResult answer;
     var form = new MessageBoxForm();
     form.StartPosition = FormStartPosition.CenterParent;
     var oldDesc = EngineHelper.GetProcessorArchitectureDescription(oldArchitecture);
     var newDesc = EngineHelper.GetProcessorArchitectureDescription(newArchitecture);
     var fileName = new FileInfo(destinationFileName).Name;
     answer = form.ShowForm(
         string.Format("You are running {2} application but {0} on the disk was built for {1} architecture.\r\n\r\nDo you want to replace {0} file with {2} version?", fileName, oldDesc, newDesc),
         "Processor architecture mismatch.",
         MessageBoxButtons.YesNo, MessageBoxIcon.Information);
     if (answer == DialogResult.Yes)
     {
         return AppHelper.WriteFile(resourceName, destinationFileName);
     }
     return true;
 }
示例#33
0
 public bool CreateFile(string sourceFileName, string destinationFileName = null, Version dllVersion = null, Version newVersion = null)
 {
     if (destinationFileName == null) destinationFileName = sourceFileName;
     DialogResult answer;
     var form = new MessageBoxForm();
     form.StartPosition = FormStartPosition.CenterParent;
     if (newVersion == null)
     {
         answer = form.ShowForm(
             string.Format("'{0}' was not found.\r\nThis file is required for emulator to function properly.\r\n\r\nDo you want to create this file?", new System.IO.FileInfo(destinationFileName).FullName),
             string.Format("'{0}' was not found.", destinationFileName),
             MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
     }
     else
     {
         answer = form.ShowForm(
             string.Format("New version of this file is available:\r\n{0}\r\n\r\nOld version: {1}\r\nNew version: {2}\r\n\r\nDo you want to update this file?", new System.IO.FileInfo(destinationFileName).FullName, dllVersion, newVersion),
             string.Format("New version of '{0}' file is available.", destinationFileName),
             MessageBoxButtons.YesNo, MessageBoxIcon.Information);
     }
     if (answer == DialogResult.Yes)
     {
         var assembly = Assembly.GetExecutingAssembly();
         var sr = assembly.GetManifestResourceStream(this.GetType().Namespace + ".Presets." + sourceFileName);
         FileStream sw = null;
         try
         {
             sw = new FileStream(destinationFileName, FileMode.Create, FileAccess.Write);
         }
         catch (Exception)
         {
             Elevate();
             return false;
         }
         var buffer = new byte[1024];
         while (true)
         {
             var count = sr.Read(buffer, 0, buffer.Length);
             if (count == 0) break;
             sw.Write(buffer, 0, count);
         }
         sr.Close();
         sw.Close();
     }
     return true;
 }
示例#34
0
 public void ReloadLibrary()
 {
     Program.ReloadCount++;
     settingsChanged = false;
     var dllInfo = Helper.GetDefaultDll();
     if (dllInfo != null && dllInfo.Exists)
     {
         bool byMicrosoft;
         var dllVersion = GetDllVersion(dllInfo.FullName, out byMicrosoft);
         StatusDllLabel.Text = dllInfo.Name + " " + dllVersion.ToString() + (byMicrosoft ? " (Microsoft)" : "");
         // If fast reload od settings is supported then...
         lock (XInputLock)
         {
             if (XInput.IsResetSupported)
             {
                 XInput.Reset();
             }
             // Slow: Reload whole x360ce.dll.
             XInput.ReLoadLibrary(dllInfo.Name);
             if (!XInput.IsLoaded)
             {
                 var msg = string.Format("Failed to load '{0}'", dllInfo.Name);
                 var form = new MessageBoxForm();
                 form.StartPosition = FormStartPosition.CenterParent;
                 form.ShowForm(msg, msg, MessageBoxButtons.OK, MessageBoxIcon.Error);
             }
         }
     }
     else
     {
         StatusDllLabel.Text = "";
     }
 }
示例#35
0
 bool CheckFiles(bool createIfNotExist)
 {
     if (createIfNotExist)
     {
         // If ini file doesn't exists.
         if (!System.IO.File.Exists(SettingManager.IniFileName))
         {
             if (!CreateFile(SettingManager.IniFileName)) return false;
         }
         // If xinput file doesn't exists.
         var embeddedDllVersion = Helper.GetEmbeddedDllVersion();
         var file = Helper.GetDefaultDll();
         if (file == null)
         {
             if (!CreateFile(Helper.dllFile3)) return false;
         }
         else
         {
             bool byMicrosoft;
             var dllVersion = GetDllVersion(file.Name, out byMicrosoft);
             if (dllVersion < embeddedDllVersion)
             {
                 CreateFile(Helper.dllFile3, file.Name, dllVersion,  embeddedDllVersion);
                 return true;
             }
         }
     }
     // Can't run witout ini.
     if (!File.Exists(SettingManager.IniFileName))
     {
         var form = new MessageBoxForm();
         form.StartPosition = FormStartPosition.CenterParent;
         form.ShowForm(
         string.Format("Configuration file '{0}' is required for application to run!", SettingManager.IniFileName),
         "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning);
         this.Close();
         return false;
     }
     // If temp file exist then.
     FileInfo iniTmp = new FileInfo(SettingManager.TmpFileName);
     if (iniTmp.Exists)
     {
         // It means that application crashed. Restore ini from temp.
         if (!CopyFile(iniTmp.FullName, SettingManager.IniFileName)) return false;
     }
     else
     {
         // Create temp file to store original settings.
         if (!CopyFile(SettingManager.IniFileName, SettingManager.TmpFileName)) return false;
     }
     // Set status labels.
     StatusIsAdminLabel.Text = Win32.WinAPI.IsVista
         ? string.Format("Elevated: {0}", Win32.WinAPI.IsElevated())
         : "";
     StatusIniLabel.Text = SettingManager.IniFileName;
     return true;
 }
示例#36
0
        public void ReloadLibrary()
        {
            Program.ReloadCount++;
            settingsChanged = false;
            var dllInfo = EngineHelper.GetDefaultDll();
            if (dllInfo != null && dllInfo.Exists)
            {
                bool byMicrosoft;
                var dllVersion = EngineHelper.GetDllVersion(dllInfo.FullName, out byMicrosoft);
                StatusDllLabel.Text = dllInfo.Name + " " + dllVersion.ToString() + (byMicrosoft ? " (Microsoft)" : "");
                // If fast reload of settings is supported then...
                lock (XInputLock)
                {
                    if (XInput.IsResetSupported)
                    {
                        XInput.Reset();
                    }
                    // Slow: Reload whole x360ce.dll.
                    Exception error;
                    XInput.ReLoadLibrary(dllInfo.Name, out error);
                    if (!XInput.IsLoaded)
                    {
                        var caption = string.Format("Failed to load '{0}'", dllInfo.Name);
                        var text = string.Format("{0}", error == null ? "Unknown error" : error.Message);
                        var form = new MessageBoxForm();
                        form.StartPosition = FormStartPosition.CenterParent;
                        form.ShowForm(text, caption, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                    else
                    {
                        for (int i = 0; i < 4; i++)
                        {

                            var currentPadControl = ControlPads[i];
                            currentPadControl.UpdateForceFeedBack();
                        }
                    }
                }
            }
            else
            {
                StatusDllLabel.Text = "";
            }
        }
示例#37
0
        bool CheckFiles(bool createIfNotExist)
        {
            if (createIfNotExist)
            {
                // If INI file doesn't exists.
                if (!System.IO.File.Exists(SettingManager.IniFileName))
                {
                    if (!CreateFile(this.GetType().Namespace + ".Presets." + SettingManager.IniFileName, SettingManager.IniFileName)) return false;
                }
                // If XInput file doesn't exists.
                var architecture = Assembly.GetExecutingAssembly().GetName().ProcessorArchitecture;
                var embeddedDllVersion = EngineHelper.GetEmbeddedDllVersion(architecture);
                var file = EngineHelper.GetDefaultDll();
                // If XInput DLL was not found then...
                if (file == null)
                {
                    var xFile = JocysCom.ClassLibrary.ClassTools.EnumTools.GetDescription(XInputMask.XInput13_x86);
                    if (!CreateFile(EngineHelper.GetXInputResoureceName(), xFile)) return false;
                }
                else
                {
                    bool byMicrosoft;
                    var dllVersion = EngineHelper.GetDllVersion(file.Name, out byMicrosoft);
                    // If file on the disk is older then...
                    if (dllVersion < embeddedDllVersion)
                    {
                        // Offer upgrade.
                        CreateFile(EngineHelper.GetXInputResoureceName(), file.Name, dllVersion, embeddedDllVersion);
                    }
                    var xiCurrentArchitecture = Engine.Win32.PEReader.GetProcessorArchitecture(file.Name);
                    if (architecture != xiCurrentArchitecture)
                    {
                        // Offer upgrade.
                        CreateFile(EngineHelper.GetXInputResoureceName(), file.Name, xiCurrentArchitecture, architecture);
                        return true;
                    }

                }
            }
            // Can't run without INI.
            if (!File.Exists(SettingManager.IniFileName))
            {
                var form = new MessageBoxForm();
                form.StartPosition = FormStartPosition.CenterParent;
                form.ShowForm(
                string.Format("Configuration file '{0}' is required for application to run!", SettingManager.IniFileName),
                "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                this.Close();
                return false;
            }
            // If temp file exist then.
            FileInfo iniTmp = new FileInfo(SettingManager.TmpFileName);
            if (iniTmp.Exists)
            {
                // It means that application crashed. Restore INI from temp.
                if (!AppHelper.CopyFile(iniTmp.FullName, SettingManager.IniFileName)) return false;
            }
            else
            {
                // Create temp file to store original settings.
                if (!AppHelper.CopyFile(SettingManager.IniFileName, SettingManager.TmpFileName)) return false;
            }
            // Set status labels.
            StatusIsAdminLabel.Text = WinAPI.IsVista
                ? string.Format("Elevated: {0}", WinAPI.IsElevated())
                : "";
            StatusIniLabel.Text = SettingManager.IniFileName;
            return true;
        }
示例#38
0
        void MainForm_FormClosing(object sender, FormClosingEventArgs e)
        {
            Program.IsClosing = true;
            UpdateTimer.Stop();
            // Disable force feedback effect before closing app.
            try
            {
                lock (XInputLock)
                {
                    for (int i = 0; i < 4; i++)
                    {
                        if (ControlPads[i].LeftMotorTestTrackBar.Value > 0 || ControlPads[i].RightMotorTestTrackBar.Value > 0)
                        {
                            var gamePad = GamePads[i];
                            if (XInput.IsLoaded && gamePad.IsConnected)
                            {
                                gamePad.SetVibration(new Vibration());
                            }
                        }

                    }
                    //BeginInvoke((MethodInvoker)delegate()
                    //{
                    //	XInput.FreeLibrary();
                    //});
                }
                System.Threading.Thread.Sleep(100);
            }
            catch (Exception) { }
            var tmp = new FileInfo(SettingManager.TmpFileName);
            var ini = new FileInfo(SettingManager.IniFileName);
            if (tmp.Exists)
            {
                // Before renaming file check for changes.
                var changed = false;
                if (tmp.Length != ini.Length) { changed = true; }
                else
                {
                    var tmpChecksum = EngineHelper.GetFileChecksum(tmp.FullName);
                    var iniChecksum = EngineHelper.GetFileChecksum(ini.FullName);
                    changed = !tmpChecksum.Equals(iniChecksum);
                }
                if (changed)
                {
                    var form = new MessageBoxForm();
                    form.StartPosition = FormStartPosition.CenterParent;
                    var result = form.ShowForm(
                    "Do you want to save changes you made to configuration?",
                    "Save Changes?",
                    MessageBoxButtons.YesNoCancel, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1);
                    if (result == DialogResult.Yes)
                    {
                        // Do nothing since INI contains latest updates.
                    }
                    else if (result == DialogResult.No)
                    {
                        // Rename temp to INI.
                        tmp.CopyTo(SettingManager.IniFileName, true);
                    }
                    else if (result == DialogResult.Cancel)
                    {
                        e.Cancel = true;
                        return;
                    }
                }
                // delete temp.
                tmp.Delete();
            }
        }
		/// <summary>Displays a message box with the specified text, caption, buttons, icon, and default button.</summary>
		/// <param name="text">The text to display in the message box.</param>
		/// <param name="caption">The text to display in the title bar of the message box.</param>
		/// <param name="buttons">One of the <see cref="T:System.Windows.Forms.MessageBoxButtons" /> values that specifies which buttons to display in the message box.</param>
		/// <param name="icon">One of the <see cref="T:System.Windows.Forms.MessageBoxIcon" /> values that specifies which icon to display in the message box.</param>
		/// <param name="defaultButton">One of the <see cref="T:System.Windows.Forms.MessageBoxDefaultButton" /> values that specifies the default button for the message box.</param>
		/// <returns>One of the <see cref="T:System.Windows.Forms.DialogResult" /> values.</returns>
		public static System.Windows.Forms.DialogResult Show(string text, string caption, MessageBoxButtons buttons, MessageBoxIcon icon, MessageBoxDefaultButton defaultButton)
		{
			MessageBoxForm form = new MessageBoxForm();
			form.StartPosition = FormStartPosition.CenterScreen;
			return form.ShowForm(text, caption, buttons, icon, defaultButton);
		}
示例#40
0
 public bool CreateFile(string resourceName, string destinationFileName, Version oldVersion = null, Version newVersion = null)
 {
     if (destinationFileName == null) destinationFileName = resourceName;
     DialogResult answer;
     var form = new MessageBoxForm();
     form.StartPosition = FormStartPosition.CenterParent;
     var fileName = new FileInfo(destinationFileName).FullName;
     if (newVersion == null)
     {
         answer = form.ShowForm(
             string.Format("'{0}' was not found.\r\nThis file is required for emulator to function properly.\r\n\r\nDo you want to create this file?", fileName),
             string.Format("'{0}' was not found.", destinationFileName),
             MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
     }
     else
     {
         answer = form.ShowForm(
             string.Format("New version of this file is available:\r\n{0}\r\n\r\nOld version: {1}\r\nNew version: {2}\r\n\r\nDo you want to update this file?", fileName, oldVersion, newVersion),
             string.Format("New version of '{0}' file is available.", destinationFileName),
             MessageBoxButtons.YesNo, MessageBoxIcon.Information);
     }
     if (answer == DialogResult.Yes)
     {
         return AppHelper.WriteFile(resourceName, destinationFileName);
     }
     return true;
 }
示例#41
0
 public void Load()
 {
     bool settingsLoaded = false;
     var settingsFi = new System.IO.FileInfo(InitialFile.FullName);
     // If configuration file exists then...
     if (settingsFi.Exists)
     {
         // Try to read file until success.
         while (true)
         {
             SettingsFile data;
             // Deserialize and load data.
             lock (saveReadFileLock)
             {
                 try
                 {
                     data = Serializer.DeserializeFromXmlFile<SettingsFile>(InitialFile.FullName);
                     if (data != null && data.IsValidVersion())
                     {
                         Programs.Clear();
                         if (data.Programs != null)
                         {
                             // Make sure default settings have unique by file name.
                             var distinctPrograms = data.Programs
                                 .GroupBy(p => p.FileName.ToLower())
                                 .Select(g => g.First())
                                 .ToList();
                             for (int i = 0; i < distinctPrograms.Count; i++)
                             {
                                 Programs.Add(distinctPrograms[i]);
                             }
                         }
                         Games.Clear();
                         if (data.Games != null)
                         {
                             // Make sure default settings have unique by file name.
                             var distinctGames = data.Games
                                 .GroupBy(p => p.FileName.ToLower())
                                 .Select(g => g.First())
                                 .ToList();
                             for (int i = 0; i < distinctGames.Count; i++)
                             {
                                 Games.Add(distinctGames[i]);
                             }
                         }
                         Pads.Clear();
                         if (data.Pads != null) for (int i = 0; i < data.Pads.Count; i++) Pads.Add(data.Pads[i]);
                         settingsLoaded = true;
                     }
                     break;
                 }
                 catch (Exception)
                 {
                     var form = new MessageBoxForm();
                     var backupFile = InitialFile.FullName + ".bak";
                     form.StartPosition = FormStartPosition.CenterParent;
                     var result = form.ShowForm(
                         "User settings file has become corrupted.\r\n" +
                         "Program must reset your user settings in order to continue.\r\n\r\n" +
                         "   Click [Yes] to reset your user settings and continue.\r\n" +
                         "   Click [No] if you wish to attempt manual repair.\r\n\r\n" +
                         "Settings File: " + InitialFile.FullName,
                         "Corrupt user settings of " + Application.ProductName, MessageBoxButtons.YesNo, MessageBoxIcon.Error);
                     if (result == DialogResult.Yes)
                     {
                         if (System.IO.File.Exists(backupFile))
                         {
                             System.IO.File.Copy(backupFile, InitialFile.FullName, true);
                             settingsFi.Refresh();
                         }
                         else
                         {
                             System.IO.File.Delete(InitialFile.FullName);
                             break;
                         }
                     }
                     else
                     {
                         // Avoid the inevitable crash by killing application first.
                         Process.GetCurrentProcess().Kill();
                         return;
                     }
                 }
             }
         }
     }
     // If settings failed to load then...
     if (!settingsLoaded)
     {
         // Get internal resources.
         var resource = EngineHelper.GetResource("x360ce_Games.xml.gz");
         // If internal preset was found.
         if (resource != null)
         {
             var sr = new StreamReader(resource);
             var compressedBytes = default(byte[]);
             using (var memstream = new MemoryStream())
             {
                 sr.BaseStream.CopyTo(memstream);
                 compressedBytes = memstream.ToArray();
             }
             var bytes = EngineHelper.Decompress(compressedBytes);
             var xml = System.Text.Encoding.UTF8.GetString(bytes);
             var programs = Serializer.DeserializeFromXmlString<List<x360ce.Engine.Data.Program>>(xml);
             Programs.Clear();
             for (int i = 0; i < programs.Count; i++) Programs.Add(programs[i]);
         }
     }
     // Check if current app doesn't exist in the list then...
     var currentFile = new System.IO.FileInfo(Application.ExecutablePath);
     var currentGame = Games.FirstOrDefault(x => x.FileName.ToLower() == currentFile.Name.ToLower());
     if (currentGame == null)
     {
         // Add x360ce.exe
         var item = x360ce.Engine.Data.Game.FromDisk(currentFile.Name);
         var program = Programs.FirstOrDefault(x => x.FileName.ToLower() == currentFile.Name.ToLower());
         item.LoadDefault(program);
         SettingsFile.Current.Games.Add(item);
     }
     else
     {
         currentGame.FullPath = currentFile.FullName;
     }
     if (!settingsLoaded)
     {
         Save(true);
     }
 }
		void DeleteSelectedPrograms()
		{
			var grid = ProgramsDataGridView;
			var selection = JocysCom.ClassLibrary.Controls.ControlsHelper.GetSelection<string>(grid, "FileName");
			var itemsToDelete = SettingManager.Programs.Items.Where(x => selection.Contains(x.FileName)).ToArray();
			MessageBoxForm form = new MessageBoxForm();
			form.StartPosition = FormStartPosition.CenterParent;
			string message;
			if (itemsToDelete.Length == 1)
			{
				var item = itemsToDelete[0];
				message = string.Format("Are you sure you want to delete default settings for?\r\n\r\n\tFile Name: {0}\r\n\tProduct Name: {1}",
					item.FileName,
					item.FileProductName);
			}
			else
			{
				message = string.Format("Delete {0} default setting(s)?", itemsToDelete.Length);
			}
			var result = form.ShowForm(message, "Delete", MessageBoxButtons.OKCancel, MessageBoxIcon.Exclamation);
			if (result == DialogResult.OK)
			{
				foreach (var item in itemsToDelete)
				{
					SettingManager.Programs.Items.Remove(item);
				}
				SettingManager.Save();
			}
		}
示例#43
0
 static void Main(string[] args)
 {
     try
     {
         //var fi = new FileInfo(Application.ExecutablePath);
         //Directory.SetCurrentDirectory(fi.Directory.FullName);
         // IMPORTANT: Make sure this method don't have any static references to x360ce.Engine library or
         // program tries to load x360ce.Engine.dll before AssemblyResolve event is available and fails.
         AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(CurrentDomain_AssemblyResolve);
         if (!RuntimePolicyHelper.LegacyV2RuntimeEnabledSuccessfully)
         {
             // Failed to enable useLegacyV2RuntimeActivationPolicy at runtime.
         }
         Application.EnableVisualStyles();
         Application.SetCompatibleTextRenderingDefault(false);
         // Requires System.Configuration.Installl reference.
         var ic = new System.Configuration.Install.InstallContext(null, args);
         if (ic.Parameters.ContainsKey("Settings"))
         {
             OpenSettingsFolder(Application.UserAppDataPath);
             OpenSettingsFolder(Application.CommonAppDataPath);
             OpenSettingsFolder(Application.LocalUserAppDataPath);
             return;
         }
         if (!CheckSettings())
         {
             return;
         }
         //Application.ThreadException += new System.Threading.ThreadExceptionEventHandler(Application_ThreadException);
         MainForm.Current = new MainForm();
         if (ic.Parameters.ContainsKey("Exit"))
         {
             MainForm.Current.BroadcastMessage(MainForm.wParam_Close);
             return;
         }
         if (!IsOneCopyRunningAlready())
         {
             Application.Run(MainForm.Current);
         }
     }
     catch (Exception ex)
     {
         var message = "";
         AddExceptionMessage(ex, ref message);
         if (ex.InnerException != null)
         {
             AddExceptionMessage(ex.InnerException, ref message);
         }
         var box = new Controls.MessageBoxForm();
         if (message.Contains("Could not load file or assembly 'Microsoft.DirectX"))
         {
             message += "===============================================================\r\n";
             message += "You can click the link below to download Microsoft DirectX.";
             box.MainLinkLabel.Text    = "http://www.microsoft.com/en-us/download/details.aspx?id=35";
             box.MainLinkLabel.Visible = true;
         }
         var result = box.ShowForm(message, "Exception!", MessageBoxButtons.RetryCancel, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1);
         if (result == DialogResult.Cancel)
         {
             Application.Exit();
         }
     }
 }
示例#44
0
 static void Main(string[] args)
 {
     try
     {
         AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(CurrentDomain_AssemblyResolve);
         if (!RuntimePolicyHelper.LegacyV2RuntimeEnabledSuccessfully)
         {
             // Failed to enable useLegacyV2RuntimeActivationPolicy at runtime.
         }
         Application.EnableVisualStyles();
         Application.SetCompatibleTextRenderingDefault(false);
         // Requires System.Configuration.Installl reference.
         var ic = new System.Configuration.Install.InstallContext(null, args);
         if (ic.Parameters.ContainsKey("Settings"))
         {
             OpenSettingsFolder(Application.UserAppDataPath);
             OpenSettingsFolder(Application.CommonAppDataPath);
             OpenSettingsFolder(Application.LocalUserAppDataPath);
             return;
         }
         if (!CheckSettings()) return;
         //Application.ThreadException += new System.Threading.ThreadExceptionEventHandler(Application_ThreadException);
         MainForm.Current = new MainForm();
         if (ic.Parameters.ContainsKey("Exit"))
         {
             MainForm.Current.BroadcastMessage(MainForm.wParam_Close);
             return;
         }
         var ini = new Ini(SettingManager.IniFileName);
         var oneCopy = !ini.File.Exists || ini.GetValue("Options", SettingName.AllowOnlyOneCopy) == "1";
         if (!(oneCopy && MainForm.Current.BroadcastMessage(MainForm.wParam_Restore)))
         {
             Application.Run(MainForm.Current);
         }
     }
     catch (Exception ex)
     {
         var message = "";
         AddExceptionMessage(ex, ref message);
         if (ex.InnerException != null) AddExceptionMessage(ex.InnerException, ref message);
         var box = new Controls.MessageBoxForm();
         if (message.Contains("Could not load file or assembly 'Microsoft.DirectX"))
         {
             message += "===============================================================\r\n";
             message += "You can click the link below to download Microsoft DirectX.";
             box.MainLinkLabel.Text = "http://www.microsoft.com/en-us/download/details.aspx?id=35";
             box.MainLinkLabel.Visible = true;
         }
         var result = box.ShowForm(message, "Exception!", MessageBoxButtons.RetryCancel, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1);
         if (result == DialogResult.Cancel) Application.Exit();
     }
 }