Home

Resume

Blog

Teikitu


// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-==-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= //
//  »Project«   Teikitu Gaming System (TgS) (∂)
//  »File«      TgS (WIN) Common - Base - API - Platform.c
//  »Author«    Andrew Aye (EMail: mailto:andrew.aye@gmail.com, Web: http://www.andrewaye.com)
//  »Version«   4.5
// -------------------------------------------------------------------------------------------------------------------------------------------------------------- //
//  Copyright: © 2002-2016, Andrew Aye.  All Rights Reserved.
//  This software is free for non-commercial use. Redistribution and use in source and binary forms, with or without modification,
//  are permitted provided that the following conditions are met: 
//    Redistributions of source code must retain this copyright notice, this list of conditions and the following disclaimers. 
//    Redistributions in binary form must reproduce this copyright notice, this list of conditions and the following
//      disclaimers in the documentation and other materials provided with the distribution. 
//  Neither the names of the copyright owner nor the names of its contributors may be used to endorse or promote products derived
//  from this software without specific prior written permission. 
//  The intellectual property rights of the algorithms used reside with Andrew Aye.  You may not use this software, in whole or
//  in part, in support of any commercial product without the express written consent of the author.
//  There is no warranty or other guarantee of fitness of this software for any purpose. It is provided solely "as is".
// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-==-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= //

#define COMMON_INCLUDE_PREAMBLE_ONLY
#include "TgS COMMON/TgS (WIN) Common -- INCLUDE.h"
#include "TgS COMMON/TgS (WIN) Common - Base - LoadDLL.h"

#define DIRECTINPUT_VERSION 0x0800
#pragma warning( push, 3 )

#include <windows.h>
#include <Psapi.h>
#include <stdio.h>
#include <excpt.h>

#pragma warning( pop )




// -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-. //
//  Public Functions
// -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-. //

TgVOID tgCM_Path_Query_Application_Data_Directory( P_TgCHAR dir, C_TgSIZE maxsize )
{
    if (!maxsize) return;
    *dir = 0;
#if !defined(WINAPI_FAMILY) || (WINAPI_FAMILY == WINAPI_FAMILY_DESKTOP_APP)
    Microsoft::WRL::ComPtr<IKnownFolderManager> mgr;
    HRESULT hr = CoCreateInstance( CLSID_KnownFolderManager, nullptr, CLSCTX_INPROC_SERVER, IID_IKnownFolderManager, (LPVOID*)&mgr );
    if (SUCCEEDED( hr ))
    {
        Microsoft::WRL::ComPtr<IKnownFolder> folder;
        hr = mgr->GetFolder( FOLDERID_LocalAppData, &folder );
        if (SUCCEEDED( hr ))
        {
            LPWSTR szPath = 0;
            hr = folder->GetPath( 0, &szPath );
            if (SUCCEEDED( hr ))
            {
                wcscpy_s( dir, maxsize, szPath );
                wcscat_s( dir, maxsize, L”\\MyUniqueApplicationName” );
                CreateDirectory( dir, nullptr );
                CoTaskMemFree( szPath );
            }
        }
    }
#else // Windows Store WinRT app
    auto folder = Windows::Storage::ApplicationData::Current->LocalFolder;
    wcscpy_s( dir, maxsize, folder->Path->Data() );
#endif
}



TgVOID tgCM_Path_Query_Temporary_Directory( P_TgCHAR dir, C_TgSIZE maxsize )
{
    if (!maxsize) return;
    *dir = 0;
#if !defined(WINAPI_FAMILY) || (WINAPI_FAMILY == WINAPI_FAMILY_DESKTOP_APP)
    DWORD nChars = GetTempPath( maxsize, dir );
    if (nChars > 0)
        dir[nChars - 1] = '\0'; // Trim trailing '\'
    else
        *dir = 0;
#else // Windows Store WinRT app
    auto folder = Windows::Storage::ApplicationData::Current->TemporaryFolder;
    wcscpy_s( dir, maxsize, folder->Path->Data() );
#endif // WINAPI_FAMILY_PARTITION
}