Fixed brain issue with the auto updater
This commit is contained in:
@@ -20,12 +20,13 @@ namespace updater {
|
||||
|
||||
auto currentTime = std::chrono::system_clock::now();
|
||||
|
||||
std::chrono::system_clock::time_point commitTimePoint = std::chrono::system_clock::from_time_t(std::mktime(&commit_date));
|
||||
|
||||
if (file_good("offsets.json")) {
|
||||
fs::file_time_type lastModifiedTime = fs::last_write_time("offsets.json");
|
||||
auto lastModifiedClockTime = std::chrono::time_point_cast<std::chrono::system_clock::duration>(
|
||||
lastModifiedTime - fs::file_time_type::clock::now() + std::chrono::system_clock::now());
|
||||
|
||||
std::chrono::system_clock::time_point commitTimePoint = std::chrono::system_clock::from_time_t(std::mktime(&commit_date));
|
||||
|
||||
// Check if the local file is older than the last GitHub commit
|
||||
if (lastModifiedClockTime < commitTimePoint) {
|
||||
std::cout << "[updater] Local file is older than the last GitHub commit." << std::endl;
|
||||
@@ -47,10 +48,29 @@ namespace updater {
|
||||
else {
|
||||
std::cout << "[updater] Local file is up to date.\n" << std::endl;
|
||||
}
|
||||
}
|
||||
else {
|
||||
std::cout << "[updater] Do you want to download the latest offsets? (y/n): ";
|
||||
char response;
|
||||
std::cin >> response;
|
||||
if (response == 'Y' || response == 'y') {
|
||||
if (download_file(raw_updated_offets.c_str(), "offsets.json")) {
|
||||
std::cout << "[updater] Successfully downloaded latest offsets.json file\n" << std::endl;
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
std::cout << "[updater] Error: Failed to download file, try downloading manually from " << raw_updated_offets << "\n" << std::endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool file_good(const std::string& name) {
|
||||
std::ifstream f(name.c_str());
|
||||
return f.good();
|
||||
}
|
||||
|
||||
bool get_last_commit_date(json& commit) {
|
||||
HINTERNET hInternet, hConnect;
|
||||
|
||||
@@ -19,6 +19,7 @@ namespace updater {
|
||||
bool check_and_update(bool prompt_update);
|
||||
bool get_last_commit_date(json& commit);
|
||||
bool download_file(const char* url, const char* localPath);
|
||||
bool file_good(const std::string& name);
|
||||
|
||||
inline std::string github_repo_api = "https://api.github.com/repos/IMXNOOBX/cs2-external-esp/commits";
|
||||
inline std::string raw_updated_offets = "https://github.com/IMXNOOBX/cs2-external-esp/raw/main/offsets/offsets.json";
|
||||
|
||||
@@ -4,13 +4,8 @@ namespace config {
|
||||
using json = nlohmann::json;
|
||||
const std::string file_path = "offsets.json";
|
||||
|
||||
bool file_exsits(const std::string& name) {
|
||||
std::ifstream f(name.c_str());
|
||||
return f.good();
|
||||
}
|
||||
|
||||
bool read() {
|
||||
if (!file_exsits(file_path)) {
|
||||
if (!updater::file_good(file_path)) {
|
||||
save();
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#pragma once
|
||||
#include <fstream>
|
||||
#include "json.hpp"
|
||||
#include "auto_updater.hpp"
|
||||
|
||||
namespace config {
|
||||
extern bool read();
|
||||
|
||||
Reference in New Issue
Block a user