Exemple #1
0
 private static Process FindTVTestProcess(string type)
 {
     foreach (Process p in Process.GetProcesses())
     {
         // 原作と異なりプロセス名ではなく接続待機用イベントの有無で判断するので注意
         try
         {
             using (System.Threading.EventWaitHandle.OpenExisting(
                        "Global\\" + type + "_Ctrl_BonConnect_" + p.Id, System.Security.AccessControl.EventWaitHandleRights.Synchronize))
             {
             }
             // 識別用IDが設定されたViewアプリは除外する
             if (type == "View")
             {
                 var cmdTvTest = new CtrlCmdUtil();
                 cmdTvTest.SetPipeSetting("Global\\View_Ctrl_BonConnect_" + p.Id, "\\\\.\\pipe\\View_Ctrl_BonPipe_" + p.Id);
                 cmdTvTest.SetConnectTimeOut(1000);
                 int id = -1;
                 if (cmdTvTest.SendViewGetID(ref id) != ErrCode.CMD_SUCCESS || id >= 0)
                 {
                     continue;
                 }
             }
             return(p);
         }
         catch { }
     }
     return(null);
 }
Exemple #2
0
        private void openFolder_Click(object sender, RoutedEventArgs e)
        {
            if (listView_recinfo.SelectedItem != null && CommonManager.Instance.NWMode == false)
            {
                RecInfoItem info = listView_recinfo.SelectedItem as RecInfoItem;
                if (info.RecFilePath.Length == 0)
                {
                    MessageBox.Show("録画ファイルが存在しません");
                }
                else
                {
                    if (System.IO.File.Exists(info.RecFilePath) == true)
                    {
                        String cmd = "/select,";
                        cmd += "\"" + info.RecFilePath + "\"";

                        System.Diagnostics.Process.Start("EXPLORER.EXE", cmd);
                    }
                    else
                    {
                        String folderPath = System.IO.Path.GetDirectoryName(info.RecFilePath);
                        System.Diagnostics.Process.Start("EXPLORER.EXE", folderPath);
                    }
                }
            }
        }
Exemple #3
0
        public bool StartStreamingPlay(String filePath, IPAddress srvIP, UInt32 srvPort)
        {
            try
            {
                if (Settings.Instance.TvTestExe.Length == 0)
                {
                    MessageBox.Show("TVTest.exeのパスが設定されていません");
                    return(false);
                }

                UInt32  ctrlID = 0;
                ErrCode err    = CommonManager.CreateSrvCtrl().SendNwPlayOpen(filePath, ref ctrlID);
                if (err != ErrCode.CMD_SUCCESS)
                {
                    MessageBox.Show(CommonManager.GetErrCodeText(err) ?? "まだ録画が開始されていません。");
                    return(false);
                }

                OpenTVTest(Settings.Instance.TvTestOpenWait, "TvTest");
                var cmdTvTest = new CtrlCmdUtil();
                cmdTvTest.SetPipeSetting("Global\\TvTest_Ctrl_BonConnect_" + process.Id, "TvTest_Ctrl_BonPipe_" + process.Id);
                cmdTvTest.SetConnectTimeOut(1000);

                UInt32 ip = 0x7F000001;
                if (srvIP != null && srvIP.GetAddressBytes().Length == 4)
                {
                    byte[] oct = srvIP.GetAddressBytes();
                    ip = (uint)oct[0] << 24 | (uint)oct[1] << 16 | (uint)oct[2] << 8 | oct[3];
                }

                TVTestStreamingInfo sendInfo = new TVTestStreamingInfo();
                sendInfo.enableMode = 1;
                sendInfo.ctrlID     = ctrlID;
                sendInfo.serverIP   = ip;
                sendInfo.serverPort = srvPort;

                if (Settings.Instance.NwTvModeUDP == true)
                {
                    sendInfo.udpSend = 1;
                }
                if (Settings.Instance.NwTvModeTCP == true)
                {
                    sendInfo.tcpSend = 1;
                }
                for (int i = 0; i < 10 && cmdTvTest.SendViewSetStreamingInfo(sendInfo) != ErrCode.CMD_SUCCESS; i++)
                {
                    System.Threading.Thread.Sleep(1000);
                }

                WakeupWindow(process.MainWindowHandle);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + "\r\n" + ex.StackTrace);
            }
            return(true);
        }
Exemple #4
0
        public static CtrlCmdUtil CreateSrvCtrl()
        {
            var cmd = new CtrlCmdUtil();

            if (Instance.NWMode)
            {
                cmd.SetSendMode(true);
                cmd.SetNWSetting(Instance.NWConnectedIP, Instance.NWConnectedPort);
            }
            return(cmd);
        }
