Skip to content

Commit f2b4e3d

Browse files
committed
Add update checker, increment version
1 parent 5c1dac6 commit f2b4e3d

File tree

7 files changed

+456
-5
lines changed

7 files changed

+456
-5
lines changed

PyLoader/PyLoader.cpp

Lines changed: 47 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#include "ScriptData.hpp"
22
#include "PyLoader.h"
33
#include <frameobject.h>
4+
#include <Urlmon.h>
5+
#include "depend/jute.h"
46
#include "sdk/PyCHud.h"
57
#include "sdk/PyCommon.h"
68
#include "sdk/PyOpcodes.h"
@@ -46,15 +48,58 @@ void PyLoader::LoadPlugins(std::string&& dir_name)
4648
FindClose(dir);
4749
}
4850

51+
void PyLoader::CheckUpdate()
52+
{
53+
const char* link = "https://api.github.com/repos/user-grinch/PyLoaderSA/tags";
54+
char* path = PLUGIN_PATH((char*)"versioninfo.json");
55+
HRESULT res = URLDownloadToFile(NULL, link, path, 0, NULL);
56+
57+
if (res == E_OUTOFMEMORY || res == INET_E_DOWNLOAD_FAILURE)
58+
{
59+
flog << "Failed checking for updates." << std::endl;
60+
return;
61+
}
62+
63+
FILE* fp = fopen(path, "r");
64+
fseek(fp, 0, SEEK_END);
65+
size_t len = ftell(fp);
66+
fseek(fp, 0, SEEK_SET);
67+
char* buf = (char*)malloc(len + 1);
68+
69+
if (buf != NULL)
70+
{
71+
fread(buf, 1, len, fp);
72+
buf[len] = '\0';
73+
fclose(fp);
74+
jute::jValue v = jute::parser::parse(buf);
75+
76+
std::string ver = v[0]["name"].as_string();
77+
if (ver > plugin_ver)
78+
flog << "New version available. Download: https:///github.com/user-grinch/PyLoaderSA/releases/tag/"
79+
<< ver << std::endl;
80+
else
81+
flog << "No updates found" << std::endl;
82+
}
83+
else
84+
flog << "Failed to download update info" << std::endl;
85+
86+
delete buf;
87+
std::remove(path);
88+
}
89+
4990
void PyLoader::PluginThread(void* param)
5091
{
5192
plugin::Events::processScriptsEvent += []
5293
{
5394
game_ticks++;
5495
};
5596

56-
flog << "------------------------------\nStarting PyLoader v" << plugin_ver
57-
<< "\nAuthor: Grinch_\n------------------------------"<< std::endl;
97+
flog << "------------------------------\nStarting PyLoader v" << plugin_ver
98+
<< "\nAuthor: Grinch_\nMore info: https:///github.com/user-grinch/PyLoaderSA/" << std::endl;
99+
100+
CheckUpdate();
101+
102+
flog << "------------------------------"<< std::endl;
58103

59104
HANDLE dir;
60105
WIN32_FIND_DATA file_data;

PyLoader/PyLoader.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ class PyLoader
77
PyLoader() = delete;
88
PyLoader(PyLoader&) = delete;
99

10+
static void CheckUpdate();
1011
static int ExecuteScript(std::string *file_name);
1112
static void LoadPlugins(std::string&& dir_name);
1213
static void PluginThread(void* param);

PyLoader/PyLoader.vcxproj

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@
7171
<GenerateDebugInformation>No</GenerateDebugInformation>
7272
<LinkTimeCodeGeneration>UseLinkTimeCodeGeneration</LinkTimeCodeGeneration>
7373
<AdditionalLibraryDirectories>$(PLUGIN_SDK_DIR)\output\lib\;C:\Program Files (x86)\Python38-32\libs;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
74-
<AdditionalDependencies>plugin.lib;%(AdditionalDependencies)</AdditionalDependencies>
74+
<AdditionalDependencies>plugin.lib;Urlmon.lib;%(AdditionalDependencies)</AdditionalDependencies>
7575
<SubSystem>Windows</SubSystem>
7676
</Link>
7777
</ItemDefinitionGroup>
@@ -89,11 +89,12 @@
8989
<GenerateDebugInformation>Debug</GenerateDebugInformation>
9090
<LinkTimeCodeGeneration>Default</LinkTimeCodeGeneration>
9191
<AdditionalLibraryDirectories>C:\Program Files (x86)\Python38-32\libs;$(PLUGIN_SDK_DIR)\output\lib\;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
92-
<AdditionalDependencies>plugin_d.lib;%(AdditionalDependencies)</AdditionalDependencies>
92+
<AdditionalDependencies>plugin_d.lib;Urlmon.lib;%(AdditionalDependencies)</AdditionalDependencies>
9393
<SubSystem>Windows</SubSystem>
9494
</Link>
9595
</ItemDefinitionGroup>
9696
<ItemGroup>
97+
<ClCompile Include="depend\jute.cpp" />
9798
<ClCompile Include="DllMain.cpp" />
9899
<ClCompile Include="PyEvents.cpp" />
99100
<ClCompile Include="sdk\PyInternal.cpp" />
@@ -106,6 +107,7 @@
106107
<ClCompile Include="sdk\PyOpcodes.cpp" />
107108
</ItemGroup>
108109
<ItemGroup>
110+
<ClInclude Include="depend\jute.h" />
109111
<ClInclude Include="PyEvents.h" />
110112
<ClInclude Include="sdk\PyInternal.h" />
111113
<ClInclude Include="pch.h" />

PyLoader/PyLoader.vcxproj.filters

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
<ClCompile Include="sdk\PyCLEO.cpp" />
1212
<ClCompile Include="sdk\PyInternal.cpp" />
1313
<ClCompile Include="PyEvents.cpp" />
14+
<ClCompile Include="depend\jute.cpp" />
1415
</ItemGroup>
1516
<ItemGroup>
1617
<ClInclude Include="pch.h" />
@@ -24,5 +25,6 @@
2425
<ClInclude Include="sdk\PyCLEO.h" />
2526
<ClInclude Include="sdk\PyInternal.h" />
2627
<ClInclude Include="PyEvents.h" />
28+
<ClInclude Include="depend\jute.h" />
2729
</ItemGroup>
2830
</Project>

0 commit comments

Comments
 (0)