Skip to content

Commit

Permalink
Managerのエラー表示をかなり強化。setting.jsonをアンインストール時に削除する機能を追加
Browse files Browse the repository at this point in the history
  • Loading branch information
gpsnmeajp committed Jun 12, 2021
1 parent 5dd0792 commit d223b5c
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 21 deletions.
8 changes: 5 additions & 3 deletions vmt_manager/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<TextBlock Name="StatusBarTextBlock" Text="Virtual Motion Tracker" FontWeight="Bold" />
</StatusBarItem>
</StatusBar>
<TabControl DockPanel.Dock="Top">
<TabControl DockPanel.Dock="Top" Name="MainTabControl">
<TabItem Header="Install">
<DockPanel LastChildFill="False">
<DockPanel.Background>
Expand All @@ -23,12 +23,14 @@
<GradientStop Color="#FF111111" Offset="1"/>
</LinearGradientBrush>
</DockPanel.Background>
<Grid DockPanel.Dock="Top" Margin="1">
<TextBlock Text="" Name="TopErrorTextBlock" Visibility="Collapsed" DockPanel.Dock="Top" Background="Red" Foreground="White" TextWrapping="Wrap" />
<TextBlock Text="VMT is not installed. Click install button to start use VMT.&#xA;VMTはインストールされていません。&#xA;使い始めるにはInstallボタンを押してください。" Name="TopNotInstalledTextBlock" DockPanel.Dock="Top" Background="Green" Foreground="White" TextWrapping="Wrap" />
<Grid DockPanel.Dock="Top" Margin="1" Name="InstallGrid">
<Grid.ColumnDefinitions>
<ColumnDefinition/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<Button Content="Install" DockPanel.Dock="Top" Click="InstallButton" Grid.Column="0" Margin="1"/>
<Button Content="Install" Name="InstallButtonName" DockPanel.Dock="Top" Click="InstallButton" Grid.Column="0" Margin="1"/>
<Button Content="Uninstall" DockPanel.Dock="Top" Click="UninstallButton" Grid.Column="1" Margin="1"/>
</Grid>
<Grid DockPanel.Dock="Top" Margin="2">
Expand Down
93 changes: 75 additions & 18 deletions vmt_manager/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,51 +60,90 @@ public MainWindow()
InitializeComponent();
}

private void TopErrorMessage(string message)
{
TopErrorTextBlock.Visibility = Visibility.Visible;
TopErrorTextBlock.Text = message;
TopErrorTextBlock.Background = new SolidColorBrush(Color.FromRgb(255, 0, 0));
TopErrorTextBlock.Foreground = new SolidColorBrush(Color.FromRgb(255, 255, 255));
TopNotInstalledTextBlock.Visibility = Visibility.Collapsed;
InstallButtonName.IsEnabled = false;

//Top以外を削除する
int count = MainTabControl.Items.Count;
for (int i = 1; i < count; i++)
{
MainTabControl.Items.Remove(MainTabControl.Items[1]);
}
}
private void TopWarningMessage(string message, bool enable = false)
{
TopErrorTextBlock.Visibility = Visibility.Visible;
TopErrorTextBlock.Text = message;
TopErrorTextBlock.Background = new SolidColorBrush(Color.FromRgb(255, 255, 0));
TopErrorTextBlock.Foreground = new SolidColorBrush(Color.FromRgb(0, 0, 0));
MainTabControl.SelectedIndex = 0;
TopNotInstalledTextBlock.Visibility = Visibility.Collapsed;

//Top以外を削除する
if (!enable) {
int count = MainTabControl.Items.Count;
for (int i = 1; i < count; i++)
{
MainTabControl.Items.Remove(MainTabControl.Items[1]);
}
}
}

