Added an version check
This commit is contained in:
parent
d4a4e50af5
commit
67c1dd8f99
5 changed files with 65 additions and 5 deletions
3
.gitignore
vendored
3
.gitignore
vendored
|
|
@ -10,4 +10,5 @@ sql_test.o
|
|||
gtk_test.o
|
||||
sys_info.o
|
||||
show_dir.o
|
||||
change_dir.o
|
||||
change_dir.o
|
||||
update_check.o
|
||||
5
main.c
5
main.c
|
|
@ -16,6 +16,7 @@
|
|||
#include "etc/logo.h"
|
||||
#include "utils/logger.h"
|
||||
#include "utils/sys_info.h"
|
||||
#include "utils/update_check.h"
|
||||
|
||||
|
||||
#define VERSION "0.2.0"
|
||||
|
|
@ -96,10 +97,10 @@ int main(int argc, char *argv[]){
|
|||
logger("================================================");
|
||||
snprintf(buffer, sizeof(buffer), "Starting netbenixCMD (Version: %s)", VERSION);
|
||||
logger(buffer);
|
||||
log_Specs();
|
||||
log_Specs(); //Log system specs
|
||||
showLogo(); //Show the Logo
|
||||
logger("Logo Displayed.");
|
||||
|
||||
checkForUpdate(VERSION); //Check for Update
|
||||
if(argc > 2){
|
||||
printf("Too many arguments. Please use --help for more information.\n");
|
||||
snprintf(buffer, sizeof(buffer), "[ERROR] Too many arguments. Argument count: %i", argc-1);
|
||||
|
|
|
|||
6
makefile
6
makefile
|
|
@ -2,7 +2,7 @@ CC= gcc
|
|||
ARGS= -export-dynamic -ansi -std=gnu99
|
||||
CFLAGS= $(shell pkg-config --cflags gtk+-3.0) -I/usr/include/mysql
|
||||
LDLIBS= $(shell pkg-config --libs gtk+-3.0) -L/usr/lib/mysql -lmysqlclient
|
||||
OBJ= main.o logo.o logger.o help.o sys_info.o gtk_test.o sql_test.o show_dir.o change_dir.o
|
||||
OBJ= main.o logo.o logger.o help.o sys_info.o gtk_test.o sql_test.o show_dir.o change_dir.o update_check.o
|
||||
|
||||
netbenixCMD: $(OBJ)
|
||||
$(CC) $(CFLAGS) $(ARGS) -o netbenixCMD $(OBJ) $(LDLIBS)
|
||||
|
|
@ -23,4 +23,6 @@ sql_test.o: utils/sql_test.c
|
|||
show_dir.o: commands/show_dir.c
|
||||
$(CC) $(CFLAGS) -c commands/show_dir.c
|
||||
change_dir.o: commands/change_dir.c
|
||||
$(CC) $(CFLAGS) -c commands/change_dir.c
|
||||
$(CC) $(CFLAGS) -c commands/change_dir.c
|
||||
update_check.o: utils/update_check.c
|
||||
$(CC) $(CFLAGS) -c utils/update_check.c
|
||||
|
|
|
|||
50
utils/update_check.c
Normal file
50
utils/update_check.c
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <sys/socket.h>
|
||||
#include <arpa/inet.h>
|
||||
#include "update_check.h"
|
||||
#include "logger.h"
|
||||
|
||||
int checkForUpdate(char ver[10]){
|
||||
int sock;
|
||||
struct sockaddr_in server;
|
||||
char server_reply[2000];
|
||||
|
||||
//Create Socket
|
||||
sock = socket(AF_INET, SOCK_STREAM, 0);
|
||||
if( sock == -1){
|
||||
printf("Error while creating socket.");
|
||||
logger("Error while creating socket");
|
||||
}
|
||||
|
||||
server.sin_addr.s_addr = inet_addr("127.0.0.1");
|
||||
server.sin_family = AF_INET;
|
||||
server.sin_port = htons( 34000 );
|
||||
|
||||
//Connect to Server
|
||||
if(connect(sock, (struct sockaddr *)&server, sizeof(server)) < 0){
|
||||
perror("Error. Connnection failed.");
|
||||
logger("[ERROR] Connection to update server failed.");
|
||||
return 1;
|
||||
}
|
||||
|
||||
if( send(sock, ver, strlen(ver), 0) < 0){
|
||||
puts("Error while communicating with server.");
|
||||
logger("[ERROR] Send to server failed.");
|
||||
}
|
||||
|
||||
if( recv(sock, server_reply, 2000, 0) < 0){
|
||||
puts("Error while communicating with server.");
|
||||
logger("[ERROR] Receive from server failed.");
|
||||
}
|
||||
if(!strcmp(server_reply, "VERSION_OUTDATED")){
|
||||
printf("\033[0;31mYour client is outdated. Please update your client.\033[0m\n");
|
||||
logger("[WARNING] Client is outdated.");
|
||||
}
|
||||
|
||||
if(!strcmp(server_reply, "VERSION_OK")){
|
||||
logger("[INFO] Client is up-to-date.");
|
||||
}
|
||||
close(sock);
|
||||
return 0;
|
||||
}
|
||||
6
utils/update_check.h
Normal file
6
utils/update_check.h
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
#ifndef _UPDATE_CHECK_H_
|
||||
#define _UPDATE_CHECK_H_
|
||||
|
||||
int checkForUpdate(char ver[10]);
|
||||
|
||||
#endif
|
||||
Reference in a new issue