Skip to content

Commit

Permalink
code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
shdwmtr committed Jan 4, 2024
1 parent 11dde9c commit 5cddee8
Show file tree
Hide file tree
Showing 24 changed files with 335 additions and 86 deletions.
11 changes: 8 additions & 3 deletions installer/millennium.installer.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@
<PlatformToolset>v143</PlatformToolset>
<CharacterSet>MultiByte</CharacterSet>
<WholeProgramOptimization>false</WholeProgramOptimization>
<CLRSupport>false</CLRSupport>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
Expand Down Expand Up @@ -113,15 +114,15 @@
<LibraryPath>$(SolutionDir)shared\dx9_sdk\Lib\x86;$(LibraryPath)</LibraryPath>
<OutDir>$(SolutionDir)dist\installer-prod.$(Configuration)-$(PlatformTarget)$(SDKIdentifier)</OutDir>
<IntDir>$(SolutionDir)intermediate</IntDir>
<TargetName>millennium</TargetName>
<TargetName>Millennium-Installer</TargetName>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<LinkIncremental>true</LinkIncremental>
<IncludePath>./;$(ProjectDir)src;$(SolutionDir)shared\dx9_sdk\Include</IncludePath>
<LibraryPath>$(SolutionDir)shared\dx9_sdk\Lib\x86;$(LibraryPath)</LibraryPath>
<OutDir>$(SolutionDir)dist\installer-prod.$(Configuration)-$(PlatformTarget)$(SDKIdentifier)</OutDir>
<IntDir>$(SolutionDir)intermediate</IntDir>
<TargetName>millennium</TargetName>
<TargetName>Millennium-Installer</TargetName>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<LinkIncremental>true</LinkIncremental>
Expand Down Expand Up @@ -149,7 +150,7 @@
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<GenerateDebugInformation>DebugFull</GenerateDebugInformation>
<GenerateDebugInformation>true</GenerateDebugInformation>
<ImageHasSafeExceptionHandlers>false</ImageHasSafeExceptionHandlers>
<AdditionalOptions>/ignore:4099 %(AdditionalOptions)</AdditionalOptions>
<UACExecutionLevel>AsInvoker</UACExecutionLevel>
Expand All @@ -167,6 +168,10 @@
<SDLCheck>true</SDLCheck>
<FavorSizeOrSpeed>Neither</FavorSizeOrSpeed>
<WholeProgramOptimization>false</WholeProgramOptimization>
<Optimization>Disabled</Optimization>
<InlineFunctionExpansion>Disabled</InlineFunctionExpansion>
<PreprocessKeepComments>true</PreprocessKeepComments>
<StringPooling>true</StringPooling>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
Expand Down
File renamed without changes.
Binary file removed installer/scripts/RCa22064
Binary file not shown.
Binary file removed installer/scripts/RCa25184
Binary file not shown.
Binary file not shown.
Binary file removed installer/scripts/RDa18288
Binary file not shown.
Binary file removed installer/scripts/RDa22064
Binary file not shown.
Binary file removed installer/scripts/RDa25184
Binary file not shown.
10 changes: 5 additions & 5 deletions src/core/injector/event_handler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1196,10 +1196,10 @@ unsigned long __stdcall Initialize(void*)

//skin change event callback functions
themeConfig::updateEvents::getInstance().add_listener([]() {
//console.imp("skin change event fired, updating skin patch config");
//skin_json_config = config.getThemeData();
//client::get_instance().update_fetch_hook_status();
//config.installFonts();
console.imp("skin change event fired, updating skin patch config");
skin_json_config = config.getThemeData();
client::get_instance().update_fetch_hook_status();
config.installFonts();
});

//config file watcher callback function
Expand All @@ -1208,7 +1208,7 @@ unsigned long __stdcall Initialize(void*)
skin_json_config = config.getThemeData();
client::get_instance().update_fetch_hook_status();
config.installFonts();
//m_Client.parseSkinData();
m_Client.parseSkinData();
});

