Basic installation -- hardcoded vers
This commit is contained in:
parent
bd85e982e5
commit
f90508cedd
7
.gitignore
vendored
7
.gitignore
vendored
|
@ -1,7 +1,8 @@
|
||||||
cmake-build-debug/
|
|
||||||
cmake-build-release/
|
|
||||||
|
|
||||||
.idea/
|
.idea/
|
||||||
|
cmake-build-*/
|
||||||
|
|
||||||
|
.vs/
|
||||||
|
out/
|
||||||
|
|
||||||
.project
|
.project
|
||||||
.workspace
|
.workspace
|
||||||
|
|
|
@ -1,4 +1,10 @@
|
||||||
add_executable(installer
|
if (WIN32)
|
||||||
|
add_executable(installer WIN32)
|
||||||
|
else()
|
||||||
|
add_executable(installer)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
target_sources(installer PRIVATE
|
||||||
main.cpp
|
main.cpp
|
||||||
ui.cpp
|
ui.cpp
|
||||||
ui.hpp
|
ui.hpp
|
||||||
|
@ -29,3 +35,4 @@ target_sources(installer PRIVATE resources/resources.cpp resources/resources.h)
|
||||||
target_link_libraries(installer PRIVATE wx::base wx::core wx::net wx::xrc)
|
target_link_libraries(installer PRIVATE wx::base wx::core wx::net wx::xrc)
|
||||||
include_directories(../lib/wx/include)
|
include_directories(../lib/wx/include)
|
||||||
include_directories(../lib/json/include)
|
include_directories(../lib/json/include)
|
||||||
|
|
|
@ -1 +1,89 @@
|
||||||
#include "installer.hpp"
|
#include "installer.hpp"
|
||||||
|
#include <nlohmann/json.hpp>
|
||||||
|
#include <wx/log.h>
|
||||||
|
#include <wx/tokenzr.h>
|
||||||
|
|
||||||
|
InstallerResult install_loader(const InstallerConfig &config) {
|
||||||
|
if (!config.installation_dir.Mkdir(wxS_DIR_DEFAULT, wxPATH_MKDIR_FULL))
|
||||||
|
return InstallerResult::CouldntCreateLauncherDataDir;
|
||||||
|
|
||||||
|
const wxString version_id = "frogloader-" + config.loader_version.version + '-' + config.minecraft_version;
|
||||||
|
const wxString version_dir = config.launcher_data_dir.GetFullPath() + "/versions/" + version_id;
|
||||||
|
const wxString version_json_path = version_dir + '/' + version_id + ".json";
|
||||||
|
|
||||||
|
if (!wxFileName::Mkdir(version_dir, wxS_DIR_DEFAULT, wxPATH_MKDIR_FULL))
|
||||||
|
return InstallerResult::CouldntCreateVersionDir;
|
||||||
|
|
||||||
|
nlohmann::json version_libraries_json = nlohmann::json::array();
|
||||||
|
|
||||||
|
for (const LoaderLibrary &library : config.loader_version.libraries) {
|
||||||
|
wxArrayString name_tokens = wxStringTokenize(library.name, ":", wxTOKEN_RET_EMPTY_ALL);
|
||||||
|
|
||||||
|
if (name_tokens.size() < 3) {
|
||||||
|
wxLogWarning("Invalid library name: %s", library.name);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (name_tokens.size() > 4) {
|
||||||
|
wxLogWarning("Don't know how to handle more than 4 components in name: %s", library.name);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
wxString base_path = name_tokens.at(0);
|
||||||
|
base_path.Replace(".", "/");
|
||||||
|
|
||||||
|
wxString path = base_path + '/' + name_tokens.at(1) + '/' + name_tokens.at(2) + '/' + name_tokens.at(1) + '-' +
|
||||||
|
name_tokens.at(2);
|
||||||
|
|
||||||
|
if (name_tokens.size() > 3)
|
||||||
|
path += '-' + name_tokens[3];
|
||||||
|
|
||||||
|
path += ".jar";
|
||||||
|
|
||||||
|
version_libraries_json.push_back({
|
||||||
|
{"downloads",
|
||||||
|
{{"artifact",
|
||||||
|
{
|
||||||
|
{"path", path},
|
||||||
|
{"url", library.url},
|
||||||
|
{"size", library.size},
|
||||||
|
{"sha1", library.sha1},
|
||||||
|
}}}},
|
||||||
|
{"name", library.name},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
nlohmann::json version_json{{"id", version_id},
|
||||||
|
{"mainClass", "dev.frogmc.frogloader.impl.launch.client.FrogClient"},
|
||||||
|
{"inheritsFrom", config.minecraft_version},
|
||||||
|
{"libraries", version_libraries_json}};
|
||||||
|
|
||||||
|
{
|
||||||
|
wxFile version_json_file(version_json_path, wxFile::write);
|
||||||
|
|
||||||
|
if (!version_json_file.IsOpened())
|
||||||
|
return InstallerResult::CouldntWriteVersion;
|
||||||
|
|
||||||
|
if (!version_json_file.Write(version_json.dump(4), wxConvUTF8))
|
||||||
|
return InstallerResult::CouldntWriteVersion;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// wxString launcher_profiles_path = config.launcher_data_dir.GetFullPath() + "/launcher-profiles.json";
|
||||||
|
// nlohmann::json launcher_profiles_json;
|
||||||
|
//
|
||||||
|
// if (wxFileExists(launcher_profiles_path)) {
|
||||||
|
// wxFile file(launcher_profiles_path, wxFile::read);
|
||||||
|
// if (!file.IsOpened())
|
||||||
|
// return InstallerResult::CouldntReadLauncherProfiles;
|
||||||
|
//
|
||||||
|
// wxString content;
|
||||||
|
// if (!file.ReadAll(&content, wxConvUTF8))
|
||||||
|
// return InstallerResult::CouldntReadLauncherProfiles;
|
||||||
|
//
|
||||||
|
// launcher_profiles_json = nlohmann::json::parse(content);
|
||||||
|
// } else
|
||||||
|
// launcher_profiles_json = nlohmann::json::object({"version", 3, "profiles", nlohmann::json::array()});
|
||||||
|
|
||||||
|
return InstallerResult::OK;
|
||||||
|
}
|
||||||
|
|
|
@ -1,7 +1,30 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include "meta.hpp"
|
||||||
#include <wx/filename.h>
|
#include <wx/filename.h>
|
||||||
|
|
||||||
wxFileName get_launcher_data_dir();
|
struct InstallerConfig {
|
||||||
|
wxFileName launcher_data_dir;
|
||||||
|
|
||||||
|
wxString minecraft_version;
|
||||||
|
LoaderVersion loader_version;
|
||||||
|
|
||||||
|
wxString installation_name;
|
||||||
|
wxFileName installation_dir;
|
||||||
|
};
|
||||||
|
|
||||||
|
enum class InstallerResult {
|
||||||
|
OK,
|
||||||
|
CouldntCreateLauncherDataDir,
|
||||||
|
CouldntCreateVersionDir,
|
||||||
|
CouldntWriteVersion,
|
||||||
|
CouldntReadLauncherProfiles,
|
||||||
|
CouldntWriteLauncherProfiles,
|
||||||
|
CouldntCreateInstallationDir,
|
||||||
|
};
|
||||||
|
|
||||||
|
wxFileName find_launcher_data_dir();
|
||||||
|
|
||||||
bool is_launcher_open();
|
bool is_launcher_open();
|
||||||
|
|
||||||
|
InstallerResult install_loader(const InstallerConfig &config);
|
||||||
|
|
|
@ -1,10 +1,12 @@
|
||||||
|
#include <wx/defs.h>
|
||||||
|
|
||||||
|
#ifdef __LINUX__
|
||||||
|
|
||||||
#include "installer.hpp"
|
#include "installer.hpp"
|
||||||
#include <wx/dir.h>
|
#include <wx/dir.h>
|
||||||
#include <wx/utils.h>
|
#include <wx/utils.h>
|
||||||
|
|
||||||
#ifdef __LINUX__
|
wxFileName find_launcher_data_dir() {
|
||||||
|
|
||||||
wxFileName get_launcher_data_dir() {
|
|
||||||
const wxString home = wxGetHomeDir();
|
const wxString home = wxGetHomeDir();
|
||||||
const wxFileName dir = wxFileName::DirName(home + "/.minecraft");
|
const wxFileName dir = wxFileName::DirName(home + "/.minecraft");
|
||||||
|
|
||||||
|
@ -52,7 +54,6 @@ bool is_launcher_open() {
|
||||||
ssize_t read;
|
ssize_t read;
|
||||||
|
|
||||||
wxString current_content;
|
wxString current_content;
|
||||||
std::vector<wxString> args;
|
|
||||||
|
|
||||||
while ((read = cmdline_file.Read(buffer, BUFSIZ)) != wxInvalidOffset && read != 0) {
|
while ((read = cmdline_file.Read(buffer, BUFSIZ)) != wxInvalidOffset && read != 0) {
|
||||||
for (size_t index = 0; index < read; ++index) {
|
for (size_t index = 0; index < read; ++index) {
|
||||||
|
@ -60,7 +61,9 @@ bool is_launcher_open() {
|
||||||
|
|
||||||
if (value == '\0') {
|
if (value == '\0') {
|
||||||
if (!current_content.empty()) {
|
if (!current_content.empty()) {
|
||||||
args.push_back(current_content);
|
if (filter(current_content))
|
||||||
|
return true;
|
||||||
|
|
||||||
current_content.clear();
|
current_content.clear();
|
||||||
}
|
}
|
||||||
} else
|
} else
|
||||||
|
@ -68,10 +71,7 @@ bool is_launcher_open() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!current_content.empty())
|
if (!current_content.empty() && filter(current_content))
|
||||||
args.push_back(current_content);
|
|
||||||
|
|
||||||
if (std::any_of(args.begin(), args.end(), filter))
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,10 +1,12 @@
|
||||||
|
#include <wx/defs.h>
|
||||||
|
|
||||||
|
#ifdef __DARWIN__
|
||||||
|
|
||||||
#include "installer.hpp"
|
#include "installer.hpp"
|
||||||
#include <wx/dir.h>
|
#include <wx/dir.h>
|
||||||
#include <wx/utils.h>
|
#include <wx/utils.h>
|
||||||
|
|
||||||
#ifdef __DARWIN__
|
wxFileName find_launcher_data_dir() {
|
||||||
|
|
||||||
wxFileName get_launcher_data_dir() {
|
|
||||||
return wxFileName::DirName(wxGetHomeDir() + "/Library/Application Support/minecraft");
|
return wxFileName::DirName(wxGetHomeDir() + "/Library/Application Support/minecraft");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,10 +1,14 @@
|
||||||
#include "installer.hpp"
|
#include <wx/defs.h>
|
||||||
#include <wx/dir.h>
|
|
||||||
#include <wx/utils.h>
|
|
||||||
|
|
||||||
#ifdef __WINDOWS__
|
#ifdef __WINDOWS__
|
||||||
|
|
||||||
wxFileName get_launcher_data_dir() {
|
#include "installer.hpp"
|
||||||
|
|
||||||
|
#include <wx/dir.h>
|
||||||
|
#include <wx/stdpaths.h>
|
||||||
|
#include <wx/utils.h>
|
||||||
|
|
||||||
|
wxFileName find_launcher_data_dir() {
|
||||||
return wxFileName::DirName(wxStandardPaths::Get().GetUserConfigDir() + "\\.minecraft");
|
return wxFileName::DirName(wxStandardPaths::Get().GetUserConfigDir() + "\\.minecraft");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -55,7 +55,7 @@ static LoaderVersion make_loader_version(const nlohmann::json &json) {
|
||||||
|
|
||||||
void get_loader_version(wxEvtHandler *handler, const wxString &version,
|
void get_loader_version(wxEvtHandler *handler, const wxString &version,
|
||||||
std::function<void(std::optional<LoaderVersion>)> callback) {
|
std::function<void(std::optional<LoaderVersion>)> callback) {
|
||||||
wxWebRequest request = wxWebSession::GetDefault().CreateRequest(handler, meta_url("loader/versions/" + version));
|
wxWebRequest request = wxWebSession::GetDefault().CreateRequest(handler, meta_url("loader/version/" + version));
|
||||||
|
|
||||||
if (!request.IsOk()) {
|
if (!request.IsOk()) {
|
||||||
wxLogError("Invalid request object");
|
wxLogError("Invalid request object");
|
||||||
|
@ -67,7 +67,15 @@ void get_loader_version(wxEvtHandler *handler, const wxString &version,
|
||||||
|
|
||||||
handler->Bind(wxEVT_WEBREQUEST_STATE, [callback = std::move(callback)](const wxWebRequestEvent &event) mutable {
|
handler->Bind(wxEVT_WEBREQUEST_STATE, [callback = std::move(callback)](const wxWebRequestEvent &event) mutable {
|
||||||
if (event.GetState() == wxWebRequest::State_Completed) {
|
if (event.GetState() == wxWebRequest::State_Completed) {
|
||||||
const nlohmann::json json = nlohmann::json::parse(event.GetResponse().AsString().utf8_string());
|
nlohmann::json json;
|
||||||
|
|
||||||
|
try {
|
||||||
|
json = nlohmann::json::parse(event.GetResponse().AsString().utf8_string());
|
||||||
|
} catch (const nlohmann::json::parse_error &error) {
|
||||||
|
wxLogError("Invalid response: %s", error.what());
|
||||||
|
callback({});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
LoaderVersion result = make_loader_version(json);
|
LoaderVersion result = make_loader_version(json);
|
||||||
|
|
||||||
|
|
|
@ -4,25 +4,51 @@
|
||||||
InstallerFrame::InstallerFrame() : InstallerFrame_UI(nullptr) {
|
InstallerFrame::InstallerFrame() : InstallerFrame_UI(nullptr) {
|
||||||
heading->SetFont(heading->GetFont().Scaled(1.6F));
|
heading->SetFont(heading->GetFont().Scaled(1.6F));
|
||||||
|
|
||||||
launcher_data_dir_input->ChangeValue(get_launcher_data_dir().GetFullPath());
|
launcher_data_dir_input->ChangeValue(find_launcher_data_dir().GetFullPath());
|
||||||
launcher_data_dir_browse->Bind(wxEVT_BUTTON, [this](wxCommandEvent &) {
|
launcher_data_dir_browse->Bind(wxEVT_BUTTON, &InstallerFrame::select_launcher_data_dir, this);
|
||||||
wxDirDialog dialog(this, _("Select launcher data directory"));
|
|
||||||
|
|
||||||
if (dialog.ShowModal() != wxID_OK)
|
name_input->SetHint("FrogLoader");
|
||||||
return;
|
|
||||||
|
|
||||||
game_data_dir_input->ChangeValue(dialog.GetPath());
|
|
||||||
});
|
|
||||||
|
|
||||||
game_data_dir_input->SetHint(_("Use Default"));
|
game_data_dir_input->SetHint(_("Use Default"));
|
||||||
game_data_dir_browse->Bind(wxEVT_BUTTON, [this](wxCommandEvent &) {
|
game_data_dir_browse->Bind(wxEVT_BUTTON, &InstallerFrame::select_game_data_dir, this);
|
||||||
wxDirDialog dialog(this, _("Select game data directory"));
|
|
||||||
|
|
||||||
if (dialog.ShowModal() != wxID_OK)
|
|
||||||
return;
|
|
||||||
|
|
||||||
game_data_dir_input->ChangeValue(dialog.GetPath());
|
|
||||||
});
|
|
||||||
|
|
||||||
cancel->Bind(wxEVT_BUTTON, [this](wxCommandEvent &) { Close(); });
|
cancel->Bind(wxEVT_BUTTON, [this](wxCommandEvent &) { Close(); });
|
||||||
|
install->Bind(wxEVT_BUTTON, &InstallerFrame::perform_install, this);
|
||||||
|
}
|
||||||
|
|
||||||
|
void InstallerFrame::select_launcher_data_dir(const wxCommandEvent &) {
|
||||||
|
wxDirDialog dialog(this, _("Select launcher data directory"));
|
||||||
|
|
||||||
|
if (dialog.ShowModal() != wxID_OK)
|
||||||
|
return;
|
||||||
|
|
||||||
|
launcher_data_dir_input->ChangeValue(dialog.GetPath());
|
||||||
|
}
|
||||||
|
|
||||||
|
void InstallerFrame::select_game_data_dir(const wxCommandEvent &) {
|
||||||
|
wxDirDialog dialog(this, _("Select game data directory"));
|
||||||
|
|
||||||
|
if (dialog.ShowModal() != wxID_OK)
|
||||||
|
return;
|
||||||
|
|
||||||
|
game_data_dir_input->ChangeValue(dialog.GetPath());
|
||||||
|
}
|
||||||
|
|
||||||
|
void InstallerFrame::perform_install(const wxCommandEvent &) {
|
||||||
|
get_loader_version(this, "0.0.1-alpha.10", [this](std::optional<LoaderVersion> version) {
|
||||||
|
if (!version.has_value())
|
||||||
|
return;
|
||||||
|
|
||||||
|
InstallerResult result = install_loader({
|
||||||
|
.launcher_data_dir = launcher_data_dir_input->GetValue(),
|
||||||
|
.minecraft_version = "1.21",
|
||||||
|
.loader_version = *version,
|
||||||
|
.installation_name = name_input->GetValue(),
|
||||||
|
.installation_dir = game_data_dir_input->GetValue(),
|
||||||
|
});
|
||||||
|
|
||||||
|
if (result == InstallerResult::OK) {
|
||||||
|
wxMessageBox(_("Reopen the launcher and FrogLoader should be available."), _("Installation Complete"));
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,4 +8,10 @@
|
||||||
class InstallerFrame final : public InstallerFrame_UI {
|
class InstallerFrame final : public InstallerFrame_UI {
|
||||||
public:
|
public:
|
||||||
explicit InstallerFrame();
|
explicit InstallerFrame();
|
||||||
|
|
||||||
|
private:
|
||||||
|
void select_launcher_data_dir(const wxCommandEvent &);
|
||||||
|
void select_game_data_dir(const wxCommandEvent &);
|
||||||
|
|
||||||
|
void perform_install(const wxCommandEvent &);
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
set(wxBUILD_SHARED OFF)
|
set(wxBUILD_SHARED OFF)
|
||||||
set(wxUSE_REGEX OFF)
|
set(wxUSE_REGEX OFF)
|
||||||
set(wxUSE_ZLIB OFF)
|
|
||||||
set(wxUSE_LIBTIFF OFF)
|
set(wxUSE_LIBTIFF OFF)
|
||||||
set(wxUSE_LIBJPEG OFF)
|
set(wxUSE_LIBJPEG OFF)
|
||||||
set(wxUSE_LIBSDL OFF)
|
set(wxUSE_LIBSDL OFF)
|
||||||
|
|
Loading…
Reference in a new issue