Пример #1
0
void		print_recursive(char **files, char *flags, char *folder, int i)
{
	char			**path;
	struct stat		*file_stat;
	int				boolean;

	if (!files || !files[0] || !ft_strlen(files[0]))
		return ;
	boolean = 0;
	if (!(path = malloc(sizeof(char*) * ALL_RECURSIVE_POSSIBILITY)))
		return ;
	path = ft_set_null(path);
	print_total(files, flags, folder);
	while (files[i])
	{
		if (!(file_stat = get_file_stat(files[i], file_stat, folder)))
			return ;
		print_by_flags(file_stat, flags, files, i);
		if (S_ISDIR(file_stat->st_mode) && files[i][0] != '.' && (boolean += 1))
			path = new_dir(path, files[i]);
		free(file_stat);
		i++;
	}
	ft_putstr("\n");
	free_files(files);
	(boolean) ? recursive_if(path, folder, flags) : free_files(path);
}
Пример #2
0
int main(int argc, char *argv[])
{
	if (argc != 3)
		fail("usage: cosunpack dump.b directory");

	cos = mmap_file(argv[1]);

	new_dir(argv[2]);

	do_toc(cos);

	return 0;
}
Пример #3
0
static int fatfs_provider_opendir(void *ip, posix_dir_t *dir) {
	FATFS *fs = (FATFS*) ip;
	DIR *d = new_dir();

	(void) fs;

	if (!d)
		return -1;
	dir->raw = d;
	if (wf_opendir(d, dir->path) != FR_OK) {
		release_dir(d);
		return -1;
	}
	return 0;
}
Пример #4
0
bool file_control::rename(QString base_name, QString old_name, QString new_name) {
    //lock mutex
    QMutexLocker locker(&mutex);
    QDir base_dir(base_name);
    QDir old_dir(base_name + "/" + old_name);
    QDir new_dir(base_name + "/" + new_name);
    QLOG_DEBUG() << "old name" << base_name + "/" + old_name;
    QLOG_DEBUG() << "new name" << base_name + "/" + new_name;
    if(old_dir.exists() && (!new_dir.exists()));
    else {
        return false;
    }
    //rename
    base_dir.rename(old_name, new_name);
    return true;
}
Пример #5
0
static int dconfirm(directive_t * d)
{
	source_t * src;

	if (d->values[0] == NULL) return 0;

	d->nd = new_dir(d->values[0], d->par);
	confirm_common(d);

	if (d->values[1] != NULL) {
		src = source_string(d->values[1]);
		d->nd = parse_directory(src, d->nd);
		free(src);
	}

	return 1;
}
Пример #6
0
bool TottAIStateMove::Update(float dt){
	AnimationMsg anim_msg;
	anim_msg.id = m_animation;
	anim_msg.loop = true;
	m_messenger->Notify(MSG_ANIMATION_PLAY, &anim_msg);
	m_messenger->Notify(MSG_NODE_GET_POSITION, &m_current_position);
	Ogre::Vector2 pos(m_current_position.x, m_current_position.z);
	float distance = pos.distance(m_target_position);
	if (distance <= 1.0f){
		return true;
	}
	Ogre::Vector2 dir = m_target_position - pos;
	dir.normalise();
	Ogre::Vector3 new_dir(dir.x, 0.0f, dir.y);
	m_messenger->Notify(MSG_CHARACTER_CONTROLLER_SET_DIRECTION, &new_dir);
	return false;
}
Пример #7
0
void SettingsDialog::selectPath()
{
    QDir cur_dir(ui->dataPathEdit->text());
    if (!cur_dir.exists())
        cur_dir.mkdir(cur_dir.absolutePath());

    QString path = QFileDialog::getExistingDirectory(
                this,
                tr("Choose path to store game"),
                cur_dir.absolutePath()
    );

    QDir new_dir(path);
    if (path.isEmpty() || cur_dir == new_dir)
        return;

    qDebug() << "SettingsDialog::selectPath() validating path" << path;
    QFileInfo fi(path);
    if (fi.isWritable()) {
        if (!QDir().rmdir(path)) {
            QMessageBox::critical(
                        this,
                        tr("Unable to use selected directory"),
                        tr("Unable to use selected directory\n\nDirectory is not empty, we need empty directory to relocate game data.")
            );
            return;
        }
        QDir().mkdir(path);
        ui->dataPathEdit->setText(path);
    } else {
        QMessageBox::critical(
                    this,
                    tr("Unable to use selected directory"),
                    tr("Unable to use selected directory\n\nDirectory is not writable, make sure that you are not using system directory.")
        );
    }
}
Пример #8
0
static void create_directory(const char *root, const char *dir) throw (CargoException) {
    const char *separator = dir;
    while (true) {
        /* find separator */
        bool found = false;
        while (separator) {
            separator++;
            if (*separator == 0) {
                break;
            }
            if (*separator == '/' || *separator == '\\') {
                found = true;
                break;
            }
        }
        if (!found) {
            break;
        }

        /* create directory */
        std::string new_dir(root);
        new_dir += "/";
        new_dir.append(dir, separator - dir);

#ifndef _WIN32
        struct stat st;
        if (stat(new_dir.c_str(), &st) == -1) {
            mkdir(new_dir.c_str(), 0700);
        }
#else
        modify_directory_separator(new_dir);
        wchar_t wdir[MaxPathLength];
        to_unicode(new_dir.c_str(), wdir, MaxPathLength);
        int rv = CreateDirectoryW(wdir, 0);
#endif
    }
}
Пример #9
0
const char* reconstruction(ImageModel* image_model,
                           unsigned int method_id,
                           const float* param_values,
                           bool check_b_table,
                           unsigned int thread_count)
{
    static std::string output_name;
    try
    {
        image_model->voxel.recon_report.clear();
        image_model->voxel.recon_report.str("");
        image_model->voxel.param = param_values;
        std::ostringstream out;
        if(method_id == 1) // DTI
        {
            image_model->voxel.need_odf = 0;
            image_model->voxel.output_jacobian = 0;
            image_model->voxel.output_mapping = 0;
            image_model->voxel.output_rdi = 0;
            image_model->voxel.scheme_balance = 0;
            image_model->voxel.half_sphere = 0;
            image_model->voxel.odf_deconvolusion = 0;
            image_model->voxel.odf_decomposition = 0;
        }
        else
        {
            out << ".odf" << image_model->voxel.ti.fold;// odf_order
            out << ".f" << image_model->voxel.max_fiber_number;
            if (image_model->voxel.need_odf)
                out << "rec";
            if (image_model->voxel.scheme_balance)
                out << ".bal";
            if (image_model->voxel.half_sphere)
                out << ".hs";
            if (image_model->voxel.csf_calibration && method_id == 4)
                out << ".csfc";
            else
                image_model->voxel.csf_calibration = false;
            if (image_model->voxel.odf_deconvolusion)
            {
                out << ".de" << param_values[2];
                if(image_model->voxel.odf_xyz[0] != 0 ||
                   image_model->voxel.odf_xyz[1] != 0 ||
                   image_model->voxel.odf_xyz[2] != 0)
                    out << ".at_" << image_model->voxel.odf_xyz[0]
                        << "_" << image_model->voxel.odf_xyz[1]
                        << "_" << image_model->voxel.odf_xyz[2];
            }
            if (image_model->voxel.odf_decomposition)
            {
                out << ".dec" << param_values[3] << "m" << (int)param_values[4];
                if(image_model->voxel.odf_xyz[0] != 0 ||
                   image_model->voxel.odf_xyz[1] != 0 ||
                   image_model->voxel.odf_xyz[2] != 0)
                    out << ".at_" << image_model->voxel.odf_xyz[0]
                        << "_" << image_model->voxel.odf_xyz[1]
                        << "_" << image_model->voxel.odf_xyz[2];
            }
        }

        // correct for b-table orientation
        if(check_b_table)
        {
            set_title("checking b-table");
            bool output_dif = image_model->voxel.output_diffusivity;
            bool output_tensor = image_model->voxel.output_tensor;
            image_model->voxel.output_diffusivity = false;
            image_model->voxel.output_tensor = false;
            image_model->reconstruct<dti_process>(thread_count);
            image_model->voxel.output_diffusivity = output_dif;
            image_model->voxel.output_tensor = output_tensor;
            std::vector<std::vector<float> > fib_fa(1);
            std::vector<std::vector<float> > fib_dir(1);
            fib_fa[0].swap(image_model->voxel.fib_fa);
            fib_dir[0].swap(image_model->voxel.fib_dir);

            const unsigned char order[18][6] = {
                                    {0,1,2,1,0,0},
                                    {0,1,2,0,1,0},
                                    {0,1,2,0,0,1},
                                    {0,2,1,1,0,0},
                                    {0,2,1,0,1,0},
                                    {0,2,1,0,0,1},
                                    {1,0,2,1,0,0},
                                    {1,0,2,0,1,0},
                                    {1,0,2,0,0,1},
                                    {1,2,0,1,0,0},
                                    {1,2,0,0,1,0},
                                    {1,2,0,0,0,1},
                                    {2,1,0,1,0,0},
                                    {2,1,0,0,1,0},
                                    {2,1,0,0,0,1},
                                    {2,0,1,1,0,0},
                                    {2,0,1,0,1,0},
                                    {2,0,1,0,0,1}};
            const char txt[18][6] = {"012fx","012fy","012fz",
                                     "021fx","021fy","021fz",
                                     "102fx","102fy","102fz",
                                     "120fx","120fy","120fz",
                                     "210fx","210fy","210fz",
                                     "201fx","201fy","201fz"};

            float result[18] = {0};
            float cur_score = evaluate_fib(image_model->voxel.dim,fib_fa,fib_dir).first;

            for(int i = 0;i < 18;++i)
            {
                std::vector<std::vector<float> > new_dir(fib_dir);
                flip_fib_dir(new_dir[0],order[i]);
                result[i] = evaluate_fib(image_model->voxel.dim,fib_fa,new_dir).first;
            }
            int best = std::max_element(result,result+18)-result;

            if(result[best] > cur_score)
            {
                out << "." << txt[best];
                image_model->flip_b_table(order[best]);
            }
        }


        switch (method_id)
        {
        case 0: //DSI local max
            image_model->voxel.recon_report <<
            " The diffusion data were reconstructed using diffusion spectrum imaging (Wedeen et al. MRM, 2005) with a Hanning filter of " << (int)param_values[0] << ".";
            if (image_model->voxel.odf_deconvolusion || image_model->voxel.odf_decomposition)
            {
                if (!image_model->reconstruct<dsi_estimate_response_function>(thread_count))
                    return "reconstruction canceled";
            }
            out << ".dsi."<< (int)param_values[0] << ".fib.gz";
            if (!image_model->reconstruct<dsi_process>(thread_count))
                return "reconstruction canceled";
            break;
        case 1://DTI
            image_model->voxel.recon_report << " The diffusion tensor was calculated.";
            out << ".dti.fib.gz";
            image_model->voxel.max_fiber_number = 1;
            if (!image_model->reconstruct<dti_process>(thread_count))
                return "reconstruction canceled";
            break;

        case 2://QBI
            image_model->voxel.recon_report << " The diffusion data was reconstructed using q-ball imaging (Tuch, MRM 2004).";
            if (image_model->voxel.odf_deconvolusion || image_model->voxel.odf_decomposition)
            {
                if (!image_model->reconstruct<qbi_estimate_response_function>(thread_count))
                    return "reconstruction canceled";
            }
            out << ".qbi."<< param_values[0] << "_" << param_values[1] << ".fib.gz";
            if (!image_model->reconstruct<qbi_process>(thread_count))
                return "reconstruction canceled";
            break;
        case 3://QBI
            image_model->voxel.recon_report << " The diffusion data was reconstructed using spherical-harmonic-based q-ball imaging (Descoteaux et al., MRM 2007).";
            if (image_model->voxel.odf_deconvolusion || image_model->voxel.odf_decomposition)
            {
                if (!image_model->reconstruct<qbi_sh_estimate_response_function>(thread_count))
                    return "reconstruction canceled";
            }
            out << ".qbi.sh"<< (int) param_values[1] << "." << param_values[0] << ".fib.gz";
            if (!image_model->reconstruct<qbi_sh_process>(thread_count))
                return "reconstruction canceled";
            break;

        case 4://GQI
            if(param_values[0] == 0.0) // spectral analysis
            {
                image_model->voxel.recon_report <<
                " The diffusion data were reconstructed using generalized q-sampling imaging (Yeh et al., IEEE TMI, ;29(9):1626-35, 2010).";
                out << (image_model->voxel.r2_weighted ? ".gqi2.spec.fib.gz":".gqi.spec.fib.gz");
                if (!image_model->reconstruct<gqi_spectral_process>(thread_count))
                    return "reconstruction canceled";
                break;
            }
            image_model->voxel.recon_report <<
            " The diffusion data were reconstructed using generalized q-sampling imaging (Yeh et al., IEEE TMI, ;29(9):1626-35, 2010) with a diffusion sampling length ratio of " << (float)param_values[0] << ".";
            if (image_model->voxel.odf_deconvolusion || image_model->voxel.odf_decomposition)
            {
                if (!image_model->reconstruct<gqi_estimate_response_function>(thread_count))
                    return "reconstruction canceled";
            }
            if(image_model->voxel.r2_weighted)
                image_model->voxel.recon_report << " The ODF calculation was weighted by the square of the diffuion displacement.";
            if (image_model->voxel.output_rdi)
                out << ".rdi";
            out << (image_model->voxel.r2_weighted ? ".gqi2.":".gqi.") << param_values[0] << ".fib.gz";
            if (!image_model->reconstruct<gqi_process>(thread_count))
                return "reconstruction canceled";
            break;
        case 6:
            image_model->voxel.recon_report
                    << " The diffusion data were converted to HARDI using generalized q-sampling method with a regularization parameter of " << param_values[2] << ".";
            out << ".hardi."<< param_values[0]
                << ".b" << param_values[1]
                << ".reg" << param_values[2] << ".src.gz";
            if (!image_model->reconstruct<hardi_convert_process>(thread_count))
                return "reconstruction canceled";
            break;
        case 7:
            image_model->voxel.recon_report
            << " The diffusion data were reconstructed in the MNI space using q-space diffeomorphic reconstruction (Yeh et al., Neuroimage, 58(1):91-9, 2011) to obtain the spin distribution function (Yeh et al., IEEE TMI, ;29(9):1626-35, 2010). "
            << " A diffusion sampling length ratio of "
            << (float)param_values[0] << " was used, and the output resolution was " << param_values[1] << " mm.";
            // run gqi to get the spin quantity
            std::vector<image::pointer_image<float,3> > tmp;
            tmp.swap(image_model->voxel.grad_dev);
            if (!image_model->reconstruct<gqi_estimate_response_function>(thread_count))
                return "reconstruction canceled";
            tmp.swap(image_model->voxel.grad_dev);
            out << ".reg" << (int)image_model->voxel.reg_method;
            out << "i" << (int)image_model->voxel.interpo_method;
            out << (image_model->voxel.r2_weighted ? ".qsdr2.":".qsdr.");
            out << param_values[0] << "." << param_values[1] << "mm";
            if(image_model->voxel.output_jacobian)
                out << ".jac";
            if(image_model->voxel.output_mapping)
                out << ".map";
            if (!image_model->reconstruct<gqi_mni_process>(thread_count))
                return "reconstruction canceled";
            out << ".R" << (int)std::floor(image_model->voxel.R2*100.0) << ".fib.gz";
            break;
        }
        image_model->save_fib(out.str());
        output_name = image_model->file_name + out.str();
    }
    catch (std::exception& e)
    {
        output_name = e.what();
        return output_name.c_str();
    }
    catch (...)
    {
        return "unknown exception";
    }
    return output_name.c_str();
}
Пример #10
0
/**
 * @brief Server::CMDcopy
 * @param resp
 * @return
 * метод копирует директорию/файл
 */
