Beispiel #1
0
static int mp3fs_readlink(const char *path, char *buf, size_t size) {
    char* origpath;
    ssize_t len;
    
    mp3fs_debug("readlink %s", path);
    
    errno = 0;
    
    origpath = translate_path(path);
    if (!origpath) {
        goto translate_fail;
    }
    
    convert_path(origpath, 1);
    
    len = readlink(origpath, buf, size - 2);
    if (len == -1) {
        goto readlink_fail;
    }
    
    buf[len] = '\0';
    
    convert_path(buf, 0);
    
readlink_fail:
    free(origpath);
translate_fail:
    return -errno;
}
Beispiel #2
0
	bool move_file(const std::string& aPathFrom, const std::string& aPathTo)
	{
		boost::system::error_code ec;
		boost::filesystem::create_directories(boost::filesystem::path(convert_path(aPathTo)).parent_path());
		boost::filesystem::rename(convert_path(aPathFrom), convert_path(aPathTo), ec);
		return !ec;
	}
Beispiel #3
0
static int
xmp_opendir (const char *path, struct fuse_file_info *fi)
{
  int res;
  struct xmp_dirp *d = malloc (sizeof (struct xmp_dirp));
  if (d == NULL)
    return -ENOMEM;

  char path2[PATH_MAX];

  convert_path (path, path2);

  openrfs_fuse_drop_privs ();
  d->dp = opendir (path2);
  openrfs_fuse_restore_privs ();
  if (d->dp == NULL)
    {
      res = -errno;
      free (d);
      return res;
    }
  d->offset = 0;
  d->entry = NULL;

  fi->fh = (unsigned long) d;
  return 0;
}
Beispiel #4
0
void BaseFile::open(const char * filename, const char * mode)
{
    flags = 0;
    const char * new_mode;
    switch (*mode) {
        case 'r':
            new_mode = "rb";
            break;
        case 'w':
            flags |= WRITE;
            new_mode = "wb";
            break;
    }

    std::string file_string = convert_path(filename);
    std::string new_path = internal_path + "/" + file_string;
    FILE * fp = fopen(new_path.c_str(), new_mode);
    if (fp != NULL) {
        handle = (void*)fp;
        return;
    }
    AAsset * asset = AAssetManager_open(global_asset_manager,
                                        file_string.c_str(),
                                        AASSET_MODE_UNKNOWN);
    if (asset == NULL) {
        flags |= CLOSED;
        return;
    }
    flags |= ANDROID_ASSET;
    handle = (void*)asset;
}
Beispiel #5
0
int KuhnMunkres::step5()
{
    int count = 0;
    path[count][0] = z0_row;
    path[count][1] = z0_column;
    bool done = false;
    while (!done) {
        int row = find_star_in_column(path.at(count).at(1));
        if (row >= 0) {
            ++count;
            path[count][0] = row;
            path[count][1] = path.at(count - 1).at(1);
        }
        else
            done = true;
        if (!done) {
            int column = find_prime_in_row(path.at(count).at(0));
            ++count;
            path[count][0] = path.at(count - 1).at(0);
            path[count][1] = column;
        }
    }
    convert_path(count);
    clear_covers();
    erase_primes();
    return 3;
}
Beispiel #6
0
void BinaryObject::save_file(const chowstring & filename)
{
    std::cout << "Save binary array: " << filename << std::endl;
    FSFile fp(convert_path(filename).c_str(), "w");
    fp.write(data, size);
    fp.close();
}
Beispiel #7
0
void SurfaceObject::load(const std::string & filename)
{
    if (selected_image == NULL)
        return;
    Color old_trans = selected_image->transparent;
    selected_image->reset();
    selected_image->transparent = Color(255, 0, 255); // old_trans;

    std::string path = convert_path(filename);
    Image * image = NULL;
#ifdef CHOWDREN_USE_CAPTURE
    if (!CaptureObject::filename.empty() &&
        CaptureObject::filename == path)
    {
        image = &CaptureObject::image;
    }
#endif
    if (image == NULL)
        image = get_image_cache(path, 0, 0, 0, 0, selected_image->transparent);
    selected_image->set_image(image);
    if (image == NULL)
        load_failed = true;

    set_edit_image(selected_index);
}
Beispiel #8
0
void INI::save_file(const chowstring & fn, bool force)
{
    if (fn.empty() || (read_only && !force))
        return;
    changed = false;
    filename = convert_path(fn);
    std::cout << "Saving: " << filename << std::endl;
    platform_create_directories(get_path_dirname(filename));
    std::stringstream out;
    get_data(out);
    chowstring outs = out.str();

    if (!encrypt_key.empty())
        encrypt_ini_data(outs, encrypt_key);

    if (use_compression) {
        compress_huffman(outs, filename.c_str());
        return;
    }

#ifdef CHOWDREN_USE_BLOWFISH_CACHE
    if (BlowfishObject::set_cache(filename, outs))
        return;
#endif

    FSFile fp(filename.c_str(), "w");
    if (!fp.is_open()) {
        std::cout << "Could not save INI file: " << filename << std::endl;
        return;
    }
	if (!outs.empty())
        fp.write(&outs[0], outs.size());
    fp.close();
}
Beispiel #9
0
void* geSysFileOpen(const char* filename, int mode){
	LibGE_AndroidContext* context = (LibGE_AndroidContext*)libge_context->syscontext;
	if(!context){
		context = _ge_GetAndroidContext();
	}
	bool isAsset = false;
	void* ret = geLibcFileOpen(filename, mode);
	if(!ret){
		ret = geLibcFileOpen(_ge_BuildPath(context->state->activity->internalDataPath, filename), mode);
	}
	if(!ret){
		char* path = convert_path(filename);
// 		gePrintDebug(0x100, "Android converted path : '%s'\n", path);
		ret = AAssetManager_open(context->state->activity->assetManager, path, AASSET_MODE_STREAMING);
		geFree(path);
		isAsset = true;
	}
	if(ret){
		_ge_android_fd* fd = (_ge_android_fd*)geMalloc(sizeof(_ge_android_fd));
		fd->isAsset = isAsset;
		fd->fd = ret;
		ret = (void*)fd;
	}
	return ret;
}
Beispiel #10
0
void ArrayObject::save(const chowstring & filename)
{
    FSFile fp(convert_path(filename).c_str(), "w");
    if (!fp.is_open())
        return;
    WriteStream stream;

    stream.write(CT_ARRAY_MAGIC, sizeof(CT_ARRAY_MAGIC));
    stream.write_int16(ARRAY_MAJOR_VERSION);
    stream.write_int16(ARRAY_MINOR_VERSION);
    stream.write_int32(data.x_size);
    stream.write_int32(data.y_size);
    stream.write_int32(data.z_size);

    int flags = 0;
    if (data.is_numeric)
        flags |= NUMERIC_FLAG;
    if (data.offset != 0)
        flags |= BASE1_FLAG;
    stream.write_int32(flags);

    for (int i = 0; i < data.x_size * data.y_size * data.z_size; i++) {
        if (data.is_numeric) {
            stream.write_int32(int(data.array[i]));
        } else {
            stream.write_int32(data.strings[i].size());
            stream.write_string(data.strings[i]);
        }
    }

    stream.save(fp);
    fp.close();
}
Beispiel #11
0
void BinaryArray::load_file(const std::string & filename)
{
    size_t size;
    char * data;
    read_file(convert_path(filename).c_str(), &data, &size);
    current->data.write(data, size);
    delete[] data;
}
Beispiel #12
0
int main(int argc, char **argv)
{
  char *input_file;
  char *output_file;

  if (argc != 3)
  {
    puts(HELP);
    return 1;
  }

  input_file = convert_path(argv[1]);
  if (input_file[0] == 0)
    {
      free(input_file);
      printf("Missing input-filename\n");
      return 1;
    }

  output_file = convert_path(argv[2]);
  if (output_file[0] == 0)
    {
      free(input_file);
      free(output_file);
      printf("Missing output-filename\n");
      return 1;
    }

  out = fopen(output_file, "wb");
  if (out == NULL)
    {
      free(input_file);
      free(output_file);
    	printf("Cannot open output file");
    	return 1;
     }

  read_input_file(input_file);

  free(input_file);
  free(output_file);
  fclose(out);

  return 0;
}
Beispiel #13
0
static int
xmp_link (const char *from, const char *to)
{
  int res;
  char from2[PATH_MAX];
  char to2[PATH_MAX];

  convert_path (from, from2);
  convert_path (to, to2);
  openrfs_fuse_drop_privs ();
  res = link (from2, to2);
  openrfs_fuse_restore_privs ();

  if (res == -1)
    return -errno;

  // TODO This operation has to be handle in different way (inode number)
  openrfs_on_modify(from);
  return 0;
}
Beispiel #14
0
void ArrayObject::load(const chowstring & filename)
{
    FSFile fp(convert_path(filename).c_str(), "r");
    if (!fp.is_open()) {
        std::cout << "Could not load data.array " << filename << std::endl;
        return;
    }

    FileStream stream(fp);

    chowstring magic;
    stream.read_string(magic, sizeof(CT_ARRAY_MAGIC));

    if (magic.compare(0, sizeof(CT_ARRAY_MAGIC),
                      CT_ARRAY_MAGIC, sizeof(CT_ARRAY_MAGIC)) != 0) {
        std::cout << "Invalid CT_ARRAY_MAGIC: " << filename << std::endl;
        std::cout << magic << " " << CT_ARRAY_MAGIC << std::endl;
        return;
    }

    if (stream.read_int16() != ARRAY_MAJOR_VERSION) {
        std::cout << "Invalid ARRAY_MAJOR_VERSION" << std::endl;
        return;
    }

    if (stream.read_int16() != ARRAY_MINOR_VERSION) {
        std::cout << "Invalid ARRAY_MINOR_VERSION" << std::endl;
        return;
    }

    data.x_size = stream.read_int32();
    data.y_size = stream.read_int32();
    data.z_size = stream.read_int32();

    int flags = stream.read_int32();
    data.is_numeric = (flags & NUMERIC_FLAG) != 0;
    data.offset = int((flags & BASE1_FLAG) != 0);

    delete[] data.array;
    delete[] data.strings;
    data.array = NULL;
    data.strings = NULL;
    clear();

    for (int i = 0; i < data.x_size * data.y_size * data.z_size; i++) {
        if (data.is_numeric) {
            data.array[i] = ArrayNumber(stream.read_int32());
        } else {
            stream.read_string(data.strings[i], stream.read_int32());
        }
    }

    fp.close();
}
Beispiel #15
0
void BinaryArray::load_workspaces(const std::string & filename)
{
    FSFile fp(convert_path(filename).c_str(), "r");
    FileStream stream(fp);
    Workspace * workspace;
    while (!stream.at_end()) {
        workspace = new Workspace(stream);
        workspaces[workspace->name] = workspace;
    }
    fp.close();
    switch_workspace(current);
}
Beispiel #16
0
static int mp3fs_readdir(const char *path, void *buf, fuse_fill_dir_t filler,
                         off_t offset, struct fuse_file_info *fi) {
    char* origpath;
    char* origfile;
    DIR *dp;
    struct dirent *de;
    
    mp3fs_debug("readdir %s", path);
    
    errno = 0;
    
    origpath = translate_path(path);
    if (!origpath) {
        goto translate_fail;
    }
    
    /* 2 for directory separator and NULL byte */
    origfile = malloc(strlen(origpath) + NAME_MAX + 2);
    if (!origfile) {
        goto origfile_fail;
    }
    
    dp = opendir(origpath);
    if (!dp) {
        goto opendir_fail;
    }
    
    while ((de = readdir(dp))) {
        struct stat st;
        
        snprintf(origfile, strlen(origpath) + NAME_MAX + 2, "%s/%s", origpath,
                 de->d_name);
        
        if (lstat(origfile, &st) == -1) {
            goto stat_fail;
        } else {
            if (S_ISREG(st.st_mode) || S_ISLNK(st.st_mode)) {
                convert_path(de->d_name, 0);
            }
        }
        
        if (filler(buf, de->d_name, &st, 0)) break;
    }
    
stat_fail:
    closedir(dp);
opendir_fail:
    free(origfile);
origfile_fail:
    free(origpath);
translate_fail:
    return -errno;
}
Beispiel #17
0
void Media::play(const std::string & in, int channel, int loop)
{
    std::string filename = convert_path(in);
    size_t size = platform_get_file_size(filename.c_str());
    if (size <= 0) {
        std::cout << "Audio file does not exist: " << filename << std::endl;
        return;
    }
    AudioType type = get_audio_type(filename);
    SoundFile data(INVALID_ASSET_ID, filename, type, size);
    play(&data, channel, loop);
}
Beispiel #18
0
static int
xmp_rename (const char *from, const char *to)
{
  int res;
  char from2[PATH_MAX];
  char to2[PATH_MAX];

  convert_path (from, from2);
  convert_path (to, to2);

  openrfs_fuse_drop_privs ();
  res = rename (from2, to2);
  openrfs_fuse_restore_privs ();
  if (res == -1)
    return -errno;

  // TODO Make more clever with one operation
  openrfs_on_delete(from);
  openrfs_on_modify(from);
  return 0;
}
Beispiel #19
0
static int mp3fs_getattr(const char *path, struct stat *stbuf) {
    char* origpath;
    struct transcoder* trans;
    
    mp3fs_debug("getattr %s", path);
    
    errno = 0;
    
    origpath = translate_path(path);
    if (!origpath) {
        goto translate_fail;
    }
    
    /* pass-through for regular files */
    if (lstat(origpath, stbuf) == 0) {
        goto passthrough;
    } else {
        /* Not really an error. */
        errno = 0;
    }
    
    convert_path(origpath, 1);
    
    if (lstat(origpath, stbuf) == -1) {
        goto stat_fail;
    }
    
    /*
     * Get size for resulting mp3 from regular file, otherwise it's a
     * symbolic link. */
    if (S_ISREG(stbuf->st_mode)) {
        trans = transcoder_new(origpath);
        if (!trans) {
            goto transcoder_fail;
        }
        
        stbuf->st_size = trans->totalsize;
        stbuf->st_blocks = (stbuf->st_size + 512 - 1) / 512;
        
        transcoder_finish(trans);
        transcoder_delete(trans);
    }
    
transcoder_fail:
stat_fail:
passthrough:
    free(origpath);
translate_fail:
    return -errno;
}
Beispiel #20
0
static int
xmp_listxattr (const char *path, char *list, size_t size)
{
  int res;
  char path2[PATH_MAX];

  convert_path (path, path2);
  openrfs_fuse_drop_privs ();
  res = llistxattr (path, list, size);
  openrfs_fuse_restore_privs ();
  if (res == -1)
    return -errno;
  return res;
}
Beispiel #21
0
static int
xmp_getxattr (const char *path, const char *name, char *value, size_t size)
{
  int res;
  char path2[PATH_MAX];

  convert_path (path, path2);
  openrfs_fuse_drop_privs ();
  res = lgetxattr (path2, name, value, size);
  openrfs_fuse_restore_privs ();
  if (res == -1)
    return -errno;
  return res;
}
Beispiel #22
0
void Active::load(const chowstring & filename, int anim, int dir, int frame,
                  int hot_x, int hot_y, int action_x, int action_y,
                  TransparentColor transparent_color)
{
    if (anim >= animations->count)
        return;
    if (dir < 0 || dir >= 32)
        return;
    Animation * animation = animations->items[anim];
    Direction * direction = animation->dirs[dir];
    if (frame >= direction->frame_count)
        return;

    Image * new_image = get_image_cache(convert_path(filename), 0, 0, 0, 0,
                                        transparent_color);

    if (new_image == NULL) {
        std::cout << "Could not load image " << filename << std::endl;
        return;
    }

    new_image->hotspot_x = get_active_load_point(hot_x, new_image->width);
    new_image->hotspot_y = get_active_load_point(hot_y, new_image->height);
    new_image->action_x = get_active_load_point(action_x, new_image->width);
    new_image->action_y = get_active_load_point(action_y, new_image->height);

#ifdef CHOWDREN_ACTIVE_LOAD_SINGLE
    image = new_image;
    direction_data = direction;
    current_animation = forced_animation = anim;
    forced_frame = frame;
#else
    Image * old_image = direction->frames[frame];
    if (old_image == new_image)
        return;
    old_image->destroy();
    new_image->upload_texture();
    direction->frames[frame] = new_image;

    // update the frame for all actives of this type
    // this may break in the future, maybe
    ObjectList::iterator it;
    ObjectList & list = this->frame->instances.items[id];
    for (it = list.begin(); it != list.end(); ++it) {
        Active * obj = (Active*)it->obj;
        obj->image = NULL;
        obj->update_frame();
    }
#endif
}
Beispiel #23
0
static int
xmp_getattr (const char *path, struct stat *stbuf)
{
  int res;
  char path2[PATH_MAX];

  convert_path (path, path2);
  openrfs_fuse_drop_privs ();
  res = lstat (path2, stbuf);
  openrfs_fuse_restore_privs ();
  if (res == -1)
    return -errno;

  return 0;
}
Beispiel #24
0
static int
xmp_open (const char *path, struct fuse_file_info *fi)
{
  int fd;
  char path2[PATH_MAX];

  convert_path (path, path2);
  openrfs_fuse_drop_privs ();
  fd = open (path2, fi->flags);
  openrfs_fuse_restore_privs ();
  if (fd == -1)
    return -errno;

  fi->fh = fd;
  return 0;
}
Beispiel #25
0
static int
xmp_access (const char *path, int mask)
{
  int res;
  char path2[PATH_MAX];

  convert_path (path, path2);

  openrfs_fuse_drop_privs ();
  res = access (path2, mask);
  openrfs_fuse_restore_privs ();
  if (res == -1)
    return -errno;

  return 0;
}
Beispiel #26
0
static int
xmp_rmdir (const char *path)
{
  int res;
  char path2[PATH_MAX];

  convert_path (path, path2);
  openrfs_fuse_drop_privs ();
  res = rmdir (path2);
  openrfs_fuse_restore_privs ();
  if (res == -1)
    return -errno;

  openrfs_on_delete(path);
  return 0;
}
Beispiel #27
0
static int
xmp_symlink (const char *from, const char *to)
{
  int res;
  char path2[PATH_MAX];

  convert_path (to, path2);
  openrfs_fuse_drop_privs ();
  res = symlink (from, path2);
  openrfs_fuse_restore_privs ();
  if (res == -1)
    return -errno;

  openrfs_on_modify(to);
  return 0;
}
Beispiel #28
0
static int mp3fs_open(const char *path, struct fuse_file_info *fi) {
    char* origpath;
    struct transcoder* trans;
    int fd;
    
    mp3fs_debug("open %s", path);
    
    errno = 0;
    
    origpath = translate_path(path);
    if (!origpath) {
        goto translate_fail;
    }
    
    fd = open(origpath, fi->flags);
    
    /* File does exist, but can't be opened. */
    if (fd == -1 && errno != ENOENT) {
        goto open_fail;
    } else {
        /* Not really an error. */
        errno = 0;
    }
    
    /* File is real and can be opened. */
    if (fd != -1) {
        close(fd);
        goto passthrough;
    }
    
    convert_path(origpath, 1);
    
    trans = transcoder_new(origpath);
    if (!trans) {
        goto transcoder_fail;
    }
    
    /* Store transcoder in the fuse_file_info structure. */
    fi->fh = (uint64_t)trans;
    
transcoder_fail:
passthrough:
open_fail:
    free(origpath);
translate_fail:
    return -errno;
}
Beispiel #29
0
/* xattr operations are optional and can safely be left unimplemented */
static int
xmp_setxattr (const char *path, const char *name, const char *value,
	      size_t size, int flags)
{
  int res;
  char path2[PATH_MAX];

  convert_path (path, path2);
  openrfs_fuse_drop_privs ();
  res = lsetxattr (path2, name, value, size, flags);
  openrfs_fuse_restore_privs ();
  if (res == -1)
    return -errno;

  openrfs_on_modify(path);
  return 0;
}
Beispiel #30
0
static int
xmp_removexattr (const char *path, const char *name)
{
  int res;
  char path2[PATH_MAX];

  convert_path (path, path2);
  openrfs_fuse_drop_privs ();
  res = lremovexattr (path, name);
  openrfs_fuse_restore_privs ();
  if (res == -1)
    return -errno;

  // TODO Avoid check of complete file
  openrfs_on_modify(path);
  return 0;
}