Пример #1
0
 /// <summary>
 /// Read settings from INI file into windows form controls.
 /// </summary>
 /// <param name="file">INI file containing settings.</param>
 /// <param name="iniSection">Read setings from specified section only. Null - read from all sections.</param>
 public void ReadSettings(string file)
 {
     var ini2 = new Ini(file);
     foreach (string path in SettingsMap.Keys)
     {
         string section = path.Split('\\')[0];
         // If this is PAD section.
         var padIndex = SettingName.GetPadIndex(path);
         if (padIndex > -1)
         {
             section = GetInstanceSection(padIndex);
             // If destination section is empty because controller is not connected then skip.
             if (string.IsNullOrEmpty(section)) continue;
         }
         Control control = SettingsMap[path];
         string key = path.Split('\\')[1];
         string v = ini2.GetValue(section, key);
         ReadSettingTo(control, key, v);
     }
     loadCount++;
     if (ConfigLoaded != null) ConfigLoaded(this, new SettingEventArgs(ini2.File.Name, loadCount));
     // Read XML too.
     SettingsFile.Current.Load();
 }
Пример #2
0
 /// <summary>
 /// Save setting from windows form control to current INI file.
 /// </summary>
 /// <param name="path">path of parameter (related to actual control)</param>
 /// <param name="dstIniSection">if not null then section will be different inside INI file than specified in path</param>
 public bool SaveSetting(Ini ini, string path)
 {
     var control = SettingsMap[path];
     string key = path.Split('\\')[1];
     string v = string.Empty;
     if (key == SettingName.HookMode || control.Name == "GamePadTypeComboBox" || control.Name == "ForceTypeComboBox")
     {
         var v1 = ((ComboBox)control).SelectedItem;
         if (v1 == null) { v = "0"; }
         else if (v1 is KeyValuePair) { v = ((KeyValuePair)v1).Value; }
         else { v = ((int)v1).ToString(); }
     }
     // If di menu strip attached.
     else if (control is ComboBox)
     {
         var cbx = (ComboBox)control;
         if (control.ContextMenuStrip == null)
         {
             v = control.Text;
         }
         else
         {
             v = new SettingsConverter(control.Text, key).ToIniSetting();
             // make sure that disabled button value is "0".
             if (SettingName.IsButton(key) && string.IsNullOrEmpty(v)) v = "0";
         }
     }
     else if (control is TextBox)
     {
         // if setting is readonly.
         if (key == SettingName.InstanceGuid || key == SettingName.ProductGuid)
         {
             v = string.IsNullOrEmpty(control.Text) ? Guid.Empty.ToString("D") : control.Text;
         }
         else v = control.Text;
     }
     else if (control is ListBox)
     {
         var lbx = (ListBox)control;
         v = string.Join(",", lbx.Items.Cast<string>().ToArray());
     }
     else if (control is NumericUpDown)
     {
         NumericUpDown nud = (NumericUpDown)control;
         v = nud.Value.ToString();
     }
     else if (control is TrackBar)
     {
         TrackBar tc = (TrackBar)control;
         // convert 100%  to 256
         if (key == SettingName.AxisToDPadDeadZone || key == SettingName.AxisToDPadOffset || key == SettingName.LeftTriggerDeadZone || key == SettingName.RightTriggerDeadZone)
         {
             v = System.Convert.ToInt32((float)tc.Value / 100F * 256F).ToString();
         }
         // convert 100%  to 500
         else if (key == SettingName.LeftMotorPeriod || key == SettingName.RightMotorPeriod)
         {
             v = System.Convert.ToInt32((float)tc.Value / 100F * 500F).ToString();
         }
         // Convert 100% to 32767
         else if (key == SettingName.LeftThumbDeadZoneX || key == SettingName.LeftThumbDeadZoneY || key == SettingName.RightThumbDeadZoneX || key == SettingName.RightThumbDeadZoneY)
         {
             v = System.Convert.ToInt32((float)tc.Value / 100F * ((float)Int16.MaxValue)).ToString();
         }
         else v = tc.Value.ToString();
     }
     else if (control is CheckBox)
     {
         CheckBox tc = (CheckBox)control;
         v = tc.Checked ? "1" : "0";
     }
     if (SettingName.IsThumbAxis(key))
     {
         v = v.Replace(SettingName.SType.Axis, "");
     }
     if (SettingName.IsDPad(key)) v = v.Replace(SettingName.SType.DPad, "");
     if (v == "v1") v = "UP";
     if (v == "v2") v = "RIGHT";
     if (v == "v3") v = "DOWN";
     if (v == "v4") v = "LEFT";
     if (v == "")
     {
         if (key == SettingName.DPadUp) v = "UP";
         if (key == SettingName.DPadDown) v = "DOWN";
         if (key == SettingName.DPadLeft) v = "LEFT";
         if (key == SettingName.DPadRight) v = "RIGHT";
     }
     // add comment.
     //var l = SettingName.MaxNameLength - key.Length + 24;
     //v = string.Format("{0, -" + l + "} # {1} Default: '{2}'.", v, SettingName.GetDescription(key), SettingName.GetDefaultValue(key));
     var section = path.Split('\\')[0];
     var padIndex = SettingName.GetPadIndex(path);
     // If this is PAD section then
     if (padIndex > -1)
     {
         section = GetInstanceSection(padIndex);
         // If destination section is empty because controller is not connected then skip.
         if (string.IsNullOrEmpty(section)) return false;
     }
     var oldValue = ini.GetValue(section, key);
     var saved = false;
     if (oldValue != v)
     {
         ini.SetValue(section, key, v);
         saveCount++;
         saved = true;
         if (ConfigSaved != null) ConfigSaved(this, new SettingEventArgs(IniFileName, saveCount));
     }
     // Flush XML too.
     SettingsFile.Current.Save();
     return saved;
 }
