diff --git a/mojp/App.xaml b/mojp/App.xaml index e64fbf41..760e3aca 100644 --- a/mojp/App.xaml +++ b/mojp/App.xaml @@ -3,6 +3,6 @@ x:Class="Mojp.App" StartupUri="MainWindow.xaml"> - + diff --git a/mojp/App.xaml.cs b/mojp/App.xaml.cs index f360bdf7..75f6a623 100644 --- a/mojp/App.xaml.cs +++ b/mojp/App.xaml.cs @@ -5,6 +5,7 @@ using System.Linq; using System.Net.Http; using System.Reflection; +using System.Threading; using System.Threading.Tasks; using System.Windows; using System.Windows.Threading; @@ -37,6 +38,26 @@ public partial class App : Application /// public static Dispatcher CurrentDispatcher => Current.Dispatcher; + /// + /// Application Entry Point. + /// + [STAThread] + public static void Main() + { + const string AppGuid = "{B99B5E4E-C7AA-4D4C-8674-DBAC723D29D5}"; + + // 多重起動防止 + using (var sema = new Semaphore(0, 1, AppGuid, out bool createdNew)) + { + if (createdNew) + { + var app = new App(); + app.InitializeComponent(); + app.Run(); + } + } + } + /// /// カードテキストデータを XML に保存します。 /// @@ -114,6 +135,29 @@ public static async Task IsOutdatedRelease(bool acceptsPrerelease) return Version.TryParse(version, out var latest) && current < latest; } + /// + /// 指定した名前のプロセスを探し、そのプロセス ID を取得します。 + /// + /// プロセスの名前。 + /// 取得したプロセス ID 。 + /// プロセスが見つかった場合は + public static bool GetProcessIDByName(string processName, out int id) + { + foreach (var proc in Process.GetProcesses()) + { + using (proc) + { + if (string.Equals(proc.ProcessName, processName, StringComparison.OrdinalIgnoreCase)) + { + id = proc.Id; + return true; + } + } + } + id = 0; + return false; + } + protected override void OnStartup(StartupEventArgs e) { base.OnStartup(e); diff --git a/mojp/CardTextProcessor.cs b/mojp/CardTextProcessor.cs index 6069923f..66bde90e 100644 --- a/mojp/CardTextProcessor.cs +++ b/mojp/CardTextProcessor.cs @@ -78,7 +78,7 @@ public static string NormalizeName(string name) /// /// アーティスト名に対応する英雄譚のカード名を取得します。 /// - public static bool GetSagaNameByArtist(string artist, out string cardName) + public static bool GetSagaByArtist(string artist, out string cardName) { switch (artist) { diff --git a/mojp/MainViewModel.cs b/mojp/MainViewModel.cs index 6365f9d9..950b00ef 100644 --- a/mojp/MainViewModel.cs +++ b/mojp/MainViewModel.cs @@ -424,7 +424,7 @@ public void ReleaseAutomationElement() } } - protected void OnPropertyChanged([CallerMemberName] string propertyName = null) + protected void OnPropertyChanged([CallerMemberName] string propertyName = null) => PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); /// @@ -433,20 +433,7 @@ protected void OnPropertyChanged([CallerMemberName] string propertyName = null) private void OnCapture(object sender, EventArgs e) { // MO のプロセス ID を取得する - int? mtgoProcessID = null; - - foreach (var proc in Process.GetProcesses()) - { - if (string.Equals(proc.ProcessName, "mtgo", StringComparison.OrdinalIgnoreCase)) - { - mtgoProcessID = proc.Id; - proc.Dispose(); - break; - } - proc.Dispose(); - } - - if (!mtgoProcessID.HasValue) + if (!App.GetProcessIDByName("mtgo", out int mtgoProcessID)) { ReleaseAutomationElement(); SetMessage("起動中のプロセスの中に MO が見つかりません。"); @@ -459,7 +446,7 @@ private void OnCapture(object sender, EventArgs e) { currentPrevWnd = AutomationElement.RootElement.FindFirst(TreeScope.Children, new AndCondition( - new PropertyCondition(AutomationElement.ProcessIdProperty, mtgoProcessID.Value), + new PropertyCondition(AutomationElement.ProcessIdProperty, mtgoProcessID), new PropertyCondition(AutomationElement.ClassNameProperty, "Window"), new PropertyCondition(AutomationElement.NameProperty, "Preview"))); } @@ -532,10 +519,10 @@ private void OnAutomaionNamePropertyChanged(object sender, AutomationPropertyCha return; } } - else if (Card.GetSagaNameByArtist(name, out string saga)) + else if (Card.GetSagaByArtist(name, out string saga)) { // 英雄譚はカード名を Automation で探せないため、アーティスト名で 1:1 対応で探す - if (CheckCardTypeForSaga(saga)) + if (CheckAndViewSaga(saga)) return; } @@ -574,9 +561,9 @@ private void SearchCardName() return; // 英雄譚の絵師かもしれない場合 - if (Card.GetSagaNameByArtist(name, out string saga)) + if (Card.GetSagaByArtist(name, out string saga)) { - if (CheckCardTypeForSaga(saga)) + if (CheckAndViewSaga(saga)) return; } @@ -647,7 +634,7 @@ private void SearchCardName() /// /// 現在のカードのカードタイプが英雄譚であるかどうかをチェックし、そうであるなら、指定したカード名のカードを表示します。 /// - private bool CheckCardTypeForSaga(string cardName) + private bool CheckAndViewSaga(string cardName) { if (App.Cards.TryGetValue(cardName, out var foundCard)) { @@ -658,7 +645,6 @@ private bool CheckCardTypeForSaga(string cardName) element = prevWnd?.FindFirst(TreeScope.Descendants, new PropertyCondition(AutomationElement.AutomationIdProperty, "CardType")); } - string cardType = GetNamePropertyValue(element); if (cardType != null && cardType.EndsWith("Saga")) diff --git a/mojp/MainWindow.xaml b/mojp/MainWindow.xaml index f21f2595..ca5446a3 100644 --- a/mojp/MainWindow.xaml +++ b/mojp/MainWindow.xaml @@ -7,9 +7,6 @@ Left="{Binding WindowLeft, Mode=TwoWay}" Top="{Binding WindowTop, Mode=TwoWay}" Icon="Resources/dictionary.ico" SnapsToDevicePixels="True" Initialized="OnInitialized"> - - - @@ -142,11 +139,11 @@ - + - + diff --git a/mojp/OptionDialog.xaml b/mojp/OptionDialog.xaml index c7e6aefb..6990dab5 100644 --- a/mojp/OptionDialog.xaml +++ b/mojp/OptionDialog.xaml @@ -18,7 +18,6 @@ - @@ -54,7 +53,13 @@ + ToolTipService.ShowDuration="60000"> + + + 起動時とこのダイアログを閉じた時に更新があるかどうかを確認します。 + 更新があったときは、ダウンロードサイトへのリンクを表示します。 + + 最新バージョンを自動的に確認する @@ -114,13 +119,13 @@ - タブに表示するカード名 + ToolTip="タブに表示されるカード名の書式を指定します。ただしテキスト本文中は《日本語》で固定です。" ToolTipService.ShowDuration="60000"> + カード名の表示方法 + ToolTip="タブに表示されるカード名の書式を指定します。ただしテキスト本文中は《日本語》で固定です。" ToolTipService.ShowDuration="60000"> 日本語 日本語 / English English / 日本語 @@ -146,14 +151,20 @@ + ToolTip="チェックを外すと、氷雪でない基本の平地、島、沼、山、森には反応しなくなります。" ToolTipService.ShowDuration="60000"> 基本土地 5 種のカードテキストを表示する - + + + + チェックを外した場合は「MO を探す」ボタン + + を適時クリックしてください。 + + MO の Preview Pane を自動的に探す diff --git a/mojp/Properties/AssemblyInfo.cs b/mojp/Properties/AssemblyInfo.cs index 5967ab06..d18b32d1 100644 --- a/mojp/Properties/AssemblyInfo.cs +++ b/mojp/Properties/AssemblyInfo.cs @@ -52,4 +52,4 @@ // 既定値にすることができます: // [assembly: AssemblyVersion("1.0.*")] [assembly: AssemblyVersion("1.8.0.0")] -[assembly: AssemblyFileVersion("1.8.30609.19")] +[assembly: AssemblyFileVersion("1.8.30609.20")] diff --git a/mojp/mojp.csproj b/mojp/mojp.csproj index 6a365961..c113f98f 100644 --- a/mojp/mojp.csproj +++ b/mojp/mojp.csproj @@ -57,10 +57,10 @@ - + MSBuild:Compile Designer - + MSBuild:Compile