Beispiel #1
0
int snapshot_read(char *name, snapshot_t *snapshot) {
	int result  = FALSE;
	int file    = -1;
	int version =  0;

	snapshot_t buffer;

	if ((file = FIO_OpenFile(name, O_RDONLY, 644)) == -1)
		goto end;

	if (FIO_ReadFile(file, &version, sizeof(version)) != sizeof(version))
		goto end;

	if (version != SETTINGS_VERSION)
		goto end;

	if (FIO_ReadFile(file, &buffer, sizeof(buffer)) != sizeof(buffer))
		goto end;

	*snapshot = buffer;

	result = TRUE;

#if SETTINGS_VERSION == 0x4A
	int nt;
	// Temporal fix for those affected by issue #333
	// Remove after increasing the version of the settings file
	if (snapshot->menu_order.named_temps[0] == 0 && snapshot->menu_order.named_temps[1] == 0)
		for (nt = 0; nt < LENGTH(snapshot->menu_order.named_temps); nt++)
			snapshot->menu_order.named_temps[nt] = nt;
#endif

end:
	if (file != -1)
		FIO_CloseFile(file);

	return result;
}
Beispiel #2
0
void cmodes_read() {
	int   id;
	int   version =  0;
	int file    = -1;

	cmodes_config_t buffer;

	for (id = 0; id < CMODES_MAX; id ++) {
		sprintf(cmodes_default.names[id], "%s %X", LP_WORD(L_S_CMODE_NAME), id);
		cmodes_default.order[id] = id;
	}

	for (id = 0; id < CMODES_MODES; id ++) {
		cmodes_default.assign[id] = CMODE_NONE;
	}

	cmodes_config = cmodes_default;

	if ((file = FIO_OpenFile(MKPATH_NEW(CMODES_CONFIG), O_RDONLY)) == -1)
		if ((file = FIO_OpenFile(MKPATH_OLD(CMODES_CONFIG), O_RDONLY)) == -1)
			goto end;

	if (FIO_ReadFile(file, &version, sizeof(version)) != sizeof(version))
		goto end;

	if (version != SNAPSHOT_VERSION)
		goto end;

	if (FIO_ReadFile(file, &buffer, sizeof(buffer)) != sizeof(buffer))
		goto end;

	cmodes_config = buffer;

end:
	if (file != -1)
		FIO_CloseFile(file);
}
Beispiel #3
0
static int script_load_symbols(void* tcc, void* script_state, char *filename)
{
    uint32_t size = 0;
    FILE* file = NULL;
    char *buf = NULL;
    uint32_t count = 0;
    uint32_t pos = 0;

    if( FIO_GetFileSize( filename, &size ) != 0 )
    {
        console_printf("Error loading '%s': File does not exist\n", filename);
        return -1;
    }
    buf = fio_malloc(size);
    if(!buf)
    {
        console_printf("Error loading '%s': File too large\n", filename);
        return -1;
    }

    file = FIO_OpenFile(filename, O_RDONLY | O_SYNC);
    if(!file)
    {
        console_printf("Error loading '%s': File does not exist\n", filename);
        fio_free(buf);
        return -1;
    }
    FIO_ReadFile(file, buf, size);
    FIO_CloseFile(file);

    while(buf[pos])
    {
        char address_buf[16];
        char symbol_buf[128];
        uint32_t length = 0;
        uint32_t address = 0;

        while(buf[pos + length] && buf[pos + length] != ' ' && length < sizeof(address_buf))
        {
            address_buf[length] = buf[pos + length];
            length++;
        }
        address_buf[length] = '\000';

        pos += length + 1;
        length = 0;

        while(buf[pos + length] && buf[pos + length] != '\r' && buf[pos + length] != '\n' && length < sizeof(symbol_buf))
        {
            symbol_buf[length] = buf[pos + length];
            length++;
        }
        symbol_buf[length] = '\000';

        pos += length + 1;
        length = 0;

        while(buf[pos + length] && (buf[pos + length] == '\r' || buf[pos + length] == '\n'))
        {
            pos++;
        }
        sscanf(address_buf, "%x", &address);

        module_exec(tcc, "tcc_add_symbol", 3, script_state, symbol_buf, (void*)address);
        count++;
    }

    /* ToDo: parse the old plugin sections as all needed OS stubs are already described there */
    module_exec(tcc, "tcc_add_symbol", 3, script_state, "strcpy", &strcpy);
    module_exec(tcc, "tcc_add_symbol", 3, script_state, "strlen", &strlen);

    fio_free(buf);
    return 0;
}
static int dng_show(char* filename)
{
    uint32_t size;
    if( FIO_GetFileSize( filename, &size ) != 0 ) return 0;

    FILE* f = FIO_OpenFile(filename, O_RDONLY | O_SYNC);
    void* buf = 0;

    /* should be big enough for the header */
    int header_maxsize = 65536;
    int* header = fio_malloc(header_maxsize);
    if (!header) return 0;

    int rc = FIO_ReadFile(f, header, header_maxsize);
    if( rc != header_maxsize ) goto err;

    if (header[0] != 0x002A4949 && header[1] != 0x00000008)
    {
        bmp_printf(FONT_MED, 0, 0, "Not a CHDK DNG");
        goto err;
    }

    raw_info.width = 0;
    raw_info.height = 0;
    
    int strip_offset = 0;

    int off = 8;
    for (int ifd = 0; off; ifd++)
        off = tif_parse_ifd(ifd, (void*)header, off, &strip_offset);

    fio_free(header); header = 0;

    if (!strip_offset) goto err;
    if (!raw_info.width) goto err;
    if (!raw_info.height) goto err;

    int raw_size = raw_info.width * raw_info.height * 14/8;
    buf = fio_malloc(raw_size);
    if (!buf) goto err;
    
    FIO_SeekSkipFile(f, strip_offset, SEEK_SET);
    rc = FIO_ReadFile(f, buf, raw_size);
    if (rc != raw_size) goto err;
    FIO_CloseFile(f); f = 0;

    info_led_on();
    /* fixme: this step is really slow */
    reverse_bytes_order(buf, raw_size);
    info_led_off();
    raw_info.buffer = buf;

    raw_set_geometry(raw_info.width, raw_info.height, raw_info.active_area.x1, raw_info.width - raw_info.active_area.x2, raw_info.active_area.y1, raw_info.height - raw_info.active_area.y2);
    raw_force_aspect_ratio_1to1();

    vram_clear_lv();
    raw_preview_fast_ex((void*)-1, (void*)-1, -1, -1, RAW_PREVIEW_COLOR_HALFRES);
    fio_free(buf); buf = 0;
    raw_set_dirty();
    
    bmp_printf(FONT_MED, 600, 460, " %dx%d ", raw_info.jpeg.width, raw_info.jpeg.height);
    return 1;
err:
    if (f) FIO_CloseFile(f);
    if (header) fio_free(header);
    if (buf) fio_free(buf);
    raw_set_dirty();
    return 0;
}