예제 #1
0
static int import_images(lua_State *L)
{
  char *full_name = g_realpath(luaL_checkstring(L, -1));
  int result;

  if(!full_name || !g_file_test(full_name, G_FILE_TEST_EXISTS))
  {
    g_free(full_name);
    return luaL_error(L, "no such file or directory");
  }
  else if(g_file_test(full_name, G_FILE_TEST_IS_DIR))
  {
    result = dt_film_import(full_name);
    if(result == 0)
    {
      g_free(full_name);
      return luaL_error(L, "error while importing");
    }
    luaA_push(L, dt_lua_film_t, &result);
  }
  else
  {
    dt_film_t new_film;
    dt_film_init(&new_film);
    char *dirname = g_path_get_dirname(full_name);
    char *expanded_path = dt_util_fix_path(dirname);
    g_free(dirname);
    char *final_path = g_realpath(expanded_path);
    g_free(expanded_path);
    if(!final_path)
    {
      g_free(full_name);
      return luaL_error(L, "Error while importing : %s\n", strerror(errno));
    }
    result = dt_film_new(&new_film, final_path);
    free(final_path);
    if(result == 0)
    {
      if(dt_film_is_empty(new_film.id)) dt_film_remove(new_film.id);
      dt_film_cleanup(&new_film);
      g_free(full_name);
      return luaL_error(L, "error while importing");
    }

    result = dt_image_import(new_film.id, full_name, TRUE);
    if(dt_film_is_empty(new_film.id)) dt_film_remove(new_film.id);
    dt_film_cleanup(&new_film);
    if(result == 0)
    {
      g_free(full_name);
      return luaL_error(L, "error while importing");
    }
    luaA_push(L, dt_lua_image_t, &result);
  }
  g_free(full_name);
  return 1;
}
예제 #2
0
static gchar * dt_make_path_absolute(const gchar * input)
{
  gchar *filename = NULL;

  if(g_str_has_prefix(input, "file://")) // in this case we should take care of %XX encodings in the string (for example %20 = ' ')
  {
    input += strlen("file://");
    filename = g_uri_unescape_string(input, NULL);
  }
  else
    filename = g_strdup(input);

  if(g_path_is_absolute(filename) == FALSE)
  {
    char* current_dir = g_get_current_dir();
    char* tmp_filename = g_build_filename(current_dir, filename, NULL);
    g_free(filename);
    filename = g_realpath(tmp_filename);
    if(filename == NULL)
    {
      g_free(current_dir);
      g_free(tmp_filename);
      g_free(filename);
      return NULL;
    }
    g_free(current_dir);
    g_free(tmp_filename);
  }

  return filename;
}
static PyObject *
pygi_source_scanner_append_filename (PyGISourceScanner *self,
				     PyObject          *args)
{
  char *filename;

  if (!PyArg_ParseTuple (args, "s:SourceScanner.append_filename", &filename))
    return NULL;

  self->scanner->filenames = g_list_append (self->scanner->filenames,
					    g_realpath (filename));

  Py_INCREF (Py_None);
  return Py_None;
}
예제 #4
0
static int import_images(lua_State *L)
{
  char* full_name= g_realpath(luaL_checkstring(L,-1));
  int result;

  if (!g_file_test(full_name, G_FILE_TEST_EXISTS))
  {
      g_free(full_name);
      return luaL_error(L,"no such file or directory");
  } else if (g_file_test(full_name, G_FILE_TEST_IS_DIR))
  {
    result =dt_film_import(full_name);
    if(result == 0)
    {
      g_free(full_name);
      return luaL_error(L,"error while importing");
    }
    luaA_push(L,dt_lua_film_t,&result);
  }
  else
  {
    dt_film_t new_film;
    dt_film_init(&new_film);
    char* dirname =g_path_get_dirname(full_name);
    result = dt_film_new(&new_film,dirname);
    if(result == 0)
    {
      g_free(full_name);
      dt_film_cleanup(&new_film);
      free(dirname);
      return luaL_error(L,"error while importing");
    }

    result =dt_image_import(new_film.id,full_name,TRUE);
    free(dirname);
    dt_film_cleanup(&new_film);
    if(result == 0)
    {
      g_free(full_name);
      return luaL_error(L,"error while importing");
    }
    luaA_push(L,dt_lua_image_t,&result);
  }
  g_free(full_name);
  return 1;
}
예제 #5
0
static int
dt_mipmap_cache_get_filename(
  gchar* mipmapfilename, size_t size)
{
  int r = -1;
  char* abspath = NULL;

  // Directory
  char cachedir[DT_MAX_PATH_LEN];
  dt_loc_get_user_cache_dir(cachedir, sizeof(cachedir));

  // Build the mipmap filename
  const gchar *dbfilename = dt_database_get_path(darktable.db);
  if (!strcmp(dbfilename, ":memory:"))
  {
    snprintf(mipmapfilename, size, "%s", dbfilename);
    r = 0;
    goto exit;
  }

  abspath = g_realpath(dbfilename);
  if(!abspath)
    abspath = g_strdup(dbfilename);

  GChecksum* chk = g_checksum_new(G_CHECKSUM_SHA1);
  g_checksum_update(chk, (guchar*)abspath, strlen(abspath));
  const gchar *filename = g_checksum_get_string(chk);

  if(!filename || filename[0] == '\0')
    snprintf(mipmapfilename, size, "%s/%s", cachedir, DT_MIPMAP_CACHE_DEFAULT_FILE_NAME);
  else
    snprintf(mipmapfilename, size, "%s/%s-%s", cachedir, DT_MIPMAP_CACHE_DEFAULT_FILE_NAME, filename);

  g_checksum_free(chk);
  r = 0;

exit:
  g_free(abspath);

  return r;
}
예제 #6
0
파일: film.c 프로젝트: Coshibu/darktable
static int films_new(lua_State *L)
{
  const char * path = luaL_checkstring(L,-1);
  char * expanded_path = dt_util_fix_path(path);
  char * final_path = g_realpath(expanded_path);
  free(expanded_path);
  if(!final_path) {
    return luaL_error(L,"Couldn't create film for directory '%s' : %s\n",path,strerror(errno));
  }

  dt_film_t my_film;
  dt_film_init(&my_film);
  int film_id = dt_film_new(&my_film,final_path);
  free(final_path);
  if(film_id) {
    luaA_push(L,dt_lua_film_t,&film_id);
    return 1;
  } else {
    return luaL_error(L,"Couldn't create film for directory %s\n",path);
  }
}