Exemple #1
0
    std::string FS::readlink(std::string path) const
    {
        LowLevel::INode buf;
        if (!this->retrievePathToINode(path, buf))
            throw Exception::FileNotFound();

        if (buf.type == LowLevel::INodeType::INT_SYMLINK)
        {
            // Read the link information out of the file.
            FSFile* file = new FSFile(this->filesystem, this->stream, buf.inodeid);
            file->open(std::ios_base::in);
            char* buffer = (char*)malloc(buf.dat_len + 1);
            std::streamsize count = file->read(buffer, buf.dat_len);
            if (count < buf.dat_len)
                buffer[count] = '\0';
            else
                buffer[buf.dat_len] = '\0';
            std::string result = buffer;
            free(buffer);

            // Check to make sure it is valid.
            if (count != buf.dat_len)
                throw Exception::InternalInconsistency();
            
            return result;
        }
        else
            throw Exception::NotSupported();
    }
Exemple #2
0
void Media::add_cache(unsigned int id, FSFile & fp)
{
    FileStream stream(fp);
    AudioType type = (AudioType)stream.read_uint32();
    if (type == NONE)
        return;
    unsigned int size = stream.read_uint32();
    size_t pos = fp.tell();

    bool is_wav = type == WAV;
    SoundData * data;
    if ((is_wav && size <= WAV_STREAM_THRESHOLD) ||
        (!is_wav && size <= OGG_STREAM_THRESHOLD))
    {
#ifdef CHOWDREN_IS_3DS
        data = new SoundMemory(id, fp, type, size);
#else
        unsigned char * sound_data = new unsigned char[size];
        fp.read(sound_data, size); 
        data = new SoundMemory(id, sound_data, type, size);
        delete[] sound_data;
#endif
    } else {
        data = new SoundCache(id, fp.tell(), type, size);
    }
    media.sounds[id] = data;
    fp.seek(pos + size);
}
Exemple #3
0
void FSDir::readContent()
{
	freeContent();
	std::string command = "ls -lh";

	command += " " + getAbsolutePath() + "/";
	command += " | tail -n +2 ";
	command += " | ";
	command += AWK;

	std::string ls = exec(command);

	std::istringstream iss(ls);
	std::string line;

	while ( line.clear(), getline(iss, line) )
	{
		std::istringstream linestream(line);
		std::string filename;
		std::string date; 
		std::string size;
		std::string owner;
		std::string perms;

		getline(linestream, filename, '#');
		getline(linestream, date, '#');
		getline(linestream, size, '#');
		getline(linestream, owner, '#');
		getline(linestream, perms);

		if ( ! hidden && filename[0] == '.' )
			continue;

		if ( perms[0] == 'd' )
		{
			FSDir * d = new FSDir( getAbsolutePath() + PATH_SEPARATOR + filename);
			d->setAttrs(date, owner, size, perms);
			content.push_back((FSObject*) d);
		}
		else if ( perms[0] == 'l' )
		{
			FSSymlink * d = new FSSymlink( getAbsolutePath() + PATH_SEPARATOR + filename);
			d->setAttrs(date, owner, size, perms);
			content.push_back((FSObject*) d);
		}
		else
		{
			FSFile * f = new FSFile(getAbsolutePath() + PATH_SEPARATOR + filename);
			f->setAttrs(date, owner, size, perms);
			content.push_back((FSObject*) f);
		}
	}

	std::sort(content.begin(), content.end(), directoriesFirst);
}
Exemple #4
0
    FSFile FS::open(std::string path)
    {
        this->ensurePathExists(path);

        LowLevel::INode buf;
        if (!this->retrievePathToINode(path, buf))
            throw Exception::FileNotFound();

        // Open the file and return it.
        FSFile file = this->filesystem->getFile(buf.inodeid);
        file.open();
        return file;
    }
