Пример #1
0
BOOL LocateFile(CString& path)
{
   if (FileExists(path))
      return TRUE;
   BOOL found = PathFindOnPath(path.GetBuffer(MAX_PATH+1), NULL);
   path.ReleaseBuffer();
   return found;
}
Пример #2
0
CFilePath & CFilePath::FindOnPath(LPCTSTR *psAdditionalDirs)
{
    DWORD dwLen = msPath.GetLength() + 1 + MAX_PATH;

    BOOL bRetCode = PathFindOnPath(CStringLock(msPath, dwLen), psAdditionalDirs) != 0;
    if (bRetCode)
        SetLastError(0);

    return *this;
}
Пример #3
0
/*
 * Calling LoadLibrary with a relative file name is a security risk:
 * see e.g. Microsoft Security Advisory (2269637)
 * "Insecure Library Loading Could Allow Remote Code Execution"
 */
HMODULE _al_win_safe_load_library(const char *filename)
{
    ALLEGRO_PATH *path1 = NULL;
    ALLEGRO_PATH *path2 = NULL;
    char buf[MAX_PATH];
    const char *other_dirs[3];
    HMODULE lib = NULL;
    bool msvc_only = false;

    /* MSVC only: if the executable is in the build configuration directory,
     * which is also just under the current directory, then also try to load the
     * library from the current directory.  This leads to less surprises when
     * running example programs.
     */
#if defined(ALLEGRO_MSVC)
    msvc_only = true;
#endif

    /* Try to load the library from the directory containing the running
     * executable, the Windows system directories, or directories on the PATH.
     * Do NOT try to load the library from the current directory.
     */

    if (al_is_system_installed()) {
        path1 = al_get_standard_path(ALLEGRO_RESOURCES_PATH);
    }
    else if (GetModuleFileName(NULL, buf, sizeof(buf)) < sizeof(buf)) {
        path1 = al_create_path(buf);
    }
    if (msvc_only) {
        path2 = maybe_parent_dir(path1);
    }

    other_dirs[0] = path1 ? al_path_cstr(path1, '\\') : NULL;
    other_dirs[1] = path2 ? al_path_cstr(path2, '\\') : NULL;
    other_dirs[2] = NULL; /* sentinel */

    _al_sane_strncpy(buf, filename, sizeof(buf));
    if (PathFindOnPath(buf, other_dirs)) {
        ALLEGRO_DEBUG("PathFindOnPath found: %s\n", buf);
        lib = load_library_at_path(buf);
    }
    else {
        ALLEGRO_WARN("PathFindOnPath failed to find %s\n", filename);
    }

    al_destroy_path(path1);
    al_destroy_path(path2);

    return lib;
}
Пример #4
0
// Find a file in the path using ShellAPI. This can be used to locate DLLs which
// QStandardPaths cannot do.
QString findInPath(const QString &file)
{
#if defined(Q_OS_WIN)
    if (file.size() < MAX_PATH -  1) {
        wchar_t buffer[MAX_PATH];
        file.toWCharArray(buffer);
        buffer[file.size()] = 0;
        if (PathFindOnPath(buffer, NULL))
            return QDir::cleanPath(QString::fromWCharArray(buffer));
    }
    return QString();
#else // Q_OS_WIN
    return QStandardPaths::findExecutable(file);
#endif // !Q_OS_WIN
}