private void Window_Loaded(object sender, RoutedEventArgs e)
{
try
{
Console.WriteLine("Loaded");
title = this.Title;
ManagerVersion.Text = Version;
DriverVersion.Text = "-";
DriverVersion.Text = " - ";

rnd = new Random();
osc = new OSC("127.0.0.1", 39571, 39570, OnBundle, OnMessage);

//タイマー起動
dispatcherTimer = new DispatcherTimer();
dispatcherTimer.Interval = new TimeSpan(0, 0, 0, 0, 100);
dispatcherTimer.Tick += new EventHandler(GenericTimer);
dispatcherTimer.Start();

util = new EasyOpenVRUtil();
if (!util.StartOpenVR())
{
var result = MessageBox.Show("Steam VR not ready. Maybe not ready for HMD or Tracking system.\nStream VRが利用できません。HMDやトラッキングシステムが利用できない状態の可能性があります。", title, MessageBoxButton.OK, MessageBoxImage.Error);
Close();
//var result = MessageBox.Show("Steam VR not ready. Maybe not ready for HMD or Tracking system.\nStream VRが利用できません。HMDやトラッキングシステムが利用できない状態の可能性があります。", title, MessageBoxButton.OK, MessageBoxImage.Error);
TopErrorMessage("Steam VR not ready. Maybe not ready for HMD or Tracking system.\nStream VRが利用できません。HMDやトラッキングシステムが利用できない状態の可能性があります。");
//Close();
return;
}

osc = new OSC("127.0.0.1", 39571, 39570, OnBundle, OnMessage);

//セーフモードチェック
EVRSettingsError eVRSettingsError = EVRSettingsError.None;
bool safemode = OpenVR.Settings.GetBool("driver_vmt", OpenVR.k_pch_Driver_BlockedBySafemode_Bool, ref eVRSettingsError);
if (eVRSettingsError == EVRSettingsError.None && safemode)
{
var result = MessageBox.Show("SteamVR runnning on safe mode and VMT has blocked.\nPlease unblock, and restart SteamVR.\n\nSteamVRがセーフモードで動作し、VMTがブロックされています。\nブロックを解除し、SteamVRを再起動してください。", title, MessageBoxButton.OK, MessageBoxImage.Error);
//var result = MessageBox.Show("SteamVR runnning on safe mode and VMT has blocked.\nPlease unblock, and restart SteamVR.\n\nSteamVRがセーフモードで動作し、VMTがブロックされています。\nブロックを解除し、SteamVRを再起動してください。", title, MessageBoxButton.OK, MessageBoxImage.Error);
TopErrorMessage("SteamVR runnning on safe mode and VMT has blocked.\nPlease unblock, and restart SteamVR.\n\nSteamVRがセーフモードで動作し、VMTがブロックされています。\nブロックを解除し、SteamVRを再起動してください。");
return;
}
//Enableチェック
eVRSettingsError = EVRSettingsError.None;
bool enable = OpenVR.Settings.GetBool("driver_vmt", OpenVR.k_pch_Driver_Enable_Bool, ref eVRSettingsError);
if (eVRSettingsError == EVRSettingsError.None && !enable)
{
var result = MessageBox.Show("VMT has disabled in Steam VR setting.\nPlease enable, and restart SteamVR.\n\nVMTはSteamVR上で無効に設定されています。\n有効にし、SteamVRを再起動してください。", title, MessageBoxButton.OK, MessageBoxImage.Error);
//var result = MessageBox.Show("VMT has disabled in Steam VR setting.\nPlease enable, and restart SteamVR.\n\nVMTはSteamVR上で無効に設定されています。\n有効にし、SteamVRを再起動してください。", title, MessageBoxButton.OK, MessageBoxImage.Error);
TopErrorMessage("VMT has disabled in Steam VR setting.\nPlease enable, and restart SteamVR.\n\nVMTはSteamVR上で無効に設定されています。\n有効にし、SteamVRを再起動してください。");
return;
}

//デバッグのためにセーフモードを有効化
//OpenVR.Settings.SetBool(OpenVR.k_pch_SteamVR_Section, OpenVR.k_pch_SteamVR_EnableSafeMode, true,ref eVRSettingsError);

//タイマー起動
dispatcherTimer = new DispatcherTimer();
dispatcherTimer.Interval = new TimeSpan(0, 0, 0, 0, 100);
dispatcherTimer.Tick += new EventHandler(GenericTimer);
dispatcherTimer.Start();

string[] args = System.Environment.GetCommandLineArgs();
if (args.Length > 1)
{
Expand Down Expand Up @@ -177,11 +216,13 @@ private void OnMessage(OscMessage message)
if (versionFromOSC != Version)
{
DriverVersion.Foreground = new SolidColorBrush(Color.FromRgb(255, 100, 100));
TopWarningMessage("Different version VMT detected. You can not use VMT Manager for setting. but you can use this to uninstall VMT driver.\n\n違うバージョンのVMTがインストールされています。このVMT Managerでは設定はできません。VMTをアンインストールすることは出来ます。");
}
else
{
DriverVersion.Foreground = new SolidColorBrush(Color.FromRgb(0, 255, 0));
}
TopNotInstalledTextBlock.Visibility = Visibility.Collapsed;
aliveCnt = 0;
});
Expand Down Expand Up @@ -317,7 +358,7 @@ private void GenericTimer(object sender, EventArgs e)
if (aliveCnt > 90)
{
installPath = "";
DriverVersion.Text = "-";
DriverVersion.Text = " - ";
DriverVersion.Foreground = new SolidColorBrush(Color.FromRgb(255, 255, 255));
ControlDock.IsEnabled = false;
}
Expand Down Expand Up @@ -456,9 +497,10 @@ private void CheckJointPosition2Button(object sender, RoutedEventArgs e)

private void InstallButton(object sender, RoutedEventArgs e)
{
if (DriverVersion.Text != "-")
if (DriverVersion.Text != " - ")
{
MessageBox.Show("Please uninstall VMT before install.\nインストールを続ける前に、VMTをアンインストールしてください", title, MessageBoxButton.OK, MessageBoxImage.Error);
//MessageBox.Show("Please uninstall VMT before install.\nインストールを続ける前に、VMTをアンインストールしてください", title, MessageBoxButton.OK, MessageBoxImage.Error);
TopWarningMessage("Please uninstall VMT before install.\nインストールを続ける前に、VMTをアンインストールしてください", true);
return;
}

Expand Down Expand Up @@ -512,7 +554,7 @@ private async void UninstallButton(object sender, RoutedEventArgs e)
else
{
//場所不明だがとりあえず現在の場所としてアンインストールしようとするか確認する
var res = MessageBox.Show("Other VMT Driver version detected.\nIn many cases, this driver located on different path.\nmanager can not uninstallation these.\nIf you want to remove currently installed VMT driver, press cancel and please use manager of drivers itself.\n\nPress OK, Try uninstallation anyway. (it will fail in many cases.)\n\n違うバージョンのVMTドライバを検出しました\n多くの場合これは別のパスにあります。\n本Managerではアンインストールできません。\nアンインストールしたい場合は、キャンセルを押し、そのVMTドライバに付属のManagerを使用してください\n\nOKを押すと、とにかくアンインストールを試します。(多くの場合失敗します。)", title, MessageBoxButton.OKCancel, MessageBoxImage.Error);
var res = MessageBox.Show("Manager couldn't communication to VMT Driver.\nOther VMT Driver version maybe installed.\nIn many cases, this driver located on different path.\nmanager can not uninstallation these.\nIf you want to remove currently installed VMT driver, press cancel and please use manager of drivers itself.\n\nIf you want to try uninstallation anyway, press OK. (it will fail in many cases.)\n\nVMTドライバと通信できませんでした。\n違うバージョンのVMTドライバが入っている可能性があります\n多くの場合これは別のパスにあります。\n本Managerではアンインストールできません。\nアンインストールしたい場合は、キャンセルを押し、そのVMTドライバに付属のManagerを使用してください\n\nOKを押すと、とにかくアンインストールを試します。(多くの場合失敗します。)", title, MessageBoxButton.OKCancel, MessageBoxImage.Error);
if (res != MessageBoxResult.OK)
{
return;
Expand All @@ -529,7 +571,22 @@ private async void UninstallButton(object sender, RoutedEventArgs e)
process.Start();
process.WaitForExit();

MessageBox.Show("OK (ExitCode=" + process.ExitCode + ")\nPlease restart SteamVR.", title);
if (File.Exists(driverPath + @"\setting.json"))
{
var res = MessageBox.Show("Do you want to remove setting.json?(Recommended: Yes)\nSetting.jsonを消去しますか?(推奨: はい)\n\n" + installPath + @"\setting.json", title, MessageBoxButton.YesNo, MessageBoxImage.Question);
if (res != MessageBoxResult.Yes)
{
MessageBox.Show("OK (ExitCode=" + process.ExitCode + ")\nPlease restart SteamVR.", title);
return;
}
File.Delete(driverPath + @"\setting.json");
MessageBox.Show("OK and remove setting.json(ExitCode=" + process.ExitCode + ")\nPlease restart SteamVR.", title);
return;
}
else {
MessageBox.Show("OK (ExitCode=" + process.ExitCode + ")\nPlease restart SteamVR.", title);
return;
}
}
catch (Exception ex)
{
Expand Down

0 comments on commit d223b5c

Please sign in to comment.