Exemple #5
0
 public void CloseTVTest()
 {
     if (process != null && process.HasExited == false)
     {
         var cmdTvTest = new CtrlCmdUtil();
         cmdTvTest.SetPipeSetting("Global\\" + processType + "_Ctrl_BonConnect_" + process.Id, "\\\\.\\pipe\\" + processType + "_Ctrl_BonPipe_" + process.Id);
         cmdTvTest.SetConnectTimeOut(1000);
         cmdTvTest.SendViewAppClose();
     }
     process = null;
     if (Settings.Instance.NwTvMode == true)
     {
         cmd.SendNwTVClose();
     }
 }
Exemple #6
0
 private void OpenTVTest(int openWait, bool acceptViewApp)
 {
     if (process == null || process.HasExited || (acceptViewApp == false && processType == "View"))
     {
         if (process != null)
         {
             process.Dispose();
         }
         processType = "TvTest";
         process     = FindTVTestProcess(processType);
         if (process == null && acceptViewApp)
         {
             processType = "View";
             process     = FindTVTestProcess(processType);
         }
         if (process == null)
         {
             // EpgTimerPlugInと仮定
             processType = "TvTest";
             process     = Process.Start(Settings.Instance.TvTestExe, Settings.Instance.TvTestCmd);
             if (acceptViewApp)
             {
                 for (int i = 0; i < 100; i++)
                 {
                     var cmdTvTest = new CtrlCmdUtil();
                     cmdTvTest.SetPipeSetting("Global\\View_Ctrl_BonConnect_" + process.Id, "View_Ctrl_BonPipe_" + process.Id);
                     if (cmdTvTest.PipeExists())
                     {
                         // Viewアプリ(EdcbPlugIn)と判断
                         processType = "View";
                         break;
                     }
                     cmdTvTest.SetPipeSetting("Global\\TvTest_Ctrl_BonConnect_" + process.Id, "TvTest_Ctrl_BonPipe_" + process.Id);
                     if (cmdTvTest.PipeExists())
                     {
                         break;
                     }
                     System.Threading.Thread.Sleep(100);
                     openWait -= 100;
                 }
             }
             if (openWait > 0)
             {
                 System.Threading.Thread.Sleep(openWait);
             }
         }
     }
 }
Exemple #7
0
        private void openFolder_Click(object sender, RoutedEventArgs e)
        {
            if (listView_recinfo.SelectedItem != null)
            {
                RecInfoItem info = listView_recinfo.SelectedItem as RecInfoItem;
                if (info.RecFilePath.Length == 0)
                {
                    MessageBox.Show("録画ファイルが存在しません");
                }
                else
                {
                    if (CommonManager.Instance.NWMode == false)
                    {
                        if (System.IO.File.Exists(info.RecFilePath) == true)
                        {
                            String cmd = "/select,";
                            cmd += "\"" + info.RecFilePath + "\"";

                            System.Diagnostics.Process.Start("EXPLORER.EXE", cmd);
                        }
                        else
                        {
                            String folderPath = System.IO.Path.GetDirectoryName(info.RecFilePath);
                            System.Diagnostics.Process.Start("EXPLORER.EXE", folderPath);
                        }
                    }
                    else
                    {
                        CtrlCmdUtil cmd   = CommonManager.Instance.CtrlCmd;
                        String      nPath = "";
                        UInt32      err   = cmd.SendGetRecFileNetworkPath(info.RecFilePath, ref nPath);
                        if (err == 1)
                        {
                            String cmdline = "/select,";
                            cmdline += "\"" + nPath + "\"";

                            System.Diagnostics.Process.Start("EXPLORER.EXE", cmdline);
                        }
                        else
                        {
                            MessageBox.Show("フォルダが開けません。録画フォルダが共有されているか確認してください。");
                        }
                    }
                }
            }
        }
