FreeConsole() private method

private FreeConsole ( ) : bool
return bool
Esempio n. 1
0
        internal static void RunServerInConsole(bool isVerbose, bool autoStart, string startupFile)
        {
            Console.Clear();
            Console.WriteLine("Welcome to the Kinect With VR (KiwiVR) Server!");
            Console.WriteLine("Press the \"E\" key at any time to exit.");

            MasterSettings settings = new MasterSettings();

            try
            {
                settings = HelperMethods.LoadSettings(startupFile);
            }
            catch
            {
                HelperMethods.WriteToLog("Cannot open settings file!");
            }

            ServerCore server = new ServerCore(isVerbose, settings);

            for (int i = 0; i < server.serverMasterOptions.kinectOptions.Count; i++) //Launch the Kinects
            {
                server.kinects.Add(new KinectCore(server, null, server.serverMasterOptions.kinectOptions[i].kinectID));
            }
            server.launchServer(); //This will still try to launch with default settings even if the settings load fails

            bool running = true;

            while (running)
            {
                Thread.Sleep(100);
                if (Console.KeyAvailable)
                {
                    ConsoleKeyInfo key = Console.ReadKey(false);
                    if (key.Key == ConsoleKey.E || (key.Key == ConsoleKey.C && key.Modifiers == ConsoleModifiers.Control))
                    {
                        running = false;
                    }
                }
            }

            Console.WriteLine("Shutting down the server.  Please wait...");
            server.stopServer();

            NativeInterop.FreeConsole();
        }
Esempio n. 2
0
        private void Application_Startup(object sender, StartupEventArgs e)
        {
            //Argument booleans
            bool   parentCommandLine = false;
            bool   newCommandLine    = false;
            bool   help        = false;
            bool   connected   = false;
            bool   verbose     = false;
            bool   autoStart   = false;
            string startupFile = "";

            string[] args = e.Args;

            //Parse command line arguments
            for (int i = 0; i < args.Length; i++)
            {
                if ((args[i].ToLower() == "-c" || args[i].ToLower() == "/c") && !newCommandLine)
                {
                    parentCommandLine = true;
                }
                else if (args[i].ToLower() == "-nc" || args[i].ToLower() == "/nc")
                {
                    parentCommandLine = false;
                    newCommandLine    = true;
                }
                else if (args[i].ToLower() == "-v" || args[i].ToLower() == "/v")
                {
                    verbose = true;
                }
                else if (args[i].ToLower() == "-s" || args[i].ToLower() == "/s")
                {
                    autoStart = true;
                }
                else if (args[i].ToLower() == "-h" || args[i].ToLower() == "/h" || args[i].ToLower() == "-?" || args[i].ToLower() == "/?")
                {
                    help      = true;
                    connected = NativeInterop.AttachConsole(-1);
                    if (connected)
                    {
                        Console.WriteLine();
                        Console.WriteLine();
                        Console.WriteLine("Usage: KinectWithVRServer [filename] [/c] [/nc] [/s] [/v]");
                        Console.WriteLine();
                        Console.WriteLine("Options:");
                        Console.WriteLine("\t/c\tLaunches the program in the pre-existing command line.");
                        Console.WriteLine("\t/nc\tLaunches the program in a new command line window.");
                        Console.WriteLine("\t/?\tShows this help message.");
                        Console.WriteLine("\t/h\tShows this help message.");
                        Console.WriteLine("\t/s\tStarts the server immediately upon program launch.\r\n\t\tThis is implied when launched in console mode.");
                        Console.WriteLine("\t/v\tVerbose output mode.");
                        NativeInterop.FreeConsole();
                    }
                }
                else if (i == 0)
                {
                    startupFile = args[i];
                }
            }

            if (!help)
            {
                //For Testing
                AvaliableDLLs dlls = new AvaliableDLLs();
                dlls.HasKinectV1        = VerifyDLLs.Kinect1Avaliable();
                dlls.HasKinectV2        = VerifyDLLs.Kinect2Avaliable();
                dlls.HasNetworkedKinect = VerifyDLLs.NetworkedKinectAvaliable();

                if (newCommandLine || parentCommandLine)
                {
                    if (newCommandLine)
                    {
                        connected = NativeInterop.AllocConsole();
                    }
                    else if (parentCommandLine)
                    {
                        connected = NativeInterop.AttachConsole(-1);

                        IntPtr consoleHandle = NativeInterop.GetStdHandle(-10);
                        uint   consoleMode   = 0;
                        NativeInterop.GetConsoleMode(consoleHandle, out consoleMode);
                        NativeInterop.SetConsoleMode(consoleHandle, (uint)(consoleMode & (~0x0002)));
                    }

                    if (connected)
                    {
                        ConsoleUI.RunServerInConsole(verbose, autoStart, startupFile, dlls);
                    }
                }
                else
                {
                    //Note: You can't put the Try/Catch here to handle if there are no Kinects because the GUI will try to launch on a different thread, and thus it can't pass the error down
                    MainWindow gui = new MainWindow(verbose, autoStart, dlls, startupFile);
                    gui.ShowDialog();
                }
            }

            this.Shutdown();
        }
Esempio n. 3
0
        internal static void RunServerInConsole(bool isVerbose, bool autoStart, string startupFile, AvaliableDLLs dlls)
        {
            Console.Clear();
            Console.WriteLine("Welcome to the Kinect With VR (KVR) Server!");
            Console.WriteLine("Press the \"E\" key at any time to exit.");

            //Notify the user if DLLs are missing
            if (!dlls.HasKinectV1)
            {
                Console.WriteLine("Warning: Kinect v1 support is unavaliable due to missing DLLs");
            }
            if (!dlls.HasKinectV2)
            {
                Console.WriteLine("Warning: Kinect v2 support is unavaliable due to missing DLLs");
            }
            if (!dlls.HasNetworkedKinect)
            {
                Console.WriteLine("Warning: Networked Kinect support is unavaliable due to missing DLLs");
            }

            KinectBase.MasterSettings settings = new KinectBase.MasterSettings();

            try
            {
                settings = HelperMethods.LoadSettings(startupFile);
            }
            catch
            {
                HelperMethods.WriteToLog("Cannot open settings file!");
            }

            ServerCore server = new ServerCore(isVerbose, settings);

            for (int i = 0; i < server.serverMasterOptions.kinectOptionsList.Count; i++) //Launch the Kinects
            {
                if (server.serverMasterOptions.kinectOptionsList[i].version == KinectBase.KinectVersion.KinectV1)
                {
                    if (dlls.HasKinectV1)
                    {
                        //server.kinects.Add(new KinectV1Core.KinectCoreV1(ref server.serverMasterOptions, false, server.serverMasterOptions.kinectOptionsList[i].kinectID));
                        server.kinects.Add(new KinectV1Wrapper.Core(ref server.serverMasterOptions, false, server.serverMasterOptions.kinectOptionsList[i].kinectID));
                    }
                    else
                    {
                        Console.WriteLine("Cannot load Kinect v1 with ID: {0} due to missing DLLs.", server.serverMasterOptions.kinectOptionsList[i].kinectID);
                    }
                }
                else if (server.serverMasterOptions.kinectOptionsList[i].version == KinectBase.KinectVersion.KinectV2)
                {
                    if (dlls.HasKinectV2)
                    {
                        server.kinects.Add(new KinectV2Wrapper.Core(ref server.serverMasterOptions, false, server.serverMasterOptions.kinectOptionsList[i].kinectID));
                    }
                    else
                    {
                        Console.WriteLine("Cannot load Kinect v2 with ID: {0} due to missing DLLs.", server.serverMasterOptions.kinectOptionsList[i].kinectID);
                    }
                }
                else if (server.serverMasterOptions.kinectOptionsList[i].version == KinectBase.KinectVersion.NetworkKinect)
                {
                    if (dlls.HasNetworkedKinect)
                    {
                        server.kinects.Add(new NetworkKinectWrapper.Core(ref server.serverMasterOptions, false, server.serverMasterOptions.kinectOptionsList[i].kinectID, server.serverMasterOptions.kinectOptionsList[i].uniqueKinectID));
                    }
                    else
                    {
                        Console.WriteLine("Cannot load network Kinect with ID: {0} due to missing DLLs.", server.serverMasterOptions.kinectOptionsList[i].kinectID);
                    }
                }
                else
                {
                    Console.WriteLine("Kinect number {0} was of an unknown version and could not be opened.", i);
                }
            }
            server.launchServer(); //This will still try to launch with default settings even if the settings load fails

            bool running = true;

            while (running)
            {
                Thread.Sleep(100);
                if (Console.KeyAvailable)
                {
                    ConsoleKeyInfo key = Console.ReadKey(false);
                    if (key.Key == ConsoleKey.E || (key.Key == ConsoleKey.C && key.Modifiers == ConsoleModifiers.Control))
                    {
                        running = false;
                    }
                }
            }

            Console.WriteLine(); //Write a blank so the next statement has its own line
            Console.WriteLine("Shutting down the server.  Please wait...");
            server.stopServer();

            NativeInterop.FreeConsole();
        }