This commit is contained in:
justuser 2025-01-29 16:49:13 +03:00
parent 36b578e37c
commit d1d2a2c252
4 changed files with 110 additions and 0 deletions

BIN
launcher.exe Executable file

Binary file not shown.

19
launcher.sh Executable file
View File

@ -0,0 +1,19 @@
#!/bin/bash
# Check if minicraft.jar exists
if [ -f "minicraft.jar" ]; then
echo "minicraft.jar found."
else
echo "minicraft.jar not found. Downloading the latest version..."
# Fetch the latest release information from GitHub
latest_release=$(curl -s https://api.github.com/repos/MinicraftPlus/minicraft-plus-online/releases/latest | grep "browser_download_url.*minicraft_plus-.*\.jar" | cut -d '"' -f 4)
# Download the latest version of minicraft_plus.jar
wget -O minicraft.jar $latest_release
echo "Download complete."
fi
# Run minicraft.jar
java -jar minicraft.jar

BIN
launcher32bit.exe Executable file

Binary file not shown.

91
main.cpp Normal file
View File

@ -0,0 +1,91 @@
#include <iostream>
#include <fstream>
#include <string>
#include <sstream>
#include <cstdlib>
// Function to check if a file exists
bool FileExists(const std::string& filename) {
std::ifstream file(filename);
return file.good();
}
// Function to download and install Java 8
void InstallJava() {
std::cout << "Java 8 or higher is not installed. Downloading Java 8..." << std::endl;
std::string command = "curl -L -o java_installer.exe https://javadl.oracle.com/webapps/download/AutoDL?BundleId=251654_7ed26d28139143f38c58992680c214a5 && start java_installer.exe";
std::system(command.c_str());
std::cout << "Please install Java and restart the program." << std::endl;
exit(1);
}
// Function to get the latest release URL from GitHub
std::string GetLatestReleaseUrl() {
std::string command = "curl -s https://api.github.com/repos/MinicraftPlus/minicraft-plus-online/releases/latest";
std::string response;
char buffer[128];
FILE* pipe = popen(command.c_str(), "r");
if (!pipe) {
std::cerr << "Failed to run curl command." << std::endl;
return "";
}
while (fgets(buffer, sizeof(buffer), pipe) != nullptr) {
response += buffer;
}
pclose(pipe);
std::istringstream stream(response);
std::string line;
while (std::getline(stream, line)) {
if (line.find("browser_download_url") != std::string::npos && line.find(".jar") != std::string::npos) {
size_t start = line.find("https://");
size_t end = line.find_last_of('"');
if (start != std::string::npos && end != std::string::npos) {
return line.substr(start, end - start);
}
}
}
return "";
}
// Function to download a file using curl command
bool DownloadFile(const std::string& url, const std::string& filename) {
std::string command = "curl -L -o " + filename + " " + url;
int result = std::system(command.c_str());
return result == 0;
}
int main() {
const std::string jarFilename = "minicraft.jar";
if (FileExists(jarFilename)) {
std::cout << jarFilename << " found." << std::endl;
} else {
std::cout << jarFilename << " not found. Downloading the latest version..." << std::endl;
std::string latestReleaseUrl = GetLatestReleaseUrl();
if (latestReleaseUrl.empty()) {
std::cerr << "Failed to get the latest release URL." << std::endl;
return 1;
}
if (DownloadFile(latestReleaseUrl, jarFilename)) {
std::cout << "Download complete." << std::endl;
} else {
std::cerr << "Failed to download the file." << std::endl;
return 1;
}
}
// Run minicraft.jar
std::cout << "Running minicraft.jar..." << std::endl;
int result = std::system(("java -jar " + jarFilename).c_str());
if (result != 0) {
std::cerr << "Java is not installed or failed to run minicraft.jar. Installing Java..." << std::endl;
InstallJava();
return 1;
}
return 0;
}