このアプリケーションを呼び出すカスタム プロトコル ハンドラーをコンピューターに登録しています。
string prefix = "runapp://";
// The name of this app for user messages
string title = "RunApp URL Protocol Handler";
// Verify the command line arguments
if (args.Length == 0 || !args[0].StartsWith(prefix))
{
MessageBox.Show("Syntax:\nrunapp://<key>", title); return;
}
string key = args[0].Remove(0, "runapp://".Length);
key.TrimEnd('/');
string application = "";
string parameters = "";
string applicationDirectory = "";
if (key.Contains("~"))
{
application = key.Split('~')[0];
parameters = key.Split('~')[1];
}
else
{
application = key;
}
applicationDirectory = Directory.GetParent(application).FullName;
ProcessStartInfo psInfo = new ProcessStartInfo();
psInfo.Arguments = parameters;
psInfo.FileName = application;
MessageBox.Show(key + Environment.NewLine + Environment.NewLine + application + " " + parameters);
// Start the application
Process.Start(psInfo);
runapp:// リクエストを取得し、「~」文字の位置に従って、アプリケーションと渡されたパラメータの 2 つの部分に分割します。(PROGRA~1 か何かを渡す場合、これはおそらく良い考えではありませんが、これを使用するのは私だけであることを考えると、問題ではありません)、実行します。
ただし、末尾の「/」は常に文字列に追加されます:
runapp://E:\Emulation\GameBoy\visualboyadvance.exe~E:\Emulation\GameBoy\zelda4.gbc
、それは次のように解釈されます
runapp://E:\Emulation\GameBoy\visualboyadvance.exe E:\Emulation\GameBoy\zelda4.gbc/
.
なぜこれを行うのですか?そして、この末尾のスラッシュを取り除けないのはなぜですか? TrimEnd('/')
、Remove(key.IndexOf('/'), 1)
、を試しReplace("/", "")
ましたが、スラッシュは残ります。何が起こっている ?