fully implemented new WHY2_CONFIG_DIR
i moved it to user folder cause it causes permission problems on multi-user machine.
This commit is contained in:
parent
8ef39ada5f
commit
3fc339a9fb
@ -26,7 +26,6 @@ extern "C" {
|
|||||||
#include <why2/flags.h> //damn i really hate including headers in headers
|
#include <why2/flags.h> //damn i really hate including headers in headers
|
||||||
|
|
||||||
//CONFIG MACROS
|
//CONFIG MACROS
|
||||||
#define WHY2_CHAT_CONFIG_DIR WHY2_CONFIG_DIR "/WHY2"
|
|
||||||
#define WHY2_CHAT_CONFIG_URL "https://raw.githubusercontent.com/ENGO150/WHY2/development/src/chat/config/"
|
#define WHY2_CHAT_CONFIG_URL "https://raw.githubusercontent.com/ENGO150/WHY2/development/src/chat/config/"
|
||||||
#define WHY2_CHAT_CONFIG_SERVER "server.toml"
|
#define WHY2_CHAT_CONFIG_SERVER "server.toml"
|
||||||
#define WHY2_CHAT_CONFIG_CLIENT "client.toml"
|
#define WHY2_CHAT_CONFIG_CLIENT "client.toml"
|
||||||
|
@ -30,7 +30,7 @@ extern "C" {
|
|||||||
#define WHY2_CHAT_PRIME_ITERS 100 //NUMBER OF ITERATIONS WHEN CHECKING PRIME NUMBER
|
#define WHY2_CHAT_PRIME_ITERS 100 //NUMBER OF ITERATIONS WHEN CHECKING PRIME NUMBER
|
||||||
#define WHY2_CHAT_RSA_EXPONENT "H33" //DEFAULT e IN BASE WHY2_CHAT_KEY_BASE
|
#define WHY2_CHAT_RSA_EXPONENT "H33" //DEFAULT e IN BASE WHY2_CHAT_KEY_BASE
|
||||||
|
|
||||||
#define WHY2_CHAT_KEY_LOCATION WHY2_CHAT_CONFIG_DIR "/keys" //KEYS LOCATION
|
#define WHY2_CHAT_KEY_LOCATION WHY2_CONFIG_DIR "/keys" //KEYS LOCATION
|
||||||
#define WHY2_CHAT_PUB_KEY "pub"
|
#define WHY2_CHAT_PUB_KEY "pub"
|
||||||
#define WHY2_CHAT_PRI_KEY "pri"
|
#define WHY2_CHAT_PRI_KEY "pri"
|
||||||
#define WHY2_CHAT_KEY_BASE 62 //BASE IN THE GENERATED KEYS ARE STORED IN WHY2_CHAT_KEY_LOCATION
|
#define WHY2_CHAT_KEY_BASE 62 //BASE IN THE GENERATED KEYS ARE STORED IN WHY2_CHAT_KEY_LOCATION
|
||||||
|
@ -50,7 +50,7 @@ enum WHY2_OUTPUT_FORMAT
|
|||||||
|
|
||||||
#define WHY2_VERSION "v5.0" //WHY2_VERSION OF CURRENT BUILD > DO NOT TOUCH THIS <
|
#define WHY2_VERSION "v5.0" //WHY2_VERSION OF CURRENT BUILD > DO NOT TOUCH THIS <
|
||||||
#define WHY2_VERSIONS_URL "https://raw.githubusercontent.com/ENGO150/WHY2/release/versions.json" //URL FOR GETTING versions.json
|
#define WHY2_VERSIONS_URL "https://raw.githubusercontent.com/ENGO150/WHY2/release/versions.json" //URL FOR GETTING versions.json
|
||||||
#define WHY2_CONFIG_DIR "/home/{USER}/.config"
|
#define WHY2_CONFIG_DIR "/home/{USER}/.config/WHY2"
|
||||||
#define WHY2_VERSIONS_NAME WHY2_CONFIG_DIR "/.versions.json" //do I have to explain this?
|
#define WHY2_VERSIONS_NAME WHY2_CONFIG_DIR "/.versions.json" //do I have to explain this?
|
||||||
|
|
||||||
#define WHY2_UPDATE_URL "https://github.com/ENGO150/WHY2.git" // REPOSITORY URL FOR UPDATES (YOU DON'T SAY)
|
#define WHY2_UPDATE_URL "https://github.com/ENGO150/WHY2.git" // REPOSITORY URL FOR UPDATES (YOU DON'T SAY)
|
||||||
|
@ -43,14 +43,14 @@ void init_config(char *filename)
|
|||||||
why2_directory();
|
why2_directory();
|
||||||
|
|
||||||
//GET THE CONFIG TYPE
|
//GET THE CONFIG TYPE
|
||||||
char *buffer = why2_malloc(strlen(WHY2_CHAT_CONFIG_DIR) + strlen(filename) + 2);
|
char *buffer = why2_malloc(strlen(WHY2_CONFIG_DIR) + strlen(filename) + 2);
|
||||||
sprintf(buffer, "%s/%s", WHY2_CHAT_CONFIG_DIR, filename);
|
sprintf(buffer, "%s/%s", WHY2_CONFIG_DIR, filename);
|
||||||
|
|
||||||
char *path = why2_replace(buffer, "{USER}", getenv("USER"));
|
char *path = why2_replace(buffer, "{USER}", getenv("USER"));
|
||||||
|
|
||||||
if (access(path, R_OK) != 0) //CONFIG DOESN'T EXIST
|
if (access(path, R_OK) != 0) //CONFIG DOESN'T EXIST
|
||||||
{
|
{
|
||||||
char *config_dir = why2_replace(WHY2_CHAT_CONFIG_DIR, "{USER}", getenv("USER"));
|
char *config_dir = why2_replace(WHY2_CONFIG_DIR, "{USER}", getenv("USER"));
|
||||||
|
|
||||||
//CREATE CONFIG DIRECTORY
|
//CREATE CONFIG DIRECTORY
|
||||||
mkdir(config_dir, 0700);
|
mkdir(config_dir, 0700);
|
||||||
@ -83,11 +83,11 @@ char *config(char *key, enum CONFIG_TYPES type)
|
|||||||
switch (type) //GET path
|
switch (type) //GET path
|
||||||
{
|
{
|
||||||
case CLIENT:
|
case CLIENT:
|
||||||
path = why2_replace(WHY2_CHAT_CONFIG_DIR "/" WHY2_CHAT_CONFIG_CLIENT, "{USER}", getenv("USER"));
|
path = why2_replace(WHY2_CONFIG_DIR "/" WHY2_CHAT_CONFIG_CLIENT, "{USER}", getenv("USER"));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case SERVER:
|
case SERVER:
|
||||||
path = why2_replace(WHY2_CHAT_CONFIG_DIR "/" WHY2_CHAT_CONFIG_SERVER, "{USER}", getenv("USER"));
|
path = why2_replace(WHY2_CONFIG_DIR "/" WHY2_CHAT_CONFIG_SERVER, "{USER}", getenv("USER"));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
@ -76,9 +76,12 @@ enum WHY2_EXIT_CODES why2_check_version(void)
|
|||||||
//FILE-CHECK VARIABLES
|
//FILE-CHECK VARIABLES
|
||||||
int not_found_buffer = 0;
|
int not_found_buffer = 0;
|
||||||
|
|
||||||
|
//GET VERSION FILE
|
||||||
|
char *version_file = why2_replace(WHY2_VERSIONS_NAME, "{USER}", getenv("USER"));
|
||||||
|
|
||||||
//CURL VARIABLES
|
//CURL VARIABLES
|
||||||
CURL *curl = curl_easy_init();
|
CURL *curl = curl_easy_init();
|
||||||
FILE *file_buffer = why2_fopen(WHY2_VERSIONS_NAME, "w+");
|
FILE *file_buffer = why2_fopen(version_file, "w+");
|
||||||
|
|
||||||
//GET versions.json
|
//GET versions.json
|
||||||
curl_easy_setopt(curl, CURLOPT_URL, WHY2_VERSIONS_URL);
|
curl_easy_setopt(curl, CURLOPT_URL, WHY2_VERSIONS_URL);
|
||||||
@ -92,19 +95,19 @@ enum WHY2_EXIT_CODES why2_check_version(void)
|
|||||||
curl_easy_cleanup(curl);
|
curl_easy_cleanup(curl);
|
||||||
why2_deallocate(file_buffer);
|
why2_deallocate(file_buffer);
|
||||||
|
|
||||||
while (access(WHY2_VERSIONS_NAME, R_OK) != 0)
|
while (access(version_file, R_OK) != 0)
|
||||||
{
|
{
|
||||||
not_found_buffer++;
|
not_found_buffer++;
|
||||||
|
|
||||||
if (not_found_buffer == WHY2_NOT_FOUND_TRIES)
|
if (not_found_buffer == WHY2_NOT_FOUND_TRIES)
|
||||||
{
|
{
|
||||||
if (!why2_get_flags().no_output) fprintf(stderr, "%s'%s' not found! Exiting...\n", WHY2_CLEAR_SCREEN, WHY2_VERSIONS_NAME);
|
if (!why2_get_flags().no_output) fprintf(stderr, "%s'%s' not found! Exiting...\n", WHY2_CLEAR_SCREEN, version_file);
|
||||||
|
|
||||||
why2_clean_memory("core_version_check");
|
why2_clean_memory("core_version_check");
|
||||||
return WHY2_DOWNLOAD_FAILED;
|
return WHY2_DOWNLOAD_FAILED;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!why2_get_flags().no_output) printf("%s'%s' not found (%dx)! Trying again in a second.\n", WHY2_CLEAR_SCREEN, WHY2_VERSIONS_NAME, not_found_buffer);
|
if (!why2_get_flags().no_output) printf("%s'%s' not found (%dx)! Trying again in a second.\n", WHY2_CLEAR_SCREEN, version_file, not_found_buffer);
|
||||||
sleep(1);
|
sleep(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -115,7 +118,7 @@ enum WHY2_EXIT_CODES why2_check_version(void)
|
|||||||
struct json_object *active;
|
struct json_object *active;
|
||||||
|
|
||||||
//COUNT LENGTH OF buffer AND STORE IT IN bufferSize
|
//COUNT LENGTH OF buffer AND STORE IT IN bufferSize
|
||||||
file_buffer = why2_fopen(WHY2_VERSIONS_NAME, "r");
|
file_buffer = why2_fopen(version_file, "r");
|
||||||
fseek(file_buffer, 0, SEEK_END);
|
fseek(file_buffer, 0, SEEK_END);
|
||||||
buffer_size = ftell(file_buffer);
|
buffer_size = ftell(file_buffer);
|
||||||
rewind(file_buffer); //REWIND file_buffer (NO SHIT)
|
rewind(file_buffer); //REWIND file_buffer (NO SHIT)
|
||||||
@ -204,7 +207,7 @@ enum WHY2_EXIT_CODES why2_check_version(void)
|
|||||||
install_code = system(install_command); //INSTALL
|
install_code = system(install_command); //INSTALL
|
||||||
|
|
||||||
//REMOVE versions.json - OTHERWISE WILL CAUSE SEGFAULT IN NEXT RUN
|
//REMOVE versions.json - OTHERWISE WILL CAUSE SEGFAULT IN NEXT RUN
|
||||||
remove(WHY2_VERSIONS_NAME);
|
remove(version_file);
|
||||||
|
|
||||||
why2_deallocate(install_command);
|
why2_deallocate(install_command);
|
||||||
|
|
||||||
@ -257,6 +260,7 @@ enum WHY2_EXIT_CODES why2_check_version(void)
|
|||||||
//DEALLOCATION
|
//DEALLOCATION
|
||||||
json_object_put(parsed_json); //THIS FREES EVERY json_object - AT LEAST JSON-C'S DOCUMENTATION SAYS THAT
|
json_object_put(parsed_json); //THIS FREES EVERY json_object - AT LEAST JSON-C'S DOCUMENTATION SAYS THAT
|
||||||
why2_deallocate(buffer);
|
why2_deallocate(buffer);
|
||||||
|
why2_deallocate(version_file);
|
||||||
|
|
||||||
why2_reset_memory_identifier();
|
why2_reset_memory_identifier();
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user