-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add logger, improve support for ARM64 & Windows 7 #13
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#include "Architecture.h" | ||
|
||
std::wstring Architecture::AsString(const Value& arch) | ||
{ | ||
switch (arch) { | ||
case X64: | ||
return L"x64"; | ||
case ARM64: | ||
return L"arm64"; | ||
case X86: | ||
return L"x86"; | ||
case UNKNOWN: | ||
default: | ||
return L"unknown"; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#pragma once | ||
|
||
#include <string> | ||
|
||
namespace Architecture | ||
{ | ||
// Ordered to ensure that we only check for JVMs that will run on the host arch. | ||
// On an x64 host only check for x64 and x86 as arm will never run. | ||
// On x86 there is no need to try any other arch as it wont run. | ||
enum Value { | ||
UNKNOWN, | ||
ARM64, | ||
X64, | ||
X86, | ||
}; | ||
|
||
constexpr Value VALUES[] = { UNKNOWN, ARM64, X64, X86 }; | ||
|
||
std::wstring AsString(const Value& arch); | ||
}; | ||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -3,10 +3,11 @@ | |||||
#include <memory> | ||||||
|
||||||
#include "ISystemHelper.h" | ||||||
#include "Logger.h" | ||||||
|
||||||
class Bootstrap { | ||||||
modmuss50 marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
public: | ||||||
explicit Bootstrap(const std::shared_ptr<ISystemHelper>& systemHelper); | ||||||
explicit Bootstrap(ISystemHelper& systemHelper, Logger& logger); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
||||||
public: | ||||||
void launch(); | ||||||
|
@@ -19,6 +20,9 @@ class Bootstrap { | |||||
|
||||||
void showErrorMessage(); | ||||||
|
||||||
const std::vector<std::wstring> getMinecraftJavaPaths(const Architecture::Value& hostArch); | ||||||
|
||||||
private: | ||||||
std::shared_ptr<ISystemHelper> systemHelper; | ||||||
ISystemHelper& systemHelper; | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for taking a look at this :) I have fixed the other points. I was told a while back that you generally shouldn't have const refrences as member vars, ill be honest I didn't fully understand the reasoning. There seems to be a bit of litrature about this online such as: https://lesleylai.info/en/const-and-reference-member-variables/ And then other places seem to suggest having const is fine. The orignal design around this is to allow a mock of ISystemHelper for unit tests (that dont exist atm), the formal name for this pattern seems to be "dependency injection via constructor". Going back to using a shared_ptr seems like it might solve most of the possible problems? Either way I'm not too worried about being 100% correct as long as it works, but it is an intresting point of conversation. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's generally bad practice to have (even non-const) references as member variables, as that article explains, because references cannot be rebound, i.e. are effectively const. There is no need to change back to |
||||||
Logger& logger; | ||||||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#include "Logger.h" | ||
#include <sstream> | ||
|
||
namespace { | ||
std::wofstream openLogFile(ISystemHelper& systemHelper) { | ||
std::wstringstream fileNameBuf; | ||
fileNameBuf << systemHelper.getTempDir() << L"/fabric-installer-" << systemHelper.getEpochTime() << L".log"; | ||
return std::wofstream(fileNameBuf.str()); | ||
} | ||
} | ||
|
||
Logger::Logger(ISystemHelper& systemHelper) : file_(openLogFile(systemHelper)) | ||
{ | ||
} | ||
|
||
Logger::~Logger() | ||
{ | ||
file_.close(); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#pragma once | ||
|
||
#include "ISystemHelper.h" | ||
#include <fstream> | ||
|
||
class Logger | ||
{ | ||
public: | ||
Logger(ISystemHelper& systemHelper); | ||
~Logger(); | ||
|
||
template<class T> | ||
void log(const T& line) { | ||
file_ << line << std::endl; | ||
modmuss50 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
private: | ||
std::wofstream file_; | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Misspelling :p
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Opps, I will open an issue to remind myself to fix this in the next version. Not a major worry as it only shows in the log file 👍