static std::string get_entire_translation(const char *filename) { int sz; unsigned char *bytes = slurp_file(getResource("%s.utf8", filename), &sz); if (!bytes) { native_error("Load error.", filename); } ALLEGRO_FILE *f = al_open_memfile(bytes, sz, "rb"); ALLEGRO_USTR *ustr; std::string whole_translation; while ((ustr = al_fget_ustr(f)) != NULL) { // remove newline int size = (int)al_ustr_size(ustr); const char *cstr = al_cstr(ustr); int count = 0; if (cstr[strlen(cstr)-1] == 0xa) count++; if (cstr[strlen(cstr)-2] == 0xd) count++; if (count > 0) { al_ustr_remove_range(ustr, size-count, size); } ustr_replace_all(ustr, '^', '\n'); whole_translation += al_cstr(ustr); } al_fclose(f); delete[] bytes; return whole_translation; }
void Sound::loadFromMemory(const char * data, int length){ ALLEGRO_FILE * memory = al_open_memfile((void*) data, length, "r"); this->data.sample = al_load_sample_f(memory, ".wav"); al_fclose(memory); own = new int; *own = 1; }
ALLEGRO_FONT * load_packed_font(unsigned char *mem, int mem_size, int font_size) { ALLEGRO_FILE *mem_file = al_open_memfile(mem, mem_size, "r"); /* "The filename (second arg) is only used to find possible additional files next to a font file." ? But works with just a blank string */ ALLEGRO_FONT *font = al_load_ttf_font_f(mem_file, "", font_size, 0); /* last variable flags */ /* https://www.allegro.cc/manual/5/al_load_ttf_font_f "The file handle is owned by the returned ALLEGRO_FONT object and must not be freed by the caller, as FreeType expects to be able to read from it at a later time." */ return font; }
ALLEGRO_BITMAP * load_packed_bitmap(unsigned char *mem, int mem_size) { /* fail nicely :) */ if (mem == NULL) return NULL; ALLEGRO_FILE *mem_file = al_open_memfile(mem, mem_size, "r"); /* file type determined by second arg */ ALLEGRO_BITMAP *bm = al_load_bitmap_f(mem_file, ".png"); al_fclose(mem_file); return bm; }
static ALLEGRO_FILE *ioOpenFile(const char *filename) { unsigned int len; char *buf = ioLoadResource(filename, &len); return al_open_memfile(buf, len, "r"); }
/** Opens a memfile. @param mem memory. @param size size. @param mode mode. @return true on success. */ bool open(void *mem, int64_t size, const char *mode) { reset(new AllegroFile(al_open_memfile(mem, size, mode))); return (bool)(*this); }