Esempio n. 1
0
 /**************************************************************************
 *		ISF_ControlPanel_fnEnumObjects
 */
static BOOL SHELL_RegisterCPanelApp(IEnumIDList* list, LPCSTR path)
{
    LPITEMIDLIST pidl;
    CPlApplet* applet;
    CPanel panel;
    CPLINFO info;
    unsigned i;
    int iconIdx;

    char displayName[MAX_PATH];
    char comment[MAX_PATH];

    WCHAR wpath[MAX_PATH];

    MultiByteToWideChar(CP_ACP, 0, path, -1, wpath, MAX_PATH);

    panel.first = NULL;
    applet = Control_LoadApplet(0, wpath, &panel);

    if (applet)
    {
        for(i=0; i<applet->count; ++i)
        {
            WideCharToMultiByte(CP_ACP, 0, applet->info[i].szName, -1, displayName, MAX_PATH, 0, 0);
            WideCharToMultiByte(CP_ACP, 0, applet->info[i].szInfo, -1, comment, MAX_PATH, 0, 0);

            applet->proc(0, CPL_INQUIRE, i, (LPARAM)&info);

            if (info.idIcon > 0)
                iconIdx = -info.idIcon; /* negative icon index instead of icon number */
            else
                iconIdx = 0;

            pidl = _ILCreateCPanelApplet(path, displayName, comment, iconIdx);

            if (pidl)
                AddToEnumList(list, pidl);
        }
        Control_UnloadApplet(applet);
    }
    return TRUE;
}
Esempio n. 2
0
static void Control_DoWindow(CPanel *panel, HWND hWnd, HINSTANCE hInst)
{
    HANDLE hFind;
    WIN32_FIND_DATAW wfd;
    WCHAR wszPath[MAX_PATH];
    WCHAR *Ptr = wszPath;

    Ptr += GetSystemDirectoryW(wszPath, MAX_PATH);
    *Ptr++ = '\\';
    wcscpy(Ptr, L"*.cpl");

    hFind = FindFirstFileW(wszPath, &wfd);
    if (hFind != INVALID_HANDLE_VALUE)
    {
        do
        {
            wcscpy(Ptr, wfd.cFileName);
            Control_LoadApplet(hWnd, wszPath, panel);
        } while (FindNextFileW(hFind, &wfd));
        FindClose(hFind);
    }

    Control_DoInterface(panel, hWnd, hInst);
}
Esempio n. 3
0
static void Control_DoLaunch(CPanel *pPanel, HWND hWnd, LPCWSTR pwszCmd)
{
    HANDLE hMutex;

    /* Make a pwszCmd copy so we can modify it */
    LPWSTR pwszCmdCopy = _wcsdup(pwszCmd);

    LPWSTR pwszPath = pwszCmdCopy, pwszArg = NULL, pwszArg2 = NULL;
    if (!pwszCmdCopy)
        return;

    /* Path can be quoted */
    if (pwszPath[0] == L'"')
    {
        ++pwszPath;
        pwszArg = wcschr(pwszPath, L'"');
        if (pwszArg)
            *(pwszArg++) = '\0';
    }
    else
        pwszArg = pwszCmdCopy;

    /* First argument starts after space or ','. Note: we ignore characters between '"' and ',' or ' '. */
    if (pwszArg)
        pwszArg = wcspbrk(pwszArg, L" ,");
    if (pwszArg)
    {
        /* NULL terminate path and find first character of arg */
        *(pwszArg++) = L'\0';
        if (pwszArg[0] == L'"')
        {
            ++pwszArg;
            pwszArg2 = wcschr(pwszArg, L'"');
            if (pwszArg2)
                *(pwszArg2++) = L'\0';
        } else
            pwszArg2 = pwszArg;

        /* Second argument always starts with ','. Note: we ignore characters between '"' and ','. */
        if (pwszArg2)
            pwszArg2 = wcschr(pwszArg2, L',');
    }

    TRACE("Launch %ls, arg %ls, arg2 %ls\n", pwszPath, pwszArg, pwszArg2);

    /* Create a mutex to disallow running multiple instances */
    hMutex = CreateMutexW(NULL, TRUE, PathFindFileNameW(pwszPath));
    if (!hMutex || GetLastError() == ERROR_ALREADY_EXISTS)
    {
        TRACE("Next instance disallowed\n");
        if (hMutex)
            CloseHandle(hMutex);
        return;
    }

    /* Load applet cpl */
    TRACE("Load applet %ls\n", pwszPath);
    Control_LoadApplet(hWnd, pwszPath, pPanel);
    if (pPanel->first)
    {
        INT i = 0;
        /* First pPanel applet is the new one */
        CPlApplet *pApplet = pPanel->first;
        assert(pApplet && pApplet->next == NULL);
        TRACE("pApplet->count %d\n", pApplet->count);

        /* Note: if there is only one applet, first argument is ignored */
        if (pApplet->count > 1 && pwszArg && pwszArg[0])
        {
            /* If arg begins with '@', number specifies applet index */
            if (pwszArg[0] == L'@')
                i = _wtoi(pwszArg + 1);
            else
            {
                /* Otherwise it's applet name */
                for (i = 0; i < (INT)pApplet->count; ++i)
                    if (!wcscmp(pwszArg, pApplet->info[i].szName))
                        break;
            }
        }

        if (i >= 0 && i < (INT)pApplet->count && pApplet->info[i].dwSize)
        {
            /* Start the applet */
            TRACE("Starting applet %d\n", i);
            if (!pApplet->proc(pApplet->hWnd, CPL_STARTWPARMSW, i, (LPARAM)pwszArg))
                pApplet->proc(pApplet->hWnd, CPL_DBLCLK, i, pApplet->info[i].lData);
        } else
            ERR("Applet not found: %ls\n", pwszArg ? pwszArg : L"NULL");

        Control_UnloadApplet(pApplet);
    }
    else
        ERR("Failed to load applet %ls\n", pwszPath);

    ReleaseMutex(hMutex);
    CloseHandle(hMutex);
    free(pwszCmdCopy);
}