Author: ekohl
Date: Tue Feb 28 23:00:19 2017
New Revision: 74006
URL:
http://svn.reactos.org/svn/reactos?rev=74006&view=rev
Log:
[FONTVIEW]
Implementation of the install button.
Patch by Baruch Rutman.
Fixes by Eric Kohl.
CORE-7355 #resolve #comment Thanks a lot!
Modified:
trunk/reactos/base/applications/fontview/CMakeLists.txt
trunk/reactos/base/applications/fontview/display.c
trunk/reactos/base/applications/fontview/display.h
trunk/reactos/base/applications/fontview/fontview.c
Modified: trunk/reactos/base/applications/fontview/CMakeLists.txt
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/fontview…
==============================================================================
--- trunk/reactos/base/applications/fontview/CMakeLists.txt [iso-8859-1] (original)
+++ trunk/reactos/base/applications/fontview/CMakeLists.txt [iso-8859-1] Tue Feb 28
23:00:19 2017
@@ -7,6 +7,6 @@
add_rc_deps(fontview.rc ${CMAKE_CURRENT_SOURCE_DIR}/ttf.ico)
add_executable(fontview ${SOURCE} fontview.rc)
set_module_type(fontview win32gui UNICODE)
-add_importlibs(fontview comdlg32 gdi32 shell32 user32 msvcrt kernel32)
+add_importlibs(fontview comdlg32 gdi32 shell32 user32 msvcrt kernel32 advapi32)
add_pch(fontview precomp.h SOURCE)
add_cd_file(TARGET fontview DESTINATION reactos/system32 FOR all)
Modified: trunk/reactos/base/applications/fontview/display.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/fontview…
==============================================================================
--- trunk/reactos/base/applications/fontview/display.c [iso-8859-1] (original)
+++ trunk/reactos/base/applications/fontview/display.c [iso-8859-1] Tue Feb 28 23:00:19
2017
@@ -521,6 +521,24 @@
return 0;
}
+LRESULT
+Display_GetFullName(HWND hwnd, INT length, PWSTR ptr)
+{
+ DISPLAYDATA *pData;
+ INT len;
+
+ pData = (DISPLAYDATA*)GetWindowLongPtr(hwnd, GWLP_USERDATA);
+
+ len = wcslen(pData->szTypeFaceName) + wcslen(pData->szFormat) + 2;
+
+ if (ptr != NULL && length >= len)
+ {
+ swprintf(ptr, L"%s%s", pData->szTypeFaceName, pData->szFormat);
+ }
+
+ return (LRESULT)len;
+}
+
LRESULT CALLBACK
DisplayProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
@@ -544,6 +562,9 @@
case FVM_SETSTRING:
return Display_SetString(hwnd, (WCHAR *)lParam);
+ case FVM_GETFULLNAME:
+ return Display_GetFullName(hwnd, (INT)wParam, (PWSTR)lParam);
+
case WM_DESTROY:
return Display_OnDestroy(hwnd);
Modified: trunk/reactos/base/applications/fontview/display.h
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/fontview…
==============================================================================
--- trunk/reactos/base/applications/fontview/display.h [iso-8859-1] (original)
+++ trunk/reactos/base/applications/fontview/display.h [iso-8859-1] Tue Feb 28 23:00:19
2017
@@ -3,6 +3,7 @@
/* Messages for the display class */
#define FVM_SETTYPEFACE WM_USER
#define FVM_SETSTRING (WM_USER + 1)
+#define FVM_GETFULLNAME (WM_USER + 2)
/* Size restrictions */
#define MAX_STRING 100
Modified: trunk/reactos/base/applications/fontview/fontview.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/fontview…
==============================================================================
--- trunk/reactos/base/applications/fontview/fontview.c [iso-8859-1] (original)
+++ trunk/reactos/base/applications/fontview/fontview.c [iso-8859-1] Tue Feb 28 23:00:19
2017
@@ -26,6 +26,7 @@
#include <winnls.h>
#include <shellapi.h>
#include <windowsx.h>
+#include <winreg.h>
#include "fontview.h"
#include "resource.h"
@@ -420,21 +421,83 @@
static LRESULT
MainWnd_OnInstall(HWND hwnd)
{
- DWORD fontExists;
-
- /* First, we have to find out if the font still exists. */
- fontExists = GetFileAttributes(g_fileName);
- if (fontExists != 0xFFFFFFFF) /* If the file does not exist */
- {
- ErrorMsgBox(0, IDS_ERROR_NOFONT, g_fileName);
- return -1;
- }
-
- //CopyFile(g_fileName, NULL, TRUE);
-
- MessageBox(hwnd, TEXT("This function is unimplemented"),
TEXT("Unimplemented"), MB_OK);
-
- return 0;
+ WCHAR szFullName[64];
+
+ WCHAR szSrcPath[MAX_PATH];
+ WCHAR szDestPath[MAX_PATH];
+ PWSTR pszFileName;
+ LONG res;
+ HKEY hKey;
+
+ SendDlgItemMessage(hwnd, IDC_DISPLAY, FVM_GETFULLNAME, 64, (LPARAM)szFullName);
+// MessageBoxW(hwnd, szFullName, L"Debug", MB_OK);
+
+ /* First, we have to find out if the font still exists */
+ if (GetFileAttributes(g_fileName) == INVALID_FILE_ATTRIBUTES)
+ {
+ /* Fail, if the source file does not exist */
+ ErrorMsgBox(0, IDS_ERROR_NOFONT, g_fileName);
+ return -1;
+ }
+
+ /* 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;
}
static LRESULT