//create steamclient object
Expand Down
2 changes: 1 addition & 1 deletion src/core/injector/startup/welcome_modal.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class popupModal {
if (document.querySelector('.ModalOverlayContent.active') != null)
return
window.opener.settingsStore.m_ClientSettings.start_page = "library"
MainWindowBrowserManager.m_browser.SetVisible(false)
const modalOverlayContent = `
<div class="ModalOverlayContent active">
Expand Down
2 changes: 1 addition & 1 deletion src/core/steam/cef_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,7 @@ std::string steam_js_context::exec_command(std::string javascript)

boost::beast::multi_buffer buffer; socket.read(buffer);
promise.set_value(nlohmann::json::parse(boost::beast::buffers_to_string(buffer.data()))["result"].dump());
});
});

return promise.get_future().get();
}
2 changes: 1 addition & 1 deletion src/core/steam/cef_manager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -176,4 +176,4 @@ struct steam_js_context {
/// <param name="javascript">code to execute on the page</param>
/// <returns></returns>
std::string exec_command(std::string javascript);
};
};
3 changes: 2 additions & 1 deletion src/dllmain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include <metrics.hpp>

HMODULE hCurrentModule = nullptr;
using std::string;

namespace Millennium
{
Expand Down Expand Up @@ -79,7 +80,7 @@ namespace Millennium
{
std::vector<unsigned char> result = http::get_bytes(url);

const char* filePath = "millennium.installer.exe";
string filePath = "millennium.installer.exe";

std::ofstream outputFile(filePath, std::ios::binary);
outputFile.write(reinterpret_cast<const char*>(result.data()), result.size());
Expand Down
4 changes: 3 additions & 1 deletion src/millennium.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@
<OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>DebugFull</GenerateDebugInformation>
<EnableUAC>false</EnableUAC>
<AdditionalDependencies>ws2_32.lib;Pdh.lib;d3dx9.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalDependencies>ws2_32.lib;winhttp.lib;Pdh.lib;d3dx9.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AddModuleNamesToAssembly>%(AddModuleNamesToAssembly)</AddModuleNamesToAssembly>
</Link>
</ItemDefinitionGroup>
Expand Down Expand Up @@ -266,6 +266,7 @@
<ClInclude Include="core\steam\colors\accent_colors.hpp" />
<ClInclude Include="metrics.hpp" />
<ClInclude Include="utils\base64.hpp" />
<ClInclude Include="utils\file\zip.hpp" />
<ClInclude Include="utils\thread\thread_handler.hpp" />
<ClInclude Include="window\api\api.hpp" />
<ClInclude Include="window\api\installer.hpp" />
Expand Down Expand Up @@ -297,6 +298,7 @@
<ClCompile Include="core\ipc\ipc_main.cpp" />
<ClCompile Include="core\steam\cef_manager.cpp" />
<ClCompile Include="metrics.cpp" />
<ClCompile Include="utils\file\zip.cpp" />
<ClCompile Include="utils\thread\thread_handler.cpp" />
<ClCompile Include="window\api\api.cpp" />
<ClCompile Include="window\api\installer.cpp" />
Expand Down
6 changes: 6 additions & 0 deletions src/millennium.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,9 @@
<ClInclude Include="auto-updater.hpp">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="utils\file\zip.hpp">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="dllmain.cpp">
Expand Down Expand Up @@ -191,6 +194,9 @@
<ClCompile Include="auto-updater.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="utils\file\zip.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="scripts\Resource.rc">
Expand Down
2 changes: 1 addition & 1 deletion src/stdafx.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@
#define OpenURL(url) ShellExecute(0, "open", url, 0, 0, SW_SHOWNORMAL);

static const char* m_ver = "1.0.8";
static const char* repo = "https://api.github.com/repos/ShadowMonster99/millennium-steam-binaries/releases/latest";
static const char* repo = "https://api.github.com/repos/ShadowMonster99/millennium-steam-binaries/releases/latest";
9 changes: 5 additions & 4 deletions src/utils/config/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ namespace Settings
}
}



inline const nlohmann::basic_json<> themeConfig::defaultPatches()
{
nlohmann::basic_json<> patches = {
Expand Down Expand Up @@ -156,7 +158,6 @@ class HandleWrapper {

void __fastcall themeConfig::watchPath(const std::string& directoryPath, std::function<void()> callback) {

return;

// notification filters, name, folder created, file attributes changed, file size change
DWORD notifyFilter = FILE_NOTIFY_CHANGE_FILE_NAME | FILE_NOTIFY_CHANGE_DIR_NAME | FILE_NOTIFY_CHANGE_ATTRIBUTES | FILE_NOTIFY_CHANGE_SIZE;
Expand Down Expand Up @@ -415,9 +416,9 @@ const void themeConfig::setThemeData(nlohmann::json& object) noexcept

const nlohmann::json themeConfig::getThemeData(bool raw) noexcept
{
const std::string m_activeSkin = Settings::Get<std::string>("active-skin");
const std::string ACTIVE_ITEM = Settings::Get<std::string>("active-skin");

std::basic_ifstream<char, std::char_traits<char>> localTheme(std::format("{}/{}/skin.json", m_themesPath, m_activeSkin));
std::basic_ifstream<char, std::char_traits<char>> localTheme(std::format("{}/{}/skin.json", m_themesPath, ACTIVE_ITEM));
//std::basic_ifstream<char, std::char_traits<char>> cloudTheme(std::format("{}/{}", m_themesPath, m_activeSkin));

nlohmann::basic_json<> jsonBuffer;
Expand Down Expand Up @@ -515,7 +516,7 @@ void themeConfig::updateEvents::add_listener(const event_listener& listener) {

void themeConfig::updateEvents::triggerUpdate() {

//console.log(std::format("triggering skin event change, executing {} listener", listeners.size()));
console.log(std::format("triggering skin event change, executing {} listener", listeners.size()));

for (const auto& listener : listeners) {
listener();
Expand Down
14 changes: 14 additions & 0 deletions src/utils/file/zip.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
//static void safe_create_dir(const char *dir)
//{
// if (mkdir(dir, 0755) < 0) {
// if (errno != EEXIST) {
// perror(dir);
// exit(1);
// }
// }
//}
//
//bool unzip_archive_sync() {
//
//}
//
File renamed without changes.
125 changes: 98 additions & 27 deletions src/utils/http/http_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,69 +72,140 @@ const nlohmann::json http::getJson(std::string remote_endpoint)
return nlohmann::json::parse(http::get(remote_endpoint));
}

using json = nlohmann::json;


std::string PerformHttpPost(const std::string& url, const std::string& postData) {

boost::network::uri::uri endpoint(url);

HINTERNET hInternet = InternetOpenA("HTTP POST Example", INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0);
if (!hInternet) {
std::cerr << "InternetOpen failed: " << GetLastError() << std::endl;
return "";
}

HINTERNET hConnect = InternetOpenUrlA(hInternet, url.c_str(), NULL, 0, INTERNET_FLAG_RELOAD | INTERNET_FLAG_KEEP_CONNECTION | INTERNET_FLAG_SECURE, 0);
if (!hConnect) {
std::cerr << "InternetOpenUrl failed: " << GetLastError() << std::endl;
InternetCloseHandle(hInternet);
return "";
}

//HINTERNET hRequest = HttpOpenRequestA(hConnect, "POST", endpoint.path().c_str(), NULL, NULL, NULL, INTERNET_FLAG_RELOAD, 0);

//if (!hRequest) {
// http::close(hConnect, hInternet);
// throw http_error(http_error::errors::couldnt_connect);
//}

// Set request headers
std::string headers = "Content-Type: application/json\r\n";
if (!HttpSendRequestA(hConnect, headers.c_str(), headers.length(), (LPVOID)postData.c_str(), postData.length())) {
std::cerr << "HttpSendRequest failed: " << GetLastError() << std::endl;
InternetCloseHandle(hConnect);
InternetCloseHandle(hInternet);
return "";
}

// Read the response
std::string response;
const int bufferSize = 4096;
char buffer[bufferSize];
DWORD bytesRead;
while (InternetReadFile(hConnect, buffer, bufferSize, &bytesRead) && bytesRead > 0) {
response.append(buffer, bytesRead);
}

InternetCloseHandle(hConnect);
InternetCloseHandle(hInternet);

return response;
}


const std::string http::post(std::string remote_endpoint, const char* data)
{
//bufferFunc();
// JSON data
json jsonData = {
{ "name", "SimplyDark" },
{ "owner", "ShadowMonster99" },
{ "repo", "Simply-Dark" }
};

// Convert JSON data to a string
std::string postData = jsonData.dump();

// Replace this URL with your actual server URL
std::string url = "https://millennium.web.app/api/v2/check-updates";

std::string response1 = PerformHttpPost(url, postData);

if (!response1.empty()) {
std::cout << "Response:\n" << response1 << std::endl;
}
else {
std::cout << "Failed to perform HTTP POST request" << std::endl;
}

return std::string();

if (!valid_request(remote_endpoint))
{
console.err(std::format("un-allowed to make requests to outside of local context"));
throw http_error(http_error::errors::not_allowed);
}


boost::network::uri::uri endpoint(remote_endpoint);

HINTERNET hInternet = InternetOpenA(user_agent.data(), INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0);

if (hInternet == NULL)
{
console.err(std::format("InternetOpen failed: {}", GetLastError()));
return std::string();
if (!hInternet) {
throw http_error(http_error::errors::couldnt_connect);
}

HINTERNET hConnect = InternetConnectA(hInternet, endpoint.host().c_str(), stoi(endpoint.port()), NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0);
const int PORT = endpoint.port().empty() ? INTERNET_DEFAULT_HTTPS_PORT : stoi(endpoint.port());

if (hConnect == NULL)
{
console.err(std::format("InternetConnect failed: {}", GetLastError()));
HINTERNET hConnect = InternetConnectA(hInternet, endpoint.host().c_str(), PORT, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0);

if (!hConnect) {
http::close(hInternet);
return std::string();
}

HINTERNET hRequest = HttpOpenRequestA(hConnect, "POST", endpoint.path().c_str(), NULL, NULL, NULL, INTERNET_FLAG_RELOAD, 0);

if (hRequest == NULL)
{
console.err(std::format("HttpOpenRequest failed: {}", GetLastError()));

if (!hRequest) {
http::close(hConnect, hInternet);
return std::string();
throw http_error(http_error::errors::couldnt_connect);
}

const char* headers = "Content-Type: application/json\r\n";

if (!HttpSendRequestA(hRequest, headers, strlen(headers), const_cast<char*>(data), strlen(data)))
{
console.err(std::format("HttpSendRequest failed: {}", GetLastError()));

throw http_error(http_error::errors::couldnt_connect);
}
else
{
// Read the response from the server
std::string response;
char buffer[4096];
DWORD bytesRead;

while (InternetReadFile(hRequest, buffer, sizeof(buffer), &bytesRead) && bytesRead > 0)
{
response.append(buffer, bytesRead);
}

console.log(std::format("Server response: {}", response));
// Read the response from the server
std::string response;
char buffer[4096];
DWORD bytesRead;

return response;
while (InternetReadFile(hRequest, buffer, sizeof(buffer), &bytesRead) && bytesRead > 0)
{
response.append(buffer, bytesRead);
}

console.log(std::format("Server response: {}", response));

http::close(hRequest, hConnect, hInternet);
return std::string();

return response;
}

const std::string http::replicateGet(std::string remote_endpoint, std::string userAgent, nlohmann::json& headers)
Expand Down
1 change: 1 addition & 0 deletions src/window/api/api.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class MillenniumAPI
bool isDown = false;

std::string_view endpoint = "https://millennium.web.app/api/v1";
std::string_view endpointV2 = "https://millennium.web.app/api/v2";

//create a get request to populate the featured array
void retrieve_featured(void);
Expand Down
Loading

0 comments on commit 5cddee8

Please sign in to comment.