Skip to content

Commit

Permalink
code update
Browse files Browse the repository at this point in the history
  • Loading branch information
ShadowMonster99 committed Sep 13, 2023
1 parent 9a084fc commit 26aa682
Show file tree
Hide file tree
Showing 9 changed files with 147 additions and 79 deletions.
Binary file added installer/scripts/RCa23216
Binary file not shown.
Binary file modified installer/scripts/icon1.ico
Binary file not shown.
Binary file removed installer/scripts/millennium.installer.aps
Binary file not shown.
44 changes: 25 additions & 19 deletions installer/src/installer/installer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,20 @@

//interact with disk when uninstalling and installing
#include <filesystem>
#include <fstream>

static
const
constexpr
std::string_view githubRepo = "https://api.github.com/repos/ShadowMonster99/millennium-steam-binaries/releases/latest";

HINTERNET getConnection() {
static HINTERNET connection = InternetOpenA("millennium.installer", INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0);
return connection;
}
bool Installer::downloadFile(std::string fileUrl, std::string filePath, std::string fileName, size_t expectedLen) {

bool Installer::downloadFile(std::string fileUrl, std::string filePath, size_t expectedLen) {
std::cout << " Getting [" << fileName << "]" << std::endl;

HINTERNET hConnection = InternetOpenUrlA(getConnection(), fileUrl.c_str(), NULL, 0, INTERNET_FLAG_RELOAD, 0);
std::cout << "Downloading to: " << filePath << std::endl;
HINTERNET connection = InternetOpenA("millennium.installer", INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0);
HINTERNET hConnection = InternetOpenUrlA(connection, fileUrl.c_str(), NULL, 0, INTERNET_FLAG_RELOAD, 0);
std::cout << " Touching [" << filePath << "]" << std::endl;

std::remove(filePath.c_str());

Expand All @@ -35,7 +34,7 @@ bool Installer::downloadFile(std::string fileUrl, std::string filePath, size_t e
DWORD totalBytesRead = 0;
DWORD totalBytesExpected = expectedLen;

while (InternetReadFile(getConnection(), buffer, sizeof(buffer), &bytesRead) && bytesRead > 0) {
while (InternetReadFile(connection, buffer, sizeof(buffer), &bytesRead) && bytesRead > 0) {
DWORD bytesWritten;
if (!WriteFile(hFile, buffer, bytesRead, &bytesWritten, NULL)) {
std::cout << "Failed to download file. Couldn't write file from buffer" << std::endl;
Expand Down Expand Up @@ -68,12 +67,11 @@ void Installer::installMillennium() {
std::string tag_name = response["tag_name"].get<std::string>();
std::string notes = response["body"].get<std::string>();

std::cout << "Getting latest release of millennium: v" << tag_name << std::endl;
std::cout << "Patch notes:\n" << notes << std::endl;
std::cout << "Evaluating " << response["assets"].size() << " files to download" << std::endl;

totalLength = response["assets"].size();

std::cout << "Bootstrapping Millennium: v" << tag_name << std::endl;
std::cout << "Queued " << totalLength << " files to download" << std::endl;

for (nlohmann::basic_json<>& item : response["assets"])
{
auto startTime = std::chrono::high_resolution_clock::now();
Expand All @@ -86,23 +84,31 @@ void Installer::installMillennium() {
double size = static_cast<double>(item["size"].get<int>()) / 1048576.0;
int download_count = item["download_count"].get<int>();

std::cout << "--------------------------------" << std::endl;
std::cout << std::endl;

std::cout << "Downloading: [" << currentFileName << "] " << std::endl;
std::cout << "File size: [" << size << "mb]" << std::endl;
std::cout << "Download Count: [" << download_count << "]" << std::endl;
std::cout << " File size: " << size << "mb" << std::endl;
std::cout << " Download Count: " << download_count << std::endl;

downloadFile(download, Steam::getInstallPath() + "/" + currentFileName, item["size"].get<size_t>());
downloadFile(download, Steam::getInstallPath() + "/" + currentFileName, currentFileName, item["size"].get<size_t>());

auto endTime = std::chrono::high_resolution_clock::now();
auto duration = std::chrono::duration_cast<std::chrono::milliseconds>(endTime - startTime).count();

std::cout << "Done! "
std::cout << "\n [+] "
<< std::chrono::duration_cast<std::chrono::milliseconds>(endTime - startTime).count()
<< " milliseconds elapsed" << std::endl;
}

std::cout << "--------------------------------" << std::endl;
std::cout << std::endl;

std::string filePath = std::format("{}/.cef-enable-remote-debugging", Steam::getInstallPath());

if (!std::ifstream(filePath))
{
std::cout << "Creating steam's remote debugging flag as it wasn't previously set." << std::endl;
std::ofstream(filePath).close();
}

std::cout << "Installation completed. You can now start Steam" << std::endl;
}

Expand Down
2 changes: 1 addition & 1 deletion installer/src/installer/installer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

class Installer {
private:
bool downloadFile(std::string fileUrl, std::string filePath, size_t expectedLen);
bool downloadFile(std::string fileUrl, std::string filePath, std::string fileName, size_t expectedLen);
public:
float fileProgress;

Expand Down
143 changes: 95 additions & 48 deletions installer/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ const char* repo_url = "https://api.github.com/repos/ShadowMonster99/millennium-
std::string terms_and_conditions;

std::string millenniumInstallVersion;
std::string millenniumPatchNotes;

class Handler
{
Expand All @@ -56,34 +57,45 @@ class Handler
public:
__declspec(noinline) static void tos_agreement_page(void)
{
ImGui::PushStyleColor(ImGuiCol_Border, ImVec4(0.20f, 0.20f, 0.20f, 1.0f));
ImGui::PushStyleColor(ImGuiCol_ChildBg, ImVec4(0.12f, 0.12f, 0.12f, 1.0f));
if (ImGui::BeginChild("##agree", ImVec2(Region.x, Region.y - 30), true)) {
ImGui::TextWrapped(terms_and_conditions.c_str());
}
ImGui::EndChild();
ImGui::PopStyleColor();

ImGui::Checkbox("I accept the following argeement", &accepted_tos);
ImGui::Checkbox("I accept the following agreement", &accepted_tos);
ImGui::SameLine();
ImGui::SetCursorPosX(ImGui::GetWindowWidth() - ImGui::GetStyle().ItemSpacing.x - ImGui::CalcTextSize("Continue >").x - 3); // Align cursor to the right

const char* header_text = " Millennium - Terms of Service";
const char* httpErrorModal = " Oops!";

if (ImGui::Button("Continue >")) {
if (!accepted_tos) show_accept_tos_popup = true;
if (!accepted_tos) {
ImGui::OpenPopup(header_text);
}
else
{
millenniumInstallVersion = nlohmann::json::parse(http::get(repo_url))["tag_name"];
current_page = 2;
try
{
const auto info = nlohmann::json::parse(http::get(repo_url));

millenniumInstallVersion = info["tag_name"];
millenniumPatchNotes = info["body"];
current_page = 2;
}
catch (const http_error& error) {
ImGui::OpenPopup(httpErrorModal);
}
}
}

Window::center_modal(ImVec2(325, 200));
const char* header_text = " Millennium - Error";

if (show_accept_tos_popup) ImGui::OpenPopup(header_text);
ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, 4.0f);
if (ImGui::BeginPopupModal(header_text, nullptr, ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoResize))
{
ImGui::TextWrapped("You need to agree with the Terms of Service in order to install Millennium.\n\nIf you don't agree with the terms please refrain from using our products.");
ImGui::TextWrapped("You need to agree with the Terms of Service in order to install Millennium. If you don't agree with the terms please refrain from using our products.");

ImGui::SetCursorPosX(ImGui::GetWindowWidth() - ImGui::GetStyle().ItemSpacing.x - ImGui::CalcTextSize("Close").x - 5);
ImGui::SetCursorPosY(ImGui::GetWindowHeight() - ImGui::GetStyle().ItemSpacing.y - 23);
Expand All @@ -95,6 +107,30 @@ class Handler
ImGui::EndPopup();
}
ImGui::PopStyleVar();

Window::center_modal(ImVec2(325, 200));
ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, 4.0f);
if (ImGui::BeginPopupModal(httpErrorModal, nullptr, ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoResize))
{
ImGui::TextWrapped("There was an error getting build information on Millennium. Check if you have a valid internet connection"
" or retry again later. If the problem persists, get help in the discord server.");


ImGui::SetCursorPosX(ImGui::GetWindowWidth() - ImGui::GetStyle().ItemSpacing.x - ImGui::CalcTextSize("Close").x - 85);
ImGui::SetCursorPosY(ImGui::GetWindowHeight() - ImGui::GetStyle().ItemSpacing.y - 23);

if (ImGui::Button("need help?")) {
ShellExecute(0, "open", "https://discord.gg/MXMWEQKgJF", 0, 0, SW_SHOWNORMAL);
}
ImGui::SameLine();
ui::shift::x(-4);
if (ImGui::Button("Close")) {
ImGui::CloseCurrentPopup();
show_accept_tos_popup = false;
}
ImGui::EndPopup();
}
ImGui::PopStyleVar();
}

__declspec(noinline) static void select_option_page(void)
Expand All @@ -110,52 +146,57 @@ class Handler
ImGui::PushStyleColor(ImGuiCol_ChildBg, ImVec4(0.09f, 0.09f, 0.09f, 1.0f));
ImGui::PushStyleColor(ImGuiCol_Border, ImVec4(0.20f, 0.20f, 0.20f, 1.0f));

ImGui::BeginChild("InstallDetailsPane", ImVec2(rx, 91));
ImGui::BeginChild("InstallDetailsPane", ImVec2(rx, 110 + ImGui::CalcTextSize(millenniumPatchNotes.c_str()).y));
{
if (selected_option == 1) {
ImGui::PushStyleColor(ImGuiCol_Button, col);
ImGui::PushStyleColor(ImGuiCol_ButtonHovered, col);
if (ImGui::Button(install, ImVec2(Region.x, 45))) selected_option = 1;
//ImGui::PushStyleColor(ImGuiCol_Button, col);
//ImGui::PushStyleColor(ImGuiCol_ButtonHovered, col);
if (ImGui::Button(std::format(">> {} <<", install).c_str(), ImVec2(Region.x, 45))) selected_option = 1;
if (ImGui::IsItemHovered()) ImGui::SetMouseCursor(ImGuiMouseCursor_Hand);
ImGui::PopStyleColor(2);
//ImGui::PopStyleColor(2);
}
else {
if (ImGui::Button(install, ImVec2(Region.x, 45))) selected_option = 1;
if (ImGui::IsItemHovered()) ImGui::SetMouseCursor(ImGuiMouseCursor_Hand);
}

ImGui::PushFont(ImGui::GetIO().Fonts->Fonts[1]);
ui::shift::x(10);
ImGui::BeginChild("BuildInfo", ImVec2(rx, ry), false);
{
static const auto path = Steam::getInstallPath();
ImGui::PushFont(ImGui::GetIO().Fonts->Fonts[1]);
{
static const auto path = Steam::getInstallPath();

ImGui::TextColored(ImVec4(1.0f, 1.0f, 1.0f, 0.4f),
std::format(" Steam Install: {}\n Installing Millennium Version: v{}",
path, millenniumInstallVersion
).c_str());
ImGui::TextColored(ImVec4(1.0f, 1.0f, 1.0f, 0.4f),
std::format("Steam Install: {}\nInstalling Millennium Version: v{}\n\nPatch Notes:\n{}",
path, millenniumInstallVersion, millenniumPatchNotes
).c_str());
}
ImGui::PopFont();
}
ImGui::PopFont();
ImGui::EndChild();
}
ImGui::PopStyleColor(2);

ImGui::EndChild();
if (selected_option == 2) {
ImGui::PushStyleColor(ImGuiCol_Button, col);
ImGui::PushStyleColor(ImGuiCol_ButtonHovered, col);
if (ImGui::Button(reset, ImVec2(Region.x, 45))) selected_option = 2;
//ImGui::PushStyleColor(ImGuiCol_Button, col);
//ImGui::PushStyleColor(ImGuiCol_ButtonHovered, col);
if (ImGui::Button(std::format(">> {} <<", reset).c_str(), ImVec2(Region.x, 45))) selected_option = 2;
if (ImGui::IsItemHovered()) ImGui::SetMouseCursor(ImGuiMouseCursor_Hand);
ImGui::PopStyleColor(2);
//ImGui::PopStyleColor(2);
}
else {
if (ImGui::Button(reset, ImVec2(Region.x, 45))) selected_option = 2;
if (ImGui::IsItemHovered()) ImGui::SetMouseCursor(ImGuiMouseCursor_Hand);
}
if (selected_option == 3)
{
ImGui::PushStyleColor(ImGuiCol_Button, col);
ImGui::PushStyleColor(ImGuiCol_ButtonHovered, col);
if (ImGui::Button(uninstall, ImVec2(Region.x, 45))) selected_option = 3;
//ImGui::PushStyleColor(ImGuiCol_Button, col);
//ImGui::PushStyleColor(ImGuiCol_ButtonHovered, col);
if (ImGui::Button(std::format(">> {} <<", uninstall).c_str(), ImVec2(Region.x, 45))) selected_option = 3;
if (ImGui::IsItemHovered()) ImGui::SetMouseCursor(ImGuiMouseCursor_Hand);
ImGui::PopStyleColor(2);
//ImGui::PopStyleColor(2);
}
else {
if (ImGui::Button(uninstall, ImVec2(Region.x, 45))) selected_option = 3;
Expand All @@ -165,12 +206,15 @@ class Handler
ImGui::EndChild();
ImGui::PopStyleColor();

ImGui::SetCursorPosX(ImGui::GetWindowWidth() - ImGui::GetStyle().ItemSpacing.x - ImGui::CalcTextSize("Continue >").x - 53); // Align cursor to the right
std::string buttonName = selected_option == 1 ? "Install >" : selected_option == 2 ? "Reset >" : selected_option == 3 ? "Uninstall >" : "";

ImGui::SetCursorPosX(ImGui::GetWindowWidth() - ImGui::GetStyle().ItemSpacing.x - (selected_option == 0 ? -13 :ImGui::CalcTextSize(buttonName.c_str()).x) - 53); // Align cursor to the right
ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2(5, 0));

if (ImGui::Button("< Back")) current_page = 1;
ImGui::SameLine(0);
if (ImGui::Button("Continue >"))

if (selected_option != 0 && ImGui::Button(buttonName.c_str()))
{
current_page = 3;

Expand Down Expand Up @@ -222,22 +266,20 @@ class Handler

ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2(5, 0));

if (ImGui::Button("Discord"))
{
if (ImGui::Button("Discord")) {
ShellExecuteA(nullptr, "open", "https://discord.gg/MXMWEQKgJF", nullptr, nullptr, SW_SHOWNORMAL);
}
ImGui::SameLine();
if (ImGui::Button("Github"))
{
if (ImGui::Button("Github")) {
ShellExecuteA(nullptr, "open", "https://github.com/ShadowMonster99/millennium-steam-patcher", nullptr, nullptr, SW_SHOWNORMAL);
}

ImGui::SameLine();
ImGui::SetCursorPosX(ImGui::GetWindowWidth() - ImGui::GetStyle().ItemSpacing.x - ImGui::CalcTextSize("Close").x - 60); // Align cursor to the right
ImGui::SetCursorPosX(ImGui::GetWindowWidth() - ImGui::GetStyle().ItemSpacing.x - ImGui::CalcTextSize("Close >").x - 60); // Align cursor to the right

if (ImGui::Button("< Back")) current_page = 2;
ImGui::SameLine();
if (ImGui::Button("Close"))
if (ImGui::Button("Close >"))
{
ShellExecuteA(nullptr, "open", "https://discord.gg/MXMWEQKgJF", nullptr, nullptr, SW_SHOWNORMAL);
exit(1);
Expand Down Expand Up @@ -349,7 +391,7 @@ class Handler
ImGui::PopFont();

listButton(" Terms of Service", 1);
listButton(" License Argeement", 2);
listButton(" License Agreement", 2);

ImGui::PushFont(ImGui::GetIO().Fonts->Fonts[1]);
{
Expand All @@ -358,6 +400,16 @@ class Handler
ImGui::PopFont();

listButton(" Install Millennium", 3);

ImGui::PushFont(ImGui::GetIO().Fonts->Fonts[1]);
{
std::string buildInfo = std::format("Build Date: {}", __DATE__);

ImGui::SetCursorPosY(ImGui::GetContentRegionMax().y - ImGui::CalcTextSize(buildInfo.c_str()).y);

ImGui::TextColored(ImVec4(0.5f, 0.5f, 0.5f, 1.0f), buildInfo.c_str());
}
ImGui::PopFont();
}
ImGui::EndChild();
}
Expand Down Expand Up @@ -416,7 +468,7 @@ class Handler
}
};

int APIENTRY WinMain(HINSTANCE, HINSTANCE, LPSTR, int)
int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE, LPSTR, int)
{
try {
//redirect std::cout events
Expand All @@ -426,20 +478,15 @@ int APIENTRY WinMain(HINSTANCE, HINSTANCE, LPSTR, int)
terms_and_conditions = http::get("https://raw.githubusercontent.com/ShadowMonster99/millennium-steam-patcher/main/.terms-of-service");
}
catch (const http_error& error) {
switch (error.code()) {
case http_error::errors::couldnt_connect: {
terms_and_conditions =
"Couldn't GET Millennium's TOS. Check the Github repository to see the TOS.\n"
"Do not proceed the installer if you haven't read the TOS";
break;
}
}
terms_and_conditions =
"Couldn't GET Millennium's TOS. Check if you have a valid internet connection or try again later. If problem persists, get help in our discord server.\n"
"Do not proceed with the installation if you haven't read the TOS";
}

Window::setTitle((char*)"Millennium Installer");
Window::setDimensions(ImVec2({ 450, 300 }));

Application::Create(&Handler::Render);
Application::Create(&Handler::Render, hInstance);
}
catch (std::exception& ex) {
MessageBoxA(0, ex.what(), "Millennium - ERROR", MB_ICONERROR);
Expand Down
Loading

0 comments on commit 26aa682

Please sign in to comment.