Skip to content

Commit

Permalink
atualização dinamica para ultima versão
Browse files Browse the repository at this point in the history
  • Loading branch information
stdmedoth committed Jun 29, 2021
1 parent 1fe0245 commit 712ff90
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/Canones/cad_ceps/consultar.c
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ struct _cad_cep *get_cep_from_consulta(gchar *cep){
return NULL;

case CURLE_HTTP_RETURNED_ERROR:
popup(NULL, "Erro de retorno da SEFAZ!");
popup(NULL, "Erro de retorno do webservice!");
return NULL;

default:
Expand Down
2 changes: 2 additions & 0 deletions src/etc/defines.h
Original file line number Diff line number Diff line change
Expand Up @@ -290,5 +290,7 @@ enum ID_OPERACOES{
OUTRAS_OPERACOES
};

#define LAST_VERSION_INFO_URL "https://calistupedidos.000webhostapp.com/last_version.php"

#define NIVEL_TECNICO_THEME "Adwaita"
#endif
71 changes: 64 additions & 7 deletions src/etc/update_version.c
Original file line number Diff line number Diff line change
@@ -1,10 +1,65 @@
char *search_last_version(){

CURL *curl;
FILE *fp;
CURLcode res;
char url[] = LAST_VERSION_INFO_URL;
char errorbuf[ CURL_ERROR_SIZE ] = "";
char *last_version;

struct upload_status upload_ctx;
upload_ctx.lines_read = 0;
struct MemoryStruct body_chunk;
body_chunk.memory = malloc(1);
body_chunk.size = 0;

gpointer loading = carregando_wnd();
carregar_interface();

curl = curl_easy_init();
if (!curl) {
popup(NULL,"Não foi possível inicializar curl na busca de versão atualizada");
return NULL;
}
curl_easy_setopt(curl, CURLOPT_URL, url);
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1);
curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, errorbuf);
//curl_easy_setopt(curl, CURLOPT_FAILONERROR, 1);
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0);
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0);
curl_easy_setopt(curl, CURLOPT_USE_SSL, (long)CURLUSESSL_NONE);
curl_easy_setopt(curl, CURLOPT_CAINFO, MOZ_CERT);
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, WriteMemoryCallback);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &body_chunk);
curl_easy_setopt(curl, CURLOPT_TIMEOUT, 10L);
carregar_interface();
res = curl_easy_perform(curl);
if(res != CURLE_OK){
file_logger("Erro na atualização:");
file_logger(errorbuf);
gtk_widget_destroy(loading);
curl_easy_cleanup(curl);
popup(NULL,"Não foi possível buscar ultima versão");
return NULL;
}

if(body_chunk.memory){
last_version = strdup(body_chunk.memory);
}
gtk_widget_destroy(loading);
curl_easy_cleanup(curl);

return last_version;
}

int download_new_version(void) {

CURL *curl;
FILE *fp;
CURLcode res;
char *url = malloc(1000);
char errorbuf[ CURL_ERROR_SIZE ] = "";
char *next_name_version;

#ifdef WIN32
int bins_qnt = 2;
Expand All @@ -18,12 +73,14 @@ int download_new_version(void) {
char *outfilenames[] = {"PedidosNew.o"};
#endif


char *next_name_version = get_text_from_input("Insira o nome da versão a ser baixada:", NULL);
next_name_version = search_last_version();
if(!next_name_version){
popup(NULL,"Nome da versão não inserida");
return 1;
}
next_name_version = get_text_from_input("Insira o nome da versão a ser baixada:", NULL);
if(!next_name_version){
popup(NULL,"Nome da versão não inserida");
return 1;
}
}

gpointer loading = carregando_wnd();
carregar_interface();
Expand All @@ -46,13 +103,13 @@ int download_new_version(void) {
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, NULL);
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1);
curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, errorbuf);
curl_easy_setopt(curl, CURLOPT_FAILONERROR, 1);
//curl_easy_setopt(curl, CURLOPT_FAILONERROR, 1);
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0);
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, fp);
carregar_interface();
res = curl_easy_perform(curl);
if(res == CURLE_HTTP_RETURNED_ERROR) {
if(res != CURLE_OK){
file_logger("Erro na atualização:");
file_logger(errorbuf);
gtk_widget_destroy(loading);
Expand Down
2 changes: 2 additions & 0 deletions src/etc/update_version.h
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
int download_new_version(void) ;

char *search_last_version();

0 comments on commit 712ff90

Please sign in to comment.