Skip to content

Commit

Permalink
November 5, 2022
Browse files Browse the repository at this point in the history
  • Loading branch information
walbourn committed Nov 5, 2022
1 parent d2e4c95 commit 307b7b5
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 19 deletions.
34 changes: 17 additions & 17 deletions FindMedia.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,17 @@

#pragma once

#if defined(WINAPI_FAMILY) && (WINAPI_FAMILY != WINAPI_FAMILY_DESKTOP_APP)
#error This header only works with Windows desktop apps
#endif

#include <exception>
#include <string.h>
#include <cstddef>
#include <cstring>
#include <stdexcept>


namespace DX
{
inline void FindMediaFile(_Out_writes_(cchDest) wchar_t* strDestPath, _In_ int cchDest, _In_z_ const wchar_t* strFilename)
inline void FindMediaFile(
_Out_writes_(cchDest) wchar_t* strDestPath,
_In_ int cchDest,
_In_z_ const wchar_t* strFilename)
{
bool bFound = false;

Expand All @@ -31,7 +31,7 @@ namespace DX
wchar_t strExePath[MAX_PATH] = {};
wchar_t strExeName[MAX_PATH] = {};
wchar_t* strLastSlash = nullptr;
GetModuleFileName(nullptr, strExePath, MAX_PATH);
std::ignore = GetModuleFileNameW(nullptr, strExePath, MAX_PATH);
strExePath[MAX_PATH - 1] = 0;
strLastSlash = wcsrchr(strExePath, TEXT('\\'));
if (strLastSlash)
Expand All @@ -48,7 +48,7 @@ namespace DX
}

wcscpy_s(strDestPath, cchDest, strFilename);
if (GetFileAttributes(strDestPath) != 0xFFFFFFFF)
if (GetFileAttributesW(strDestPath) != 0xFFFFFFFF)
return;

// Search all parent directories starting at .\ and using strFilename as the leaf name
Expand All @@ -60,37 +60,37 @@ namespace DX
wchar_t strSearch[MAX_PATH] = {};
wchar_t* strFilePart = nullptr;

GetFullPathName(strExePath, MAX_PATH, strFullPath, &strFilePart);
std::ignore = GetFullPathNameW(strExePath, MAX_PATH, strFullPath, &strFilePart);
if (!strFilePart)
throw std::exception("FindMediaFile");
throw std::runtime_error("FindMediaFile");

while (strFilePart && *strFilePart != '\0')
{
swprintf_s(strFullFileName, MAX_PATH, L"%ls\\%ls", strFullPath, strLeafName);
if (GetFileAttributes(strFullFileName) != 0xFFFFFFFF)
if (GetFileAttributesW(strFullFileName) != 0xFFFFFFFF)
{
wcscpy_s(strDestPath, cchDest, strFullFileName);
bFound = true;
break;
}

swprintf_s(strFullFileName, MAX_PATH, L"%ls\\%ls\\%ls", strFullPath, strExeName, strLeafName);
if (GetFileAttributes(strFullFileName) != 0xFFFFFFFF)
if (GetFileAttributesW(strFullFileName) != 0xFFFFFFFF)
{
wcscpy_s(strDestPath, cchDest, strFullFileName);
bFound = true;
break;
}

swprintf_s(strSearch, MAX_PATH, L"%ls\\..", strFullPath);
GetFullPathName(strSearch, MAX_PATH, strFullPath, &strFilePart);
std::ignore = GetFullPathNameW(strSearch, MAX_PATH, strFullPath, &strFilePart);
}
if (bFound)
return;

// On failure, return the file as the path but also return an error code
wcscpy_s(strDestPath, cchDest, strFilename);
// On failure, return the file as the path but also throw an error
wcscpy_s(strDestPath, size_t(cchDest), strFilename);

throw std::exception("File not found");
throw std::runtime_error("File not found");
}
}
4 changes: 4 additions & 0 deletions HISTORY.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ Release available for download on [GitHub](https://github.com/walbourn/directxtk

## Release History

### November 5, 2022
* Updated for October 2022 release of DirectX Tool Kit
* Added lighting vs. unlit toggle

### March 22, 2022
* Updated for March 2022 release of DirectX Tool Kit
* Converted Desktop project to VS 2019
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@

Copyright (c) Microsoft Corporation.

**March 22, 2022**
**November 5, 2022**

The DirectX Tool Kit Model Viewer is an interactive test application for validating ``.SDKMESH``, ``.VBO``, and ``.CMO`` files rendered using the DirectX Tool Kit.

This code is designed to build with Visual Studio 2017 ([15.9](https://walbourn.github.io/vs-2017-15-9-update/)) or VS 2019 (16.4 or later).
This code is designed to build with Visual Studio 2017 ([15.9](https://walbourn.github.io/vs-2017-15-9-update/)) or VS 2019 (16.11).

## Notices

Expand Down

0 comments on commit 307b7b5

Please sign in to comment.