2014-01-29 18:33:24 +08:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.ObjectModel;
|
2014-03-11 23:54:37 +08:00
|
|
|
|
using System.IO;
|
2014-01-29 18:33:24 +08:00
|
|
|
|
using System.Linq;
|
2014-03-27 12:58:36 +08:00
|
|
|
|
using System.Text;
|
2014-01-29 18:33:24 +08:00
|
|
|
|
using System.Threading;
|
|
|
|
|
using System.Windows;
|
2014-03-27 12:58:36 +08:00
|
|
|
|
using System.Windows.Forms;
|
|
|
|
|
using System.Windows.Threading;
|
2014-01-29 18:33:24 +08:00
|
|
|
|
using Microsoft.VisualBasic.ApplicationServices;
|
2014-03-27 12:58:36 +08:00
|
|
|
|
using Wox;
|
2014-01-29 18:33:24 +08:00
|
|
|
|
using Wox.Commands;
|
2014-03-11 23:54:37 +08:00
|
|
|
|
using Wox.Helper;
|
2014-03-27 12:58:36 +08:00
|
|
|
|
using Wox.Helper.ErrorReporting;
|
|
|
|
|
using Application = System.Windows.Application;
|
|
|
|
|
using MessageBox = System.Windows.MessageBox;
|
|
|
|
|
using MessageBoxOptions = System.Windows.Forms.MessageBoxOptions;
|
2014-01-29 18:33:24 +08:00
|
|
|
|
using StartupEventArgs = System.Windows.StartupEventArgs;
|
2014-03-27 12:58:36 +08:00
|
|
|
|
using UnhandledExceptionEventArgs = System.UnhandledExceptionEventArgs;
|
2014-01-29 18:33:24 +08:00
|
|
|
|
|
2014-05-10 09:24:16 +08:00
|
|
|
|
namespace Wox {
|
|
|
|
|
public static class EntryPoint {
|
|
|
|
|
[STAThread]
|
2014-05-21 07:45:11 +08:00
|
|
|
|
[System.Diagnostics.DebuggerStepThrough]
|
2014-05-10 09:24:16 +08:00
|
|
|
|
public static void Main(string[] args) {
|
|
|
|
|
AppDomain.CurrentDomain.UnhandledException += ErrorReporting.UnhandledExceptionHandle;
|
|
|
|
|
System.Windows.Forms.Application.ThreadException += ErrorReporting.ThreadException;
|
|
|
|
|
|
|
|
|
|
// don't combine Main and Entry since Microsoft.VisualBasic may be unable to load
|
|
|
|
|
// seperating them into two methods can make error reporting have the chance to catch exception
|
|
|
|
|
Entry(args);
|
|
|
|
|
}
|
|
|
|
|
|
2014-05-21 07:45:11 +08:00
|
|
|
|
[System.Diagnostics.DebuggerStepThrough]
|
2014-05-10 09:24:16 +08:00
|
|
|
|
private static void Entry(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
|
|
|
|
|
[System.Diagnostics.DebuggerStepThrough]
|
|
|
|
|
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();
|
2014-05-09 06:58:38 +08:00
|
|
|
|
//app.InitializeComponent();
|
2014-05-10 09:24:16 +08:00
|
|
|
|
app.Run();
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void OnStartupNextInstance(StartupNextInstanceEventArgs eventArgs) {
|
|
|
|
|
// Subsequent launches
|
|
|
|
|
base.OnStartupNextInstance(eventArgs);
|
|
|
|
|
app.Activate(eventArgs.CommandLine.ToArray());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public partial class App : Application {
|
|
|
|
|
|
|
|
|
|
private static MainWindow window;
|
|
|
|
|
|
|
|
|
|
public static MainWindow Window {
|
|
|
|
|
get {
|
|
|
|
|
return window;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void OnStartup(StartupEventArgs e) {
|
|
|
|
|
this.DispatcherUnhandledException += ErrorReporting.DispatcherUnhandledException;
|
|
|
|
|
|
|
|
|
|
base.OnStartup(e);
|
|
|
|
|
|
|
|
|
|
//for install plugin command when wox didn't start up
|
|
|
|
|
//we shouldn't init MainWindow, just intall plugin and exit.
|
|
|
|
|
if (e.Args.Length > 0 && e.Args[0].ToLower() == "installplugin") {
|
|
|
|
|
var path = e.Args[1];
|
|
|
|
|
if (!File.Exists(path)) {
|
|
|
|
|
MessageBox.Show("Plugin " + path + " didn't exist");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
PluginInstaller.Install(path);
|
|
|
|
|
Environment.Exit(0);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (e.Args.Length > 0 && e.Args[0].ToLower() == "plugindebugger") {
|
|
|
|
|
var path = e.Args[1];
|
|
|
|
|
PluginLoader.Plugins.ActivatePluginDebugger(path);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
window = new MainWindow();
|
|
|
|
|
if (e.Args.Length == 0 || e.Args[0].ToLower() != "hidestart") {
|
|
|
|
|
window.ShowApp();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
window.ParseArgs(e.Args);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Activate(string[] args) {
|
|
|
|
|
if (args.Length == 0 || args[0].ToLower() != "hidestart") {
|
|
|
|
|
window.ShowApp();
|
|
|
|
|
}
|
|
|
|
|
window.ParseArgs(args);
|
|
|
|
|
}
|
|
|
|
|
}
|
2014-01-29 18:33:24 +08:00
|
|
|
|
}
|