Skip to content

Commit

Permalink
同時起動するパスに変な文字が含まれているばあいに落ちないようにした #6
Browse files Browse the repository at this point in the history
  • Loading branch information
onihusube committed Jul 30, 2022
1 parent f98a9a8 commit a5f68d5
Showing 1 changed file with 59 additions and 34 deletions.
93 changes: 59 additions & 34 deletions 2chAPIProxy/ViewModels/ViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -288,51 +288,76 @@ public void Init()
DatProxy.End();
}
}
//同時起動と終了を設定
if (!String.IsNullOrEmpty(Setting.SenburaPath))

// 同時起動と終了を設定
if (!string.IsNullOrEmpty(Setting.SenburaPath))
{
bool kage = true;
System.Diagnostics.Process p = new System.Diagnostics.Process();
p.StartInfo.FileName = Setting.SenburaPath;
if (System.IO.Path.GetFileName(Setting.SenburaPath) != "kage.exe")
{
kage = false;
p.EnableRaisingEvents = true;
p.Exited += (sender, e) =>
{
App.Current.Dispatcher.BeginInvoke((Action)(() => { if (Setting.SyncEnd) BeforeShutdown(); }), null);
};
}
try

do
{
p.Start();
m_SenburaPID = p.Id;
SystemLog = Setting.SenburaPath + " を起動";
m_SyncStart = true;
//かちゅ~しゃの場合の終了同期処理の追加
if (kage)
// かちゅ~しゃにたいするkageは、実際に起動しているプロセス名が異なる
// 終了を同期するときに特別扱いする必要がある
bool kage = true;

try
{
System.Diagnostics.Process[] plist = null;
for (int i = 0; i < 50; ++i)
// 同時起動したい専ブラのパスが""で囲われているなどすると、ここで例外
if (System.IO.Path.GetFileName(Setting.SenburaPath) != "kage.exe")
{
plist = System.Diagnostics.Process.GetProcessesByName("Katjusha");
if (plist.Length != 0) break;
System.Threading.Thread.Sleep(100);
kage = false;

p.EnableRaisingEvents = true;
p.Exited += (sender, e) =>
{
App.Current.Dispatcher.BeginInvoke((Action)(() => { if (Setting.SyncEnd) BeforeShutdown(); }), null);
};
}
plist[0].EnableRaisingEvents = true;
plist[0].Exited += (sender, e) =>
}
catch (ArgumentException)
{
SystemLog = "同時起動する専ブラのパス文字列に無効な文字が含まれています(\" < > など)\n同時起動は無効化されます";

// パス文字列が使用できないので同時起動はしない
break;
}
try
{
// 対象を起動
_ = p.Start();

m_SenburaPID = p.Id;
SystemLog = Setting.SenburaPath + " を起動";
m_SyncStart = true;

// かちゅ~しゃの場合の終了同期処理の追加
if (kage)
{
App.Current.Dispatcher.BeginInvoke((Action)(() => { if (Setting.SyncEnd) BeforeShutdown(); }), null);
};
m_SenburaPID = plist[0].Id;
System.Diagnostics.Process[] plist = null;
for (int i = 0; i < 50; ++i)
{
plist = System.Diagnostics.Process.GetProcessesByName("Katjusha");
if (plist.Length != 0) break;
System.Threading.Thread.Sleep(100);
}
plist[0].EnableRaisingEvents = true;
plist[0].Exited += (sender, e) =>
{
App.Current.Dispatcher.BeginInvoke((Action)(() => { if (Setting.SyncEnd) BeforeShutdown(); }), null);
};
m_SenburaPID = plist[0].Id;
}
}
}
catch (Exception err)
{
SystemLog = Setting.SenburaPath + " の起動に失敗\n" + err.ToString();
}
catch (Exception err)
{
SystemLog = Setting.SenburaPath + " の起動に失敗\n" + err.ToString();
}
} while (false);
}

Setting.change = false;

//プロセス間通信のサーバ登録
try
{
Expand Down

0 comments on commit a5f68d5

Please sign in to comment.