예제 #1
0
        public static int Main(string[] args)
        {
            if (args.Length == 1)
            {
                if (args[0] == "--install")
                {
                    return((int)ShellExtension.Install(true));
                }
                if (args[0] == "--uninstall")
                {
                    return((int)ShellExtension.Uninstall(true));
                }
            }

            int i;

            var files = new List <string>(args.Length);

            if (args.Length == 1 && args[0] == "--pipe")
            {
                var reader = new StreamReader(Console.OpenStandardInput(), Encoding.UTF8);

                string path;
                while (true)
                {
                    path = reader.ReadLine();
                    if (string.IsNullOrEmpty(path))
                    {
                        break;
                    }

                    if (Check(path))
                    {
                        files.Add(path);
                    }
                }
            }
            else
            {
                for (i = 0; i < args.Length; ++i)
                {
                    if (Check(args[i]))
                    {
                        files.Add(args[i]);
                    }
                }
            }

            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            using (Instance = new InstanceHelperEx(KISBO_MUTEX_NAME))
            {
                if (Instance.IsInstance)
                {
                    var frm = new SearchWindow();
                    Instance.DataReceived += frm.AddFile;
                    Instance.Ready();

                    frm.AddFile(files);

                    Application.Run(frm);
                }
                else
                {
                    if (files.Count > 0)
                    {
                        byte[] data;
                        var    sb = new StringBuilder(4096);
                        for (i = 0; i < args.Length; ++i)
                        {
                            if (i > 0)
                            {
                                sb.Append('\n');
                            }
                            sb.Append(args[i]);
                        }

                        data = Encoding.UTF8.GetBytes(sb.ToString());

                        Instance.Send(data);
                    }
                    else
                    {
                        Instance.Send(new byte[1] {
                            0
                        });
                    }
                }
            }

            return(0);
        }