Last active
December 19, 2015 14:28
-
-
Save peterooch/5968956 to your computer and use it in GitHub Desktop.
Rough implemtation of the install button of fontview
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static LRESULT | |
MainWnd_OnInstall(HWND hwnd) | |
{ | |
DWORD fontExists; | |
HKEY hKey; | |
LPWSTR subKey = L"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Fonts"; | |
WCHAR szDestDir[256]; | |
/* First, we have to find out if the font still exists. */ | |
fontExists = GetFileAttributesW(g_fileName); | |
if (fontExists != 0xFFFFFFFF) /* If the file does not exist */ | |
{ | |
ErrorMsgBox(0, IDS_ERROR, IDS_ERROR_NOFONT, g_fileName); | |
return -1; | |
} | |
// Prepare the Registry Key | |
LONG res = RegOpenKeyExW(HKEY_LOCAL_MACHINE, subKey, 0, KEY_ALL_ACCESS, &hKey); | |
if(res != ERROR_SUCCESS) | |
{ | |
MessageBoxW(hwnd, L"There is a corruption in the Registry.", L"Registry Fault", MB_OK); | |
RegCloseKey(hKey); | |
return -1; | |
} | |
/* | |
Prepare the final directory string | |
*/ | |
WCHAR filename[256]; | |
wcscpy(filename, g_fileName); | |
UINT i; | |
for(i=wcslen(filename);;i--) | |
{ | |
if(filename[i]==L'\\') | |
{ | |
i++; | |
break; | |
} | |
} | |
LPWSTR fileExt; | |
UINT j; | |
for(j=i;j<=wcslen(filename);j++) | |
{ | |
wcscat(fileExt,(LPWSTR)&filename[j]); | |
}; | |
/* Or Maybe \\WINDOWS\\Fonts ?*/ | |
swprintf(szDestDir, L"%%windir%%\\Fonts\\%s", fileExt); | |
// Check if already exists. | |
DWORD exists = GetFileAttributesW(szDestDir); | |
if (exists == 0xFFFFFFFF) | |
{ | |
//To Register if the value is missing? | |
MessageBoxW(hwnd,L"This font is already installed!", L"Already Installed", MB_OK); | |
RegCloseKey(hKey); | |
return 0; | |
} | |
/* Copy the file */ | |
if(!CopyFileW(filename, szDestDir, TRUE)) | |
{ | |
MessageBoxW(hwnd,L"Error with copying the font file.", L"File Error", MB_OK); | |
RegCloseKey(hKey); | |
return -1; | |
} | |
/* Register The Font */ | |
res = RegSetValueExW(hKey, g_ExtLogFontW.elfFullName, 0, REG_SZ, (LPBYTE)fileExt, wcslen(fileExt)+1); | |
if(res != ERROR_SUCCESS) | |
{ | |
MessageBoxW(hwnd, L"There is a corruption in the Registry.", L"Registry Fault", MB_OK); | |
RegCloseKey(hKey); | |
return -1; | |
} | |
/* if all of this goes correctly, message the user about success */ | |
MessageBox(hwnd, L"Font Installation Completed.", L"Success", MB_OK); | |
// And to get rid of the below! | |
//MessageBox(hwnd, TEXT("This function is unimplemented"), TEXT("Unimplemented"), MB_OK); | |
// Close the key | |
RegCloseKey(hKey); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment