Begin porting common functions to common file
For easier readability and expandability
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
globalize_all_functions
|
||||
|
||||
|
||||
void function pulsePrintt (string content)
|
||||
{
|
||||
printt(format("%s " + content, pulsePrefix))
|
||||
}
|
||||
|
||||
table function pulseGetCurrentVersionAsTable
|
||||
{
|
||||
table result = ["MajorVersion" = GetConVarString("MajorVersion"), "MinorVersion" = GetConVarString("MinorVersion"), "PatchVersion" = GetConVarString("PatchVersion")]
|
||||
return result
|
||||
}
|
||||
|
||||
string function pulseFormatAsVersion(table Version)
|
||||
{
|
||||
return format("v%s.%s.%s", Version["MajorVersion"], Version["MinorVersion"], Version["PatchVersion"])
|
||||
}
|
||||
|
||||
bool function pulseIsUpToDate(string givenURL)
|
||||
{
|
||||
bool result = false
|
||||
HttpRequest versionreq
|
||||
versionreq.method = HttpRequestMethod.GET
|
||||
versionreq.url = givenURL
|
||||
void functionref (HttpRequestResponse) onSuccess = void function(HttpRequestResponse response)
|
||||
{
|
||||
table DecodedJSON = DecodeJSON(response.body)
|
||||
if (pulseFormatAsVersion(DecodedJSON) == pulseFormatAsVersion(pulseGetCurrentVersionAsTable()))
|
||||
{
|
||||
result = true
|
||||
} else {
|
||||
result = false
|
||||
}
|
||||
}
|
||||
void functionref (HttpRequestFailure) onFailure = void function(HttpRequestFailure failure)
|
||||
{
|
||||
pulsePrintt("Something went wrong while getting latest version.")
|
||||
}
|
||||
NSHttpRequest(versionreq, onSuccess, onFailure)
|
||||
return result
|
||||
}
|
||||
Reference in New Issue
Block a user