Exemple #8
0
 private static Process FindTVTestProcess(string type)
 {
     Process[] processes = Process.GetProcesses();
     foreach (Process p in processes)
     {
         // 原作と異なりプロセス名ではなく接続待機用イベントの有無で判断するので注意
         try
         {
             using (System.Threading.EventWaitHandle.OpenExisting(
                        "Global\\" + type + "_Ctrl_BonConnect_" + p.Id, System.Security.AccessControl.EventWaitHandleRights.Synchronize))
             {
             }
             if (type == "View")
             {
                 // TVTestではなさそうなViewアプリは除外する(※EpgDataCap_BonもViewアプリ)
                 if (p.ProcessName.Equals(System.IO.Path.GetFileNameWithoutExtension(Settings.Instance.TvTestExe),
                                          StringComparison.OrdinalIgnoreCase) == false)
                 {
                     continue;
                 }
                 // 識別用IDが設定されたViewアプリは除外する
                 var cmdTvTest = new CtrlCmdUtil();
                 cmdTvTest.SetPipeSetting("Global\\View_Ctrl_BonConnect_" + p.Id, "View_Ctrl_BonPipe_" + p.Id);
                 cmdTvTest.SetConnectTimeOut(1000);
                 int id = -1;
                 if (cmdTvTest.SendViewGetID(ref id) != ErrCode.CMD_SUCCESS || id >= 0)
                 {
                     continue;
                 }
             }
             foreach (Process pp in processes.Where(pp => pp != p))
             {
                 pp.Dispose();
             }
             return(p);
         }
         catch { }
     }
     foreach (Process p in processes)
     {
         p.Dispose();
     }
     return(null);
 }
Exemple #9
0
 public void CloseTVTest()
 {
     if (process != null)
     {
         if (process.HasExited == false)
         {
             var cmdTvTest = new CtrlCmdUtil();
             cmdTvTest.SetPipeSetting("Global\\" + processType + "_Ctrl_BonConnect_" + process.Id, processType + "_Ctrl_BonPipe_" + process.Id);
             cmdTvTest.SetConnectTimeOut(1000);
             cmdTvTest.SendViewAppClose();
         }
         process.Dispose();
     }
     process = null;
     if (Settings.Instance.NwTvMode == true)
     {
         CommonManager.CreateSrvCtrl().SendNwTVClose();
     }
 }
Exemple #10
0
        public bool ConnectServer(IPAddress srvIP, UInt32 srvPort, UInt32 waitPort, Func <uint, byte[], Tuple <ErrCode, byte[], uint> > pfnCmdProc)
        {
            ConnectedIP   = null;
            ConnectedPort = 0;

            cmdProc       = pfnCmdProc;
            pollingClient = null;

            if (server == null && srvIP != null && waitPort != 0)
            {
                //TODO: 再接続などを考えるとこの生成方法は正確でないが、ほとんど互換のために残しているだけの機能なので適当
                server = new TcpListener(srvIP.AddressFamily == AddressFamily.InterNetworkV6 ? IPAddress.IPv6Any : IPAddress.Any, (int)waitPort);
                server.Start();
                server.BeginAcceptTcpClient(new AsyncCallback(DoAcceptTcpClientCallback), server);
            }

            var cmd = new CtrlCmdUtil();

            cmd.SetSendMode(true);

            cmd.SetNWSetting(srvIP, srvPort);

            var status = new NotifySrvInfo();

            if (waitPort == 0 && cmd.SendGetNotifySrvStatus(ref status) != ErrCode.CMD_SUCCESS ||
                waitPort != 0 && cmd.SendRegistTCP(waitPort) != ErrCode.CMD_SUCCESS)
            {
                //サーバが存在しないかロングポーリングに未対応
                return(false);
            }
            else
            {
                ConnectedIP   = srvIP;
                ConnectedPort = srvPort;
                if (waitPort == 0)
                {
                    pollingClient = new TcpClient(srvIP.AddressFamily);
                    StartPolling(pollingClient, srvIP, srvPort, 0);
                }
                return(true);
            }
        }
