[FONTVIEW]
authorEric Kohl <eric.kohl@reactos.org>
Tue, 28 Feb 2017 23:00:19 +0000 (23:00 +0000)
committerEric Kohl <eric.kohl@reactos.org>
Tue, 28 Feb 2017 23:00:19 +0000 (23:00 +0000)
Implementation of the install button.
Patch by Baruch Rutman.
Fixes by Eric Kohl.
CORE-7355 #resolve #comment Thanks a lot!

svn path=/trunk/; revision=74006

reactos/base/applications/fontview/CMakeLists.txt
reactos/base/applications/fontview/display.c
reactos/base/applications/fontview/display.h
reactos/base/applications/fontview/fontview.c

index bfe97f4..4883297 100644 (file)
@@ -7,6 +7,6 @@ list(APPEND SOURCE
 add_rc_deps(fontview.rc ${CMAKE_CURRENT_SOURCE_DIR}/ttf.ico)
 add_executable(fontview ${SOURCE} fontview.rc)
 set_module_type(fontview win32gui UNICODE)
 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)
 add_pch(fontview precomp.h SOURCE)
 add_cd_file(TARGET fontview DESTINATION reactos/system32 FOR all)
index 49c28d1..7ffc9b1 100644 (file)
@@ -521,6 +521,24 @@ Display_OnPrint(HWND hwnd)
        return 0;
 }
 
        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)
 {
 LRESULT CALLBACK
 DisplayProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
 {
@@ -544,6 +562,9 @@ DisplayProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
                case FVM_SETSTRING:
                        return Display_SetString(hwnd, (WCHAR *)lParam);
 
                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);
 
                case WM_DESTROY:
                        return Display_OnDestroy(hwnd);
 
index 37b0fc0..939880f 100644 (file)
@@ -3,6 +3,7 @@
 /* Messages for the display class */
 #define FVM_SETTYPEFACE WM_USER
 #define FVM_SETSTRING (WM_USER + 1)
 /* 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
 
 /* Size restrictions */
 #define MAX_STRING 100
index 695e19e..654f6a9 100644 (file)
@@ -26,6 +26,7 @@
 #include <winnls.h>
 #include <shellapi.h>
 #include <windowsx.h>
 #include <winnls.h>
 #include <shellapi.h>
 #include <windowsx.h>
+#include <winreg.h>
 
 #include "fontview.h"
 #include "resource.h"
 
 #include "fontview.h"
 #include "resource.h"
@@ -420,21 +421,83 @@ MainWnd_OnPaint(HWND hwnd)
 static LRESULT
 MainWnd_OnInstall(HWND hwnd)
 {
 static LRESULT
 MainWnd_OnInstall(HWND hwnd)
 {
-       DWORD fontExists;
+    WCHAR szFullName[64];
 
 
-       /* 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;
-       }
+    WCHAR szSrcPath[MAX_PATH];
+    WCHAR szDestPath[MAX_PATH];
+    PWSTR pszFileName;
+    LONG res;
+    HKEY hKey;
 
 
-       //CopyFile(g_fileName, NULL, TRUE);
+    SendDlgItemMessage(hwnd, IDC_DISPLAY, FVM_GETFULLNAME, 64, (LPARAM)szFullName);
+//    MessageBoxW(hwnd, szFullName, L"Debug", MB_OK);
 
 
-       MessageBox(hwnd, TEXT("This function is unimplemented"), TEXT("Unimplemented"), 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;
+    }
 
 
-       return 0;
+    /* 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
 }
 
 static LRESULT