diff --git a/.gitattributes b/.gitattributes
new file mode 100644
index 0000000..0f09d32
--- /dev/null
+++ b/.gitattributes
@@ -0,0 +1,2 @@
+* text=auto eol=lf
+*.bat text eol=crlf
\ No newline at end of file
diff --git a/.gitignore b/.gitignore
index 2dea6d7..050e667 100644
--- a/.gitignore
+++ b/.gitignore
@@ -4,8 +4,10 @@
!/res
!/platform
!/.github
+!/packager
!.gitignore
+!.gitattributes
!*.cpp
!*.h
!*.sln
@@ -14,6 +16,7 @@
!*.ico
!*.rc
!*.manifest
+!packages.config
!LICENSE
!build.gradle
\ No newline at end of file
diff --git a/fabric-installer-native-bootstrap.rc b/fabric-installer-native-bootstrap.rc
index de441d2..a1b2b6d 100644
--- a/fabric-installer-native-bootstrap.rc
+++ b/fabric-installer-native-bootstrap.rc
@@ -1,6 +1,6 @@
// Microsoft Visual C++ generated resource script.
//
-#include "resource.h"
+#include "src\resource.h"
#define APSTUDIO_READONLY_SYMBOLS
/////////////////////////////////////////////////////////////////////////////
diff --git a/fabric-installer-native-bootstrap.sln b/fabric-installer-native-bootstrap.sln
index 875feaf..09526be 100644
--- a/fabric-installer-native-bootstrap.sln
+++ b/fabric-installer-native-bootstrap.sln
@@ -5,28 +5,32 @@ VisualStudioVersion = 17.0.32112.339
MinimumVisualStudioVersion = 10.0.40219.1
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "fabric-installer-native-bootstrap", "fabric-installer-native-bootstrap.vcxproj", "{B900FD00-808B-4A95-B40B-9B243B186FF0}"
EndProject
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "packager", "packager\packager.vcxproj", "{A3999EF4-14BF-4910-A6AB-13FB5730F7E6}"
+EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|ARM64 = Debug|ARM64
- Debug|Win32 = Debug|Win32
Debug|x64 = Debug|x64
Release|ARM64 = Release|ARM64
- Release|Win32 = Release|Win32
Release|x64 = Release|x64
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{B900FD00-808B-4A95-B40B-9B243B186FF0}.Debug|ARM64.ActiveCfg = Debug|ARM64
{B900FD00-808B-4A95-B40B-9B243B186FF0}.Debug|ARM64.Build.0 = Debug|ARM64
- {B900FD00-808B-4A95-B40B-9B243B186FF0}.Debug|Win32.ActiveCfg = Debug|Win32
- {B900FD00-808B-4A95-B40B-9B243B186FF0}.Debug|Win32.Build.0 = Debug|Win32
{B900FD00-808B-4A95-B40B-9B243B186FF0}.Debug|x64.ActiveCfg = Debug|x64
{B900FD00-808B-4A95-B40B-9B243B186FF0}.Debug|x64.Build.0 = Debug|x64
{B900FD00-808B-4A95-B40B-9B243B186FF0}.Release|ARM64.ActiveCfg = Release|ARM64
{B900FD00-808B-4A95-B40B-9B243B186FF0}.Release|ARM64.Build.0 = Release|ARM64
- {B900FD00-808B-4A95-B40B-9B243B186FF0}.Release|Win32.ActiveCfg = Release|Win32
- {B900FD00-808B-4A95-B40B-9B243B186FF0}.Release|Win32.Build.0 = Release|Win32
{B900FD00-808B-4A95-B40B-9B243B186FF0}.Release|x64.ActiveCfg = Release|x64
{B900FD00-808B-4A95-B40B-9B243B186FF0}.Release|x64.Build.0 = Release|x64
+ {A3999EF4-14BF-4910-A6AB-13FB5730F7E6}.Debug|ARM64.ActiveCfg = Debug|x64
+ {A3999EF4-14BF-4910-A6AB-13FB5730F7E6}.Debug|ARM64.Build.0 = Debug|x64
+ {A3999EF4-14BF-4910-A6AB-13FB5730F7E6}.Debug|x64.ActiveCfg = Debug|x64
+ {A3999EF4-14BF-4910-A6AB-13FB5730F7E6}.Debug|x64.Build.0 = Debug|x64
+ {A3999EF4-14BF-4910-A6AB-13FB5730F7E6}.Release|ARM64.ActiveCfg = Release|x64
+ {A3999EF4-14BF-4910-A6AB-13FB5730F7E6}.Release|ARM64.Build.0 = Release|x64
+ {A3999EF4-14BF-4910-A6AB-13FB5730F7E6}.Release|x64.ActiveCfg = Release|x64
+ {A3999EF4-14BF-4910-A6AB-13FB5730F7E6}.Release|x64.Build.0 = Release|x64
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
diff --git a/fabric-installer-native-bootstrap.vcxproj b/fabric-installer-native-bootstrap.vcxproj
index c89ab9a..2a917c3 100644
--- a/fabric-installer-native-bootstrap.vcxproj
+++ b/fabric-installer-native-bootstrap.vcxproj
@@ -131,11 +131,13 @@
true
WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)
true
- stdcpp20
+ stdcpplatest
MultiThreadedDebug
false
true
true
+ true
+ %(AdditionalIncludeDirectories)
Windows
@@ -154,10 +156,12 @@
true
WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)
true
- stdcpp20
+ stdcpplatest
MultiThreaded
Guard
true
+ true
+ %(AdditionalIncludeDirectories)
Windows
@@ -176,11 +180,13 @@
true
_DEBUG;_CONSOLE;%(PreprocessorDefinitions)
true
- stdcpp20
+ stdcpplatest
MultiThreadedDebug
false
true
true
+ true
+ %(AdditionalIncludeDirectories)
Windows
@@ -197,11 +203,13 @@
true
_DEBUG;_CONSOLE;%(PreprocessorDefinitions)
true
- stdcpp20
+ stdcpplatest
MultiThreadedDebug
false
true
true
+ true
+ %(AdditionalIncludeDirectories)
Windows
@@ -221,9 +229,11 @@
NDEBUG;_CONSOLE;%(PreprocessorDefinitions)
true
MultiThreaded
- stdcpp20
+ stdcpplatest
Guard
true
+ true
+ %(AdditionalIncludeDirectories)
Windows
@@ -245,9 +255,11 @@
NDEBUG;_CONSOLE;%(PreprocessorDefinitions)
true
MultiThreaded
- stdcpp20
+ stdcpplatest
Guard
true
+ true
+ %(AdditionalIncludeDirectories)
Windows
@@ -261,6 +273,7 @@
+
@@ -268,10 +281,11 @@
+
-
+
@@ -281,7 +295,17 @@
+
+
+
+
+
+
+ This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.
+
+
+
\ No newline at end of file
diff --git a/fabric-installer-native-bootstrap.vcxproj.filters b/fabric-installer-native-bootstrap.vcxproj.filters
index 60c4956..a7c503e 100644
--- a/fabric-installer-native-bootstrap.vcxproj.filters
+++ b/fabric-installer-native-bootstrap.vcxproj.filters
@@ -27,6 +27,12 @@
Source Files
+
+ Source Files
+
+
+ Source Files
+
@@ -38,12 +44,18 @@
Header Files
-
+
Header Files
Header Files
+
+ Header Files
+
+
+ Header Files
+
@@ -55,4 +67,11 @@
Resource Files
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/packager/.gitignore b/packager/.gitignore
new file mode 100644
index 0000000..176b251
--- /dev/null
+++ b/packager/.gitignore
@@ -0,0 +1,9 @@
+/*
+
+!.gitignore
+!*.cpp
+!*.h
+!*.sln
+!*.vcxproj
+!*.filters
+!packages.config
\ No newline at end of file
diff --git a/packager/packager.cpp b/packager/packager.cpp
new file mode 100644
index 0000000..ef3eec3
--- /dev/null
+++ b/packager/packager.cpp
@@ -0,0 +1,80 @@
+#include
+#include
+#include
+#include
+#include
+
+namespace {
+ constexpr auto IDI_EMBEDDED_JAR = 201;
+
+ std::vector readFile(const std::filesystem::path& path) {
+ wil::unique_hfile file{
+ ::CreateFileW(
+ path.c_str(),
+ GENERIC_READ,
+ FILE_SHARE_READ,
+ nullptr,
+ OPEN_EXISTING,
+ FILE_ATTRIBUTE_NORMAL,
+ nullptr
+ )
+ };
+ THROW_LAST_ERROR_IF_MSG(!file, "CreateFileW");
+
+ LARGE_INTEGER fileSize{};
+ THROW_LAST_ERROR_IF(::GetFileSizeEx(file.get(), &fileSize) == 0);
+ THROW_WIN32_IF(ERROR_FILE_TOO_LARGE, fileSize.QuadPart > SIZE_MAX);
+
+ std::vector buffer(static_cast(fileSize.QuadPart));
+ DWORD bytesRead = 0;
+ THROW_LAST_ERROR_IF(!::ReadFile(file.get(), buffer.data(), static_cast(buffer.size()), &bytesRead, nullptr));
+ THROW_WIN32_IF(ERROR_HANDLE_EOF, bytesRead != buffer.size());
+
+ return buffer;
+ }
+
+ void updateResource(const std::filesystem::path& exe, const std::vector& data, WORD resourceId) {
+ HANDLE handle = THROW_LAST_ERROR_IF_NULL(::BeginUpdateResourceW(exe.c_str(), false));
+
+ bool success = false;
+ auto _ = wil::scope_exit([&]() noexcept { ::EndUpdateResourceW(handle, !success); });
+
+ auto intResource{ MAKEINTRESOURCE(resourceId) };
+ THROW_LAST_ERROR_IF(!::UpdateResourceW(handle, RT_RCDATA, intResource, MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL), (LPVOID)data.data(), static_cast(data.size())));
+
+ success = true;
+ }
+
+ void packageInstaller(const std::filesystem::path& bootstrap, const std::filesystem::path& installer) {
+ THROW_WIN32_IF_MSG(ERROR_FILE_NOT_FOUND, !std::filesystem::exists(bootstrap), "Boostrap not found");
+ THROW_WIN32_IF_MSG(ERROR_FILE_NOT_FOUND, !std::filesystem::exists(installer), "Installer not found");
+
+ auto installerBytes = readFile(installer);
+ updateResource(bootstrap, installerBytes, IDI_EMBEDDED_JAR);
+
+ std::print("Done, {} updated to embed {}\n", bootstrap.string(), installer.string());
+ }
+}
+
+int wmain(int argc, wchar_t* argv[])
+{
+ if (argc != 3) {
+ std::print("Usage: packager \n");
+ return 1;
+ }
+
+ std::filesystem::path bootstrap{ argv[1] };
+ std::filesystem::path installer{ argv[2] };
+
+ std::print("Packager: {} Installer: {}\n", bootstrap.string(), installer.string());
+
+ try {
+ packageInstaller(bootstrap, installer);
+ }
+ catch (const std::exception& error) {
+ std::print("Packager failed: {}\n", error.what());
+ throw;
+ }
+
+ return 0;
+}
\ No newline at end of file
diff --git a/packager/packager.vcxproj b/packager/packager.vcxproj
new file mode 100644
index 0000000..c488099
--- /dev/null
+++ b/packager/packager.vcxproj
@@ -0,0 +1,158 @@
+
+
+
+
+ Debug
+ Win32
+
+
+ Release
+ Win32
+
+
+ Debug
+ x64
+
+
+ Release
+ x64
+
+
+
+ 17.0
+ Win32Proj
+ {a3999ef4-14bf-4910-a6ab-13fb5730f7e6}
+ packager
+ 10.0
+
+
+
+ Application
+ true
+ v143
+ Unicode
+
+
+ Application
+ false
+ v143
+ true
+ Unicode
+
+
+ Application
+ true
+ v143
+ Unicode
+
+
+ Application
+ false
+ v143
+ true
+ Unicode
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ $(SolutionDir)$(Platform)\$(Configuration)\
+
+
+ $(SolutionDir)$(Platform)\$(Configuration)\
+
+
+
+ Level3
+ true
+ WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)
+ true
+ true
+ stdcpplatest
+
+
+ Console
+ true
+
+
+
+
+ Level3
+ true
+ true
+ true
+ WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)
+ true
+ true
+ stdcpplatest
+
+
+ Console
+ true
+
+
+
+
+ Level3
+ true
+ _DEBUG;_CONSOLE;%(PreprocessorDefinitions)
+ true
+ true
+ stdcpplatest
+
+
+ Console
+ true
+
+
+
+
+ Level3
+ true
+ true
+ true
+ NDEBUG;_CONSOLE;%(PreprocessorDefinitions)
+ true
+ true
+ stdcpplatest
+
+
+ Console
+ true
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.
+
+
+
+
\ No newline at end of file
diff --git a/packager/packager.vcxproj.filters b/packager/packager.vcxproj.filters
new file mode 100644
index 0000000..2b7f7b5
--- /dev/null
+++ b/packager/packager.vcxproj.filters
@@ -0,0 +1,34 @@
+
+
+
+
+ {4FC737F1-C7A5-4376-A066-2A32D752A2FF}
+ cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx
+
+
+ {93995380-89BD-4b04-88EB-625FBE52EBFB}
+ h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd
+
+
+ {67DA6AB6-F800-4c08-8B7A-83BB121AAD01}
+ rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms
+
+
+
+
+ Source Files
+
+
+
+
+
+
+
+
+
+
+
+ Header Files
+
+
+
\ No newline at end of file
diff --git a/packager/packages.config b/packager/packages.config
new file mode 100644
index 0000000..d690ede
--- /dev/null
+++ b/packager/packages.config
@@ -0,0 +1,4 @@
+
+
+
+
\ No newline at end of file
diff --git a/packages.config b/packages.config
new file mode 100644
index 0000000..a4d92ef
--- /dev/null
+++ b/packages.config
@@ -0,0 +1,4 @@
+
+
+
+
\ No newline at end of file
diff --git a/src/Bootstrap.cpp b/src/Bootstrap.cpp
index 98f95fb..d253a1f 100644
--- a/src/Bootstrap.cpp
+++ b/src/Bootstrap.cpp
@@ -1,5 +1,9 @@
#include "Bootstrap.h"
+#include "EmbeddedResource.h"
+#include "resource.h"
+#include
+
#include
#include
@@ -77,7 +81,7 @@ bool Bootstrap::launchMinecraftLauncher() {
}
}
}
- else {
+ else {
logger.log(L"Did not find Minecraft UWP at " + launcherPath);
}
}
@@ -130,7 +134,9 @@ bool Bootstrap::attemptLaunch(const std::wstring& path, bool checkExists) {
logger.log(L"Found valid Java path (" + path + L")");
- exit = systemHelper.createProcess({ path, L"-jar", systemHelper.getBootstrapFilename(), L"-fabricInstallerBootstrap", L"true" });
+ auto installerPath{ getExtractedInstaller() };
+
+ exit = systemHelper.createProcess({ path, L"-jar", installerPath, L"-fabricInstallerBootstrap", L"true" });
if (exit != 0) {
// The installer returned a none 0 exit code, meaning that most likely the installer crashed.
logger.log(L"Installer failed or crashed, exit code: " + std::to_wstring(exit));
@@ -183,4 +189,25 @@ const std::vector Bootstrap::getMinecraftJavaPaths(const Architect
}
return paths;
-}
\ No newline at end of file
+}
+
+std::filesystem::path Bootstrap::getExtractedInstaller()
+{
+ if (extractedInstaller.has_value()) {
+ return *extractedInstaller;
+ }
+
+ std::filesystem::path tempDir{ systemHelper.getTempDir() };
+
+ wchar_t buffer[MAX_PATH] = {};
+ THROW_LAST_ERROR_IF(!GetTempFileNameW(tempDir.c_str(), L"fabric-installer", 0, buffer));
+
+ std::filesystem::path path{ buffer };
+ logger.log(L"Extracting installer to: " + path.native());
+
+ EmbeddedResource resource{ IDI_EMBEDDED_JAR };
+ resource.ExtractToFile(path);
+
+ extractedInstaller = path;
+ return path;
+}
diff --git a/src/Bootstrap.h b/src/Bootstrap.h
index 5939381..c4d52df 100644
--- a/src/Bootstrap.h
+++ b/src/Bootstrap.h
@@ -1,6 +1,8 @@
#pragma once
#include
+#include
+#include
#include "ISystemHelper.h"
#include "Logger.h"
@@ -22,7 +24,10 @@ class Bootstrap {
const std::vector getMinecraftJavaPaths(const Architecture::Value& hostArch);
+ std::filesystem::path getExtractedInstaller();
+
private:
ISystemHelper& systemHelper;
Logger& logger;
+ std::optional extractedInstaller = std::nullopt;
};
\ No newline at end of file
diff --git a/src/EmbeddedResource.cpp b/src/EmbeddedResource.cpp
new file mode 100644
index 0000000..ae05c78
--- /dev/null
+++ b/src/EmbeddedResource.cpp
@@ -0,0 +1,46 @@
+#include "EmbeddedResource.h"
+
+#include
+
+#include
+#include
+
+EmbeddedResource::EmbeddedResource(WORD resourceId) :
+ resourceId(resourceId)
+{
+}
+
+void EmbeddedResource::ExtractToFile(const std::filesystem::path& path) const
+{
+ auto module{ ::GetModuleHandle(nullptr) };
+
+ auto intResource{ MAKEINTRESOURCEW(resourceId) };
+ auto resource{ THROW_LAST_ERROR_IF_NULL(::FindResourceW(module, intResource, RT_RCDATA)) };
+ auto resourceInfo{ THROW_LAST_ERROR_IF_NULL(::LoadResource(module, resource)) };
+ auto resourceSize{ ::SizeofResource(module, resource) };
+ auto resourceData{ THROW_LAST_ERROR_IF_NULL(::LockResource(resourceInfo)) };
+
+ wil::unique_hfile file{
+ ::CreateFileW(
+ path.c_str(),
+ GENERIC_WRITE,
+ 0,
+ nullptr,
+ CREATE_ALWAYS,
+ FILE_ATTRIBUTE_NORMAL,
+ nullptr
+ )
+ };
+ THROW_LAST_ERROR_IF_MSG(!file, "CreateFileW");
+
+ DWORD bytesWritten{ 0 };
+ auto success{ ::WriteFile(
+ file.get(),
+ resourceData,
+ resourceSize,
+ &bytesWritten,
+ nullptr
+ ) };
+ THROW_LAST_ERROR_IF_MSG(!success, "WriteFile");
+ THROW_WIN32_IF_MSG(ERROR_HANDLE_EOF, bytesWritten != resourceSize, "Incomplete file write");
+}
diff --git a/src/EmbeddedResource.h b/src/EmbeddedResource.h
new file mode 100644
index 0000000..bf04d83
--- /dev/null
+++ b/src/EmbeddedResource.h
@@ -0,0 +1,14 @@
+#pragma once
+
+#include
+#include
+
+class EmbeddedResource {
+public:
+ explicit EmbeddedResource(WORD resourceId);
+
+ void ExtractToFile(const std::filesystem::path& path) const;
+
+private:
+ WORD resourceId;
+};
\ No newline at end of file
diff --git a/src/ISystemHelper.h b/src/ISystemHelper.h
index f0668d4..bee7bf2 100644
--- a/src/ISystemHelper.h
+++ b/src/ISystemHelper.h
@@ -13,7 +13,7 @@ class ISystemHelper {
virtual std::optional getRegValue(HKEY hive, const std::wstring& path, const std::wstring& key) const = 0;
virtual std::optional getEnvVar(const std::wstring& key) const = 0;
virtual void showErrorMessage(const std::wstring& title, const std::wstring& message, const std::wstring& url) const = 0;
- virtual DWORD createProcess(std::vector args) const = 0;
+ virtual DWORD createProcess(const std::vector& args) const = 0;
virtual bool fileExists(const std::wstring& path) const = 0;
virtual bool dirExists(const std::wstring& path) const = 0;
virtual std::wstring getBootstrapFilename() const = 0;
diff --git a/src/SystemHelper.cpp b/src/SystemHelper.cpp
index 91d177d..afa902e 100644
--- a/src/SystemHelper.cpp
+++ b/src/SystemHelper.cpp
@@ -3,62 +3,21 @@
#include
#include
#include
+#include
+#include
std::optional SystemHelper::getRegValue(HKEY hive, const std::wstring& path, const std::wstring& key) const {
- DWORD dataSize{};
- LONG retCode = ::RegGetValueW(
- hive,
- path.c_str(),
- key.c_str(),
- RRF_RT_REG_SZ,
- nullptr,
- nullptr,
- &dataSize
- );
-
- if (retCode != ERROR_SUCCESS) {
- return std::nullopt;
- }
-
- std::wstring value;
- value.resize(dataSize / sizeof(wchar_t));
-
- retCode = ::RegGetValueW(
- hive,
- path.c_str(),
- key.c_str(),
- RRF_RT_REG_SZ,
- nullptr,
- value.data(),
- &dataSize
- );
-
- if (retCode != ERROR_SUCCESS) {
- return std::nullopt;
- }
-
- DWORD stringLengthInWchars = dataSize / sizeof(wchar_t);
- stringLengthInWchars--; // Exclude the NUL written by the Win32 API
- value.resize(stringLengthInWchars);
- return value;
+ return wil::reg::try_get_value_string(hive, path.c_str(), key.c_str());
}
std::optional SystemHelper::getEnvVar(const std::wstring& key) const {
- // Read the size of the env var
- DWORD size = ::GetEnvironmentVariableW(key.c_str(), nullptr, 0);
- if (!size || ::GetLastError() == ERROR_ENVVAR_NOT_FOUND) {
- return std::nullopt;
- }
+ auto value{ wil::TryGetEnvironmentVariableW(key.c_str()) };
- // Read the env var
- std::wstring value(size, L'\0');
- size = ::GetEnvironmentVariableW(key.c_str(), value.data(), size);
- if (!size || size >= value.size()) {
- return std::nullopt;
+ if (value) {
+ return wil::str_raw_ptr(value);
}
- value.resize(size);
- return value;
+ return std::nullopt;
}
void SystemHelper::showErrorMessage(const std::wstring& title, const std::wstring& message, const std::wstring& url) const {
@@ -74,21 +33,20 @@ void SystemHelper::showErrorMessage(const std::wstring& title, const std::wstrin
}
}
-DWORD SystemHelper::createProcess(std::vector args) const {
- STARTUPINFOW info;
- PROCESS_INFORMATION processInfo;
-
- ZeroMemory(&info, sizeof(info));
- ZeroMemory(&processInfo, sizeof(processInfo));
+DWORD SystemHelper::createProcess(const std::vector& args) const {
+ STARTUPINFOW info{ 0 };
+ wil::unique_process_information processInfo;
std::wstringstream cls;
for (auto& arg : args) {
cls << L"\"" << arg << L"\" ";
}
+
+ // Must copy as CreateProcessW can mutate this!!
std::wstring commandLine = cls.str();
// Create the child process
- if (::CreateProcessW(
+ THROW_LAST_ERROR_IF(!::CreateProcessW(
nullptr,
commandLine.data(),
nullptr,
@@ -98,26 +56,18 @@ DWORD SystemHelper::createProcess(std::vector args) const {
nullptr,
nullptr,
&info,
- &processInfo)) {
+ &processInfo)
+ );
- // Wait for exit
- ::WaitForSingleObject(processInfo.hProcess, INFINITE);
+ // Wait for exit
+ ::WaitForSingleObject(processInfo.hProcess, INFINITE);
- // Read exit code
- DWORD exitCode;
- ::GetExitCodeProcess(processInfo.hProcess, &exitCode);
+ // Read exit code
+ DWORD exitCode;
+ ::GetExitCodeProcess(processInfo.hProcess, &exitCode);
- // Clean up
- ::CloseHandle(processInfo.hThread);
- ::CloseHandle(processInfo.hProcess);
+ return exitCode;
- return exitCode;
- }
- else {
- std::string msg = "Failed to create process: " + std::to_string(GetLastError());
- return 255;
- // throw std::exception(msg.c_str());
- }
}
bool SystemHelper::fileExists(const std::wstring& path) const {
@@ -138,19 +88,13 @@ std::wstring SystemHelper::getBootstrapFilename() const {
std::wstring SystemHelper::getTempDir() const {
std::wstring tempDir;
- DWORD size = ::GetTempPath(0, nullptr);
+ DWORD size = ::GetTempPathW(0, nullptr);
+ THROW_LAST_ERROR_IF(!size);
- if (!size) {
- throw std::runtime_error("Failed to get temp path");
- }
-
- tempDir.resize((size_t) size + 1);
- size = ::GetTempPath(size + 1, tempDir.data());
+ tempDir.resize((size_t)size + 1);
+ size = ::GetTempPathW(size + 1, tempDir.data());
+ THROW_LAST_ERROR_IF(!size || size >= tempDir.size());
- if (!size || size >= tempDir.size()) {
- throw std::runtime_error("Failed to get temp path");
- }
-
tempDir.resize(size);
return tempDir;
}
diff --git a/src/SystemHelper.h b/src/SystemHelper.h
index 1b67147..fbe0131 100644
--- a/src/SystemHelper.h
+++ b/src/SystemHelper.h
@@ -7,7 +7,7 @@ class SystemHelper : public ISystemHelper {
std::optional getRegValue(HKEY hive, const std::wstring& path, const std::wstring& key) const override;
std::optional getEnvVar(const std::wstring& key) const override;
void showErrorMessage(const std::wstring& title, const std::wstring& message, const std::wstring& url) const override;
- DWORD createProcess(std::vector args) const override;
+ DWORD createProcess(const std::vector& args) const override;
bool fileExists(const std::wstring& path) const override;
bool dirExists(const std::wstring& path) const override;
std::wstring getBootstrapFilename() const override;
diff --git a/src/main.cpp b/src/main.cpp
index ebf2ee1..4a21559 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -29,7 +29,7 @@ _Use_decl_annotations_ int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevI
::HeapSetInformation(::GetProcessHeap(), HeapEnableTerminationOnCorruption, NULL, 0);
SystemHelper systemHelper;
- Logger logger { systemHelper };
+ Logger logger{ systemHelper };
logger.log(L"Fabric launcher native bootstrap log:");
@@ -37,8 +37,9 @@ _Use_decl_annotations_ int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevI
try {
bs.launch();
- } catch (const std::runtime_error& error) {
- logger.log(L"a runtime error occured:");
+ }
+ catch (const std::runtime_error& error) {
+ logger.log(L"A runtime error occurred:");
logger.log(error.what());
return 1;
}
diff --git a/resource.h b/src/resource.h
similarity index 82%
rename from resource.h
rename to src/resource.h
index d3496b0..bfc5433 100644
--- a/resource.h
+++ b/src/resource.h
@@ -3,6 +3,7 @@
// Used by fabric-installer-native-bootstrap.rc
//
#define IDI_ICON1 101
+#define IDI_EMBEDDED_JAR 201
// Next default values for new objects
//
@@ -11,6 +12,6 @@
#define _APS_NEXT_RESOURCE_VALUE 102
#define _APS_NEXT_COMMAND_VALUE 40001
#define _APS_NEXT_CONTROL_VALUE 1001
-#define _APS_NEXT_SYMED_VALUE 101
+#define _APS_NEXT_SYMED_VALUE 102
#endif
#endif