std::string Server::CMDcopy(ResponceItem* resp)
{
    std::string result("");
    FSNode* find_src = 0; //
    FSNode* find_dest = 0; //

    resp->response.result = CMD_RESULT_OK;

    resp->client->Lock();

    //обработка источника
    size_t pos = resp->response.address.find('/',0); //относительный или полный путь
    if(pos == std::string::npos || pos > 0)
    {
        //относительно текущей
        find_src = resp->client->GetCurrentDir()->Find("/" + resp->response.address, resp->client->GetCurrentDir());
    }
    else
    {
        //относительно корня
        find_src = fs->Find(resp->response.address, fs);
    }

    if(find_src == 0)
    {
        if(resp->response.code == CMD_RD)
            resp->response.result = CMD_RESULT_UNKNOWN_DIR;

        if(resp->response.code == CMD_DEL)
            resp->response.result = CMD_RESULT_UNKNOWN_FILE;

        resp->client->Unlock();
        return result;
    }


    pos = resp->response.value.find('/',0); //относительный или полный путь
    if(pos == std::string::npos || pos > 0)
    {
        //относительно текущей
        find_dest = resp->client->GetCurrentDir()->Find("/" + resp->response.value, resp->client->GetCurrentDir());
    }
    else
    {
        //относительно корня
        find_dest = fs->Find(resp->response.value, fs);
    }

    if(find_dest == 0)
    {
        if(resp->response.code == CMD_RD)
            resp->response.result = CMD_RESULT_UNKNOWN_DIR;

        if(resp->response.code == CMD_DEL)
            resp->response.result = CMD_RESULT_UNKNOWN_FILE;

        resp->client->Unlock();
        return result;
    }


    if(find_dest->GetType() == FSNode::TYPE_FILE)
    {
        resp->response.result = CMD_RESULT_BAD_REQUES;
        resp->client->Unlock();
        return result;
    }

    //проверка наличия копии
    FSNode* find_copy = find_dest->Find("/" + find_src->GetName(), find_dest);

    if(find_copy != 0) //что-то нашли
    {
        if(find_copy->GetType() == find_src->GetType())
        {
            if(find_src->GetType() == FSNode::TYPE_DIR)
                resp->response.result = CMD_RESULT_DIR_ALREADY_EXISTS;

            if(find_src->GetType() == FSNode::TYPE_FILE)
                resp->response.result = CMD_RESULT_FILE_ALREADY_EXISTS;

            resp->client->Unlock();
            return result;
        }
    }

    if(find_src->GetType() == FSNode::TYPE_DIR)
    {
        FSDir new_dir(find_src->GetName());
        *((FSDir*)find_dest) += new_dir;
        find_dest = find_dest->GetNodeContent()->back();
    }

    if(find_src->GetType() == FSNode::TYPE_FILE)
    {
        FSFile new_file(find_src->GetName());
        *((FSDir*)find_dest) += new_file;
        find_dest = find_dest->GetNodeContent()->back();
    }

    FSNode::_copy(find_src, find_dest); //копирование содержания, если оно есть

    result = "BROADCAST: " + resp->response.user + " performs command: COPY " + resp->response.address + " " + resp->response.value;

    resp->client->Unlock();

    return result;
}
Пример #11
0
void IconList::directoryChanged(const QString &path)
{
	QDir new_dir (path);
	if(m_dir.absolutePath() != new_dir.absolutePath())
	{
		m_dir.setPath(path);
		m_dir.refresh();
		if(is_watching)
			stopWatching();
		startWatching();
	}
	if(!m_dir.exists())
		if(!ensureFolderPathExists(m_dir.absolutePath()))
			return;
	m_dir.refresh();
	auto new_list = m_dir.entryList(QDir::Files, QDir::Name);
	for (auto it = new_list.begin(); it != new_list.end(); it++)
	{
		QString &foo = (*it);
		foo = m_dir.filePath(foo);
	}
	auto new_set = new_list.toSet();
	QList<QString> current_list;
	for (auto &it : icons)
	{
		if (!it.has(MMCIcon::FileBased))
			continue;
		current_list.push_back(it.m_images[MMCIcon::FileBased].filename);
	}
	QSet<QString> current_set = current_list.toSet();

	QSet<QString> to_remove = current_set;
	to_remove -= new_set;

	QSet<QString> to_add = new_set;
	to_add -= current_set;

	for (auto remove : to_remove)
	{
		QLOG_INFO() << "Removing " << remove;
		QFileInfo rmfile(remove);
		QString key = rmfile.baseName();
		int idx = getIconIndex(key);
		if (idx == -1)
			continue;
		icons[idx].remove(MMCIcon::FileBased);
		if (icons[idx].type() == MMCIcon::ToBeDeleted)
		{
			beginRemoveRows(QModelIndex(), idx, idx);
			icons.remove(idx);
			reindex();
			endRemoveRows();
		}
		else
		{
			dataChanged(index(idx), index(idx));
		}
		m_watcher->removePath(remove);
		emit iconUpdated(key);
	}

	for (auto add : to_add)
	{
		QLOG_INFO() << "Adding " << add;
		QFileInfo addfile(add);
		QString key = addfile.baseName();
		if (addIcon(key, QString(), addfile.filePath(), MMCIcon::FileBased))
		{
			m_watcher->addPath(add);
			emit iconUpdated(key);
		}
	}
}