File: lastversion.cpp

package info (click to toggle)
gogglesmm 1.2.5-6
  • links: PTS
  • area: main
  • in suites: forky, sid
  • size: 16,812 kB
  • sloc: cpp: 231,960; ansic: 893; xml: 222; makefile: 33
file content (46 lines) | stat: -rw-r--r-- 1,330 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#include <fx.h>

typedef FXArray<FXString> FXStringList;
#include <FXTextCodec.h>
#include <ap.h>


FXbool gm_parse_iso8601(const FXString & str, FXTime & timestamp) {
  /// 1 second expresed in nanoseconds
  const FXlong seconds = 1000000000;
  FXint year,month,day,hour,minute,second;
  if (str.scan("%d-%d-%dT%d:%d:%dZ",&year,&month,&day,&hour,&minute,&second)==6) {
    timestamp  = FXDate(year,month,day).getTime();
    timestamp += seconds * ((hour*3600)+(minute*60)+(second));
    return true;
    }
  return false;
  }


void check_lastversion() {
  FXString version;
  FXTime date;

  HttpClient client;
  client.setAcceptEncoding(HttpClient::AcceptEncodingGZip);
  if (client.basic("GET","https://api.github.com/repos/gogglesmm/gogglesmm/releases/latest","User-Agent: gogglesmm/1.1\r\n")) {
    FXString data = client.textBody();
    FXVariant info;
    FXJSON json(data.text(),data.length());
    if (json.load(info)==FXJSON::ErrOK) {
      version = info["tag_name"];
      if (!gm_parse_iso8601(info["published_at"],date))
        return;
      fxmessage("gogglesmm version: %s\ndate: %s\n%s\n",version.text(),info["published_at"].asChars(),FXSystem::localTime(date).text());
      }
    }
  }


int main(int /*argc*/,char ** /*argv*/) {
  ap_init_crypto();
  check_lastversion();
  ap_free_crypto();
  return 1;
  }