Newer
Older
JumpListUtil / ShortcutUtil / Program.cs
using Entries;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
using NativeHelpers;
using System.Runtime.InteropServices;

namespace ShortcutUtil
{
    public class HelperLocation
    {
        public string Location;
        public bool Valid
        {
            get
            {
                return File.Exists(Location);
            }
        }
        public HelperLocation(string fileName)
        {
            Location = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, fileName);
            if (Valid) return;

            Location = Path.Combine(Environment.CurrentDirectory, fileName);
        }
    }
    static class Program
    {
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main()
        {
            AppResolver appResolver = new AppResolver();

            string[] args = Environment.GetCommandLineArgs();

            if (args.Length < 2)
            {
                MessageBox.Show("Drag a shortcuts.json onto this executable");
                return;
            }

            EntryList entryList = null;
            try
            {
                entryList = EntryList.FromFile(args[1]);
            }
            catch (Exception e)
            {
                MessageBox.Show("Couldn't load settings file " + args[1] + "\n" + e);
                return;
            }

            if (entryList.Entries.Count == 0)
            {
                MessageBox.Show("No shorcuts in that settings file!");
                return;
            }

            Environment.CurrentDirectory = Path.GetDirectoryName(Path.GetFullPath(args[1]));

            HelperLocation location = new HelperLocation("JumpListUtil.exe");


            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new MainForm(entryList, appResolver, location));
        }
    }
}