Пример #1
0
/* Create the "save-path" / "tmp-path" directories, if they don't exist. */
int
AG_CreateDataDir(void)
{
	char dataDir[AG_PATHNAME_MAX];
	char tmpDir[AG_PATHNAME_MAX];

	AG_GetString(agConfig, "save-path", dataDir, sizeof(dataDir));
	AG_GetString(agConfig, "tmp-path", tmpDir, sizeof(tmpDir));

	if (AG_FileExists(dataDir) == 0 && AG_MkDir(dataDir) != 0)
		return (-1);
	if (AG_FileExists(tmpDir) == 0 && AG_MkDir(tmpDir) != 0)
		return (-1);
	
	return (0);
}
Пример #2
0
/*
 * Dump the display surface(s) to a jpeg in ~/.appname/screenshot/.
 * It is customary to assign a AG_GlobalKeys(3) shortcut for this function.
 */
void
AG_ViewCapture(void)
{
	AG_Surface *s;
	char *pname;
	char dir[AG_PATHNAME_MAX];
	char file[AG_PATHNAME_MAX];
	Uint seq;

	if (agDriverSw == NULL) {
		Verbose("AG_ViewCapture() is not implemented under "
		        "multiple-window drivers\n");
		return;
	}

	AG_LockVFS(&agDrivers);

	if (AGDRIVER_SW_CLASS(agDriverSw)->videoCapture(agDriverSw, &s) == -1) {
		Verbose("Capture failed: %s\n", AG_GetError());
		goto out;
	}

	/* Save to a new file. */
	AG_GetString(agConfig, "save-path", dir, sizeof(dir));
	Strlcat(dir, AG_PATHSEP, sizeof(dir));
	Strlcat(dir, "screenshot", sizeof(dir));
	if (!AG_FileExists(dir) && AG_MkPath(dir) == -1) {
		Verbose("Capture failed: %s\n", AG_GetError());
		goto out;
	}
	pname = (agProgName != NULL) ? agProgName : "agarapp";
	for (seq = 0; ; seq++) {
		Snprintf(file, sizeof(file), "%s%c%s%u.jpg",
		    dir, AG_PATHSEPCHAR, pname, seq++);
		if (!AG_FileExists(file))
			break;			/* XXX race condition */
	}
	if (AG_SurfaceExportJPEG(s, file) == 0) {
		Verbose("Saved capture to: %s\n", file);
	} else {
		Verbose("Capture failed: %s\n", AG_GetError());
	}
	AG_SurfaceFree(s);
out:
	AG_UnlockVFS(&agDrivers);
}
Пример #3
0
Файл: anim.c Проект: adsr/agar
/* Load an animation from a series of PNG files. */
AG_Anim *
AG_AnimFromPNGs(const char *pattern)
{
	AG_Anim *a = NULL;
	AG_Surface *su;
	char path[AG_PATHNAME_MAX];
	int i;

	for (i = 0; ; i++) {
		Snprintf(path, sizeof(path), pattern, i);
		if (!AG_FileExists(path)) {
			if (i == 0) {
				continue;
			} else {
				break;
			}
		}
		if ((su = AG_SurfaceFromPNG(path)) == NULL) {
			break;
		}
		if (a == NULL) {
			a = AG_AnimRGBA(su->w, su->h,
			    su->format->BitsPerPixel, 0,
			    su->format->Rmask,
			    su->format->Gmask,
			    su->format->Bmask,
			    su->format->Amask);
			if (a == NULL) {
				AG_SurfaceFree(su);
				return (NULL);
			}
		}
		if (AG_AnimFrameNew(a,su) == -1) {
			goto fail;
		}
	}
	return (a);
fail:
	AG_AnimFree(a);
	return (NULL);
}
Пример #4
0
/* Copy the full pathname of a data file to a sized buffer. */
int
AG_ConfigFile(const char *path_key, const char *name, const char *ext,
    char *path, size_t path_len)
{
	char file[AG_PATHNAME_MAX];
	char *dir, *pathp = path;
	int rv;

	AG_GetString(agConfig, path_key, path, path_len);

	for (dir = Strsep(&pathp, AG_PATHSEPMULTI);
	     dir != NULL;
	     dir = Strsep(&pathp, AG_PATHSEPMULTI)) {
		Strlcpy(file, dir, sizeof(file));

		if (name[0] != AG_PATHSEPCHAR) {
			Strlcat(file, AG_PATHSEP, sizeof(file));
		}
		Strlcat(file, name, sizeof(file));
		if (ext != NULL) {
			Strlcat(file, ".", sizeof(file));
			Strlcat(file, ext, sizeof(file));
		}
		if ((rv = AG_FileExists(file)) == 1) {
			if (Strlcpy(path, file, path_len) >= path_len) {
				AG_SetError(_("The search path is too big."));
				return (-1);
			}
			return (0);
		} else if (rv == -1) {
			AG_SetError("%s: %s", file, AG_GetError());
			return (-1);
		}
	}
	AG_GetString(agConfig, path_key, path, path_len);
	AG_SetError(_("Cannot find %s.%s (in <%s>:%s)."), name,
	    (ext != NULL) ? ext : "", path_key, path);
	return (-1);
}
Пример #5
0
BOOL LoadGlobalIconPng(char *path, char *filename)
{
	
   char fullpath[MAXPATHLEN + 1];
   int len;
      
   if(filename == NULL) return FALSE;
   if(strlen(filename) >= MAXPATHLEN) return FALSE;
   fullpath[0] = '\0';
   if(path == NULL) {
#ifdef RSSDIR
      strcpy(fullpath, RSSDIR);
#else
      strcpy(fullpath, "./.xm7/");
#endif
   } else {
      if(strlen(path) >= MAXPATHLEN) return FALSE;
      strcpy(fullpath, path); 
   }
   
   len = strlen(fullpath) + strlen(filename);
   if(len >= MAXPATHLEN) return FALSE;
   strcat(fullpath, filename);
   
   if(!AG_FileExists(fullpath)) { // Fallback
      return FALSE;
   } else {
      AG_Surface *mark;
      AG_Surface *scaled;
      scaled = NULL;
      
      mark = AG_SurfaceFromPNG(fullpath);
      if(mark != NULL) {
	 SDL_Surface *icon;
	 
	 if(AG_ScaleSurface(mark, 32, 32, &scaled) < 0) { // Scale because Windows-Icon must be 32x32.
	    AG_SurfaceFree(mark);
	    return FALSE;
	 }
	 
	 icon = (SDL_Surface *)AG_SurfaceExportSDL(scaled);
	 if(icon == NULL) {
	    AG_SurfaceFree(scaled);
	    AG_SurfaceFree(mark);
	    return FALSE;
	 }
	 
	 if(AG_UsingSDL(NULL) && (agDriverSw != NULL)) {
	    SDL_WM_SetIcon(icon, NULL);
	 } else if(agDriverMw) {
//	    AG_WindowSetIcon(MainWindow, mark);
	 }
	 
	 SDL_FreeSurface(icon);
	 AG_SurfaceFree(scaled);
	 AG_SurfaceFree(mark);
	 return TRUE;
      } else {
	 return FALSE; // Illegal PNG.
      }
   }

}