Exemple #5
0
        int FuseLink::open(const char *path, struct fuse_file_info *options)
        {
            FuseLink::filesystem->setuid(fuse_get_context()->uid);
            FuseLink::filesystem->setgid(fuse_get_context()->gid);

            // Open the file to see whether it exists.
            try
            {
                FSFile file = FuseLink::filesystem->open(path);
                file.close();
                return 0;
            }
            catch (std::exception& e)
            {
                return FuseLink::handleException(e, "open");
            }
        }
Exemple #6
0
        int FuseLink::write(const char *path, const char *in, size_t length,
                off_t offset, struct fuse_file_info *options)
        {
            FuseLink::filesystem->setuid(fuse_get_context()->uid);
            FuseLink::filesystem->setgid(fuse_get_context()->gid);

            // Write data to the file.
            try
            {
                if (offset > MSIZE_FILE || ((uint64_t) offset + (uint64_t) length) > MSIZE_FILE)
                    return -EFBIG;
                FuseLink::filesystem->touch(path, "cma");
                FSFile file = FuseLink::filesystem->open(path);
                file.seekp(offset);
                file.write(in, length);
                file.close();
                if (file.fail() || file.bad())
                    return -EIO;
                return length;
            }
            catch (std::exception& e)
            {
                return FuseLink::handleException(e, "write");
            }
        }
Exemple #7
0
        int FuseLink::read(const char *path, char *out, size_t length,
                off_t offset, struct fuse_file_info *options)
        {
            FuseLink::filesystem->setuid(fuse_get_context()->uid);
            FuseLink::filesystem->setgid(fuse_get_context()->gid);

            // Read data from the file.
            try
            {
                if (offset > MSIZE_FILE || ((uint64_t) offset + (uint64_t) length) > MSIZE_FILE)
                    return -EFBIG;
                FuseLink::filesystem->touch(path, "a");
                FSFile file = FuseLink::filesystem->open(path);
                file.seekg(offset);
                uint32_t read = file.read(out, length);
                file.close();
                if (file.fail() || file.bad())
                    return -EIO;
                return read;
            }
            catch (std::exception& e)
            {
                return FuseLink::handleException(e, "read");
            }
        }
Exemple #8
0
    void FS::symlink(std::string linkPath, std::string targetPath)
    {
        auto configuration = [&](LowLevel::INode& buf)
        {
        };
        this->performCreation(LowLevel::INodeType::INT_SYMLINK, linkPath, 0755, configuration);

        // We just created the file, so if this fails then
        // it's an internal inconsistency.
        LowLevel::INode buf;
        if (!this->retrievePathToINode(linkPath, buf))
            throw Exception::FileNotFound();
       
        try
        {
            FSFile f = this->filesystem->getFile(buf.inodeid);
            f.open();
            f.write(targetPath.c_str(), targetPath.length());
            f.close();
            if (f.fail() || f.bad())
                throw Exception::InternalInconsistency();
        }
        catch (...)
        {
            // Delete the file from disk since we failed to
            // write to it (at least in some manner).  Then
            // rethrow the exception.
            this->unlink(linkPath);
            throw;
        }
    }
Exemple #9
0
void GameManager::set_frame(int index)
{
    ignore_controls = false;

#ifdef CHOWDREN_IS_DEMO
    idle_timer = 0.0;
    idle_timer_started = false;
#endif

#ifndef CHOWDREN_SAMPLES_OVER_FRAMES
    media.stop_samples();
#endif

    if (frame->index != -1)
        frame->on_end();

    if (index == -2) {
        platform_begin_draw();
        media.stop_samples();
        Render::clear(Color(0, 0, 0, 255));
        platform_swap_buffers();
#ifdef CHOWDREN_IS_DEMO
        reset_timer = 0.0;
#endif
        index = 0;
        // reset_global_data();
        reset_globals();
    }

    std::cout << "Setting frame: " << index << std::endl;

#ifdef CHOWDREN_USER_PROFILER
    std::string logline = "Setting frame: " + number_to_string(index) + "\n";
    user_log.write(&logline[0], logline.size());
#endif

    frame->set_index(index);

    std::cout << "Frame set" << std::endl;
}
Exemple #10
0
    void FS::truncate(std::string path, off_t size)
    {
        if (size > MSIZE_FILE)
            throw Exception::FileTooBig();
        this->ensurePathExists(path);

        LowLevel::INode buf;
        if (!this->retrievePathToINode(path, buf))
            throw Exception::FileNotFound();
        this->touchINode(buf, "cma");
        this->saveINode(buf);

        // Truncate the file to the desired size.
        FSFile file = this->filesystem->getFile(buf.inodeid);
        file.open();
        file.truncate(size);
        file.close();
        if (file.fail() || file.bad())
            throw Exception::InternalInconsistency();
    }
Exemple #11
0
void GameManager::init()
{
#ifdef CHOWDREN_USER_PROFILER
    user_log.open("log.txt", "w");
#endif

#ifdef CHOWDREN_USE_PROFILER
    PROFILE_SET_DAMPING(0.0);
#endif
    frame = &static_frames;

#ifdef CHOWDREN_IS_DEMO
    idle_timer_started = false;
    global_time = show_build_timer = reset_timer = manual_reset_timer = 0.0;
#endif

#ifdef CHOWDREN_USE_JOYTOKEY
    simulate_count = 0;
    axis_moved = false;
    last_axis = -1;
    deadzone = 0.4f;
    pad_selected = false;
    pad_disconnected = false;
    for (int i = 0; i < CHOWDREN_BUTTON_MAX-1; i++)
        key_mappings[i] = -1;
    for (int i = 0; i < CHOWDREN_AXIS_MAX-1; i++) {
        axis_pos_mappings[i] = -1;
        axis_neg_mappings[i] = -1;
        axis_values[i] = 0;
    }
#endif
    platform_init();
    media.init();
    set_window(false);

    // application setup
    preload_images();
    reset_globals();
    setup_keys(this);

    // setup random generator from start
    cross_srand((unsigned int)platform_get_global_time());

    fps_limit.start();
    set_framerate(FRAMERATE);

    int start_frame = 0;
#if defined(CHOWDREN_IS_AVGN)
    start_frame = 0;
#elif defined(CHOWDREN_IS_HFA)
    start_frame = 0;
#elif defined(CHOWDREN_IS_FP)
    player_died = false;
    lives = 3;
    start_frame = 0;
    // values->set(1, 2);
    // values->set(12, 2);
#elif defined(CHOWDREN_IS_NAH)
    platform_set_scale_type(2);
    // start_frame = 3;
    // set_local("fre");
    // values->set(13, 25);
    // strings->set(23, "OBJETS");
    // strings->set(9, "-fre");
#else
    start_frame = 0;
#endif

#ifdef NDEBUG
    set_frame(0);
#else
    set_frame(start_frame);
#endif
}
Exemple #12
0
bool GameManager::update()
{
#ifdef CHOWDREN_USE_DYNAMIC_NUMBER
    static int save_time = 0;
    save_time--;
    if (save_time <= 0) {
        save_alterable_debug();
        save_time += 60;
    }
#endif

#ifdef SHOW_STATS
    bool show_stats = false;
    static int measure_time = 0;
    measure_time -= 1;
    if (measure_time <= 0) {
        measure_time = 200;
        show_stats = true;
    }
#endif

#ifdef CHOWDREN_USER_PROFILER
    static int frame = 0;
    frame++;
    std::stringstream ss;
    ss << "Frame " << frame << ": " << fps_limit.dt << " ";
#endif

    // update input
    keyboard.update();
    mouse.update();

    platform_poll_events();

#ifdef CHOWDREN_USE_GWEN
    gwen.update();
#endif

    // player controls
    int new_control = get_player_control_flags(1);
    player_press_flags = new_control & ~(player_flags);
    player_flags = new_control;

    // joystick controls
    new_control = get_joystick_control_flags(1);
    joystick_press_flags = new_control & ~(joystick_flags);
    joystick_release_flags = joystick_flags & ~(new_control);
    joystick_flags = new_control;

#ifdef CHOWDREN_USE_JOYTOKEY
    for (int i = 0; i < simulate_count; i++) {
        if (simulate_keys[i].down) {
            simulate_keys[i].down = false;
            continue;
        }
        keyboard.remove(simulate_keys[i].key);
        simulate_keys[i] = simulate_keys[simulate_count-1];
        i--;
        simulate_count--;
    }

    for (int i = 0; i < CHOWDREN_BUTTON_MAX-1; i++) {
        int key = key_mappings[i];
        if (key == -1)
            continue;
        if (is_joystick_pressed_once(1, i+1))
            keyboard.add(key);
        else if (is_joystick_released_once(1, i+1))
            keyboard.remove(key);
    }
    axis_moved = false;
    for (int i = 0; i < CHOWDREN_AXIS_MAX-1; i++) {
        float value = get_joystick_axis(1, i+1);
        int pos = axis_pos_mappings[i];
        int neg = axis_neg_mappings[i];

        int axis_value = 0;
        if (value > deadzone) {
            last_axis = i;
            if (pos != -1 && axis_values[i] != 1)
                keyboard.add(pos);
            axis_value = 1;
        } else {
            if (pos != -1 && axis_values[i] == 1)
                keyboard.remove(pos);
        }

        if (value < -deadzone) {
            last_axis = i;
            if (neg != -1 && axis_values[i] != -1)
                keyboard.add(neg);
            axis_value = -1;
        } else {
            if (neg != -1 && axis_values[i] == -1)
                keyboard.remove(neg);
        }

        axis_values[i] = axis_value;

        static bool last_move = false;
        bool new_move = axis_value != 0;
        if (new_move && new_move != last_move)
            axis_moved = true;

        last_move = new_move;
    }

    static bool last_connected = false;
    bool connected = is_joystick_attached(1);
    pad_selected = connected && last_connected != connected;
    pad_disconnected = !connected && last_connected != connected;
    last_connected = connected;
#endif

    // update mouse position
    platform_get_mouse_pos(&mouse_x, &mouse_y);

#ifdef SHOW_STATS
    if (show_stats)
        std::cout << "Framerate: " << fps_limit.current_framerate
            << std::endl;
#endif

    if (platform_has_error()) {
        if (platform_display_closed())
            return false;
    } else {
        double event_update_time = platform_get_time();

        int ret = update_frame();

#ifdef CHOWDREN_USER_PROFILER
        ss << (platform_get_time() - event_update_time) << " ";
#endif
#ifdef SHOW_STATS
        if (show_stats)
            std::cout << "Event update took " <<
                platform_get_time() - event_update_time << std::endl;
#endif

        if (ret == 0)
            return false;
        else if (ret == 2)
            return true;

        if (platform_display_closed())
            return false;
    }

    double draw_time = platform_get_time();

    draw();

#ifdef CHOWDREN_USER_PROFILER
    ss << (platform_get_time() - draw_time) << " ";
#endif

#ifdef SHOW_STATS
    if (show_stats) {
        std::cout << "Draw took " << platform_get_time() - draw_time
            << std::endl;
#ifndef NDEBUG
        print_instance_stats();
#endif
        platform_print_stats();
    }
#endif

    fps_limit.finish();

#ifdef CHOWDREN_USER_PROFILER
    ss << "\n";
    std::string logline = ss.str();
    user_log.write(&logline[0], logline.size());
#endif

#ifdef CHOWDREN_USE_PROFILER
    static int profile_time = 0;
    profile_time -= 1;
    if (profile_time <= 0) {
        profile_time += 500;
        PROFILE_UPDATE();
        PROFILE_OUTPUT("data:/profile.txt");
    }
#endif

    return true;
}