Add FreeType, progress to title screen

This commit is contained in:
elasota
2019-12-21 18:40:17 -05:00
parent c9c6976344
commit 8354d13a84
901 changed files with 444265 additions and 440 deletions

View File

@@ -1,11 +1,11 @@
#include "GpFileSystem_Win32.h"
#include "GpFileStream_Win32.h"
#include "GpWindows.h"
#include "GpFileSystem_Win32.h"
#include "GpFileStream_Win32.h"
#include "GpWindows.h"
#include "GpMemoryBuffer.h"
#include "HostDirectoryCursor.h"
#include <string>
#include <Shlwapi.h>
#include "HostDirectoryCursor.h"
#include <string>
#include <Shlwapi.h>
#include <ShlObj.h>
#include <assert.h>
@@ -24,7 +24,7 @@ private:
HANDLE m_handle;
WIN32_FIND_DATAW m_findData;
char m_chars[MAX_PATH + 1];
bool m_haveNext;
bool m_haveNext;
};
GpDirectoryCursor_Win32 *GpDirectoryCursor_Win32::Create(const HANDLE &handle, const WIN32_FIND_DATAW &findData)
@@ -85,66 +85,111 @@ GpDirectoryCursor_Win32::GpDirectoryCursor_Win32(const HANDLE &handle, const WIN
: m_handle(handle)
, m_findData(findData)
, m_haveNext(true)
{
{
}
GpDirectoryCursor_Win32::~GpDirectoryCursor_Win32()
{
FindClose(m_handle);
}
GpFileSystem_Win32::GpFileSystem_Win32()
{
PWSTR docsPath;
if (!FAILED(SHGetKnownFolderPath(FOLDERID_Documents, KF_FLAG_DEFAULT, nullptr, &docsPath)))
{
try
{
m_prefsDir = docsPath;
}
catch(...)
{
CoTaskMemFree(docsPath);
throw;
}
m_prefsDir.append(L"\\GlidePort");
CreateDirectoryW(m_prefsDir.c_str(), nullptr);
m_prefsDir.append(L"\\");
}
}
bool GpFileSystem_Win32::FileExists(PortabilityLayer::EVirtualDirectory virtualDirectory, const char *path)
{
wchar_t winPath[MAX_PATH + 1];
if (!ResolvePath(virtualDirectory, path, winPath))
return false;
return PathFileExistsW(winPath) != 0;
}
PortabilityLayer::IOStream *GpFileSystem_Win32::OpenFile(PortabilityLayer::EVirtualDirectory virtualDirectory, const char *path, bool writeAccess, bool create)
{
wchar_t winPath[MAX_PATH + 1];
if (!ResolvePath(virtualDirectory, path, winPath))
return false;
const DWORD desiredAccess = writeAccess ? (GENERIC_WRITE | GENERIC_READ) : GENERIC_READ;
const DWORD creationDisposition = create ? OPEN_ALWAYS : OPEN_EXISTING;
HANDLE h = CreateFileW(winPath, desiredAccess, FILE_SHARE_READ, nullptr, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, nullptr);
return new GpFileStream_Win32(h, true, writeAccess, true);
GpFileSystem_Win32::GpFileSystem_Win32()
{
m_executablePath[0] = 0;
PWSTR docsPath;
if (!FAILED(SHGetKnownFolderPath(FOLDERID_Documents, KF_FLAG_DEFAULT, nullptr, &docsPath)))
{
try
{
m_prefsDir = docsPath;
}
catch(...)
{
CoTaskMemFree(docsPath);
throw;
}
m_prefsDir.append(L"\\GlidePort");
CreateDirectoryW(m_prefsDir.c_str(), nullptr);
m_prefsDir.append(L"\\");
}
DWORD modulePathSize = GetModuleFileNameW(nullptr, m_executablePath, MAX_PATH);
if (modulePathSize == MAX_PATH || modulePathSize == 0)
m_executablePath[0] = 0;
size_t currentPathLength = wcslen(m_executablePath);
for (;;)
{
while (currentPathLength > 0 && m_executablePath[currentPathLength - 1] != '\\')
currentPathLength--;
m_executablePath[currentPathLength] = 0;
if (currentPathLength + 11 > MAX_PATH)
{
// "Resources" append is a longer path than the executable
continue;
}
if (wcscat_s(m_executablePath, L"Resources"))
{
currentPathLength = 0;
break;
}
if (PathFileExistsW(m_executablePath) && PathIsDirectoryW(m_executablePath))
{
m_executablePath[currentPathLength] = 0;
break;
}
else
currentPathLength--;
}
if (currentPathLength > 0)
{
m_packagedDir = std::wstring(m_executablePath) + L"Packaged\\";
m_housesDir = std::wstring(m_executablePath) + L"Packaged\\Houses\\";
m_resourcesDir = std::wstring(m_executablePath) + L"Resources\\";
}
}
bool GpFileSystem_Win32::FileExists(PortabilityLayer::EVirtualDirectory virtualDirectory, const char *path)
{
wchar_t winPath[MAX_PATH + 1];
if (!ResolvePath(virtualDirectory, path, winPath))
return false;
return PathFileExistsW(winPath) != 0;
}
PortabilityLayer::IOStream *GpFileSystem_Win32::OpenFile(PortabilityLayer::EVirtualDirectory virtualDirectory, const char *path, bool writeAccess, bool create)
{
wchar_t winPath[MAX_PATH + 1];
if (!ResolvePath(virtualDirectory, path, winPath))
return false;
const DWORD desiredAccess = writeAccess ? (GENERIC_WRITE | GENERIC_READ) : GENERIC_READ;
const DWORD creationDisposition = create ? OPEN_ALWAYS : OPEN_EXISTING;
HANDLE h = CreateFileW(winPath, desiredAccess, FILE_SHARE_READ, nullptr, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, nullptr);
if (h == INVALID_HANDLE_VALUE)
return false;
return new GpFileStream_Win32(h, true, writeAccess, true);
}
PortabilityLayer::HostDirectoryCursor *GpFileSystem_Win32::ScanDirectory(PortabilityLayer::EVirtualDirectory virtualDirectory)
{
wchar_t winPath[MAX_PATH + 2];
if (!ResolvePath(virtualDirectory, "*", winPath))
{
wchar_t winPath[MAX_PATH + 2];
if (!ResolvePath(virtualDirectory, "*", winPath))
return nullptr;
WIN32_FIND_DATAW findData;
@@ -153,49 +198,52 @@ PortabilityLayer::HostDirectoryCursor *GpFileSystem_Win32::ScanDirectory(Portabi
if (ff == INVALID_HANDLE_VALUE)
return nullptr;
return GpDirectoryCursor_Win32::Create(ff, findData);
}
GpFileSystem_Win32 *GpFileSystem_Win32::GetInstance()
{
return &ms_instance;
}
bool GpFileSystem_Win32::ResolvePath(PortabilityLayer::EVirtualDirectory virtualDirectory, const char *path, wchar_t *outPath)
{
const wchar_t *baseDir = nullptr;
switch (virtualDirectory)
{
case PortabilityLayer::EVirtualDirectory_ApplicationData:
baseDir = L"D:\\Source Code\\GlidePort\\Packaged\\";
break;
case PortabilityLayer::EVirtualDirectory_GameData:
baseDir = L"D:\\Source Code\\GlidePort\\Packaged\\Houses\\";
break;
case PortabilityLayer::EVirtualDirectory_Prefs:
baseDir = m_prefsDir.c_str();
break;
default:
return false;
}
if (baseDir == nullptr)
return false;
const size_t baseDirLen = wcslen(baseDir);
const size_t pathLen = strlen(path);
if (baseDirLen >= MAX_PATH || MAX_PATH - baseDirLen < pathLen)
return false;
memcpy(outPath, baseDir, sizeof(wchar_t) * baseDirLen);
for (size_t i = 0; i < pathLen; i++)
outPath[baseDirLen + i] = static_cast<wchar_t>(path[i]);
outPath[baseDirLen + pathLen] = static_cast<wchar_t>(0);
return true;
}
GpFileSystem_Win32 GpFileSystem_Win32::ms_instance;
return GpDirectoryCursor_Win32::Create(ff, findData);
}
GpFileSystem_Win32 *GpFileSystem_Win32::GetInstance()
{
return &ms_instance;
}
bool GpFileSystem_Win32::ResolvePath(PortabilityLayer::EVirtualDirectory virtualDirectory, const char *path, wchar_t *outPath)
{
const wchar_t *baseDir = nullptr;
switch (virtualDirectory)
{
case PortabilityLayer::EVirtualDirectory_ApplicationData:
baseDir = m_packagedDir.c_str();
break;
case PortabilityLayer::EVirtualDirectory_GameData:
baseDir = m_housesDir.c_str();
break;
case PortabilityLayer::EVirtualDirectory_Prefs:
baseDir = m_prefsDir.c_str();
break;
case PortabilityLayer::EVirtualDirectory_Fonts:
baseDir = m_resourcesDir.c_str();
break;
default:
return false;
}
if (baseDir == nullptr)
return false;
const size_t baseDirLen = wcslen(baseDir);
const size_t pathLen = strlen(path);
if (baseDirLen >= MAX_PATH || MAX_PATH - baseDirLen < pathLen)
return false;
memcpy(outPath, baseDir, sizeof(wchar_t) * baseDirLen);
for (size_t i = 0; i < pathLen; i++)
outPath[baseDirLen + i] = static_cast<wchar_t>(path[i]);
outPath[baseDirLen + pathLen] = static_cast<wchar_t>(0);
return true;
}
GpFileSystem_Win32 GpFileSystem_Win32::ms_instance;