Esempio n. 1
0
        private static void salir_Click(object sender, EventArgs e)
        {
            taskIcon.Visible = false;

            /*Networking.stopUdpListener();
            *  Networking.stopTcpListener();*/
            Networking.stop();
            HardwareMonitor.stopThreaded();
            RTSS.finishRTSS();
            Application.Exit();
        }
Esempio n. 2
0
        static void Main()
        {
            // Catchear todas las excepciones no controladas para loguearlas
            Application.ThreadException += new ThreadExceptionEventHandler(Application_ThreadException);
            Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException);
            AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);

            //Application.EnableVisualStyles();
            //Application.SetCompatibleTextRenderingDefault(false);

            //icon = new Icon();

            Log.Initialize(".\\WearFPS.log", LogLevel.All, true);

            if (File.Exists(@"update-info"))
            {
                Log.Debug("Eliminando archivos de actualización...");
                File.Delete(@"update-info");
                File.Delete(@"updater.exe");
            }

            using (MyWebClient client = new MyWebClient()) {
                int ver = -1;

                try {
                    string s = client.DownloadString("http://pc.oviedo.me/wfs/v");
                    ver = Int32.Parse(s);
                } catch (Exception e) {
                    Log.Warn("No se ha podido conectar con el servidor de actualización: " + e.Message);
                }
                if (ver > 0)
                {
                    Log.Info("Última versión en línea: " + ver + ". Versión local: " + VERSION);
                    if (ver > VERSION)
                    {
                        File.WriteAllBytes(@"updater.exe", Properties.Resources.updater);
                        using (StreamWriter sw = new StreamWriter("update-info")) {
                            sw.Write("zip;http://pc.oviedo.me/wfs/" + ver + ".zip;release.zip");
                        }
                        Process.Start("updater.exe");
                        return;
                    }
                }
            }

            //
            var ini = new IniFile();

            if (ini.Read("firstRun") != "false")
            {
                FirewallHelper fh = FirewallHelper.Instance;
                if (fh.IsFirewallInstalled)
                {
                    Log.Debug("Windows Firewall is installed. Adding exception...");
                    var path = Application.ExecutablePath;
                    Log.Debug("Executable path is " + path);
                    fh.GrantAuthorization(path, "WearFPS");
                    fh = null;

                    /*Properties.Settings.Default.firstRun = false;
                     * Properties.Settings.Default.Save();*/
                    ini.Write("firstRun", "false");
                }
                else
                {
                    Log.Debug("Windows Firewall is not installed.");
                }
            }
            ini = null;

            menu = new ContextMenuStrip();
            menu.Items.Add("Salir").Click += salir_Click;

            taskIcon                  = new NotifyIcon();
            taskIcon.Text             = "WearFPS Server 0.1." + VERSION;
            taskIcon.Icon             = Properties.Resources.NotifyIcon;
            taskIcon.ContextMenuStrip = menu;
            taskIcon.Visible          = true;

            Console.WriteLine((int)-1f);



            //Application.Run(new Form1());

            HardwareMonitor.initThreaded();
            RTSS.init();

            Application.Run();

            //taskIcon.Visible = false;

            //taskIcon.Dispose();
        }
Esempio n. 3
0
        private static void HandleClientComm(object client)
        {
            TcpClient tcpClient = (TcpClient)client;

            tcpClient.NoDelay = true;

            Log.Info("Cliente conectado: " + tcpClient.Client.RemoteEndPoint.ToString());

            NetworkStream clientStream = tcpClient.GetStream();

            /*string str = "";
             * ASCIIEncoding encoder = new ASCIIEncoding();*/
            //byte[] buffer = new byte[256];
            //int len = 0;
            bool run = true;

            /*var sendStr = new Action(() => {
             *  len = encoder.GetBytes(str, 0, str.Length, buffer, 0);
             *
             *  try {
             *      clientStream.Write(buffer, 0, len);
             *      clientStream.Flush();
             *      //GC.Collect();
             *  } catch (System.IO.IOException) {
             *      Log.Info("El cliente " + tcpClient.Client.RemoteEndPoint.ToString() + " se ha desconectado");
             *      run = false;
             *  } catch (Exception e) {
             *      Log.Error("Exception: " + e.ToString());
             *      run = false;
             *  }
             * });*/

            //Thread.Sleep(150);

            ComputerInfo ci = new ComputerInfo {
                CpuName = HardwareMonitor.CPUName,
                GpuName = HardwareMonitor.GPUName
            };

            /*str = ":cpu=" + HardwareMonitor.CPUName + "\n";
             * sendStr();
             * str = ":gpu=" + HardwareMonitor.GPUName + "\n";
             * sendStr();*/

            try {
                // Tipo
                clientStream.WriteByte(0x00);
                // Tamaño

                /*int size = ci.CalculateSize();
                 * clientStream.WriteByte((byte)(size >> 8));
                 * clientStream.WriteByte((byte)size);*/
                // Datos
                //ci.WriteTo(clientStream);
                ci.WriteDelimitedTo(clientStream);
                clientStream.Flush();
            } catch (System.IO.IOException) {
                Log.Info("El cliente " + tcpClient.Client.RemoteEndPoint.ToString() + " se ha desconectado");
                run = false;
            } catch (Exception e) {
                Log.Error("Exception: " + e.ToString());
                run = false;
            }

            ci = null;



            while (runTcpServer && run)
            {
                //bufferincmessage = encoder.GetString(message, 0, bytesRead);

                HardwareMonitor.update();

                DataInt dataProto = new DataInt {
                    CpuFreq = (int)Math.Round(HardwareMonitor.CPUFreq),
                    CpuLoad = (int)Math.Round(HardwareMonitor.CPULoad),
                    CpuTemp = (int)Math.Round(HardwareMonitor.CPUTemp),
                    Fps     = (int)Math.Round(RTSS.getFPS()),
                    GpuFreq = (int)Math.Round(HardwareMonitor.GPUFreq),
                    GpuLoad = (int)Math.Round(HardwareMonitor.GPULoad),
                    GpuTemp = (int)Math.Round(HardwareMonitor.GPUTemp)
                };
                //byte[] type = { 0x01 };
                //clientStream.Write(type, 0, 1);
                try {
                    clientStream.WriteByte(0x01);
                    //dataProto.WriteTo(clientStream);
                    dataProto.WriteDelimitedTo(clientStream);
                    clientStream.Flush();
                } catch (System.IO.IOException) {
                    Log.Info("El cliente " + tcpClient.Client.RemoteEndPoint.ToString() + " se ha desconectado");
                    run = false;
                } catch (Exception e) {
                    Log.Error("Exception: " + e.ToString());
                    run = false;
                }

                /*str = (int)Math.Round(HardwareMonitor.CPULoad) + ";" + (int)Math.Round(HardwareMonitor.GPULoad) + ";";
                 * str += (int)Math.Round(RTSS.getFPS());
                 * str += ";" + (int)Math.Round(HardwareMonitor.CPUTemp) + ";" + (int)Math.Round(HardwareMonitor.GPUTemp);
                 * str += ";" + (int)Math.Round(HardwareMonitor.CPUFreq) + ";" + (int)Math.Round(HardwareMonitor.GPUFreq) + "\n";
                 * //Log.Data(s);
                 * //byte[] buffer = encoder.GetBytes(buf,);
                 *
                 * sendStr();*/
                //dataProto.WriteTo()


                Thread.Sleep(freq);
            }
        }