Start with backend
This commit is contained in:
parent
552da59007
commit
0c5b6e4a73
|
@ -1,4 +1,16 @@
|
|||
add_executable(installer main.cpp ui.cpp ui.hpp meta.cpp meta.hpp info.hpp)
|
||||
add_executable(installer
|
||||
main.cpp
|
||||
ui.cpp
|
||||
ui.hpp
|
||||
meta.cpp
|
||||
meta.hpp
|
||||
info.hpp
|
||||
installer.cpp
|
||||
installer.hpp
|
||||
installer_windows.cpp
|
||||
installer_mac.cpp
|
||||
installer_linux.cpp
|
||||
)
|
||||
|
||||
configure_file(info.hpp.in info.hpp)
|
||||
|
||||
|
@ -6,11 +18,11 @@ configure_file(info.hpp.in info.hpp)
|
|||
set(XRC_FILES ${CMAKE_CURRENT_SOURCE_DIR}/resources/InstallerFrame_UI.xrc)
|
||||
set(WXRC $<TARGET_FILE:wxrc>)
|
||||
add_custom_command(
|
||||
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/resources/resources.cpp ${CMAKE_CURRENT_BINARY_DIR}/resources/resources.h
|
||||
COMMAND ${WXRC} -c -e -o ${CMAKE_CURRENT_BINARY_DIR}/resources/resources.cpp ${XRC_FILES}
|
||||
DEPENDS ${XRC_FILES}
|
||||
DEPENDS wxrc
|
||||
COMMENT "Compiling XRC resources"
|
||||
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/resources/resources.cpp ${CMAKE_CURRENT_BINARY_DIR}/resources/resources.h
|
||||
COMMAND ${WXRC} -c -e -o ${CMAKE_CURRENT_BINARY_DIR}/resources/resources.cpp ${XRC_FILES}
|
||||
DEPENDS ${XRC_FILES}
|
||||
DEPENDS wxrc
|
||||
COMMENT "Compiling XRC resources"
|
||||
)
|
||||
target_sources(installer PRIVATE resources/resources.cpp resources/resources.h)
|
||||
|
||||
|
|
1
installer/installer.cpp
Normal file
1
installer/installer.cpp
Normal file
|
@ -0,0 +1 @@
|
|||
#include "installer.hpp"
|
7
installer/installer.hpp
Normal file
7
installer/installer.hpp
Normal file
|
@ -0,0 +1,7 @@
|
|||
#pragma once
|
||||
|
||||
#include <wx/filename.h>
|
||||
|
||||
wxFileName get_launcher_data_dir();
|
||||
|
||||
bool is_launcher_open();
|
81
installer/installer_linux.cpp
Normal file
81
installer/installer_linux.cpp
Normal file
|
@ -0,0 +1,81 @@
|
|||
#include "installer.hpp"
|
||||
#include <wx/dir.h>
|
||||
#include <wx/utils.h>
|
||||
|
||||
#ifdef __LINUX__
|
||||
|
||||
wxFileName get_launcher_data_dir() {
|
||||
const wxString home = wxGetHomeDir();
|
||||
const wxFileName dir = wxFileName::DirName(home + "/.minecraft");
|
||||
|
||||
if (!dir.DirExists()) {
|
||||
const wxFileName flatpak_dir = wxFileName::DirName(home + "/.var/app/com.mojang.Minecraft/.minecraft");
|
||||
|
||||
// if the flatpak directory is the only directory present, use it
|
||||
// otherwise we will make the for the official launcher
|
||||
if (flatpak_dir.DirExists())
|
||||
return flatpak_dir;
|
||||
}
|
||||
|
||||
return dir;
|
||||
}
|
||||
|
||||
bool is_launcher_open() {
|
||||
auto filter = [](const wxString &arg) {
|
||||
return arg == "minecraft-launcher" || arg.EndsWith("/minecraft-launcher") ||
|
||||
(arg.StartsWith("--log-file=") && arg.EndsWith(".minecraft/launcher_cef_log.txt"));
|
||||
};
|
||||
|
||||
wxDir dir("/proc");
|
||||
if (!dir.IsOpened())
|
||||
return {};
|
||||
|
||||
wxString proc_entry;
|
||||
|
||||
for (bool has_more = dir.GetFirst(&proc_entry, wxEmptyString, wxDIR_DIRS); has_more;
|
||||
has_more = dir.GetNext(&proc_entry)) {
|
||||
bool is_pid =
|
||||
std::all_of(proc_entry.begin(), proc_entry.end(), [](auto chr) { return chr >= '0' && chr <= '9'; });
|
||||
|
||||
if (!is_pid)
|
||||
continue;
|
||||
|
||||
wxFile cmdline_file(dir.GetNameWithSep() + proc_entry + "/cmdline", wxFile::read);
|
||||
|
||||
if (!cmdline_file.IsOpened())
|
||||
continue;
|
||||
|
||||
// unfortunately, c style code is needed here, watch out for buffer overflow :|
|
||||
// wx does not like \0
|
||||
|
||||
char buffer[BUFSIZ];
|
||||
ssize_t read;
|
||||
|
||||
wxString current_content;
|
||||
std::vector<wxString> args;
|
||||
|
||||
while ((read = cmdline_file.Read(buffer, BUFSIZ)) != wxInvalidOffset && read != 0) {
|
||||
for (size_t index = 0; index < read; ++index) {
|
||||
char value = buffer[index];
|
||||
|
||||
if (value == '\0') {
|
||||
if (!current_content.empty()) {
|
||||
args.push_back(current_content);
|
||||
current_content.clear();
|
||||
}
|
||||
} else
|
||||
current_content += value;
|
||||
}
|
||||
}
|
||||
|
||||
if (!current_content.empty())
|
||||
args.push_back(current_content);
|
||||
|
||||
if (std::any_of(args.begin(), args.end(), filter))
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
#endif
|
16
installer/installer_mac.cpp
Normal file
16
installer/installer_mac.cpp
Normal file
|
@ -0,0 +1,16 @@
|
|||
#include "installer.hpp"
|
||||
#include <wx/dir.h>
|
||||
#include <wx/utils.h>
|
||||
|
||||
#ifdef __DARWIN__
|
||||
|
||||
wxFileName get_launcher_data_dir() {
|
||||
return wxFileName::DirName(wxGetHomeDir() + "/Library/Application Support/minecraft");
|
||||
}
|
||||
|
||||
bool is_launcher_open() {
|
||||
wxASSERT_MSG(false, "TODO");
|
||||
return false; // TODO
|
||||
}
|
||||
|
||||
#endif
|
16
installer/installer_windows.cpp
Normal file
16
installer/installer_windows.cpp
Normal file
|
@ -0,0 +1,16 @@
|
|||
#include "installer.hpp"
|
||||
#include <wx/dir.h>
|
||||
#include <wx/utils.h>
|
||||
|
||||
#ifdef __WINDOWS__
|
||||
|
||||
wxFileName get_launcher_data_dir() {
|
||||
return wxFileName::DirName(wxStandardPaths::Get().GetUserConfigDir() + "\\.minecraft");
|
||||
}
|
||||
|
||||
bool is_launcher_open() {
|
||||
wxASSERT_MSG(false, "TODO");
|
||||
return false; // TODO
|
||||
}
|
||||
|
||||
#endif
|
|
@ -50,7 +50,7 @@
|
|||
<property name="minimum_size"></property>
|
||||
<property name="name">InstallerFrame_UI</property>
|
||||
<property name="pos"></property>
|
||||
<property name="size">500,450</property>
|
||||
<property name="size">500,480</property>
|
||||
<property name="style">wxDEFAULT_FRAME_STYLE</property>
|
||||
<property name="subclass">; ; forward_declare</property>
|
||||
<property name="title">FrogLoader Installer</property>
|
||||
|
@ -74,6 +74,16 @@
|
|||
<property name="name">options</property>
|
||||
<property name="orient">wxVERTICAL</property>
|
||||
<property name="permission">none</property>
|
||||
<object class="sizeritem" expanded="true">
|
||||
<property name="border">5</property>
|
||||
<property name="flag">wxEXPAND</property>
|
||||
<property name="proportion">1</property>
|
||||
<object class="spacer" expanded="true">
|
||||
<property name="height">0</property>
|
||||
<property name="permission">protected</property>
|
||||
<property name="width">0</property>
|
||||
</object>
|
||||
</object>
|
||||
<object class="sizeritem" expanded="true">
|
||||
<property name="border">5</property>
|
||||
<property name="flag">wxALL</property>
|
||||
|
@ -839,6 +849,16 @@
|
|||
</object>
|
||||
</object>
|
||||
</object>
|
||||
<object class="sizeritem" expanded="true">
|
||||
<property name="border">5</property>
|
||||
<property name="flag">wxEXPAND</property>
|
||||
<property name="proportion">1</property>
|
||||
<object class="spacer" expanded="true">
|
||||
<property name="height">0</property>
|
||||
<property name="permission">protected</property>
|
||||
<property name="width">0</property>
|
||||
</object>
|
||||
</object>
|
||||
</object>
|
||||
</object>
|
||||
<object class="sizeritem" expanded="false">
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
||||
<resource xmlns="http://www.wxwidgets.org/wxxrc" version="2.5.3.0">
|
||||
<object class="wxFrame" name="InstallerFrame_UI">
|
||||
<size>500,450</size>
|
||||
<size>500,480</size>
|
||||
<style>wxDEFAULT_FRAME_STYLE|wxTAB_TRAVERSAL</style>
|
||||
<title>FrogLoader Installer</title>
|
||||
<centered>1</centered>
|
||||
|
@ -14,6 +14,12 @@
|
|||
<option>1</option>
|
||||
<object class="wxBoxSizer" name="options">
|
||||
<orient>wxVERTICAL</orient>
|
||||
<object class="spacer">
|
||||
<flag>wxEXPAND</flag>
|
||||
<border>5</border>
|
||||
<option>1</option>
|
||||
<size>0,0</size>
|
||||
</object>
|
||||
<object class="sizeritem">
|
||||
<flag>wxALL</flag>
|
||||
<border>5</border>
|
||||
|
@ -158,6 +164,12 @@
|
|||
</object>
|
||||
</object>
|
||||
</object>
|
||||
<object class="spacer">
|
||||
<flag>wxEXPAND</flag>
|
||||
<border>5</border>
|
||||
<option>1</option>
|
||||
<size>0,0</size>
|
||||
</object>
|
||||
</object>
|
||||
</object>
|
||||
<object class="sizeritem">
|
||||
|
|
|
@ -1,5 +1,10 @@
|
|||
#include "ui.hpp"
|
||||
#include "installer.hpp"
|
||||
|
||||
InstallerFrame::InstallerFrame() : InstallerFrame_UI(nullptr) {
|
||||
heading->SetFont(heading->GetFont().Scaled(2));
|
||||
heading->SetFont(heading->GetFont().Scaled(1.6F));
|
||||
launcher_data_dir_input->ChangeValue(get_launcher_data_dir().GetFullPath());
|
||||
game_data_dir_input->SetHint(_("Use Default"));
|
||||
|
||||
cancel->Bind(wxEVT_BUTTON, [this] (wxCommandEvent &) { Close(); });
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue