/src/MarkPad/App.xaml.cs
https://github.com/bcott/DownmarkerWPF · C# · 60 lines · 47 code · 11 blank · 2 comment · 7 complexity · c4fa6817ee02332312b2fcdfe1ab5291 MD5 · raw file
- using System;
- using System.Collections.Generic;
- using System.IO;
- using System.Linq;
- using System.Reflection;
- using MarkPad.Events;
- using MarkPad.Infrastructure;
- using MarkPad.Preview;
- namespace MarkPad
- {
- public partial class App : ISingleInstanceApp
- {
- private const string Unique = "There can be only one MARKPAD!!! (We ignore crappy sequels here)";
- private readonly AppBootstrapper bootstrapper;
- public App()
- {
- InitializeComponent();
- HtmlPreview.Init();
- bootstrapper = new AppBootstrapper();
- }
- public void HandleArguments(string[] args)
- {
- if (args.Length == 2)
- {
- var filePath = args[1];
- bootstrapper.GetEventAggregator().Publish(new FileOpenEvent(filePath));
- }
- }
- [STAThread]
- public static void Main()
- {
- var directoryName = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location);
- if (directoryName != null && Directory.GetCurrentDirectory() != directoryName)
- Directory.SetCurrentDirectory(directoryName);
- if (SingleInstance<App>.InitializeAsFirstInstance(Unique))
- {
- new App().Run();
- // Allow single instance code to perform cleanup operations
- SingleInstance<App>.Cleanup();
- }
- }
- public bool SignalExternalCommandLineArgs(IList<string> args)
- {
- // handle command line arguments of second instance
- HandleArguments(args.ToArray());
- return true;
- }
- }
- }