Exemple #11
0
        public bool ConnectServer(IPAddress srvIP, uint srvPort, uint waitPort, Func <uint, byte[], Tuple <ErrCode, byte[], uint> > cmdProc)
        {
            StopWorker();

            if (srvIP != null && waitPort != 0)
            {
                //待ち受け方式(互換のために残しているだけ)
                var server = new TcpListener(srvIP.AddressFamily == AddressFamily.InterNetworkV6 ? IPAddress.IPv6Any : IPAddress.Any, (int)waitPort);
                server.Start();
                stopEvent    = new AutoResetEvent(false);
                workerThread = new Thread(() =>
                {
                    for (;;)
                    {
                        TcpClient client;
                        IAsyncResult ar = server.BeginAcceptTcpClient(null, null);
                        using (ar.AsyncWaitHandle)
                        {
                            if (WaitHandle.WaitAny(new WaitHandle[] { stopEvent, ar.AsyncWaitHandle }) != 1)
                            {
                                server.Stop();
                                ar.AsyncWaitHandle.WaitOne();
                                break;
                            }
                            client = server.EndAcceptTcpClient(ar);
                        }
                        using (client)
                            using (NetworkStream stream = client.GetStream())
                            {
                                byte[] bHead = new byte[8];
                                if (ReadAll(stream, bHead, 0, 8) == 8)
                                {
                                    uint cmdParam  = BitConverter.ToUInt32(bHead, 0);
                                    byte[] cmdData = new byte[BitConverter.ToUInt32(bHead, 4)];
                                    if (ReadAll(stream, cmdData, 0, cmdData.Length) == cmdData.Length)
                                    {
                                        Tuple <ErrCode, byte[], uint> res = cmdProc(cmdParam, cmdData);
                                        BitConverter.GetBytes((uint)res.Item1).CopyTo(bHead, 0);
                                        BitConverter.GetBytes(res.Item2 == null ? 0 : res.Item2.Length).CopyTo(bHead, 4);
                                        stream.Write(bHead, 0, 8);
                                        if (res.Item2 != null && res.Item2.Length > 0)
                                        {
                                            stream.Write(res.Item2, 0, res.Item2.Length);
                                        }
                                    }
                                }
                            }
                    }
                    server.Stop();
                });
                workerThread.Start();
            }

            var cmd = new CtrlCmdUtil();

            cmd.SetSendMode(true);

            cmd.SetNWSetting(srvIP, srvPort);

            var status = new NotifySrvInfo();

            if (waitPort == 0 && cmd.SendGetNotifySrvStatus(ref status) != ErrCode.CMD_SUCCESS ||
                waitPort != 0 && cmd.SendRegistTCP(waitPort) != ErrCode.CMD_SUCCESS)
            {
                //サーバが存在しないかロングポーリングに未対応
                StopWorker();
                return(false);
            }
            else if (waitPort == 0)
            {
                //ロングポーリング方式
                stopEvent    = new AutoResetEvent(false);
                workerThread = new Thread(() =>
                {
                    uint targetCount = 0;
                    for (;;)
                    {
                        //巡回カウンタがtargetCountよりも大きくなる新しい通知を待ち受ける
                        var w = new CtrlCmdWriter(new MemoryStream());
                        w.Write((ushort)0);
                        w.Write(targetCount);
                        byte[] bHead = new byte[8 + w.Stream.Length];
                        BitConverter.GetBytes((uint)CtrlCmd.CMD_EPG_SRV_GET_STATUS_NOTIFY2).CopyTo(bHead, 0);
                        BitConverter.GetBytes((uint)w.Stream.Length).CopyTo(bHead, 4);
                        w.Stream.Close();
                        w.Stream.ToArray().CopyTo(bHead, 8);

                        using (var client = new TcpClient(srvIP.AddressFamily))
                        {
                            try
                            {
                                client.Connect(srvIP, (int)srvPort);
                            }
                            catch (SocketException ex)
                            {
                                System.Diagnostics.Trace.WriteLine(ex);
                                //少し待つ
                                if (stopEvent.WaitOne(5000))
                                {
                                    break;
                                }
                                continue;
                            }
                            using (NetworkStream stream = client.GetStream())
                            {
                                stream.Write(bHead, 0, bHead.Length);
                                int readSize;
                                IAsyncResult ar = stream.BeginRead(bHead, 0, 8, null, null);
                                using (ar.AsyncWaitHandle)
                                {
                                    if (WaitHandle.WaitAny(new WaitHandle[] { stopEvent, ar.AsyncWaitHandle }) != 1)
                                    {
                                        stream.Dispose();
                                        ar.AsyncWaitHandle.WaitOne();
                                        break;
                                    }
                                    try
                                    {
                                        readSize = stream.EndRead(ar);
                                    }
                                    catch (IOException ex)
                                    {
                                        System.Diagnostics.Trace.WriteLine(ex);
                                        //少し待つ
                                        if (stopEvent.WaitOne(5000))
                                        {
                                            break;
                                        }
                                        continue;
                                    }
                                }
                                if (readSize > 0 && ReadAll(stream, bHead, readSize, 8 - readSize) == 8 - readSize)
                                {
                                    uint cmdParam  = BitConverter.ToUInt32(bHead, 0);
                                    byte[] cmdData = new byte[BitConverter.ToUInt32(bHead, 4)];
                                    if (ReadAll(stream, cmdData, 0, cmdData.Length) == cmdData.Length && cmdParam == (uint)ErrCode.CMD_SUCCESS)
                                    {
                                        //通常の通知コマンドに変換
                                        targetCount = cmdProc((uint)CtrlCmd.CMD_TIMER_GUI_SRV_STATUS_NOTIFY2, cmdData).Item3;
                                    }
                                }
                            }
                        }
                    }
                });
                workerThread.Start();
            }
            return(true);
        }
