/// <summary>
        /// Execute when quiting this app.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Window_Closed(object sender, EventArgs e)
        {
            try
            {
                if (appReg == null)
                {
                    return;
                }

                // Save UI Properties(Like Button Status).
                appProperties.SaveUISetup();
                if (ApplicationOverride.IsChecked == false)
                {
                    appReg.getOverrideWriter().Execute(inGameAxis, deviceControl, keyFile);
                }
            }
            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();
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// As the name inplies...
        /// </summary>
        protected virtual void SaveJoystickCal(Hashtable inGameAxis, DeviceControl deviceControl)
        {
            string filename    = appReg.GetInstallDir() + "/User/Config/joystick.cal";
            string fbackupname = appReg.GetInstallDir() + "/User/Config/Backup/joystick.cal";

            if ((!System.IO.File.Exists(fbackupname)) & (System.IO.File.Exists(filename)))
            {
                System.IO.File.Copy(filename, fbackupname, true);
            }

            if (System.IO.File.Exists(filename))
            {
                System.IO.File.SetAttributes(filename, System.IO.File.GetAttributes(filename) & (~System.IO.FileAttributes.ReadOnly));
            }

            System.IO.FileStream fs = new System.IO.FileStream
                                          (filename, System.IO.FileMode.Create, System.IO.FileAccess.Write);

            byte[] bs;

            AxisName[] localJoystickCalList = appReg.getOverrideWriter().getJoystickCalList();
            foreach (AxisName nme in localJoystickCalList)
            {
                bs = new byte[]
                {
                    0x00, 0x00, 0x00, 0x00, 0x98, 0x3A, 0x00, 0x00,
                    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                    0x00, 0x00, 0x00, 0x00
                };
                if (((InGameAxAssgn)inGameAxis[nme.ToString()]).GetDeviceNumber() != -1)
                {
                    bs[12] = 0x01;

                    if (nme == AxisName.Throttle)
                    {
                        double iAB   = (double)deviceControl.throttlePos.GetAB();
                        double iIdle = (double)deviceControl.throttlePos.GetIDLE();

                        const double MAXIN  = 65536;
                        const double MAXOUT = 14848;

                        iAB   = -iAB * (MAXOUT / MAXIN) + MAXOUT;
                        iIdle = -iIdle * (MAXOUT / MAXIN) + MAXOUT;

                        byte[] ab   = BitConverter.GetBytes((int)iAB);
                        byte[] idle = BitConverter.GetBytes((int)iIdle);

                        bs[1] = ab[1];
                        bs[5] = idle[1];

                        if (deviceControl.throttlePos.GetAB() > (65536 - 256))
                        {
                            bs[1] = 0x00;
                        }
                        if (deviceControl.throttlePos.GetIDLE() < 256)
                        {
                            bs[5] = 0x3A;
                        }
                    }
                }
                if (((InGameAxAssgn)inGameAxis[nme.ToString()]).GetInvert())
                {
                    bs[20] = 0x01;
                }
                fs.Write(bs, 0, bs.Length);
            }
            fs.Close();
        }
Exemplo n.º 3
0
        /// <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 (System.IO.Path.GetFileName(deviceSorting) != "DeviceSorting.txt")
            {
                return;
            }
            if (System.IO.File.Exists(deviceSorting) == false)
            {
                return;
            }
            string[] lines     = System.IO.File.ReadAllLines(deviceSorting, Encoding.UTF8);
            int      currentID = -1;

            for (int i = 0; i < lines.Count(); i++)
            {
                if (lines[i] == this.GetDeviceSortingLine().Replace("\r\n", ""))
                {
                    currentID = i;
                }
            }
            if (currentID == -1)
            {
                return;
            }
            string keyfile = appReg.GetInstallDir() + "/User/Config/" + appReg.getKeyFileName();

            string[] Klines = System.IO.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 ((string)stArrayData[2] == "-1")
                    {
                        invokeStatus = Invoke.Default;
                    }
                    if ((string)stArrayData[2] == "-2")
                    {
                        invokeStatus = Invoke.Down;
                    }
                    if ((string)stArrayData[2] == "-4")
                    {
                        invokeStatus = Invoke.Up;
                    }
                    if ((string)stArrayData[2] == "8")
                    {
                        invokeStatus = Invoke.UI;
                    }
                    if ((string)stArrayData[3] == "0")
                    {
                        behaviourStatus = Behaviour.Press;
                    }
                    if ((string)stArrayData[3] == "0x42")
                    {
                        behaviourStatus = Behaviour.Release;
                    }
                }
                // Import DX Setup
                if (stArrayData[3] == "-2")
                {
                    for (int i = 0; i < 32; i++)
                    {
                        if (Int32.Parse(stArrayData[1]) == i + currentID * 32)
                        {
                            this.dx[i].Assign((string)stArrayData[0], Pinky.UnShift, behaviourStatus, invokeStatus, 0);
                        }
                        if (Int32.Parse(stArrayData[1]) == i + currentID * 32 + devcount * 32) // Okay This has to be the problem. I have to read FalconBMS.cfg for
                        {
                            this.dx[i].Assign((string)stArrayData[0], Pinky.Shift, behaviourStatus, invokeStatus, 0);
                        }
                    }
                }
                // Import POV Setup
                if (stArrayData[3] == "-3")
                {
                    for (int i = 0; i < 4; i++)
                    {
                        if (Int32.Parse(stArrayData[1]) != i)
                        {
                            continue;
                        }
                        if (povnum < 3)
                        {
                            if (i == 0 | i == 1)
                            {
                                this.pov[i].direction[Int32.Parse(stArrayData[4])].Assign((string)stArrayData[0], Pinky.UnShift, 0);
                            }
                            if (i == 2 | i == 3)
                            {
                                this.pov[i - 2].direction[Int32.Parse(stArrayData[4])].Assign((string)stArrayData[0], Pinky.Shift, 0);
                            }
                            continue;
                        }
                        this.pov[i].direction[Int32.Parse(stArrayData[4])].Assign((string)stArrayData[0], Pinky.UnShift, 0);
                    }
                }
                // Import Axis Setup
                string filename = appReg.GetInstallDir() + "/User/Config/axismapping.dat";
                if (!System.IO.File.Exists(filename))
                {
                    return;
                }
                System.IO.FileStream fs = new System.IO.FileStream(filename, System.IO.FileMode.Open, System.IO.FileAccess.Read);
                byte[] ad = new byte[fs.Length];
                fs.Read(ad, 0, ad.Length);
                fs.Close();

                filename = appReg.GetInstallDir() + "/User/Config/joystick.cal";
                if (!System.IO.File.Exists(filename))
                {
                    return;
                }
                fs = new System.IO.FileStream(filename, System.IO.FileMode.Open, System.IO.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.Count(); i++)
                {
                    for (int ii = 0; ii < devcount; ii++)
                    {
                        if ((int)ad[24 + i * 16] == currentID + 2)
                        {
                            int     axisNum  = (int)ad[24 + i * 16 + 4];
                            AxCurve deadzone = AxCurve.None;
                            if ((int)ad[24 + i * 16 + 8] == 0x64)
                            {
                                deadzone = AxCurve.Small;
                            }
                            if ((int)ad[24 + i * 16 + 8] == 0xF4)
                            {
                                deadzone = AxCurve.Medium;
                            }
                            if ((int)ad[24 + i * 16 + 8] == 0xE8)
                            {
                                deadzone = AxCurve.Large;
                            }
                            AxCurve saturation = AxCurve.None;
                            if ((int)ad[24 + i * 16 + 12] == 0x1C)
                            {
                                saturation = AxCurve.Small;
                            }
                            if ((int)ad[24 + i * 16 + 12] == 0x28)
                            {
                                saturation = AxCurve.Medium;
                            }
                            if ((int)ad[24 + i * 16 + 12] == 0x34)
                            {
                                saturation = AxCurve.Large;
                            }
                            bool invert = false;

                            for (int iii = 0; iii < joystickCalList.Count(); iii++)
                            {
                                // read joystick.cal
                                if (axisMappingList[i] != joystickCalList[iii])
                                {
                                    continue;
                                }
                                int invertnum = (int)jc[iii * 28 + 20];
                                if (invertnum == 1)
                                {
                                    invert = true;
                                }
                            }

                            InGameAxAssgn inGameAxAssgn = new InGameAxAssgn(currentID, axisNum, invert, deadzone, saturation);
                            this.axis[axisNum] = new AxAssgn(axisMappingList[i].ToString(), inGameAxAssgn);
                        }
                    }
                }
            }
        }
        /// <summary>
        ///  Launch BMS utilities.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Launch_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                System.Diagnostics.Process process;
                switch (((System.Windows.Controls.Button)sender).Name)
                {
                case "Launch_BMS":
                    string strCmdText = "";
                    if (CMD_ACMI.IsChecked == false)
                    {
                        strCmdText += "-acmi ";
                    }
                    if (CMD_WINDOW.IsChecked == false)
                    {
                        strCmdText += "-window ";
                    }
                    if (CMD_NOMOVIE.IsChecked == false)
                    {
                        strCmdText += "-nomovie ";
                    }
                    if (CMD_EF.IsChecked == false)
                    {
                        strCmdText += "-ef ";
                    }
                    if (CMD_MONO.IsChecked == false)
                    {
                        strCmdText += "-mono ";
                    }
                    strCmdText += "-bw " + appProperties.bandWidthDefault;

                    // OVERRIDE SETTINGS.
                    if (this.ApplicationOverride.IsChecked == true)
                    {
                        string textMessage = "You are going to launch BMS without any setup override from AxisAssign and KeyMapping section. Will you continue?";
                        if (MessageBox.Show(textMessage, "WARNING", MessageBoxButton.OKCancel, MessageBoxImage.Information) == MessageBoxResult.Cancel)
                        {
                            return;
                        }
                    }
                    else
                    {
                        appReg.getOverrideWriter().Execute(inGameAxis, deviceControl, keyFile);
                    }

                    String appPlatform = appReg.GetInstallDir() + "/Bin/x86/Falcon BMS.exe";
                    if (this.Misc_Platform.IsChecked == true)
                    {
                        appPlatform = appReg.GetInstallDir() + "/Bin/x64/Falcon BMS.exe";
                    }
                    if (File.Exists(appPlatform) == false)
                    {
                        this.Misc_Platform.IsChecked = false;
                        appPlatform = appReg.GetInstallDir() + "/Bin/x86/Falcon BMS.exe";
                        return;
                    }
                    process = System.Diagnostics.Process.Start(appPlatform, strCmdText);
                    this.Close();
                    //this.WindowState = WindowState.Minimized;
                    //process.Exited += new EventHandler(window_Normal);
                    //process.EnableRaisingEvents = true;
                    //this.WindowState = WindowState.Minimized;
                    break;

                case "Launch_CFG":
                    process         = System.Diagnostics.Process.Start(appReg.GetInstallDir() + "/Config.exe");
                    process.Exited += new EventHandler(window_Normal);
                    process.EnableRaisingEvents = true;
                    this.WindowState            = WindowState.Minimized;
                    break;

                case "Launch_DISX":
                    System.Diagnostics.Process.Start(appReg.GetInstallDir() + "/Bin/x86/Display Extraction.exe");
                    break;

                case "Launch_IVCC":
                    System.IO.Directory.SetCurrentDirectory(appReg.GetInstallDir() + "/Bin/x86/IVC/");
                    System.Diagnostics.Process.Start("IVC Client.exe");
                    break;

                case "Launch_IVCS":
                    System.Diagnostics.Process.Start(appReg.GetInstallDir() + "/Bin/x86/IVC/IVC Server.exe");
                    break;

                case "Launch_AVC":
                    System.IO.Directory.SetCurrentDirectory(appReg.GetInstallDir() + "/Bin/x86/");
                    System.Diagnostics.Process.Start("Avionics Configurator.exe");
                    break;

                case "Launch_EDIT":
                    if (System.IO.File.Exists(appReg.GetInstallDir() + "/Bin/x86/Editor.exe"))
                    {
                        System.Diagnostics.Process.Start(appReg.GetInstallDir() + "/Bin/x86/Editor.exe");
                    }
                    else
                    {
                        if (System.IO.File.Exists(appReg.GetInstallDir() + "/Bin/x64/Editor.exe"))
                        {
                            System.Diagnostics.Process.Start(appReg.GetInstallDir() + "/Bin/x64/Editor.exe");
                        }
                    }
                    break;
                }
            }
            catch (System.IO.FileNotFoundException ex)
            {
                System.Console.WriteLine(ex.Message);

                System.IO.StreamWriter sw = new System.IO.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);

                this.Close();
            }
        }