+ /* Build the full destination file name */
+ GetFullPathNameW(g_fileName, MAX_PATH, szSrcPath, &pszFileName);
+
+ GetWindowsDirectoryW(szDestPath, MAX_PATH);
+ wcscat(szDestPath, L"\\Fonts\\");
+ wcscat(szDestPath, pszFileName);
+
+ /* Debug Message */
+// MessageBoxW(hwnd, szDestPath, L"szDestPath", MB_OK);
+// MessageBoxW(hwnd, pszFileName, L"pszFileExt", MB_OK);
+
+ /* Check if the file already exists */
+ if (GetFileAttributesW(szDestPath) != INVALID_FILE_ATTRIBUTES)
+ {
+ MessageBoxW(hwnd, L"This font is already installed!", L"Already Installed", MB_OK);
+ return 0;
+ }
+
+ /* Copy the font file */
+ if (!CopyFileW(g_fileName, szDestPath, TRUE))
+ {
+ MessageBoxW(hwnd,L"Failed to copy the font file!", L"File Error", MB_OK);
+ return -1;
+ }
+
+ /* Open the fonts key */
+ res = RegOpenKeyExW(HKEY_LOCAL_MACHINE,
+ L"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Fonts",
+ 0,
+ KEY_ALL_ACCESS,
+ &hKey);
+ if (res != ERROR_SUCCESS)
+ {
+ MessageBoxW(hwnd, L"Failed top open the fonts key!", L"Debug1", MB_OK);
+ return -1;
+ }
+
+ /* Register the font */
+ res = RegSetValueExW(hKey,
+ szFullName,
+ 0,
+ REG_SZ,
+ (LPBYTE)pszFileName,
+ (wcslen(pszFileName) + 1) * sizeof(WCHAR));
+ if (res != ERROR_SUCCESS)
+ {
+ MessageBoxW(hwnd, L"Failed to register the new font!", L"Debug2", MB_OK);
+ RegCloseKey(hKey);
+ return -1;
+ }
+
+ /* Close the fonts key */
+ RegCloseKey(hKey);
+
+ /* if all of this goes correctly, message the user about success */
+ MessageBoxW(hwnd, L"Font Installation Completed.", L"Success", MB_OK);
+
+ return 0;