2014-01-06 22:21:08 +08:00
|
|
|
|
using System;
|
2014-01-12 18:15:30 +08:00
|
|
|
|
using System.Collections.ObjectModel;
|
|
|
|
|
using System.Linq;
|
2014-01-06 22:21:08 +08:00
|
|
|
|
using System.Threading;
|
|
|
|
|
using System.Windows;
|
2014-01-12 18:15:30 +08:00
|
|
|
|
using Microsoft.VisualBasic.ApplicationServices;
|
2014-01-12 21:02:39 +08:00
|
|
|
|
using WinAlfred.Commands;
|
2014-01-12 18:15:30 +08:00
|
|
|
|
using StartupEventArgs = System.Windows.StartupEventArgs;
|
2014-01-06 22:21:08 +08:00
|
|
|
|
|
|
|
|
|
namespace WinAlfred
|
|
|
|
|
{
|
2014-01-12 18:15:30 +08:00
|
|
|
|
public static class EntryPoint
|
|
|
|
|
{
|
|
|
|
|
[STAThread]
|
|
|
|
|
public static void Main(string[] args)
|
|
|
|
|
{
|
|
|
|
|
SingleInstanceManager manager = new SingleInstanceManager();
|
|
|
|
|
manager.Run(args);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Using VB bits to detect single instances and process accordingly:
|
|
|
|
|
// * OnStartup is fired when the first instance loads
|
|
|
|
|
// * OnStartupNextInstance is fired when the application is re-run again
|
|
|
|
|
// NOTE: it is redirected to this instance thanks to IsSingleInstance
|
|
|
|
|
public class SingleInstanceManager : WindowsFormsApplicationBase
|
|
|
|
|
{
|
|
|
|
|
App app;
|
|
|
|
|
|
|
|
|
|
public SingleInstanceManager()
|
|
|
|
|
{
|
|
|
|
|
this.IsSingleInstance = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override bool OnStartup(Microsoft.VisualBasic.ApplicationServices.StartupEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
// First time app is launched
|
|
|
|
|
app = new App();
|
|
|
|
|
app.InitializeComponent();
|
|
|
|
|
app.Run();
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void OnStartupNextInstance(StartupNextInstanceEventArgs eventArgs)
|
|
|
|
|
{
|
|
|
|
|
// Subsequent launches
|
|
|
|
|
base.OnStartupNextInstance(eventArgs);
|
|
|
|
|
app.Activate(eventArgs.CommandLine.ToArray());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-01-06 22:21:08 +08:00
|
|
|
|
public partial class App : Application
|
|
|
|
|
{
|
2014-01-26 21:18:01 +08:00
|
|
|
|
|
|
|
|
|
private static MainWindow window;
|
|
|
|
|
|
|
|
|
|
public static MainWindow Window
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return window;
|
|
|
|
|
}
|
|
|
|
|
}
|
2014-01-12 18:15:30 +08:00
|
|
|
|
|
2014-01-06 22:21:08 +08:00
|
|
|
|
protected override void OnStartup(StartupEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
base.OnStartup(e);
|
2014-01-12 18:15:30 +08:00
|
|
|
|
|
|
|
|
|
window = new MainWindow();
|
2014-01-12 21:02:39 +08:00
|
|
|
|
window.ShowApp();
|
|
|
|
|
window.ParseArgs(e.Args);
|
2014-01-12 18:15:30 +08:00
|
|
|
|
}
|
|
|
|
|
|
2014-01-12 21:02:39 +08:00
|
|
|
|
public void Activate(string[] args)
|
2014-01-12 18:15:30 +08:00
|
|
|
|
{
|
2014-01-12 21:02:39 +08:00
|
|
|
|
window.ShowApp();
|
|
|
|
|
window.ParseArgs(args);
|
2014-01-06 22:21:08 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|