Ejemplo n.º 1
0
char* GetDataFilePath(char* filename) {

	char *result = 0;

	if (al_filename_exists(filename)) {
		return strdup(filename);
	}

	char origfn[255] = "data/";
	strcat(origfn, filename);

	if (al_filename_exists(origfn)) {
		return strdup(origfn);
	}

	void TestPath(char* subpath) {
		ALLEGRO_PATH *tail = al_create_path(filename);
		ALLEGRO_PATH *path = al_get_standard_path(ALLEGRO_RESOURCES_PATH);
		ALLEGRO_PATH *data = al_create_path(subpath);
		al_join_paths(path, data);
		al_join_paths(path, tail);
		//printf("Testing for %s\n", al_path_cstr(path, ALLEGRO_NATIVE_PATH_SEP));
		if (al_filename_exists(al_path_cstr(path, ALLEGRO_NATIVE_PATH_SEP))) {
			result = strdup(al_path_cstr(path, ALLEGRO_NATIVE_PATH_SEP));
		}
		al_destroy_path(tail);
		al_destroy_path(data);
		al_destroy_path(path);
	}
Ejemplo n.º 2
0
bool Windows::LoadProfile()
{
#ifdef WIN32
	char szPath[MAX_PATH];
	ALLEGRO_PATH* alPath;
	bool res;

	if( al_filename_exists( "c4a-prof" ) )
		return ParseProfileFile( "c4a-prof" );

	if( SHGetFolderPathA( 0, CSIDL_PERSONAL, 0, 0, (char*)&szPath ) == S_OK )
	{
		alPath = al_create_path( (char*)&szPath );
		al_append_path_component( alPath, "c4a-prof" );

		if( al_filename_exists( al_path_cstr( alPath, '/' ) ) )
			res = ParseProfileFile( (char*)al_path_cstr( alPath, '/' ) );

		al_destroy_path( alPath );
		return res;
	}
	return false;

#else
	return false;
#endif
}
Ejemplo n.º 3
0
/* Function: al_open_video
 */
ALLEGRO_VIDEO *al_open_video(char const *filename)
{
   ALLEGRO_VIDEO *video;
   const char *extension = filename + strlen(filename) - 1;

   while ((extension >= filename) && (*extension != '.'))
      extension--;
   video = al_calloc(1, sizeof *video);
   
   video->vtable = find_handler(extension);

   if (video->vtable == NULL) {
      ALLEGRO_ERROR("No handler for video extension %s - "
         "therefore not trying to load %s.\n", extension, filename);
      al_free(video);
      return NULL;
   }
   
   video->filename = al_create_path(filename);
   video->playing = true;

   if (!video->vtable->open_video(video)) {
      ALLEGRO_ERROR("Could not open %s.\n", filename);
      al_destroy_path(video->filename);
      al_free(video);
      return NULL;
   }
   
   al_init_user_event_source(&video->es);
   video->es_inited = true;
   
   return video;
}
Ejemplo n.º 4
0
const char* getResource(const char* fmt, ...)
{
   va_list ap;
   static char res[512];
   static ALLEGRO_PATH *dir;
   static ALLEGRO_PATH *path;

   va_start(ap, fmt);
   memset(res, 0, 512);
   snprintf(res, 511, fmt, ap);

   if (!dir) {
      dir = al_get_standard_path(ALLEGRO_RESOURCES_PATH);
#ifdef ALLEGRO_MSVC
      {
         /* Hack to cope automatically with MSVC workspaces. */
         const char *last = al_get_path_component(dir, -1);
         if (0 == strcmp(last, "Debug")
            || 0 == strcmp(last, "RelWithDebInfo")
            || 0 == strcmp(last, "Release")
            || 0 == strcmp(last, "Profile")) {
            al_remove_path_component(dir, -1);
         }
      }
#endif
      al_append_path_component(dir, "data");
   }

   if (path)
      al_destroy_path(path);

   path = al_create_path(res);
   al_rebase_path(dir, path);
   return al_path_cstr(path, '/');
}
Ejemplo n.º 5
0
SlotManager::SlotManager(bool a_blLoading,  ALLEGRO_PATH * a_pSearchpath,void (* a_pCallBack)(string))

{
    m_ColorInner     = al_map_rgb(0,0,0);
    m_ColorOuter     = al_map_rgb(100,100,255);
    m_ColorHighlight = al_map_rgb(0,0,255);
    m_pActiveSlot    = NULL;
    m_blLoading      = a_blLoading;
    m_pCallBack      = a_pCallBack;
    m_nIndex         = 1;

    if (a_pSearchpath!=NULL)
    {
        ALLEGRO_FS_ENTRY * pDir = al_create_fs_entry(al_path_cstr(a_pSearchpath,ALLEGRO_NATIVE_PATH_SEP));
        if (al_open_directory(pDir))
        {
            ALLEGRO_FS_ENTRY * pFile;
            while (pFile = al_read_directory(pDir))
            {
                ALLEGRO_PATH * pPath = al_create_path(al_get_fs_entry_name(pFile));

                AddSlot(al_get_path_basename(pPath));

                al_destroy_path(pPath);
                al_destroy_fs_entry(pFile);
            }
        }
        al_destroy_fs_entry(pDir);
    }

    if (!a_blLoading)
    {
        AddSlot("NEW SAVE...");
    }
}
static ALLEGRO_PATH *follow_symlinks(ALLEGRO_PATH *path)
{
   for (;;) {
      const char *path_str = al_path_cstr(path, '/');
      char buf[PATH_MAX];
      int len;

      len = readlink(path_str, buf, sizeof(buf) - 1);
      if (len <= 0)
         break;
      buf[len] = '\0';
      al_destroy_path(path);
      path = al_create_path(buf);
   }

   /* Make absolute path. */
   {
      const char *cwd = al_get_current_directory();
      ALLEGRO_PATH *cwd_path = al_create_path_for_directory(cwd);
      if (al_rebase_path(cwd_path, path))
         al_make_path_canonical(path);
      al_destroy_path(cwd_path);
      al_free((void *) cwd);
   }

   return path;
}
Ejemplo n.º 7
0
static bool select_folder(ALLEGRO_DISPLAY_WIN *win_display,
   ALLEGRO_NATIVE_DIALOG *fd)
{
   BROWSEINFO folderinfo;
   LPCITEMIDLIST pidl;
   char buf[MAX_PATH] = "";
   char dbuf[MAX_PATH] = "";

   folderinfo.hwndOwner = win_display->window;
   folderinfo.pidlRoot = NULL;
   folderinfo.pszDisplayName = dbuf;
   folderinfo.lpszTitle = al_cstr(fd->title);
   folderinfo.ulFlags = 0;
   folderinfo.lpfn = NULL;

   pidl = SHBrowseForFolder(&folderinfo);
   if (pidl) {
      SHGetPathFromIDList(pidl, buf);
      fd->fc_path_count = 1;
      fd->fc_paths = al_malloc(sizeof(void *));
      fd->fc_paths[0] = al_create_path(buf);
      return true;
   }
   return false;
}
Ejemplo n.º 8
0
s_sprite c_tile::get_from_ini(ALLEGRO_CONFIG *config, const char * section, ALLEGRO_PATH * base_path)
{
    s_sprite temp;

    const char * buffer_file = al_get_config_value(config, section, "image_file");
    if(!buffer_file)
    {
        temp.index = -1;
        return temp;
    }
    ALLEGRO_PATH * imagepath = al_create_path(buffer_file);
    al_rebase_path(base_path, imagepath);
    temp.index = imagelist.load_image(al_path_cstr(imagepath, ALLEGRO_NATIVE_PATH_SEP));

    temp.x = get_config_int(config, section, "x");
    temp.y = get_config_int(config, section, "y");

    temp.width = get_config_int(config, section, "width");
    temp.height = get_config_int(config, section, "height");

    temp.origin_x = get_config_int(config, section, "origin_x");
    temp.origin_y = get_config_int(config, section, "origin_y");

    temp.origin_x = 0 - temp.origin_x;
    temp.origin_y = 0 - temp.origin_y;

    temp.palette_number = get_config_int(config, section, "palette_index");

    temp.column_height = get_config_int(config, section, "column_height");

    const char * color_selection = al_get_config_value(config, section, "color_source");
    if(color_selection)
        temp.color_by = get_color_selector(color_selection);

    const char * pal_source = al_get_config_value(config, section, "palette_source");
    if(pal_source)
        temp.color_source = get_color_source(pal_source);

    const char * color = al_get_config_value(config, section, "color_html");
    if(color)
        temp.color = color_html(color);

    const char * off = al_get_config_value(config, section, "offset_type");
    if(off)
        temp.offset_type = get_offset_type(off);

    const char * neigh = al_get_config_value(config, section, "border_terrain");
    if(neigh)
        temp.border_terrain = get_terrain_type(neigh);

    const char * neighbobj = al_get_config_value(config, section, "border_structure");
    if(neighbobj)
        temp.border_structure = get_structure_type(neighbobj);

    temp.offset_amount = get_config_int(config, section, "offset_amount");

    al_destroy_path(imagepath);
    return temp;
}
Ejemplo n.º 9
0
/* Function: al_set_exe_name
 */
void al_set_exe_name(char const *path)
{
   ASSERT(active_sysdrv);
   if (active_sysdrv->user_exe_path) {
      al_destroy_path(active_sysdrv->user_exe_path);
   }
   active_sysdrv->user_exe_path = al_create_path(path);
}
Ejemplo n.º 10
0
void InitConfig(void) {
	ALLEGRO_PATH *path = al_get_standard_path(ALLEGRO_USER_SETTINGS_PATH);
	ALLEGRO_PATH *data = al_create_path("SuperDerpy.ini");
	al_join_paths(path, data);
	config = al_load_config_file(al_path_cstr(path, ALLEGRO_NATIVE_PATH_SEP));
	if (!config) config=al_create_config();
	al_destroy_path(path);
	al_destroy_path(data);
}
Ejemplo n.º 11
0
Archivo: path.c Proyecto: trezker/allua
static int allua_Path_create(lua_State * L)
{
   const char *str = luaL_checkstring(L, 1);

   ALLUA_path path = al_create_path(str);
   allua_pushPath(L, path, true);

   return 1;
}
Ejemplo n.º 12
0
void DeinitConfig(void) {
	ALLEGRO_PATH *path = al_get_standard_path(ALLEGRO_USER_SETTINGS_PATH);
	ALLEGRO_PATH *data = al_create_path("SuperDerpy.ini");
	al_make_directory(al_path_cstr(path, ALLEGRO_NATIVE_PATH_SEP));
	al_join_paths(path, data);
	al_save_config_file(al_path_cstr(path, ALLEGRO_NATIVE_PATH_SEP), config);
	al_destroy_path(path);
	al_destroy_path(data);
	al_destroy_config(config);
}
Ejemplo n.º 13
0
void mapEditor::saveMap() {
	ALLEGRO_FILECHOOSER* fC = al_create_native_file_dialog(al_create_path(""),"Select Location..","*.map",ALLEGRO_FILECHOOSER_SAVE);
	al_show_native_file_dialog(this->display,fC);
	const ALLEGRO_PATH* savePath = al_get_native_file_dialog_path(fC,0);
	const char* pathName = al_path_cstr(savePath, ALLEGRO_NATIVE_PATH_SEP);
	ALLEGRO_FILE* fHandle = al_fopen(pathName,"wb");
	mapSaver* newSaver = new mapSaver(*this->mHandler->mData);
	newSaver->writeData(fHandle);
	al_fclose(fHandle);
}
Ejemplo n.º 14
0
/* Function: al_create_path_for_directory
 */
ALLEGRO_PATH *al_create_path_for_directory(const char *str)
{
   ALLEGRO_PATH *path = al_create_path(str);
   if (al_ustr_length(path->filename)) {
      ALLEGRO_USTR *last = path->filename;
      path->filename = al_ustr_new("");
      al_append_path_component(path, al_cstr(last));
      al_ustr_free(last);
   }
   return path;
}
Ejemplo n.º 15
0
/* _find_executable_file:
 *  Helper function: searches path and current directory for executable.
 *  Returns 1 on succes, 0 on failure.
 */
static ALLEGRO_PATH *_find_executable_file(const char *filename)
{
   char *env;

   /* If filename has an explicit path, search current directory */
   if (strchr(filename, '/')) {
      if (filename[0] == '/') {
         /* Full path; done */
         return al_create_path(filename);
      }
      else {
         struct stat finfo;
         char pathname[1024];
    
         /* Prepend current directory */
         ALLEGRO_PATH *path = al_get_current_directory();
         al_append_path_component(path, filename);

         if ((stat(pathname, &finfo)==0) &&
            (!S_ISDIR (finfo.st_mode))) {
            return path;
         }
      }
   }
   /* If filename has no explicit path, but we do have $PATH, search
    * there
    */
   else if ((env = getenv("PATH"))) {
      struct stat finfo;
      ALLEGRO_USTR *us = al_ustr_new(env);
      int start_pos = 0;
      while (start_pos >= 0) {
         int next_start_pos = al_ustr_find_chr(us, start_pos + 1, ':');
         int end_pos = next_start_pos;
         if (next_start_pos < 0)
            end_pos = al_ustr_size(us);
         ALLEGRO_USTR_INFO info;
         ALLEGRO_USTR *sub = al_ref_ustr(&info, us, start_pos, end_pos);

         ALLEGRO_PATH *path = al_create_path_for_directory(al_cstr(sub));
         al_append_path_component(path, filename);

         if (stat(al_path_cstr(path, '/'), &finfo) == 0 &&
            !S_ISDIR (finfo.st_mode)) {
            return path;
         }
         start_pos = next_start_pos;
      }
   }

   return NULL;
}
Ejemplo n.º 16
0
SYMBOL_EXPORT void DeinitConfig(struct Game* game) {
	const ALLEGRO_FILE_INTERFACE* iface = al_get_new_file_interface();
	al_set_standard_file_interface();
	ALLEGRO_PATH* path = al_get_standard_path(ALLEGRO_USER_SETTINGS_PATH);
	ALLEGRO_PATH* data = al_create_path("SuperDerpy.ini");
	al_make_directory(al_path_cstr(path, ALLEGRO_NATIVE_PATH_SEP));
	al_join_paths(path, data);
	al_save_config_file(al_path_cstr(path, ALLEGRO_NATIVE_PATH_SEP), game->_priv.config);
	al_destroy_path(path);
	al_destroy_path(data);
	al_destroy_config(game->_priv.config);
	al_set_new_file_interface(iface);
}
Ejemplo n.º 17
0
	void Map::SaveMapDialog()
	{
		ALLEGRO_FILECHOOSER *saveDialog;
		saveDialog = al_create_native_file_dialog("..\\Maps\\", "Save Map", "*.*", ALLEGRO_FILECHOOSER_SAVE);
		al_show_native_file_dialog(display_, saveDialog);
		mapPath_ = al_create_path(al_get_native_file_dialog_path(saveDialog,0));
		if(strcmp(al_get_path_extension(mapPath_),"") == 0)
		{
			al_set_path_extension(mapPath_, ".mapa");
		}
		SaveMap();
		al_destroy_native_file_dialog(saveDialog);
	}
Ejemplo n.º 18
0
/*
 * Calling LoadLibrary with a relative file name is a security risk:
 * see e.g. Microsoft Security Advisory (2269637)
 * "Insecure Library Loading Could Allow Remote Code Execution"
 */
HMODULE _al_win_safe_load_library(const char *filename)
{
    ALLEGRO_PATH *path1 = NULL;
    ALLEGRO_PATH *path2 = NULL;
    char buf[MAX_PATH];
    const char *other_dirs[3];
    HMODULE lib = NULL;
    bool msvc_only = false;

    /* MSVC only: if the executable is in the build configuration directory,
     * which is also just under the current directory, then also try to load the
     * library from the current directory.  This leads to less surprises when
     * running example programs.
     */
#if defined(ALLEGRO_MSVC)
    msvc_only = true;
#endif

    /* Try to load the library from the directory containing the running
     * executable, the Windows system directories, or directories on the PATH.
     * Do NOT try to load the library from the current directory.
     */

    if (al_is_system_installed()) {
        path1 = al_get_standard_path(ALLEGRO_RESOURCES_PATH);
    }
    else if (GetModuleFileName(NULL, buf, sizeof(buf)) < sizeof(buf)) {
        path1 = al_create_path(buf);
    }
    if (msvc_only) {
        path2 = maybe_parent_dir(path1);
    }

    other_dirs[0] = path1 ? al_path_cstr(path1, '\\') : NULL;
    other_dirs[1] = path2 ? al_path_cstr(path2, '\\') : NULL;
    other_dirs[2] = NULL; /* sentinel */

    _al_sane_strncpy(buf, filename, sizeof(buf));
    if (PathFindOnPath(buf, other_dirs)) {
        ALLEGRO_DEBUG("PathFindOnPath found: %s\n", buf);
        lib = load_library_at_path(buf);
    }
    else {
        ALLEGRO_WARN("PathFindOnPath failed to find %s\n", filename);
    }

    al_destroy_path(path1);
    al_destroy_path(path2);

    return lib;
}
Ejemplo n.º 19
0
static char* test_level_write_to_file()
{
    char* level_name = "test-write.world";

    ALLEGRO_PATH* path = al_create_path(FILES_ASSETS_PATH);
    al_append_path_component(path, FILES_LEVELS_SUBDIRNAME);
    al_set_path_filename(path, level_name);
    const char* filename = al_path_cstr(path, ALLEGRO_NATIVE_PATH_SEP);

    // create new test level
    Level* level_new = level_alloc_empty(LEVEL_TEST_WIDTH, LEVEL_TEST_HEIGHT);
    level_new->cells[3][4] = cell_init(UNIT_1, OWNER_HUMAN, 3, 4);

    // write level to file
    level_write_to_file(level_new, filename);
    level_free(level_new);

    // read level from file 
    // (this function is assumed to work correctly
    // because it has been tested earlier)
    Level* level = level_alloc_read_from_file(filename);

    // test if level was correctly written
    mu_assert(level != NULL);
    mu_assert(level->width == LEVEL_TEST_WIDTH);
    mu_assert(level->height == LEVEL_TEST_HEIGHT);

    // test if cells were correctly written
    int i;
    int j;
    for (i = 0; i < level->height; i++) // rows
    {
        for (j = 0; j < level->width; j++) // cols
        {
            mu_assert(level->cells[i][j].row == i);
            mu_assert(level->cells[i][j].col == j);
        }
    }

    mu_assert(level->cells[0][0].type == GROUND);
    mu_assert(level->cells[0][0].owner == OWNER_NONE);
    mu_assert(level->cells[3][4].type == UNIT_1);
    mu_assert(level->cells[3][4].owner == OWNER_HUMAN);

    al_destroy_path(path);
    level_free(level);

    return NULL;
}
Ejemplo n.º 20
0
static void filesel_ok(GtkWidget *w, GtkFileSelection *fs)
{
   ALLEGRO_NATIVE_DIALOG *fc;
   fc = g_object_get_data(G_OBJECT(w), "ALLEGRO_NATIVE_DIALOG");
   gchar **paths = gtk_file_selection_get_selections(fs);
   int n = 0, i;
   while (paths[n]) {
      n++;
   }
   fc->fc_path_count = n;
   fc->fc_paths = al_malloc(n * sizeof(void *));
   for (i = 0; i < n; i++)
      fc->fc_paths[i] = al_create_path(paths[i]);
   g_strfreev(paths);
}
Ejemplo n.º 21
0
static int allua_Filechooser_create(lua_State * L)
{
   const char *ipath = luaL_checkstring(L, 1);
   const char *title = luaL_checkstring(L, 2);
   const char *patterns = luaL_checkstring(L, 3);
   int mode = luaL_checkint(L, 4);
   ALLEGRO_PATH *initial_path = al_create_path(ipath);
   ALLUA_filechooser d =
       al_create_native_file_dialog(al_path_cstr
                                    (initial_path, ALLEGRO_NATIVE_PATH_SEP),
                                    title, patterns, mode);
   al_destroy_path(initial_path);
   if (d)
      allua_pushFilechooser(L, d);
   else
      lua_pushnil(L);
   return 1;
}
Ejemplo n.º 22
0
static char* test_level_alloc_read_from_file_read_invalid_level_size_for_dimensions()
{
    char* level_name = "test-invalid-level-size-for-dimensions.world";

    ALLEGRO_PATH* path = al_create_path(FILES_ASSETS_PATH);
    al_append_path_component(path, FILES_LEVELS_SUBDIRNAME);
    al_set_path_filename(path, level_name);
    const char* filename = al_path_cstr(path, ALLEGRO_NATIVE_PATH_SEP);

    Level* level = level_alloc_read_from_file(filename);

    mu_assert(level == NULL);

    al_destroy_path(path);
    level_free(level);

    return NULL;
}
bool includeFile(SpriteNode* node, TiXmlElement* includeNode, SpriteBlock* &oldSibling)
{
    // get path... ugly
    char configfilepath[FILENAME_BUFFERSIZE] = {0};
    const char* documentRef = getDocument(includeNode);

    if (!getLocalFilename(configfilepath,includeNode->Attribute("file"),documentRef))
    {
        return false;
    }
    ALLEGRO_PATH * incpath = al_create_path(configfilepath);
    al_append_path_component(incpath, "include");
    TiXmlDocument doc( al_path_cstr(incpath, ALLEGRO_NATIVE_PATH_SEP) );
    al_destroy_path(incpath);
	bool loadOkay = doc.LoadFile();
	TiXmlHandle hDoc(&doc);
	TiXmlElement* elemParent;
	if(!loadOkay)
	{
		contentError("Include failed",includeNode);
        WriteErr("File load failed: %s\n",configfilepath);
		WriteErr("Line %d: %s\n",doc.ErrorRow(),doc.ErrorDesc());
		return false;
	}
	elemParent = hDoc.FirstChildElement("include").Element();
	if( elemParent == NULL)
	{
		contentError("Main <include> node not present",&doc);
		return false;
	}
	TiXmlElement* elemNode =  elemParent->FirstChildElement();
	if (elemNode == NULL)
	{
		contentError("Empty include",elemParent);
		return false;
	}
	while (elemNode)
	{ 
		if (!readNode(node, elemNode, elemParent, oldSibling))
			return false;
		elemNode = elemNode->NextSiblingElement();
	}
	return true;
}
Ejemplo n.º 24
0
	void Map::LoadMapDialog()
	{
		ALLEGRO_FILECHOOSER *loadDialog = NULL;
		loadDialog = al_create_native_file_dialog("..\\Maps\\", "Load Mapx file","*.*",0);	
		al_show_native_file_dialog(display_, loadDialog);
		mapPath_ = al_create_path(al_get_native_file_dialog_path(loadDialog, 0));
		LoadMap();


		//ADJUST offset if a player has been placed but since player placed is false somteimes set it to top left corner as players pos will be created at this point
		mapXoffset_ = width_*Constants::TileSize <= settings_->GetScreenWidth() ? settings_->GetScreenWidth()/2-width_*Constants::TileSize/2 : 0;
		mapYoffset_ = height_*Constants::TileSize <= settings_->GetScreenHeight() ? settings_->GetScreenHeight()/2-height_*Constants::TileSize/2 : 0;

		PreCalc();


		al_destroy_native_file_dialog(loadDialog);

	}
static char* test_find_path_non_empty_level_around_obstacles()
{
    char* level_name = "test-around-obstacles.world";

    ALLEGRO_PATH* file_path = al_create_path(FILES_ASSETS_PATH);
    al_append_path_component(file_path, FILES_LEVELS_SUBDIRNAME);
    al_set_path_filename(file_path, level_name);
    const char* filename = al_path_cstr(file_path, ALLEGRO_NATIVE_PATH_SEP);

    Level* level = level_alloc_read_from_file(filename);

    mu_assert(level != NULL);
    Cell* start_cell = &level->cells[0][0];
    Cell* target_cell = &level->cells[11][24];

    Path* path = find_path(level, start_cell, target_cell);

    mu_assert(path != NULL);
    mu_assert(path->distance == 12 * 95 + 17 * 26);
    mu_assert(path->step_count == 122);

    mu_assert(path->steps != NULL);
    mu_assert(test_is_path_start_and_end_step_correct(path, start_cell, target_cell));
    mu_assert(test_is_path_walkable(path, level) == 1);

    // test a few steps
    mu_assert(path->steps[5].row == 5);
    mu_assert(path->steps[5].col == 1);
    mu_assert(path->steps[11].row == 11);
    mu_assert(path->steps[11].col == 2);
    mu_assert(path->steps[65].row == 1);
    mu_assert(path->steps[65].col == 12);
    mu_assert(path->steps[119].row == 11);
    mu_assert(path->steps[119].col == 22);

    path_free(path);
    al_destroy_path(file_path);
    level_free(level);

    return NULL;
}
Ejemplo n.º 26
0
/* Function: al_open_video
 */
ALLEGRO_VIDEO *al_open_video(char const *filename)
{
   ALLEGRO_VIDEO *video;

   video = al_calloc(1, sizeof *video);
   
   video->vtable = _al_video_vtable;
   
   video->filename = al_create_path(filename);

   if (!video->vtable->open_video(video)) {
      al_destroy_path(video->filename);
      al_free(video);
      return NULL;
   }
   
   al_init_user_event_source(&video->es);
   video->es_inited = true;
   
   return video;
}
Ejemplo n.º 27
0
/* Function: al_create_native_file_dialog
 */
ALLEGRO_FILECHOOSER *al_create_native_file_dialog(
   char const *initial_path,
   char const *title,
   char const *patterns,
   int mode)
{
   ALLEGRO_NATIVE_DIALOG *fc;
   fc = al_calloc(1, sizeof *fc);

   if (initial_path) {
      fc->fc_initial_path = al_create_path(initial_path);
   }
   fc->title = al_ustr_new(title);
   fc->fc_patterns = al_ustr_new(patterns);
   fc->flags = mode;

   _al_register_destructor(_al_dtor_list, fc,
      (void (*)(void *))al_destroy_native_file_dialog);

   return (ALLEGRO_FILECHOOSER *)fc;
}
Ejemplo n.º 28
0
static ALLEGRO_FS_ENTRY *fs_apk_create_entry(const char *path)
{
   ALLEGRO_FS_ENTRY_APK *e;
   ALLEGRO_USTR *us;

   e = al_calloc(1, sizeof *e);
   if (!e)
      return NULL;
   e->fs_entry.vtable = &fs_apk_vtable;

   us = apply_cwd(path);
   e->path = al_create_path(al_cstr(us));
   al_ustr_free(us);
   if (!e->path) {
      al_free(e);
      return NULL;
   }
   e->path_cstr = al_path_cstr(e->path, '/');
   
   return &e->fs_entry;
}
Ejemplo n.º 29
0
/* Function: al_clone_path
 */
ALLEGRO_PATH *al_clone_path(const ALLEGRO_PATH *path)
{
   ALLEGRO_PATH *clone;
   unsigned int i;

   ASSERT(path);

   clone = al_create_path(NULL);
   if (!clone) {
      return NULL;
   }

   al_ustr_assign(clone->drive, path->drive);
   al_ustr_assign(clone->filename, path->filename);

   for (i = 0; i < _al_vector_size(&path->segments); i++) {
      ALLEGRO_USTR **slot = _al_vector_alloc_back(&clone->segments);
      (*slot) = al_ustr_dup(get_segment(path, i));
   }

   return clone;
}
Ejemplo n.º 30
0
/* drop build configuration directory tail */
static ALLEGRO_PATH *get_resources_path(void)
{
   ALLEGRO_PATH *path;
   const char *last;

   path = al_get_standard_path(ALLEGRO_RESOURCES_PATH);
   if (!path)
      return al_create_path("");

   /* If the last directory component is the name of an MSVC build
    * configuration, then drop it.
    */
   last = al_get_path_tail(path);
   if (last &&
         (0 == strcmp(last, "Debug") ||
          0 == strcmp(last, "Release") ||
          0 == strcmp(last, "RelWithDebInfo") ||
          0 == strcmp(last, "Profile"))) {
      al_drop_path_tail(path);
   }

   return path;
}