retrieve name from file description, as a backup just input the name of the file, almost got a cool feature here just wip it up a little more, not working properly yet

This commit is contained in:
freedom
2023-10-02 13:47:57 -06:00
parent 3245d93436
commit c7d3ae27d1
2 changed files with 44 additions and 13 deletions

View File

@@ -17,6 +17,7 @@
#include <Windows.h> #include <Windows.h>
#include <pathcch.h> #include <pathcch.h>
#include <Shlobj.h> #include <Shlobj.h>
#include <shlwapi.h>
#include <strsafe.h> #include <strsafe.h>
/* Variables */ /* Variables */
@@ -266,10 +267,12 @@ BOOL CALLBACK NewItemDlgProc(HWND hWndDlg, UINT message, WPARAM wParam, LPARAM l
case IDD_BROWSE: case IDD_BROWSE:
{ {
OPENFILENAME ofn; OPENFILENAME ofn;
WCHAR szAppName = TEXT("\0"); LPVOID lpData;
DWORD dwAppBuffer = 0; DWORD dwVerBuffer = 0;
UINT uiTitleLen = MAX_TITLE_LENGTH;
WCHAR szFileBuffer[MAX_PATH] = { L"\0" };
GetDlgItemText(hWndDlg, IDD_PATH, (LPWSTR)&szBuffer, ARRAYSIZE(szBuffer)); GetDlgItemText(hWndDlg, IDD_PATH, (LPWSTR)&szFileBuffer, ARRAYSIZE(szFileBuffer));
// Initialize the structure // Initialize the structure
ZeroMemory(&ofn, sizeof(ofn)); ZeroMemory(&ofn, sizeof(ofn));
@@ -277,27 +280,54 @@ BOOL CALLBACK NewItemDlgProc(HWND hWndDlg, UINT message, WPARAM wParam, LPARAM l
ofn.hwndOwner = hWndDlg; ofn.hwndOwner = hWndDlg;
ofn.lpstrFilter = TEXT("Programs\0*.exe;*.bat;*.com;*.cmd;*.lnk\0All Files (*.*)\0*.*\0"); ofn.lpstrFilter = TEXT("Programs\0*.exe;*.bat;*.com;*.cmd;*.lnk\0All Files (*.*)\0*.*\0");
ofn.nFilterIndex = 1; ofn.nFilterIndex = 1;
ofn.lpstrFile = (LPWSTR)&szBuffer; ofn.lpstrFile = (LPWSTR)&szFileBuffer;
// ofn.lpstrFile[0] = '\0'; // ofn.lpstrFile[0] = '\0';
ofn.nMaxFile = ARRAYSIZE(szBuffer); ofn.nMaxFile = ARRAYSIZE(szFileBuffer);
ofn.lpstrFileTitle = NULL; ofn.lpstrFileTitle = NULL;
ofn.nMaxFileTitle = 0; ofn.nMaxFileTitle = 0;
ofn.lpstrInitialDir = NULL; ofn.lpstrInitialDir = NULL;
ofn.Flags = OFN_FILEMUSTEXIST; ofn.Flags = OFN_FILEMUSTEXIST;
if (GetOpenFileName(&ofn) == TRUE) { if (GetOpenFileName(&ofn) == TRUE)
SetDlgItemText(hWndDlg, IDD_PATH, (LPWSTR)&szBuffer); SetDlgItemText(hWndDlg, IDD_PATH, (LPWSTR)&szFileBuffer);
} else
break;
// copy the filename to a new buffer for later
StringCchCopy(szBuffer, ARRAYSIZE(szBuffer), szFileBuffer);
// let's retrieve the application's friendly name too // let's retrieve the application's friendly name too
dwAppBuffer = GetFileVersionInfoSize(&szBuffer, NULL); dwVerBuffer = GetFileVersionInfoSize((LPCWSTR)szBuffer, NULL);
if (dwAppBuffer != 0) { if (dwVerBuffer != 0) {
GetFileVersionInfo(&szBuffer, NULL, dwAppBuffer, szAppName); lpData = malloc(dwVerBuffer);
MAX_TITLE_LENGTH; if (lpData != NULL)
SetDlgItemText(hWndDlg, IDD_NAME, (LPWSTR)&szBuffer); GetFileVersionInfo((LPCWSTR)szBuffer, (DWORD)0, dwVerBuffer, lpData);
else
break;
// TODO: this is hardcoded to english. make it dynamic later
// TODO: this is so busted lol, really make it dynamic so it works
if (VerQueryValue(lpData,
TEXT("\\StringFileInfo\\040904b0\\FileDescription"),
(LPVOID)szBuffer, &uiTitleLen) == 0)
{
// copy the filename back to the og buffer
StringCchCopy(szFileBuffer, ARRAYSIZE(szFileBuffer), szBuffer);
} }
if (lpData)
free(lpData);
}
else
{
// TODO: fix this lol
PathStripPath(szFileBuffer);
PathCchRemoveExtension(szFileBuffer, ARRAYSIZE(szFileBuffer));
}
SetDlgItemText(hWndDlg, IDD_NAME, (LPWSTR)szFileBuffer);
break; break;
} }

View File

@@ -12,6 +12,7 @@
#pragma comment(lib, "Pathcch.lib") #pragma comment(lib, "Pathcch.lib")
#pragma comment(lib, "Shlwapi.lib") #pragma comment(lib, "Shlwapi.lib")
#pragma comment(lib, "Secur32.lib") #pragma comment(lib, "Secur32.lib")
#pragma comment(lib, "Version.lib")
/* Includes */ /* Includes */
#include <wtypes.h> #include <wtypes.h>