void init_custom_update() { char *str = NULL; size_t str_size = 256; Uint32 i; memset(update_thread_data, 0, sizeof(update_thread_data)); update_thread_data[0].dir = datadir; update_thread_data[1].dir = get_path_config_base(); if ((str = (char *)calloc(sizeof(char), str_size)) == NULL) return; for (i = 0; i < 2; i++) { safe_snprintf(str, str_size, "%s%s", get_path_config_base(), zip_names[i]); load_zip_archive(str); safe_snprintf(update_thread_data[i].str, sizeof(update_thread_data[i].str), "%s custom updates: %s", update_names[i], "waiting"); update_thread_data[i].mutex = SDL_CreateMutex(); update_thread_data[i].condition = SDL_CreateCond(); update_thread_data[i].zip = zip_names[i]; update_thread_data[i].name = update_names[i]; update_thread_data[i].running = 1; update_thread_data[i].error = 0; update_thread_data[i].thread = SDL_CreateThread( custom_update_thread, "CustomupdateThread", &update_thread_data[i]); } free(str); }
void set_server_details() { char id[20]; int num; safe_strncpy(id, check_server_id_on_command_line(), sizeof(id)); if (!strcmp(id, "")) { safe_strncpy(id, "main", sizeof(id)); } num = find_server_from_id(id); if (num == -1) { // Oops... what they they specify on the command line? LOG_ERROR("Server profile not found in servers.lst for server: %s. Failover to server: main.", id); // Failover to the main server num = find_server_from_id("main"); if (num == -1) { // Error, this is a problem! LOG_ERROR("Fatal error: Server profile not found in servers.lst for server: main"); exit(1); } } // We found a valid profile so set some vars LOG_DEBUG("Using the server profile: %s", servers[num].id); cur_server = num; safe_strncpy((char *)server_address, (char *)servers[num].address, sizeof(server_address)); port = servers[num].port; // Check if the config directory for the profile exists and if not then create and // copy main's ini file into it if (!check_configdir()) { char src[1000]; char dest[1000]; mkdir_tree(get_path_config(), 0); // First, try to copy the ini file out of $CONF/main safe_snprintf(src, sizeof(src), "%smain/el.ini", get_path_config_base()); safe_snprintf(dest, sizeof(dest), "%sel.ini", get_path_config()); copy_file(src, dest); // Secondly, try to copy the ini file out of $CONF (this will fail without harm if above succeeds) safe_snprintf(src, sizeof(src), "%s/el.ini", get_path_config_base()); safe_snprintf(dest, sizeof(dest), "%sel.ini", get_path_config()); copy_file(src, dest); } }
el_file_ptr el_open_custom(const char* file_name) { el_file_ptr result; ENTER_DEBUG_MARK("file open"); result = file_open(file_name, get_path_config_base()); LEAVE_DEBUG_MARK("file open"); return result; }
int el_custom_file_exists(const char* file_name) { int result; ENTER_DEBUG_MARK("file exists"); result = file_exists_path(file_name, get_path_config_base()); LEAVE_DEBUG_MARK("file exists"); return result; }
static Uint32 custom_update_threaded(const char* dir, const char* zip_file, void* data) { char *buffer = NULL; size_t buffer_size = 1024; char *str = NULL; size_t str_size = 256; char* server; FILE* file; Uint32 count, index, idx, len, result; const char* file_name = "custom_mirrors.lst"; if ((buffer = (char *)calloc(sizeof(char), buffer_size)) == NULL) return 1; if ((str = (char *)calloc(sizeof(char), str_size)) == NULL) { free(buffer); return 1; } safe_snprintf(str, str_size, "%s%s", dir, file_name); file = fopen(str, "r"); if (file == 0) { safe_snprintf(buffer, buffer_size, "Can't find server list file" " '%s'.", str); progress_function(buffer, 0, 0, data); free(buffer); free(str); return 1; } count = 0; server = fgets(buffer, buffer_size, file); while (server != 0) { len = strlen(buffer); // is this line worth handling? if ((len > 6) && (buffer[0] > ' ') && (buffer[0] != '#')) { count++; } // read the next line server = fgets(buffer, buffer_size, file); } if (count == 0) { safe_snprintf(buffer, buffer_size, "No server in file '%s'", str); progress_function(buffer, 0, 0, data); fclose(file); free(buffer); free(str); return 1; } rewind(file); srand(time(0)); idx = rand() % count; index = 0; server = fgets(buffer, buffer_size, file); while (server != 0) { len = strlen(buffer); // is this line worth handling? if ((len > 6) && (buffer[0] > ' ') && (buffer[0] != '#')) { index++; if (index > idx) { while (isspace(buffer[len-1])) { buffer[len - 1] = '\0'; len--; if (len == 0) { break; } } break; } } // read the next line server = fgets(buffer, buffer_size, file); } fclose(file); if (server == 0) { safe_snprintf(buffer, buffer_size, "Can't get server from file" " '%s'", str); progress_function(buffer, 0, 0, data); free(buffer); free(str); return 1; } safe_snprintf(str, str_size, "Downloading from server %s", server); progress_function(str, 0, 0, data); safe_snprintf(str, str_size, "%s%s", get_path_config_base(), zip_file); result = update(server, "custom_files.lst", "updates", str, progress_function, data); free(buffer); free(str); return result; }