Skip to content

Commit a88c387

Browse files
committed
[0.2.3] Added Toolkit Updater
1 parent 2423880 commit a88c387

File tree

6 files changed

+80
-2
lines changed

6 files changed

+80
-2
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,7 @@ paket-files/
258258
*.exe
259259
!premake5-windows.exe
260260
!geo.exe
261+
*.exe.old
261262

262263
# RenderDoc Captures
263264
*.rdc

Geometria/Files/Files.cpp

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,18 @@ std::vector<std::string> Files::ReadAndGetLines(const char* url)
6868

6969
std::string Files::Write(const char* url, std::string content)
7070
{
71-
std::ofstream file(url);
71+
return Files::Write(url, content, false);
72+
}
73+
74+
std::string Files::Write(const char* url, std::string content, bool isBinary)
75+
{
76+
std::ofstream file;
77+
78+
if(isBinary)
79+
file = std::ofstream(url, std::ios::binary);
80+
else
81+
file = std::ofstream(url);
82+
7283
file << content;
7384
file.close();
7485

@@ -91,6 +102,11 @@ std::string Files::Replace(const char* oldFile, const char* newFile, bool isBina
91102
return Files::Write(oldFile, newFileContent);
92103
}
93104

105+
bool Files::Rename(const char* oldFile, const char* newFile)
106+
{
107+
return std::rename(oldFile, newFile) == 0;
108+
}
109+
94110
std::string Files::OpenImage(const char* url, int& width, int& height)
95111
{
96112
std::vector<unsigned char> png;

Geometria/Files/Files.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,11 @@ struct Files
2323
static std::string Read(const char* url, bool isBinary);
2424
static std::vector<std::string> ReadAndGetLines(const char* url);
2525
static std::string Write(const char* url, std::string content);
26+
static std::string Write(const char* url, std::string content, bool isBinary);
2627
static std::string Replace(const char* oldFile, const char* newFile, bool isBinary);
2728
static std::string Replace(const char* oldFile, const char* newFile);
29+
static bool Rename(const char* oldFile, const char* newFile);
30+
2831
static std::string OpenImage(const char* url, int& width, int& height);
2932

3033
static std::vector<std::string> OpenTexturePack(const char* gtxp);
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#ifndef TOOLKIT_UPDATER_H
2+
#define TOOLKIT_UPDATER_H
3+
4+
struct ToolkitUpdater
5+
{
6+
static void DownloadLatestToolkit()
7+
{
8+
std::cout << "Downloading Latest Toolkit..." << std::endl;
9+
10+
if(Application::IsPlatform(Application::Platform::Windows))
11+
InstallNewToolkit(DWLT_Windows());
12+
}
13+
14+
static std::string DWLT_Windows()
15+
{
16+
std::string downloadCnt = Web::Get("https://github.com/Geometria-Engine/Geometria/raw/main/geo.exe", true);
17+
std::cout << "Download has completed successfully!" << std::endl;
18+
return downloadCnt;
19+
}
20+
21+
static void InstallNewToolkit(std::string content)
22+
{
23+
std::string exePath = Files::GetExecutablePath();
24+
std::string oldExePath = exePath + ".old";
25+
26+
if(Files::Rename(exePath.c_str(), oldExePath.c_str()))
27+
{
28+
Files::Write(exePath.c_str(), content, true);
29+
30+
std::cout << "Update completed sucessfully!" << std::endl;
31+
exit(0);
32+
}
33+
else
34+
{
35+
std::cout << "ERROR: Executable can't be renamed! Cancelling..." << std::endl;
36+
exit(0);
37+
}
38+
}
39+
40+
};
41+
42+
#endif

Geometria/main.cpp

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include "Game/Scripts/HubManager.h"
88
#include "Game/Scripts/DynamicLinker.h"
99
#include "Game/Scripts/EngineUpdater.h"
10+
#include "Game/Scripts/ToolkitUpdater.h"
1011

1112
DONT_UPDATE_FILE()
1213

@@ -44,6 +45,12 @@ void Main_Compile()
4445

4546
int main(int argc, char** argv)
4647
{
48+
if(argc != 0)
49+
{
50+
if(std::experimental::filesystem::exists("geo.exe.old"))
51+
Files::Remove("geo.exe.old");
52+
}
53+
4754
for (int i = 0; i < argc; i++)
4855
{
4956
std::string commandLine = argv[i];
@@ -91,6 +98,11 @@ int main(int argc, char** argv)
9198

9299
exit(0);
93100
}
101+
else if(commandLine == "--update-toolkit")
102+
{
103+
ToolkitUpdater::DownloadLatestToolkit();
104+
exit(0);
105+
}
94106
else if(commandLine == "--create")
95107
{
96108
HubManager::isFromCommandLine = true;
@@ -131,9 +143,13 @@ int main(int argc, char** argv)
131143
std::cout << Files::GetExecutablePath() << std::endl;
132144
exit(0);
133145
}
146+
else if(commandLine == "--version")
147+
{
148+
std::cout << "0.2.3" << std::endl;
149+
}
134150
else if(commandLine == "--macro-test")
135151
{
136-
EngineUpdater::ReturnBackupFiles();
152+
//ToolkitUpdater::InstallNewToolkit("hello :D");
137153
exit(0);
138154
}
139155
}

geo.exe

1.5 KB
Binary file not shown.

0 commit comments

Comments
 (0)