Exemple #12
0
        public bool StartStreamingPlay(string filePath, uint reserveID)
        {
            try
            {
                if (Settings.Instance.TvTestExe.Length == 0)
                {
                    MessageBox.Show("TVTest.exeのパスが設定されていません");
                    return(false);
                }
                if (CommonManager.Instance.NWMode == false)
                {
                    if (IniFileHandler.GetPrivateProfileInt("SET", "EnableTCPSrv", 0, SettingPath.TimerSrvIniPath) == 0)
                    {
                        MessageBox.Show("動作設定でネットワーク接続を許可する必要があります。");
                        return(false);
                    }
                }
                var sendInfo = new TVTestStreamingInfo();
                if (filePath == null)
                {
                    var     playInfo = new NWPlayTimeShiftInfo();
                    ErrCode err      = CommonManager.CreateSrvCtrl().SendNwTimeShiftOpen(reserveID, ref playInfo);
                    if (err != ErrCode.CMD_SUCCESS)
                    {
                        MessageBox.Show(CommonManager.GetErrCodeText(err) ?? "まだ録画が開始されていません。");
                        return(false);
                    }
                    sendInfo.ctrlID   = playInfo.ctrlID;
                    sendInfo.filePath = playInfo.filePath;
                }
                else
                {
                    ErrCode err = CommonManager.CreateSrvCtrl().SendNwPlayOpen(filePath, ref sendInfo.ctrlID);
                    if (err != ErrCode.CMD_SUCCESS)
                    {
                        MessageBox.Show(CommonManager.GetErrCodeText(err) ?? "ファイルを開けませんでした。");
                        return(false);
                    }
                }

                OpenTVTest(1000, false);
                var cmdTvTest = new CtrlCmdUtil();
                cmdTvTest.SetPipeSetting("Global\\TvTest_Ctrl_BonConnect_" + process.Id, "TvTest_Ctrl_BonPipe_" + process.Id);
                cmdTvTest.SetConnectTimeOut(1000);

                sendInfo.enableMode = 1;
                if (CommonManager.Instance.NWMode == false)
                {
                    sendInfo.serverIP = 0x7F000001;
                    // 原作はここで自ホスト名を取得して解決したアドレスを格納している。(ないとは思うが)不具合があれば戻すこと
                    sendInfo.serverPort = (UInt32)IniFileHandler.GetPrivateProfileInt("SET", "TCPPort", 4510, SettingPath.TimerSrvIniPath);
                }
                else
                {
                    sendInfo.serverIP = 0x7F000001;
                    IPAddress srvIP = CommonManager.Instance.NWConnectedIP;
                    if (srvIP != null && srvIP.GetAddressBytes().Length == 4)
                    {
                        byte[] oct = srvIP.GetAddressBytes();
                        sendInfo.serverIP = (uint)oct[0] << 24 | (uint)oct[1] << 16 | (uint)oct[2] << 8 | oct[3];
                    }
                    sendInfo.serverPort = CommonManager.Instance.NWConnectedPort;
                }
                if (Settings.Instance.NwTvModeUDP == true)
                {
                    sendInfo.udpSend = 1;
                }
                if (Settings.Instance.NwTvModeTCP == true)
                {
                    sendInfo.tcpSend = 1;
                }
                for (int i = 0; i < 10 && cmdTvTest.SendViewSetStreamingInfo(sendInfo) != ErrCode.CMD_SUCCESS; i++)
                {
                    System.Threading.Thread.Sleep(1000);
                }

                WakeupWindow(process.MainWindowHandle);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + "\r\n" + ex.StackTrace);
            }
            return(true);
        }
Exemple #13
0
        public bool SetLiveCh(UInt16 ONID, UInt16 TSID, UInt16 SID)
        {
            try
            {
                if (Settings.Instance.TvTestExe.Length == 0)
                {
                    MessageBox.Show("TVTest.exeのパスが設定されていません");
                    return(false);
                }
                OpenTVTest(Settings.Instance.TvTestOpenWait, Settings.Instance.NwTvMode == false);
                var cmdTvTest = new CtrlCmdUtil();
                cmdTvTest.SetPipeSetting("Global\\" + processType + "_Ctrl_BonConnect_" + process.Id, processType + "_Ctrl_BonPipe_" + process.Id);
                cmdTvTest.SetConnectTimeOut(1000);

                if (Settings.Instance.NwTvMode == true)
                {
                    SetChInfo chInfo = new SetChInfo();
                    chInfo.useSID   = 1;
                    chInfo.useBonCh = 0;
                    chInfo.ONID     = ONID;
                    chInfo.TSID     = TSID;
                    chInfo.SID      = SID;

                    UInt32 nwMode      = 0;
                    String nwBonDriver = "BonDriver_UDP.dll";
                    if (Settings.Instance.NwTvModeUDP == true)
                    {
                        nwMode += 1;
                    }
                    if (Settings.Instance.NwTvModeTCP == true)
                    {
                        nwMode     += 2;
                        nwBonDriver = "BonDriver_TCP.dll";
                    }

                    if (CommonManager.CreateSrvCtrl().SendNwTVMode(nwMode) == ErrCode.CMD_SUCCESS)
                    {
                        if (CommonManager.CreateSrvCtrl().SendNwTVSetCh(chInfo) == ErrCode.CMD_SUCCESS)
                        {
                            String val = "";
                            for (int i = 0; i < 10; i++)
                            {
                                if (cmdTvTest.SendViewGetBonDrivere(ref val) != ErrCode.CMD_SUCCESS)
                                {
                                    System.Threading.Thread.Sleep(1000);
                                    continue;
                                }
                                if (val.Equals(nwBonDriver, StringComparison.OrdinalIgnoreCase) == false)
                                {
                                    cmdTvTest.SendViewSetBonDrivere(nwBonDriver);
                                }
                                break;
                            }
                        }
                    }
                }
                else
                {
                    UInt64 key = ((UInt64)ONID) << 32 |
                                 ((UInt64)TSID) << 16 |
                                 ((UInt64)SID);
                    TvTestChChgInfo chInfo = new TvTestChChgInfo();
                    ErrCode         err    = CommonManager.CreateSrvCtrl().SendGetChgChTVTest(key, ref chInfo);
                    if (err == ErrCode.CMD_SUCCESS)
                    {
                        String val = "";
                        for (int i = 0; i < 10; i++)
                        {
                            if (cmdTvTest.SendViewGetBonDrivere(ref val) != ErrCode.CMD_SUCCESS)
                            {
                                System.Threading.Thread.Sleep(1000);
                                continue;
                            }
                            // 識別用IDが設定されたViewアプリは弄らない
                            if (processType == "View")
                            {
                                int id = -1;
                                if (cmdTvTest.SendViewGetID(ref id) != ErrCode.CMD_SUCCESS || id >= 0)
                                {
                                    break;
                                }
                            }
                            if (val.Equals(chInfo.bonDriver, StringComparison.OrdinalIgnoreCase) == false)
                            {
                                if (cmdTvTest.SendViewSetBonDrivere(chInfo.bonDriver) == ErrCode.CMD_SUCCESS)
                                {
                                    System.Threading.Thread.Sleep(Settings.Instance.TvTestChgBonWait);
                                    cmdTvTest.SendViewSetCh(chInfo.chInfo);
                                }
                            }
                            else
                            {
                                cmdTvTest.SendViewSetCh(chInfo.chInfo);
                            }
                            break;
                        }
                    }
                    else
                    {
                        MessageBox.Show(CommonManager.GetErrCodeText(err) ?? "指定サービスを受信できるBonDriverが設定されていません。");
                        return(false);
                    }
                }

                WakeupWindow(process.MainWindowHandle);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + "\r\n" + ex.StackTrace);
            }
            return(true);
        }
Exemple #14
0
 public TVTestCtrlClass(CtrlCmdUtil ctrlCmd)
 {
     cmd = ctrlCmd;
 }
Exemple #15
0
 public DBManager(CtrlCmdUtil ctrlCmd)
 {
     cmd = ctrlCmd;
 }
