allow librewolf-portable.exe to pass its parameters to librewolf.exe (issue #154)

This commit is contained in:
Bert van der Weerd 2022-01-26 21:19:25 +01:00
parent b2a92cc6ec
commit 31eb346039
No known key found for this signature in database
GPG key ID: 4CFABB96ADE0F5B1
2 changed files with 26 additions and 31 deletions

View file

@ -1,55 +1,47 @@
// librewolf-portable.cpp : Run librewolf.exe with -profile parameter. // librewolf-portable.cpp : Run librewolf.exe with -profile parameter.
// //
#define _CRT_SECURE_NO_WARNINGS
#include <windows.h> #include <windows.h>
int
int fileExists(TCHAR* file) fileExists(TCHAR* file)
{ {
WIN32_FIND_DATA FindFileData; WIN32_FIND_DATA FindFileData;
HANDLE handle = FindFirstFile(file, &FindFileData); HANDLE handle = FindFirstFile(file, &FindFileData);
int found = handle != INVALID_HANDLE_VALUE; int found = (handle != INVALID_HANDLE_VALUE);
if (found) if (found)
{
//FindClose(&handle); this will crash
FindClose(handle); FindClose(handle);
}
return found; return found;
} }
int APIENTRY wWinMain(_In_ HINSTANCE hInstance, int APIENTRY
_In_opt_ HINSTANCE hPrevInstance, wWinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _In_ LPWSTR lpCmdLine, _In_ int nCmdShow)
_In_ LPWSTR lpCmdLine,
_In_ int nCmdShow)
{ {
//https://docs.microsoft.com/en-us/windows/win32/fileio/maximum-file-path-limitation?tabs=cmd //https://docs.microsoft.com/en-us/windows/win32/fileio/maximum-file-path-limitation?tabs=cmd
//constexpr int max_path = _MAX_PATH+1; constexpr DWORD max_path = 32767;
constexpr int max_path = 32767+1; static TCHAR path[max_path], dir[max_path], exe[max_path], cmdline[max_path];
static wchar_t path[max_path], dir[max_path], exe[max_path], cmdline[max_path];
GetModuleFileName(NULL, path, max_path);
GetModuleFileName(NULL, path, _MAX_PATH);
*wcsrchr(path,L'\\') = L'\0'; *wcsrchr(path,L'\\') = L'\0';
wcscpy(dir, path); wcscpy_s(dir, path);
wcscat(dir, L"\\Profiles\\Default"); wcscat_s(dir, L"\\Profiles\\Default");
wcscpy(exe, path); wcscpy_s(exe, path);
wcscat(exe, L"\\librewolf.exe"); wcscat_s(exe, L"\\librewolf.exe");
if (!fileExists(exe)) { if (!fileExists(exe)) {
wcscpy(exe, path); wcscpy_s(exe, path);
wcscat(exe, L"\\LibreWolf\\librewolf.exe"); wcscat_s(exe, L"\\LibreWolf\\librewolf.exe");
if (!fileExists(exe)) { if (!fileExists(exe)) {
MessageBox(NULL, L"Can\'t find librewolf.exe in . or LibreWolf", path, MB_OK); MessageBox(NULL, L"Can\'t find librewolf.exe in the current or LibreWolf folder.", path, MB_OK);
return 1; return 1;
} }
} }
wsprintf(cmdline, L"\"%s\" -profile \"%s\"", exe, dir); wsprintf(cmdline, L"\"%s\" -profile \"%s\" %s", exe, dir, lpCmdLine);
STARTUPINFOW siStartupInfo; STARTUPINFOW siStartupInfo;
PROCESS_INFORMATION piProcessInfo; PROCESS_INFORMATION piProcessInfo;
@ -65,5 +57,8 @@ int APIENTRY wWinMain(_In_ HINSTANCE hInstance,
return 1; return 1;
} }
CloseHandle(piProcessInfo.hProcess);
CloseHandle(piProcessInfo.hThread);
return 0; return 0;
} }

View file

@ -29,26 +29,26 @@
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType> <ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries> <UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset> <PlatformToolset>v143</PlatformToolset>
<CharacterSet>Unicode</CharacterSet> <CharacterSet>Unicode</CharacterSet>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType> <ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries> <UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset> <PlatformToolset>v143</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization> <WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet> <CharacterSet>Unicode</CharacterSet>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType> <ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries> <UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset> <PlatformToolset>v143</PlatformToolset>
<CharacterSet>Unicode</CharacterSet> <CharacterSet>Unicode</CharacterSet>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType> <ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries> <UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset> <PlatformToolset>v143</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization> <WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet> <CharacterSet>Unicode</CharacterSet>
</PropertyGroup> </PropertyGroup>