public MainWindow() { CommonManager.Instance.NWMode = true; Settings.LoadFromXmlFileNW(); ChSet5.LoadFile(); cmd.SetSendMode(true); cmd.SetNWSetting(Settings.Instance.NWServerIP, Settings.Instance.NWServerPort); CommonManager.Instance.ReloadCustContentColorList(); CommonManager.Instance.DB.SetNoAutoReloadEPG(Settings.Instance.NgAutoEpgLoadNW); if (Settings.Instance.NoStyle == 0) { ResourceDictionary rd = new ResourceDictionary(); rd.MergedDictionaries.Add( Application.LoadComponent(new Uri("/PresentationFramework.Aero, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35;component/themes/aero.normalcolor.xaml", UriKind.Relative)) as ResourceDictionary //Application.LoadComponent(new Uri("/PresentationFramework.Classic, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, ProcessorArchitecture=MSIL;component/themes/Classic.xaml", UriKind.Relative)) as ResourceDictionary ); this.Resources = rd; } mutex = new System.Threading.Mutex(false, "Global\\EpgTimer_BonNW"); if (!mutex.WaitOne(0, false)) { CheckCmdLine(); mutex.Close(); mutex = null; closeFlag = true; Close(); return; } if (CommonManager.Instance.NWMode == false) { bool startExe = false; try { if (ServiceCtrlClass.ServiceIsInstalled("EpgTimer Service") == true) { if (ServiceCtrlClass.IsStarted("EpgTimer Service") == false) { bool check = false; for (int i = 0; i < 5; i++) { if (ServiceCtrlClass.StartService("EpgTimer Service") == true) { check = true; } System.Threading.Thread.Sleep(1000); if (ServiceCtrlClass.IsStarted("EpgTimer Service") == true) { check = true; } } if (check == false) { MessageBox.Show("サービスの開始に失敗しました。\r\nVista以降のOSでは、管理者権限で起動されている必要があります。"); closeFlag = true; Close(); return; } else { serviceMode = true; startExe = true; } } else { serviceMode = true; startExe = true; } } } catch (Exception ex) { MessageBox.Show(ex.Message + "\r\n" + ex.StackTrace); serviceMode = false; } try { if (serviceMode == false) { String moduleFolder = System.IO.Path.GetDirectoryName(Environment.GetCommandLineArgs()[0]); String exePath = moduleFolder + "\\EpgTimerSrv.exe"; System.Diagnostics.Process process = System.Diagnostics.Process.Start(exePath); startExe = true; } } catch (Exception ex) { MessageBox.Show(ex.Message + "\r\n" + ex.StackTrace); startExe = false; } if (startExe == false) { MessageBox.Show("EpgTimerSrv.exeの起動ができませんでした"); closeFlag = true; Close(); return; } } InitializeComponent(); initExe = true; try { if (Settings.Instance.WakeMin == true) { this.Visibility = System.Windows.Visibility.Hidden; } //ウインドウ位置の復元 if (Settings.Instance.MainWndTop != -100) { this.Top = Settings.Instance.MainWndTop; } if (Settings.Instance.MainWndLeft != -100) { this.Left = Settings.Instance.MainWndLeft; } if (Settings.Instance.MainWndWidth != -100) { this.Width = Settings.Instance.MainWndWidth; } if (Settings.Instance.MainWndHeight != -100) { this.Height = Settings.Instance.MainWndHeight; } this.WindowState = Settings.Instance.LastWindowState; //上のボタン Button settingButton = new Button(); settingButton.MinWidth = 75; settingButton.Margin = new Thickness(2, 2, 2, 5); settingButton.Click += new RoutedEventHandler(settingButton_Click); settingButton.Content = "設定"; if (Settings.Instance.NoStyle == 0) { settingButton.Style = (Style)App.Current.Resources["ButtonStyle1"]; } buttonList.Add("設定", settingButton); Button searchButton = new Button(); searchButton.MinWidth = 75; searchButton.Margin = new Thickness(2, 2, 2, 5); searchButton.Click += new RoutedEventHandler(searchButton_Click); searchButton.Content = "検索"; if (Settings.Instance.NoStyle == 0) { searchButton.Style = (Style)App.Current.Resources["ButtonStyle1"]; } buttonList.Add("検索", searchButton); Button closeButton = new Button(); closeButton.MinWidth = 75; closeButton.Margin = new Thickness(2, 2, 2, 5); closeButton.Click += new RoutedEventHandler(closeButton_Click); closeButton.Content = "終了"; if (Settings.Instance.NoStyle == 0) { closeButton.Style = (Style)App.Current.Resources["ButtonStyle1"]; } buttonList.Add("終了", closeButton); Button stanbyButton = new Button(); stanbyButton.MinWidth = 75; stanbyButton.Margin = new Thickness(2, 2, 2, 5); stanbyButton.Click += new RoutedEventHandler(standbyButton_Click); stanbyButton.Content = "スタンバイ"; if (Settings.Instance.NoStyle == 0) { stanbyButton.Style = (Style)App.Current.Resources["ButtonStyle1"]; } buttonList.Add("スタンバイ", stanbyButton); Button suspendButton = new Button(); suspendButton.MinWidth = 75; suspendButton.Margin = new Thickness(2, 2, 2, 5); suspendButton.Click += new RoutedEventHandler(suspendButton_Click); suspendButton.Content = "休止"; if (Settings.Instance.NoStyle == 0) { suspendButton.Style = (Style)App.Current.Resources["ButtonStyle1"]; } buttonList.Add("休止", suspendButton); Button epgCapButton = new Button(); epgCapButton.MinWidth = 75; epgCapButton.Margin = new Thickness(2, 2, 2, 5); epgCapButton.Click += new RoutedEventHandler(epgCapButton_Click); epgCapButton.Content = "EPG取得"; if (Settings.Instance.NoStyle == 0) { epgCapButton.Style = (Style)App.Current.Resources["ButtonStyle1"]; } buttonList.Add("EPG取得", epgCapButton); Button epgReloadButton = new Button(); epgReloadButton.MinWidth = 75; epgReloadButton.Margin = new Thickness(2, 2, 2, 5); epgReloadButton.Click += new RoutedEventHandler(epgReloadButton_Click); epgReloadButton.Content = "EPG再読み込み"; if (Settings.Instance.NoStyle == 0) { epgReloadButton.Style = (Style)App.Current.Resources["ButtonStyle1"]; } buttonList.Add("EPG再読み込み", epgReloadButton); Button custum1Button = new Button(); custum1Button.MinWidth = 75; custum1Button.Margin = new Thickness(2, 2, 2, 5); custum1Button.Click += new RoutedEventHandler(custum1Button_Click); custum1Button.Content = "カスタム1"; if (Settings.Instance.NoStyle == 0) { custum1Button.Style = (Style)App.Current.Resources["ButtonStyle1"]; } buttonList.Add("カスタム1", custum1Button); Button custum2Button = new Button(); custum2Button.MinWidth = 75; custum2Button.Margin = new Thickness(2, 2, 2, 5); custum2Button.Click += new RoutedEventHandler(custum2Button_Click); custum2Button.Content = "カスタム2"; if (Settings.Instance.NoStyle == 0) { custum2Button.Style = (Style)App.Current.Resources["ButtonStyle1"]; } buttonList.Add("カスタム2", custum2Button); Button nwTVEndButton = new Button(); nwTVEndButton.MinWidth = 75; nwTVEndButton.Margin = new Thickness(2, 2, 2, 5); nwTVEndButton.Click += new RoutedEventHandler(nwTVEndButton_Click); nwTVEndButton.Content = "NetworkTV終了"; if (Settings.Instance.NoStyle == 0) { nwTVEndButton.Style = (Style)App.Current.Resources["ButtonStyle1"]; } buttonList.Add("NetworkTV終了", nwTVEndButton); Button logViewButton = new Button(); logViewButton.MinWidth = 75; logViewButton.Margin = new Thickness(2, 2, 2, 5); logViewButton.Click += new RoutedEventHandler(logViewButton_Click); logViewButton.Content = "情報通知ログ"; if (Settings.Instance.NoStyle == 0) { logViewButton.Style = (Style)App.Current.Resources["ButtonStyle1"]; } buttonList.Add("情報通知ログ", logViewButton); Button connectButton = new Button(); connectButton.MinWidth = 75; connectButton.Margin = new Thickness(2, 2, 2, 5); connectButton.Click += new RoutedEventHandler(connectButton_Click); connectButton.Content = "再接続"; if (Settings.Instance.NoStyle == 0) { connectButton.Style = (Style)App.Current.Resources["ButtonStyle1"]; } buttonList.Add("再接続", connectButton); ResetButtonView(); //タスクトレイの表示 taskTray = new TaskTrayClass(this); taskTray.Icon = Properties.Resources.TaskIconBlue; taskTray.Visible = true; taskTray.ContextMenuClick += new EventHandler(taskTray_ContextMenuClick); if (CommonManager.Instance.NWMode == false) { pipeServer = new PipeServer(); pipeName += System.Diagnostics.Process.GetCurrentProcess().Id.ToString(); pipeEventName += System.Diagnostics.Process.GetCurrentProcess().Id.ToString(); pipeServer.StartServer(pipeEventName, pipeName, OutsideCmdCallback, this); cmd.SendRegistGUI((uint)System.Diagnostics.Process.GetCurrentProcess().Id); CommonManager.Instance.DB.ReloadReserveInfo(); ReserveData item = new ReserveData(); if (CommonManager.Instance.DB.GetNextReserve(ref item) == true) { String timeView = item.StartTime.ToString("yyyy/MM/dd(ddd) HH:mm:ss ~ "); DateTime endTime = item.StartTime + TimeSpan.FromSeconds(item.DurationSecond); timeView += endTime.ToString("HH:mm:ss"); taskTray.Text = "次の予約:" + item.StationName + " " + timeView + " " + item.Title; } else { taskTray.Text = "次の予約なし"; } } ResetTaskMenu(); CheckCmdLine(); if (CommonManager.Instance.NWMode == true) { if (Settings.Instance.WakeReconnectNW == false) { return; } if (CommonManager.Instance.NW.ConnectServer(Settings.Instance.NWServerIP, Settings.Instance.NWServerPort, Settings.Instance.NWWaitPort, OutsideCmdCallback, this) == false) { return; } iniConnectNW = true; byte[] binData; if (cmd.SendFileCopy("ChSet5.txt", out binData) == 1) { string filePath = SettingPath.SettingFolderPath; System.IO.Directory.CreateDirectory(filePath); filePath += "\\ChSet5.txt"; using (System.IO.BinaryWriter w = new System.IO.BinaryWriter(System.IO.File.Create(filePath))) { w.Write(binData); w.Close(); } ChSet5.LoadFile(); } CommonManager.Instance.DB.ReloadReserveInfo(); ReserveData item = new ReserveData(); if (CommonManager.Instance.DB.GetNextReserve(ref item) == true) { String timeView = item.StartTime.ToString("yyyy/MM/dd(ddd) HH:mm:ss ~ "); DateTime endTime = item.StartTime + TimeSpan.FromSeconds(item.DurationSecond); timeView += endTime.ToString("HH:mm:ss"); taskTray.Text = "次の予約:" + item.StationName + " " + timeView + " " + item.Title; } else { taskTray.Text = "次の予約なし"; } } } catch (Exception ex) { MessageBox.Show(ex.Message + "\r\n" + ex.StackTrace); } }
bool ConnectSrv() { IniSetting.Instance.Clear(); serviceMode = ServiceCtrlClass.ServiceIsInstalled("EpgTimer Service"); Title = appName; DisconnectServer(); CommonManager.Instance.DB.ClearRecFileAppend(true); CommonManager.Instance.DB.SetNoAutoReloadEPG(Settings.Instance.NgAutoEpgLoadNW); if (initExe == true) { ChkTimerWork(); } if (Settings.Instance.NWMode == false) { bool startExe = false; try { if (System.Diagnostics.Process.GetProcessesByName("EpgTimerSrv").Count() == 0) { if (serviceMode == true) { if (ServiceCtrlClass.IsStarted("EpgTimer Service") == false) { ServiceCtrlClass.StartService("EpgTimer Service"); int count = 5; do { System.Threading.Thread.Sleep(1000); } while (ServiceCtrlClass.IsStarted("EpgTimer Service") == false && --count > 0); if (count == 0) { MessageBox.Show("サービスの開始に失敗しました。\r\nVista以降のOSでは、管理者権限で起動されている必要があります。"); } else { startExe = true; } } else { startExe = true; } } else { String moduleFolder = SettingPath.ModulePath.TrimEnd('\\'); String exePath = moduleFolder + "\\EpgTimerSrv.exe"; if (System.IO.File.Exists(exePath)) { System.Diagnostics.Process process = System.Diagnostics.Process.Start(exePath); startExe = true; //EpgTimerSrvを自分で起動させた場合、後でUpdateNotifyItem.EpgDataが来るので、初期フラグをリセットする。 CommonManager.Instance.DB.ResetUpdateNotifyEpg(); } else //if (showDialog == true) { MessageBox.Show("EpgTimerSrv.exeの起動ができませんでした"); } } } else { startExe = true; } } catch (Exception ex) { MessageBox.Show(ex.Message + "\r\n" + ex.StackTrace); serviceMode = false; startExe = false; } if (startExe == true) { CommonManager.Instance.DB.SetNoAutoReloadEPG(false); CommonManager.Instance.NWMode = false; cmd.SetSendMode(false); pipeServer = new PipeServer(); pipeServer.StartServer(pipeEventName, pipeName, (c, r) => OutsideCmdCallback(c, r, false)); ErrCode err = ErrCode.CMD_SUCCESS; for (int i = 0; i < 150 && (err = cmd.SendRegistGUI((uint)System.Diagnostics.Process.GetCurrentProcess().Id)) != ErrCode.CMD_SUCCESS; i++) { Thread.Sleep(100); } CommonManager.Instance.IsConnected = (err == ErrCode.CMD_SUCCESS); } else { CommonManager.Instance.NWMode = true; // ローカル接続できないのでネットワークモードとして動作させる cmd.SetSendMode(true); CommonManager.Instance.IsConnected = false; } } else { try { foreach (var address in System.Net.Dns.GetHostAddresses(Settings.Instance.NWServerIP)) { if (address.IsIPv6LinkLocal == false && CommonManager.Instance.NW.ConnectServer(address, Settings.Instance.NWServerPort, Settings.Instance.NWWaitPort, (c, r) => OutsideCmdCallback(c, r, true)) == true) { CommonManager.Instance.IsConnected = CommonManager.Instance.NW.IsConnected; break; } } } catch { } if (CommonManager.Instance.IsConnected == false) { if (Settings.Instance.ChkSrvRegistTCP == true && taskTray != null) { taskTray.Icon = TaskIconSpec.TaskIconGray; } cmd.SetNWSetting("", 0); } } return InitializeClient(); }
void DisconnectServer() { if (pipeServer != null) { cmd.SetConnectTimeOut(3000); cmd.SendUnRegistGUI((uint)System.Diagnostics.Process.GetCurrentProcess().Id); pipeServer.StopServer(); pipeServer = null; } CommonManager.Instance.NW.DisconnectServer(); CommonManager.Instance.NWMode = true; cmd.SetSendMode(CommonManager.Instance.NWMode); cmd.SetNWSetting("", 0); CommonManager.Instance.IsConnected = false; }
bool ConnectCmd(bool showDialog) { IniSetting.Instance.Clear(); bool reconnect = true; if (showDialog == true) { ConnectWindow dlg = new ConnectWindow(); PresentationSource topWindow = PresentationSource.FromVisual(this); if (topWindow != null) { dlg.Owner = (Window)topWindow.RootVisual; } reconnect = dlg.ShowDialog() == true; } serviceMode = ServiceCtrlClass.ServiceIsInstalled("EpgTimer Service"); if (reconnect) { Title = appName; DisconnectServer(); CommonManager.Instance.DB.SetNoAutoReloadEPG(Settings.Instance.NgAutoEpgLoadNW); ChkRegistTCPTimerWork(); if (Settings.Instance.NWMode == false) { bool startExe = false; try { if (System.Diagnostics.Process.GetProcessesByName("EpgTimerSrv").Count() == 0) { if (serviceMode == true) { if (ServiceCtrlClass.IsStarted("EpgTimer Service") == false) { ServiceCtrlClass.StartService("EpgTimer Service"); int count = 5; do { System.Threading.Thread.Sleep(1000); } while (ServiceCtrlClass.IsStarted("EpgTimer Service") == false && --count > 0); if (count == 0) { MessageBox.Show("サービスの開始に失敗しました。\r\nVista以降のOSでは、管理者権限で起動されている必要があります。"); } else { startExe = true; } } else { startExe = true; } } else { String moduleFolder = SettingPath.ModulePath.TrimEnd('\\'); String exePath = moduleFolder + "\\EpgTimerSrv.exe"; if (System.IO.File.Exists(exePath)) { System.Diagnostics.Process process = System.Diagnostics.Process.Start(exePath); startExe = true; } else if (showDialog == true) { MessageBox.Show("EpgTimerSrv.exeの起動ができませんでした"); } } } else { startExe = true; } } catch (Exception ex) { MessageBox.Show(ex.Message + "\r\n" + ex.StackTrace); serviceMode = false; startExe = false; } if (startExe == true) { CommonManager.Instance.DB.SetNoAutoReloadEPG(false); CommonManager.Instance.NWMode = false; cmd.SetSendMode(false); pipeServer = new PipeServer(); pipeServer.StartServer(pipeEventName, pipeName, (c, r) => OutsideCmdCallback(c, r, false)); ErrCode err = ErrCode.CMD_SUCCESS; for (int i = 0; i < 150 && (err = cmd.SendRegistGUI((uint)System.Diagnostics.Process.GetCurrentProcess().Id)) != ErrCode.CMD_SUCCESS; i++) { Thread.Sleep(100); } CommonManager.Instance.IsConnected = (err == ErrCode.CMD_SUCCESS); } else { CommonManager.Instance.NWMode = true; // ローカル接続できないのでネットワークモードとして動作させる cmd.SetSendMode(true); CommonManager.Instance.IsConnected = false; } } else { try { foreach (var address in System.Net.Dns.GetHostAddresses(Settings.Instance.NWServerIP)) { if (address.IsIPv6LinkLocal == false && CommonManager.Instance.NW.ConnectServer(address, Settings.Instance.NWServerPort, Settings.Instance.NWWaitPort, (c, r) => OutsideCmdCallback(c, r, true)) == true) { CommonManager.Instance.IsConnected = CommonManager.Instance.NW.IsConnected; break; } } } catch { } if (CommonManager.Instance.IsConnected == false) { if (showDialog == true) { MessageBox.Show("サーバーへの接続に失敗しました"); } cmd.SetNWSetting("", 0); } } IniFileHandler.UpdateSrvProfileIniNW(); CommonManager.Instance.DB.SetUpdateNotify((UInt32)UpdateNotifyItem.ReserveInfo); CommonManager.Instance.DB.SetUpdateNotify((UInt32)UpdateNotifyItem.RecInfo); CommonManager.Instance.DB.SetUpdateNotify((UInt32)UpdateNotifyItem.AutoAddEpgInfo); CommonManager.Instance.DB.SetUpdateNotify((UInt32)UpdateNotifyItem.AutoAddManualInfo); CommonManager.Instance.DB.SetUpdateNotify((UInt32)UpdateNotifyItem.EpgData); CommonManager.Instance.DB.SetUpdateNotify((UInt32)UpdateNotifyItem.PlugInFile); CommonManager.Instance.DB.ReloadReserveInfo(); CommonManager.Instance.DB.ReloadEpgData(); reserveView.UpdateInfo(); tunerReserveView.UpdateInfo(); autoAddView.UpdateAutoAddInfo(); recInfoView.UpdateInfo(); epgView.UpdateEpgData(); SearchWindow.UpdatesInfo(); recLogView.onConnected(this); searchLogView.onConnected(recLogView); } if (CommonManager.Instance.IsConnected) { ChSet5.Clear(); if (CommonManager.Instance.NWMode) { Title = appName + " - " + Settings.Instance.NWServerIP + ":" + Settings.Instance.NWServerPort.ToString(); } else { Title = appName + " - ローカル接続"; } } else { Title = appName + " - 未接続"; } return CommonManager.Instance.IsConnected; }