private void BMSChanged() { try { statusAssign = Status.GetNeutralPos; LargeTab.SelectedIndex = 0; // Read Theater List TheaterList.PopulateAndSave(appReg, Dropdown_TheaterList); // Read BMS-FULL.key string fname = appReg.GetInstallDir() + "\\User\\Config\\" + appReg.getKeyFileName(); string fnameauto = appReg.GetInstallDir() + "\\User\\Config\\" + appReg.getAutoKeyFileName(); if (!File.Exists(fnameauto)) { File.Copy(fname, fnameauto); } keyFile = new KeyFile(fnameauto, appReg); // Write Data Grid WriteDataGrid(); } catch (Exception ex) { Diagnostics.WriteLogFile(ex); Close(); } }
/// <summary> /// Make new instance. /// </summary> public void ImportStockSetup(AppRegInfo appReg, int devcount, int povnum, int joynum) { Invoke invokeStatus = Invoke.UI; Behaviour behaviourStatus = Behaviour.Press; string deviceSorting = appReg.GetInstallDir() + "/User/Config/DeviceSorting.txt"; if (Path.GetFileName(deviceSorting) != "DeviceSorting.txt") { return; } if (File.Exists(deviceSorting) == false) { return; } string[] lines = File.ReadAllLines(deviceSorting, Encoding.UTF8); int currentID = -1; for (int i = 0; i < lines.Length; i++) { if (lines[i] == GetDeviceSortingLine().Replace("\r\n", "")) { currentID = i; } } if (currentID == -1) { return; } string keyfile = appReg.GetInstallDir() + "/User/Config/" + appReg.getKeyFileName(); string[] Klines = File.ReadAllLines(keyfile, Encoding.UTF8); foreach (string stBuffer in Klines) { string[] stArrayData = stBuffer.Split(' '); if (stArrayData.Length < 7) { continue; } if (stBuffer.Substring(0, 1) == "#") { continue; } if (stArrayData[3] == "-2" | stArrayData[3] == "-3") { if (stArrayData[2] == "-1") { invokeStatus = Invoke.Default; } if (stArrayData[2] == "-2") { invokeStatus = Invoke.Down; } if (stArrayData[2] == "-4") { invokeStatus = Invoke.Up; } if (stArrayData[2] == "8") { invokeStatus = Invoke.UI; } if (stArrayData[3] == "0") { behaviourStatus = Behaviour.Press; } if (stArrayData[3] == "0x42") { behaviourStatus = Behaviour.Release; } } // Import DX Setup if (stArrayData[3] == "-2") { for (int i = 0; i < 32; i++) { if (int.Parse(stArrayData[1]) == i + currentID * 32) { dx[i].Assign(stArrayData[0], Pinky.UnShift, behaviourStatus, invokeStatus, 0); } if (int.Parse(stArrayData[1]) == i + currentID * 32 + devcount * 32) // Okay This has to be the problem. I have to read FalconBMS.cfg for { dx[i].Assign(stArrayData[0], Pinky.Shift, behaviourStatus, invokeStatus, 0); } } } // Import POV Setup if (stArrayData[3] == "-3") { for (int i = 0; i < 4; i++) { if (int.Parse(stArrayData[1]) != i) { continue; } if (povnum < 3) { if (i == 0 | i == 1) { pov[i].direction[int.Parse(stArrayData[4])].Assign(stArrayData[0], Pinky.UnShift, 0); } if (i == 2 | i == 3) { pov[i - 2].direction[int.Parse(stArrayData[4])].Assign(stArrayData[0], Pinky.Shift, 0); } continue; } pov[i].direction[int.Parse(stArrayData[4])].Assign(stArrayData[0], Pinky.UnShift, 0); } } // Import Axis Setup string filename = appReg.GetInstallDir() + "/User/Config/axismapping.dat"; if (!File.Exists(filename)) { return; } FileStream fs = new FileStream(filename, FileMode.Open, FileAccess.Read); byte[] ad = new byte[fs.Length]; fs.Read(ad, 0, ad.Length); fs.Close(); filename = appReg.GetInstallDir() + "/User/Config/joystick.cal"; if (!File.Exists(filename)) { return; } fs = new FileStream(filename, FileMode.Open, FileAccess.Read); byte[] jc = new byte[fs.Length]; fs.Read(jc, 0, jc.Length); fs.Close(); AxisName[] axisMappingList = appReg.getOverrideWriter().getAxisMappingList(); AxisName[] joystickCalList = appReg.getOverrideWriter().getJoystickCalList(); for (int i = 0; i < axisMappingList.Length; i++) { for (int ii = 0; ii < devcount; ii++) { if (ad[24 + i * 16] == currentID + 2) { int axisNum = ad[24 + i * 16 + 4]; AxCurve deadzone = AxCurve.None; if (ad[24 + i * 16 + 8] == 0x64) { deadzone = AxCurve.Small; } if (ad[24 + i * 16 + 8] == 0xF4) { deadzone = AxCurve.Medium; } if (ad[24 + i * 16 + 8] == 0xE8) { deadzone = AxCurve.Large; } AxCurve saturation = AxCurve.None; if (ad[24 + i * 16 + 12] == 0x1C) { saturation = AxCurve.Small; } if (ad[24 + i * 16 + 12] == 0x28) { saturation = AxCurve.Medium; } if (ad[24 + i * 16 + 12] == 0x34) { saturation = AxCurve.Large; } bool invert = false; for (int iii = 0; iii < joystickCalList.Length; iii++) { // read joystick.cal if (axisMappingList[i] != joystickCalList[iii]) { continue; } int invertnum = jc[iii * 28 + 20]; if (invertnum == 1) { invert = true; } } InGameAxAssgn inGameAxAssgn = new InGameAxAssgn(currentID, axisNum, invert, deadzone, saturation); axis[axisNum] = new AxAssgn(axisMappingList[i].ToString(), inGameAxAssgn); } } } } }
public KeyFile(string Filename, AppRegInfo appReg) { string stParentName = Path.GetDirectoryName(Filename); // Do BMS - FULL.key file exists at User/Config? if (File.Exists(Filename) == false) { MessageBoxResult result = MessageBox.Show ("App could not find " + Filename, "Error", MessageBoxButton.OK, MessageBoxImage.Exclamation); return; } string[] lines = File.ReadAllLines(Filename, Encoding.UTF8); keyAssign = new KeyAssgn[lines.Length]; int i = -1; foreach (string stBuffer in lines) { string[] stArrayData = stBuffer.Split(' '); if (stArrayData.Length < 7) { continue; } if (stBuffer.Substring(0, 1) == "#") { continue; } if (stArrayData[3] == "-2" | stArrayData[3] == "-3") { continue; } // Okay now this line is confirmed to be a line that shows keyboard assignment. i += 1; keyAssign[i] = new KeyAssgn(stBuffer); // What if the line format was broken? if (keyAssign[i].CheckFileCollapsing() == false) { continue; } MessageBoxResult result = MessageBox.Show ("App found " + appReg.getKeyFileName() + " broken\nWould you like to restore it to the default?", "Error", MessageBoxButton.OKCancel, MessageBoxImage.Exclamation); if (result == MessageBoxResult.OK) { string fnamestock = appReg.GetInstallDir() + "\\Docs\\Key Files & Input\\" + appReg.getKeyFileName(); string fname = appReg.GetInstallDir() + "\\User\\Config\\" + appReg.getKeyFileName(); if (File.Exists(fnamestock)) { File.Copy(fnamestock, fname, true); Application.Current.Shutdown(); Process.Start(Application.ResourceAssembly.Location); return; } MessageBox.Show("App could not find " + appReg.getKeyFileName() + " at\nDocs\\Key Files & Input\\", "Error", MessageBoxButton.OK, MessageBoxImage.Exclamation); Application.Current.Shutdown(); return; } Application.Current.Shutdown(); return; } Array.Resize(ref keyAssign, i + 1); }
/// <summary> /// Execute when launching this app. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void Window_Loaded(object sender, RoutedEventArgs e) { try { // load command line. string[] args = Environment.GetCommandLineArgs(); if (args.Length % 2 == 1) { Dictionary <string, string> option = new Dictionary <string, string>(); for (int index = 1; index < args.Length; index += 2) { option.Add(args[index], args[index + 1]); } if (option.ContainsKey("/yame")) { if (option["/yame"] == "true") { FLG_YAME64 = true; } } if (FLG_YAME64) { LargeTab.SelectedIndex = 1; Tab_Launcher.Visibility = Visibility.Collapsed; Background = new SolidColorBrush(Color.FromArgb(255, 240, 240, 240)); BackGroundBox1.Background = new SolidColorBrush(Color.FromArgb(255, 240, 240, 240)); BackGroundBox2.Background = new SolidColorBrush(Color.FromArgb(255, 240, 240, 240)); BackGroundBox3.Background = new SolidColorBrush(Color.FromArgb(255, 240, 240, 240)); BackGroundBox4.Background = new SolidColorBrush(Color.FromArgb(255, 240, 240, 240)); BackGroundImage.Opacity = 0; Button_Apply_YAME64.Visibility = Visibility.Visible; } else { Button_Apply_YAME64.Visibility = Visibility.Hidden; } } } catch (FileNotFoundException ex) { Console.WriteLine(ex.Message); StreamWriter sw = new StreamWriter("C:\\FBMSAltLauncherErrorLog.txt", false, System.Text.Encoding.GetEncoding("shift_jis")); sw.Write(ex.Message); sw.Close(); MessageBox.Show("Error Log Saved To C:\\FBMSAltLauncherErrorLog.txt", "WARNING", MessageBoxButton.OK, MessageBoxImage.Information); Close(); } // Load UI Properties(Like Button Status). appProperties = new AppProperties(this); // Read Registry appReg = new AppRegInfo(this); if (appReg.getBMSVersion() == BMS_Version.UNDEFINED) { Close(); return; } try { // Read Theater List TheaterList.Populate(appReg, Dropdown_TheaterList); // Get Devices deviceControl = new DeviceControl(appReg); neutralButtons = new NeutralButtons[deviceControl.devList.Count]; // Aquire joySticks AquireAll(true); // Reset All Axis Settings foreach (AxisName nme in axisNameList) { inGameAxis[nme.ToString()] = new InGameAxAssgn(); } joyAssign_2_inGameAxis(); ResetAssgnWindow(); // Read BMS-FULL.key string fname = appReg.GetInstallDir() + "\\User\\Config\\" + appReg.getKeyFileName(); keyFile = new KeyFile(fname, appReg); // Write Data Grid WriteDataGrid(); // Set Timer AxisMovingTimer.Tick += AxisMovingTimer_Tick; AxisMovingTimer.Interval = new TimeSpan(0, 0, 0, 0, 16); KeyMappingTimer.Tick += KeyMappingTimer_Tick; KeyMappingTimer.Interval = new TimeSpan(0, 0, 0, 0, 16); //System.Diagnostics.PresentationTraceSources.DataBindingSource.Switch.Level = System.Diagnostics.SourceLevels.Critical; } catch (FileNotFoundException ex) { Console.WriteLine(ex.Message); StreamWriter sw = new StreamWriter(appReg.GetInstallDir() + "\\Error.txt", false, System.Text.Encoding.GetEncoding("shift_jis")); sw.Write(ex.Message); sw.Close(); MessageBox.Show("Error Log Saved To " + appReg.GetInstallDir() + "\\Error.txt", "WARNING", MessageBoxButton.OK, MessageBoxImage.Information); Close(); } }