コード例 #1
0
    /// <summary>
    /// Processes command line of this program. Called after partial initialization.
    /// Returns true if this instance must exit:
    ///		1. If finds previous program instance; then sends the command line to it if need.
    ///		2. If incorrect command line.
    /// </summary>
    public static bool ProgramStarted2(string[] args)
    {
        string s   = null;
        int    cmd = 0;

        if (args.Length > 0)
        {
            //print.it(args);

            for (int i = 0; i < args.Length; i++)
            {
                if (args[i].Starts('-'))
                {
                    args[i] = args[i].ReplaceAt(0, 1, "/");
                }
                //if (args[i].Starts('/')) args[i] = args[i].Lower();
            }

            s = args[0];
            if (s.Starts('/'))
            {
                for (int i = 0; i < args.Length; i++)
                {
                    s = args[i];
                    switch (s)
                    {
                    case "/test":
                        if (++i < args.Length)
                        {
                            TestArg = args[i];
                        }
                        break;

                    case "/v":
                        StartVisible = true;
                        break;

                    default:
                        dialog.showError("Unknown command line parameter", s);
                        return(true);
                    }
                }
            }
            else                 //one or more files
            {
                if (args.Length == 1 && FilesModel.IsWorkspaceDirectoryOrZip_ShowDialogOpenImport(s, out cmd))
                {
                    switch (cmd)
                    {
                    case 1: WorkspaceDirectory = s; break;

                    case 2: _importWorkspace = s; break;

                    default: return(true);
                    }
                }
                else
                {
                    cmd          = 3;
                    _importFiles = args;
                }
                StartVisible = true;
            }
        }

        //single instance
        s_mutex = new Mutex(true, "Au.Editor.Mutex.m3gVxcTJN02pDrHiQ00aSQ", out bool createdNew);
        if (createdNew)
        {
            return(false);
        }

        var w = wnd.findFast(null, script.c_msgWndClassName, true);

        if (!w.Is0)
        {
            w.Send(Api.WM_USER, 0, 1);             //auto-creates, shows and activates main window

            if (cmd != 0)
            {
                Thread.Sleep(100);

                if (cmd == 3)
                {
                    s = string.Join("\0", args);                           //import files
                }
                WndCopyData.Send <char>(w, cmd, s);
            }
        }
        return(true);
    }