Implement real update check and sync version v1.9.1
This commit is contained in:
parent
ba136f5784
commit
a96e983ef8
Binary file not shown.
|
|
@ -0,0 +1 @@
|
||||||
|
v1.9.1
|
||||||
Binary file not shown.
|
|
@ -0,0 +1 @@
|
||||||
|
v1.9.1
|
||||||
43
src/main.cpp
43
src/main.cpp
|
|
@ -94,6 +94,7 @@ void GenerateChunk(int cx, int cz);
|
||||||
void SetBlock(int x, int y, int z, int type);
|
void SetBlock(int x, int y, int z, int type);
|
||||||
void SaveConfig();
|
void SaveConfig();
|
||||||
void LoadConfig();
|
void LoadConfig();
|
||||||
|
std::string GetRemoteVersion();
|
||||||
|
|
||||||
// ---- Inventory System ----
|
// ---- Inventory System ----
|
||||||
struct InventorySlot {
|
struct InventorySlot {
|
||||||
|
|
@ -241,6 +242,23 @@ void SetBlock(int x, int y, int z, int type) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string GetRemoteVersion() {
|
||||||
|
std::string url = "https://git.linology.tech/michael/MorriCraft/raw/branch/master/version.txt";
|
||||||
|
char buffer[128];
|
||||||
|
std::string result = "";
|
||||||
|
std::string cmd = "curl -s -m 5 " + url; // 5 second timeout
|
||||||
|
FILE* pipe = popen(cmd.c_str(), "r");
|
||||||
|
if (!pipe) return "error";
|
||||||
|
while (fgets(buffer, sizeof(buffer), pipe) != NULL) {
|
||||||
|
result += buffer;
|
||||||
|
}
|
||||||
|
pclose(pipe);
|
||||||
|
// Trim result
|
||||||
|
size_t last = result.find_last_not_of(" \n\r\t");
|
||||||
|
if (last != std::string::npos) result = result.substr(0, last + 1);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
void SaveConfig() {
|
void SaveConfig() {
|
||||||
std::ofstream file("config.cfg");
|
std::ofstream file("config.cfg");
|
||||||
if (file.is_open()) {
|
if (file.is_open()) {
|
||||||
|
|
@ -724,7 +742,15 @@ int main(void)
|
||||||
bool updateReady = false;
|
bool updateReady = false;
|
||||||
float updateTimer = 0.0f;
|
float updateTimer = 0.0f;
|
||||||
float downloadProgress = 0.0f;
|
float downloadProgress = 0.0f;
|
||||||
std::string updateNotes = "";
|
std::string latestVersion = "";
|
||||||
|
std::string localVersion = "v1.9.0"; // Default fallback
|
||||||
|
|
||||||
|
// Read local version
|
||||||
|
std::ifstream vfile("assets/version.txt");
|
||||||
|
if (vfile.is_open()) {
|
||||||
|
std::getline(vfile, localVersion);
|
||||||
|
vfile.close();
|
||||||
|
}
|
||||||
|
|
||||||
InventorySlot mouseHeldItem(AIR, 0);
|
InventorySlot mouseHeldItem(AIR, 0);
|
||||||
float gameTime = 75.0f; // Start at 6:00 AM
|
float gameTime = 75.0f; // Start at 6:00 AM
|
||||||
|
|
@ -1200,11 +1226,15 @@ int main(void)
|
||||||
DrawRectangle(0, 0, currentWidth, currentHeight, (Color){ 20, 20, 20, 255 });
|
DrawRectangle(0, 0, currentWidth, currentHeight, (Color){ 20, 20, 20, 255 });
|
||||||
DrawTextEx(customFont, "CHECKING FOR UPDATES...", (Vector2){ (float)currentWidth/2 - 150, (float)currentHeight/2 - 20 }, 24, 1.0f, WHITE);
|
DrawTextEx(customFont, "CHECKING FOR UPDATES...", (Vector2){ (float)currentWidth/2 - 150, (float)currentHeight/2 - 20 }, 24, 1.0f, WHITE);
|
||||||
|
|
||||||
// Simulate check (2 seconds)
|
// Perform real check after 1 second
|
||||||
|
if (updateTimer > 1.0f && latestVersion == "") {
|
||||||
|
latestVersion = GetRemoteVersion();
|
||||||
|
if (latestVersion != "error" && latestVersion != localVersion) {
|
||||||
|
updateReady = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (updateTimer > 2.0f) {
|
if (updateTimer > 2.0f) {
|
||||||
// Update check logic: Only show if remote version > local version
|
|
||||||
// For now, we are at v1.9.1, so we set to false.
|
|
||||||
updateReady = false;
|
|
||||||
if (updateReady) currentState = UPDATE_FOUND;
|
if (updateReady) currentState = UPDATE_FOUND;
|
||||||
else currentState = MAIN_MENU;
|
else currentState = MAIN_MENU;
|
||||||
}
|
}
|
||||||
|
|
@ -1216,7 +1246,8 @@ int main(void)
|
||||||
DrawRectangleLinesEx(pBox, 4.0f, GREEN);
|
DrawRectangleLinesEx(pBox, 4.0f, GREEN);
|
||||||
|
|
||||||
DrawTextEx(customFont, "NEW VERSION AVAILABLE!", (Vector2){ pBox.x + 40, pBox.y + 30 }, 24, 1.0f, GREEN);
|
DrawTextEx(customFont, "NEW VERSION AVAILABLE!", (Vector2){ pBox.x + 40, pBox.y + 30 }, 24, 1.0f, GREEN);
|
||||||
DrawTextEx(customFont, "v1.9.1 is now ready for download.", (Vector2){ pBox.x + 40, pBox.y + 70 }, 18, 1.0f, LIGHTGRAY);
|
std::string updMsg = latestVersion + " is now ready for download.";
|
||||||
|
DrawTextEx(customFont, updMsg.c_str(), (Vector2){ pBox.x + 40, pBox.y + 70 }, 18, 1.0f, LIGHTGRAY);
|
||||||
|
|
||||||
// Update Button
|
// Update Button
|
||||||
Rectangle updBtn = { pBox.x + 40, pBox.y + 120, 370, 40 };
|
Rectangle updBtn = { pBox.x + 40, pBox.y + 120, 370, 40 };
|
||||||
|
|
|
||||||
|
|
@ -1 +1 @@
|
||||||
v1.9.0
|
v1.9.1
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue