bool t3f_scan_files(const char * path, bool (*process_file)(const char * fn, bool isfolder, void * data), bool subdir, void * data) { ALLEGRO_FS_ENTRY * dir; ALLEGRO_FS_ENTRY * fp; char cname[1024] = {0}; /* ignore ./ and ../ path entries */ strcpy(cname, path); if(strlen(cname) > 0) { if(cname[strlen(cname) - 1] == '/') { if(subdir) { if(cname[strlen(cname) - 2] == '.') { return false; } } cname[strlen(cname) - 1] = 0; } } // printf("!Looking in %s\n", cname); dir = al_create_fs_entry(cname); if(!dir) { return false; } if(!al_open_directory(dir)) { return false; } // printf("Looking in %s\n", cname); while(1) { fp = al_read_directory(dir); if(!fp) { break; } // name = al_path_to_string(al_get_entry_name(fp), '/'); if(al_get_fs_entry_mode(fp) & ALLEGRO_FILEMODE_ISDIR) { if(process_file(al_get_fs_entry_name(fp), true, data)) { } t3f_scan_files(al_get_fs_entry_name(fp), process_file, true, data); } else { if(process_file(al_get_fs_entry_name(fp), false, data)) { } } al_destroy_fs_entry(fp); } al_destroy_fs_entry(dir); return true; }
bool ScreenPlay::scan_save_files() { //reduntant finction? if(gms == nullptr) gms = new GameSave(); savefiles.clear(); std::string dum; int a = 0; ALLEGRO_FS_ENTRY* dir = al_create_fs_entry("saves/"); if(al_open_directory(dir) == false) { al_make_directory("saves/"); } if(al_open_directory(dir)) { ALLEGRO_FS_ENTRY* file; while(file = al_read_directory(dir)) { dum = al_get_fs_entry_name(file); if( al_get_fs_entry_mode(file) == ALLEGRO_FILEMODE_ISDIR || dum.substr(dum.size()-4,4) != ".sav") { continue; } gms->Load(dum); savefiles.push_back(dum); scba->AddText(5, a * 100 +10, gms->Get_player_name(), al_map_rgb(255,215,0), &n_font); scba->AddButton("resources/fonts/Calibri.ttf", 400, a * 100 + 60, 75, 30, "Load", al_map_rgb(0,0,139)); scba->AddRectangle(1,a * 100 , 500, 100, 2, al_map_rgb(10,10,10)); scba->AddText(10, a * 100 + 60, "Mission: " + std::to_string(gms->Get_mission_number()), al_map_rgb(255,255,250), &m_font); a++; gms->Save(); } al_destroy_fs_entry(file); } al_destroy_fs_entry(dir); return true; }
static void print_entry(ALLEGRO_FS_ENTRY *entry) { print_file(entry); if (al_get_fs_entry_mode(entry) & ALLEGRO_FILEMODE_ISDIR) { ALLEGRO_FS_ENTRY *next; al_open_directory(entry); while (1) { next = al_read_directory(entry); if (!next) break; print_entry(next); al_destroy_fs_entry(next); } al_close_directory(entry); } }
static void print_file(ALLEGRO_FS_ENTRY *entry) { int mode = al_get_fs_entry_mode(entry); time_t now = time(NULL); time_t atime = al_get_fs_entry_atime(entry); time_t ctime = al_get_fs_entry_ctime(entry); time_t mtime = al_get_fs_entry_mtime(entry); off_t size = al_get_fs_entry_size(entry); const char *name = al_get_fs_entry_name(entry); log_printf("%-36s %s%s%s%s%s%s %8u %8u %8u %8u\n", name, mode & ALLEGRO_FILEMODE_READ ? "r" : ".", mode & ALLEGRO_FILEMODE_WRITE ? "w" : ".", mode & ALLEGRO_FILEMODE_EXECUTE ? "x" : ".", mode & ALLEGRO_FILEMODE_HIDDEN ? "h" : ".", mode & ALLEGRO_FILEMODE_ISFILE ? "f" : ".", mode & ALLEGRO_FILEMODE_ISDIR ? "d" : ".", (unsigned)(now - ctime), (unsigned)(now - mtime), (unsigned)(now - atime), (unsigned)size); }
ScreenPlay::ScreenPlay(Button *ext_b) : but(ext_b) { n_font = al_load_font("resources/fonts/Asimov.otf",40,0); m_font = al_load_font("resources/fonts/Calibri.ttf",30,0); std::string bnames[SCREENPLAY_NMB] = {"Back", "New game", "OK"}; int bpoz[SCREENPLAY_NMB][4] = { {1300, global::dHeight -70, 120, 50}, {(global::dWidth-120)/2, global::dHeight -70, 120, 50}, {(global::dWidth-120)/2, (global::dHeight-50)/2 +45, 120, 50} }; for(int a = 0;a < SCREENPLAY_NMB;a++) { buttons.push_back(new Button("resources/fonts/Calibri.ttf", bpoz[a][0], bpoz[a][1], bpoz[a][0] + bpoz[a][2],bpoz[a][1] + bpoz[a][3], bnames[a], al_map_rgb(0,0,128))); } buttons[OK]->Active(false); buttons[OK]->Print_active(false); scba = new ScrollableArea(((float)global::dWidth - 500.0f)/2.0f ,100, 500 ,global::dHeight-200); scba->background_col = al_map_rgba(50,50,50,120); //graphic background trash zemak_bitmpa = al_load_bitmap("resources/graphics/zemiacik.png"); if(zemak_bitmpa == nullptr) { error_message("Could not load image : resources/graphics/zemiacik.png"); } std::mt19937 generator(std::chrono::system_clock::now().time_since_epoch().count()); std::uniform_int_distribution<int> distribution(1,5); std::uniform_real_distribution<float> change(-10, 10); std::uniform_int_distribution<int> width(0,global::dWidth - ZEMIAK_SIZE); std::uniform_int_distribution<int> height(0,global::dHeight-ZEMIAK_SIZE); number_of_zemaky = distribution(generator); zemaky = new float[number_of_zemaky*4]; for(int a = 0;a < number_of_zemaky*4;a+=4) { zemaky[a] = width(generator); zemaky[a+1] = height(generator); zemaky[a+2] = round(change(generator)); zemaky[a+3] = round(change(generator)); } //------------------------------------------ //Saves loading gms = new GameSave(); std::string dum; int a = 0; ALLEGRO_FS_ENTRY* dir = al_create_fs_entry("saves/"); if(al_open_directory(dir) == false) { al_make_directory("saves/"); } if(al_open_directory(dir)) { ALLEGRO_FS_ENTRY* file; while(file = al_read_directory(dir)) { dum = al_get_fs_entry_name(file); if( al_get_fs_entry_mode(file) == ALLEGRO_FILEMODE_ISDIR || dum.substr(dum.size()-4,4) != ".sav") { continue; } gms->Load(dum); savefiles.push_back(dum); scba->AddText(5, a * 100 +10, gms->Get_player_name(), al_map_rgb(255,215,0), &n_font); scba->AddButton("resources/fonts/Calibri.ttf", 400, a * 100 + 60, 75, 30, "Load", al_map_rgb(0,0,139)); scba->AddRectangle(1,a * 100 , 500, 100, 2, al_map_rgb(10,10,10)); scba->AddText(10, a * 100 + 60, "Mission: " + std::to_string(gms->Get_mission_number()), al_map_rgb(255,255,250), &m_font); a++; gms->Save(); } al_destroy_fs_entry(file); } al_destroy_fs_entry(dir); }
ALLEGRO_PATH *_al_unix_get_path(int id) { switch (id) { case ALLEGRO_TEMP_PATH: { /* Check: TMP, TMPDIR, TEMP or TEMPDIR */ char *envs[] = { "TMP", "TMPDIR", "TEMP", "TEMPDIR", NULL}; uint32_t i = 0; for (; envs[i] != NULL; ++i) { char *tmp = getenv(envs[i]); if (tmp) { return al_create_path_for_directory(tmp); } } /* next try: /tmp /var/tmp /usr/tmp */ char *paths[] = { "/tmp/", "/var/tmp/", "/usr/tmp/", NULL }; for (i=0; paths[i] != NULL; ++i) { ALLEGRO_FS_ENTRY *fse = al_create_fs_entry(paths[i]); bool found = (al_get_fs_entry_mode(fse) & ALLEGRO_FILEMODE_ISDIR) != 0; al_destroy_fs_entry(fse); if (found) { return al_create_path_for_directory(paths[i]); } } /* Give up? */ return NULL; } break; case ALLEGRO_RESOURCES_PATH: { ALLEGRO_PATH *exe = get_executable_name(); exe = follow_symlinks(exe); al_set_path_filename(exe, NULL); return exe; } break; case ALLEGRO_USER_DATA_PATH: case ALLEGRO_USER_SETTINGS_PATH: { ALLEGRO_PATH *local_path = NULL; const char *org_name = al_get_org_name(); const char *app_name = al_get_app_name(); /* to avoid writing directly into the user's directory, require at least an app name */ if (!app_name) return NULL; /* find the appropriate path from the xdg environment variables, if possible */ if (id == ALLEGRO_USER_DATA_PATH) { const char *xdg_data_home = getenv("XDG_DATA_HOME"); local_path = al_create_path_for_directory(xdg_data_home ? xdg_data_home : ".local/share"); } else { const char *xdg_config_home = getenv("XDG_CONFIG_HOME"); local_path = al_create_path_for_directory(xdg_config_home ? xdg_config_home : ".config"); } if (!local_path) return NULL; /* if the path is relative, prepend the user's home directory */ if (al_path_cstr(local_path, '/')[0] != '/') { ALLEGRO_PATH *home_path = _unix_find_home(); if (!home_path) return NULL; al_rebase_path(home_path, local_path); al_destroy_path(home_path); } /* only add org name if not blank */ if (org_name && org_name[0]) { al_append_path_component(local_path, al_get_org_name()); } al_append_path_component(local_path, al_get_app_name()); return local_path; } break; case ALLEGRO_USER_HOME_PATH: return _unix_find_home(); case ALLEGRO_USER_DOCUMENTS_PATH: { ALLEGRO_PATH *local_path = _get_xdg_path("DOCUMENTS"); return local_path ? local_path : _unix_find_home(); } break; case ALLEGRO_EXENAME_PATH: return get_executable_name(); break; default: return NULL; } return NULL; }