Exemple #16
0
        public bool SetLiveCh(UInt16 ONID, UInt16 TSID, UInt16 SID)
        {
            try
            {
                if (Settings.Instance.TvTestExe.Length == 0)
                {
                    MessageBox.Show("TVTest.exeのパスが設定されていません");
                    return(false);
                }
                // TVTestのパスが録画用アプリと一致する場合はViewアプリとして扱う
                bool isView = CommonManager.Instance.NWMode == false &&
                              Settings.Instance.NwTvMode == false &&
                              string.Compare(IniFileHandler.GetPrivateProfileString("SET", "RecExePath", "", SettingPath.CommonIniPath), Settings.Instance.TvTestExe, true) == 0;
                OpenTVTest(Settings.Instance.TvTestOpenWait, isView ? "View" : "TvTest");
                var cmdTvTest = new CtrlCmdUtil();
                cmdTvTest.SetPipeSetting("Global\\" + processType + "_Ctrl_BonConnect_" + process.Id, "\\\\.\\pipe\\" + processType + "_Ctrl_BonPipe_" + process.Id);
                cmdTvTest.SetConnectTimeOut(1000);

                if (Settings.Instance.NwTvMode == true)
                {
                    SetChInfo chInfo = new SetChInfo();
                    chInfo.useSID   = 1;
                    chInfo.useBonCh = 0;
                    chInfo.ONID     = ONID;
                    chInfo.TSID     = TSID;
                    chInfo.SID      = SID;

                    UInt32 nwMode      = 0;
                    String nwBonDriver = "BonDriver_UDP.dll";
                    if (Settings.Instance.NwTvModeUDP == true)
                    {
                        nwMode += 1;
                    }
                    if (Settings.Instance.NwTvModeTCP == true)
                    {
                        nwMode     += 2;
                        nwBonDriver = "BonDriver_TCP.dll";
                    }

                    if (cmd.SendNwTVMode(nwMode) == ErrCode.CMD_SUCCESS)
                    {
                        if (cmd.SendNwTVSetCh(chInfo) == ErrCode.CMD_SUCCESS)
                        {
                            String val = "";
                            for (int i = 0; i < 10; i++)
                            {
                                if (cmdTvTest.SendViewGetBonDrivere(ref val) != ErrCode.CMD_SUCCESS)
                                {
                                    System.Threading.Thread.Sleep(1000);
                                    continue;
                                }
                                if (String.Compare(val, nwBonDriver, true) != 0)
                                {
                                    cmdTvTest.SendViewSetBonDrivere(nwBonDriver);
                                }
                                break;
                            }
                        }
                    }
                }
                else
                {
                    UInt64          key    = CommonManager.Create64Key(ONID, TSID, SID);
                    TvTestChChgInfo chInfo = new TvTestChChgInfo();
                    ErrCode         err    = cmd.SendGetChgChTVTest(key, ref chInfo);
                    if (err == ErrCode.CMD_SUCCESS)
                    {
                        String val = "";
                        for (int i = 0; i < 10; i++)
                        {
                            if (cmdTvTest.SendViewGetBonDrivere(ref val) != ErrCode.CMD_SUCCESS)
                            {
                                System.Threading.Thread.Sleep(1000);
                                continue;
                            }
                            // 識別用IDが設定されたViewアプリは弄らない
                            if (processType == "View")
                            {
                                int id = -1;
                                if (cmdTvTest.SendViewGetID(ref id) != ErrCode.CMD_SUCCESS || id >= 0)
                                {
                                    break;
                                }
                            }
                            if (String.Compare(val, chInfo.bonDriver, true) != 0)
                            {
                                if (cmdTvTest.SendViewSetBonDrivere(chInfo.bonDriver) == ErrCode.CMD_SUCCESS)
                                {
                                    System.Threading.Thread.Sleep(Settings.Instance.TvTestChgBonWait);
                                    cmdTvTest.SendViewSetCh(chInfo.chInfo);
                                }
                            }
                            else
                            {
                                cmdTvTest.SendViewSetCh(chInfo.chInfo);
                            }
                            break;
                        }
                    }
                    else if (err == ErrCode.CMD_ERR_CONNECT)
                    {
                        MessageBox.Show("サーバーに接続できませんでした");
                        return(false);
                    }
                    else
                    {
                        MessageBox.Show("指定サービスを受信できるBonDriverが設定されていません。");
                        return(false);
                    }
                }

                WakeupWindow(process.MainWindowHandle);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + "\r\n" + ex.StackTrace);
            }
            return(true);
        }
Exemple #17
0
 public NWConnect(CtrlCmdUtil ctrlCmd)
 {
     connectFlag = false;
     cmd         = ctrlCmd;
 }