Пример #3
0
 /// <summary>
 /// Read PAD settings from INI file to form.
 /// </summary>
 /// <param name="file">INI file name.</param>
 /// <param name="iniSection">Source INI pad section.</param>
 /// <param name="padIndex">Destination pad index.</param>
 public void ReadPadSettings(string file, string iniSection, int padIndex)
 {
     var ini2 = new Ini(file);
     var pad = string.Format("PAD{0}", padIndex + 1);
     foreach (string path in SettingsMap.Keys)
     {
         string section = path.Split('\\')[0];
         if (section != pad) continue;
         string key = path.Split('\\')[1];
         Control control = SettingsMap[path];
         string dstPath = string.Format("{0}\\{1}", pad, key);
         control = SettingsMap[dstPath];
         string v = ini2.GetValue(iniSection, key);
         ReadSettingTo(control, key, v);
     }
     loadCount++;
     if (ConfigLoaded != null) ConfigLoaded(this, new SettingEventArgs(ini2.File.Name, loadCount));
 }
Пример #4
0
 /// <summary>
 /// Get PadSetting object from INI by device Instance GUID.
 /// </summary>
 /// <param name="instanceGuid">Instance GUID.</param>
 /// <returns>PadSettings object.</returns>
 public PadSetting GetPadSetting(string padSectionName)
 {
     var ini2 = new Ini(IniFileName);
     var ps = new PadSetting();
     ps.PadSettingChecksum = Guid.Empty;
     ps.AxisToDPadDeadZone = ini2.GetValue(padSectionName, SettingName.AxisToDPadDeadZone);
     ps.AxisToDPadEnabled = ini2.GetValue(padSectionName, SettingName.AxisToDPadEnabled);
     ps.AxisToDPadOffset = ini2.GetValue(padSectionName, SettingName.AxisToDPadOffset);
     ps.ButtonA = ini2.GetValue(padSectionName, SettingName.ButtonA);
     ps.ButtonB = ini2.GetValue(padSectionName, SettingName.ButtonB);
     ps.ButtonGuide = ini2.GetValue(padSectionName, SettingName.ButtonGuide);
     ps.ButtonBig = ini2.GetValue(padSectionName, SettingName.ButtonBig);
     ps.ButtonBack = ini2.GetValue(padSectionName, SettingName.ButtonBack);
     ps.ButtonStart = ini2.GetValue(padSectionName, SettingName.ButtonStart);
     ps.ButtonX = ini2.GetValue(padSectionName, SettingName.ButtonX);
     ps.ButtonY = ini2.GetValue(padSectionName, SettingName.ButtonY);
     ps.DPad = ini2.GetValue(padSectionName, SettingName.DPad);
     ps.DPadDown = ini2.GetValue(padSectionName, SettingName.DPadDown);
     ps.DPadLeft = ini2.GetValue(padSectionName, SettingName.DPadLeft);
     ps.DPadRight = ini2.GetValue(padSectionName, SettingName.DPadRight);
     ps.DPadUp = ini2.GetValue(padSectionName, SettingName.DPadUp);
     ps.ForceEnable = ini2.GetValue(padSectionName, SettingName.ForceEnable);
     ps.ForceOverall = ini2.GetValue(padSectionName, SettingName.ForceOverall);
     ps.ForceSwapMotor = ini2.GetValue(padSectionName, SettingName.ForceSwapMotor);
     ps.ForceType = ini2.GetValue(padSectionName, SettingName.ForceType);
     ps.GamePadType = ini2.GetValue(padSectionName, SettingName.GamePadType);
     ps.LeftMotorPeriod = ini2.GetValue(padSectionName, SettingName.LeftMotorPeriod);
     ps.LeftShoulder = ini2.GetValue(padSectionName, SettingName.LeftShoulder);
     ps.LeftThumbAntiDeadZoneX = ini2.GetValue(padSectionName, SettingName.LeftThumbAntiDeadZoneX);
     ps.LeftThumbAntiDeadZoneY = ini2.GetValue(padSectionName, SettingName.LeftThumbAntiDeadZoneY);
     ps.LeftThumbAxisX = ini2.GetValue(padSectionName, SettingName.LeftThumbAxisX);
     ps.LeftThumbAxisY = ini2.GetValue(padSectionName, SettingName.LeftThumbAxisY);
     ps.LeftThumbButton = ini2.GetValue(padSectionName, SettingName.LeftThumbButton);
     ps.LeftThumbDeadZoneX = ini2.GetValue(padSectionName, SettingName.LeftThumbDeadZoneX);
     ps.LeftThumbDeadZoneY = ini2.GetValue(padSectionName, SettingName.LeftThumbDeadZoneY);
     ps.LeftThumbDown = ini2.GetValue(padSectionName, SettingName.LeftThumbDown);
     ps.LeftThumbLeft = ini2.GetValue(padSectionName, SettingName.LeftThumbLeft);
     ps.LeftThumbRight = ini2.GetValue(padSectionName, SettingName.LeftThumbRight);
     ps.LeftThumbUp = ini2.GetValue(padSectionName, SettingName.LeftThumbUp);
     ps.LeftTrigger = ini2.GetValue(padSectionName, SettingName.LeftTrigger);
     ps.LeftTriggerDeadZone = ini2.GetValue(padSectionName, SettingName.LeftTriggerDeadZone);
     ps.PassThrough = ini2.GetValue(padSectionName, SettingName.PassThrough);
     ps.RightMotorPeriod = ini2.GetValue(padSectionName, SettingName.RightMotorPeriod);
     ps.RightShoulder = ini2.GetValue(padSectionName, SettingName.RightShoulder);
     ps.RightThumbAntiDeadZoneX = ini2.GetValue(padSectionName, SettingName.RightThumbAntiDeadZoneX);
     ps.RightThumbAntiDeadZoneY = ini2.GetValue(padSectionName, SettingName.RightThumbAntiDeadZoneY);
     ps.RightThumbAxisX = ini2.GetValue(padSectionName, SettingName.RightThumbAxisX);
     ps.RightThumbAxisY = ini2.GetValue(padSectionName, SettingName.RightThumbAxisY);
     ps.RightThumbButton = ini2.GetValue(padSectionName, SettingName.RightThumbButton);
     ps.RightThumbDeadZoneX = ini2.GetValue(padSectionName, SettingName.RightThumbDeadZoneX);
     ps.RightThumbDeadZoneY = ini2.GetValue(padSectionName, SettingName.RightThumbDeadZoneY);
     ps.RightThumbDown = ini2.GetValue(padSectionName, SettingName.RightThumbDown);
     ps.RightThumbLeft = ini2.GetValue(padSectionName, SettingName.RightThumbLeft);
     ps.RightThumbRight = ini2.GetValue(padSectionName, SettingName.RightThumbRight);
     ps.RightThumbUp = ini2.GetValue(padSectionName, SettingName.RightThumbUp);
     ps.RightTrigger = ini2.GetValue(padSectionName, SettingName.RightTrigger);
     ps.RightTriggerDeadZone = ini2.GetValue(padSectionName, SettingName.RightTriggerDeadZone);
     return ps;
 }
Пример #5
0
 public bool ContainsProductSection(Guid productGuid, string iniFileName, out string sectionName)
 {
     var ini2 = new Ini(iniFileName);
     var section = GetInstanceSection(productGuid);
     var contains = !string.IsNullOrEmpty(ini2.GetValue(section, "ProductGUID"));
     sectionName = contains ? section : null;
     return contains;
 }
Пример #6
0
 public bool ContainsInstanceSectionOld(Guid instanceGuid, string iniFileName, out string sectionName)
 {
     var ini2 = new Ini(iniFileName);
     for (int i = 1; i <= 4; i++)
     {
         var section = string.Format("PAD{0}", i);
         var v = ini2.GetValue(section, "InstanceGUID");
         if (string.IsNullOrEmpty(v)) continue;
         if (v.ToLower() == instanceGuid.ToString("D").ToLower())
         {
             sectionName = section;
             return true;
         }
     }
     sectionName = null;
     return false;
 }
Пример #7
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();
     }
 }