Exemple #18
0
        static void Main(string[] args)
        {
            if (args.Length < 2)
            {
                Console.WriteLine("Usage: EdcbSchUploader <user> <pass> [epgurl] [slot] [upload_url]");
                Environment.Exit(2);
            }

            // サービス名としょぼかる放送局名の対応ファイル"SyoboiCh.txt"があれば読み込む
            var chMap = new Dictionary <string, string>();

            try
            {
                string[] chList = File.ReadAllText(
                    Path.Combine(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location), "SyoboiCh.txt"), Encoding.GetEncoding(932)
                    ).Split(new string[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries);
                foreach (string ch in chList)
                {
                    string[] chSplit = ch.Split(new char[] { '\t' });
                    if (chSplit.Length >= 2 && chSplit[0].StartsWith(";") == false)
                    {
                        chMap[chSplit[0]] = chSplit[1];
                    }
                }
            }
            catch
            {
            }

            // EpgTimerSrvから予約情報を取得
            var cmd = new CtrlCmdUtil();
            var rl  = new List <ReserveData>();
            var tl  = new List <TunerReserveInfo>();

            if (cmd.SendEnumReserve(ref rl) != ErrCode.CMD_SUCCESS ||
                cmd.SendEnumTunerReserve(ref tl) != ErrCode.CMD_SUCCESS)
            {
                Console.WriteLine("Failed to communicate with EpgTimerSrv.");
                Environment.Exit(1);
            }
            string data      = "";
            int    dataCount = 0;

            foreach (ReserveData r in rl)
            {
                string tuner = null;
                foreach (TunerReserveInfo tr in tl)
                {
                    if (tr.reserveList.Contains(r.ReserveID))
                    {
                        // T+{BonDriver番号(上2桁)}+{チューナ番号(下2桁)},チューナ不足はT9999
                        tuner = "T" + ("" + (10000 + Math.Min(tr.tunerID / 65536, 99) * 100 + Math.Min(tr.tunerID % 65536, 99))).Substring(1);
                        break;
                    }
                }
                if (tuner != null && r.RecSetting.RecMode <= 3 && r.RecSetting.Priority >= UPLOAD_REC_PRIORITY)
                {
                    // "最大200行"
                    if (dataCount++ >= 200)
                    {
                        break;
                    }
                    else
                    {
                        // "開始時間 終了時間 デバイス名 番組名 放送局名 サブタイトル オフセット XID"
                        string title = r.Title.Replace("\t", "").Replace("\r", "").Replace("\n", "");
                        data += ""
                                + (r.StartTime.ToUniversalTime() - (new DateTime(1970, 1, 1))).TotalSeconds + "\t"
                                + (r.StartTime.ToUniversalTime().AddSeconds(r.DurationSecond) - (new DateTime(1970, 1, 1))).TotalSeconds + "\t"
                                + tuner + "\t"
                                + (title.Length > UPLOAD_TITLE_MAXLEN ? title.Substring(0, UPLOAD_TITLE_MAXLEN - 1) + "…" : title) + "\t"
                                + (chMap.ContainsKey(r.StationName) ? chMap[r.StationName] : r.StationName) + "\t\t0\t"
                                + r.ReserveID + "\n";
                    }
                }
            }

            // 以前の内容と同じなら送信しない
            string lastPath = Path.ChangeExtension(Assembly.GetEntryAssembly().Location, "last");

            try
            {
                if (File.ReadAllText(lastPath) == data.Replace("\n", "\r\n"))
                {
                    Console.WriteLine("Not modified, nothing to do.");
                    Environment.Exit(0);
                }
            }
            catch
            {
            }

            // しょぼかるのPOSTは"Expect: 100-Continue"に対応してないっぽい
            ServicePointManager.Expect100Continue = false;

            // 予約情報をサーバに送信
            using (var wc = new WebClientWithTimeout())
            {
                // WebClientはデフォルトでIEのプロキシ設定に従う(wc.Proxy = WebRequest.DefaultWebProxy)
                // 認証プロキシなど必要であればwc.Proxyをここで設定すること
                wc.Timeout     = TIMEOUT;
                wc.Encoding    = Encoding.UTF8;
                wc.Credentials = new NetworkCredential(Uri.EscapeDataString(args[0]), Uri.EscapeDataString(args[1]));
                wc.Headers[HttpRequestHeader.ContentType] = "application/x-www-form-urlencoded";
                wc.Headers[HttpRequestHeader.UserAgent]   = USER_AGENT;
                var body = new System.Collections.Specialized.NameValueCollection();
                body["slot"]      = args.Length < 4 ? "0" : args[3];
                body["devcolors"] = DEV_COLORS;
                body["epgurl"]    = args.Length < 3 ? "" : args[2];
                body["data"]      = data;
                try
                {
                    wc.UploadValues(args.Length < 5 ? UPLOAD_URL : args[4], body);
                    File.WriteAllText(lastPath, data.Replace("\n", "\r\n"), Encoding.UTF8);
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.GetType().ToString() + " : " + ex.Message);
                    Environment.Exit(1);
                }
            }
            Console.WriteLine("Done.");
            Environment.Exit(0);
        }