Example #1
0
bool system_menu::remove_dir_info(const QString prefix_name, const QString dir_name) {
    QString file_path;
    QString dir_path;

    dir_path = get_dir_path(prefix_name, dir_name);
    file_path = get_dirfile_path(prefix_name, dir_name);

#ifdef DEBUG
    qDebug()<<"[DD] rm_dir_info:"<<file_path<<dir_path;
#endif

    QFile file(file_path);
    file.remove();

    if (dir_name.isEmpty()){
        QDir dir(base_directory);
        QRegExp rx(QString("%1-%2-.*\\.directory").arg(APP_SHORT_NAME).arg(prefix_name));
        QFileInfoList list = dir.entryInfoList();
        for (int i = 0; i < list.size(); ++i) {
            if (rx.exactMatch(list.at(i).fileName())){
#ifdef DEBUG
                qDebug()<<"[DD]"<<list.at(i).fileName();
#endif
                dir.remove(list.at(i).absoluteFilePath());
            }
        }
    }

    QDir dir(dir_path);
    if (dir.exists()){
        CoreLib->removeDirectory(dir_path);
        dir.rmdir(dir_path);
    }
    return true;
}
Example #2
0
bool system_menu::move_dir_info(const QString prefix_name, const QString dir_name, const QString new_name) {
    QString file_path;
    QString dir_path;
    QString dir_path_new;

    dir_path = get_dir_path(prefix_name, dir_name);
    dir_path_new = get_dir_path(prefix_name, new_name);
    file_path = get_dirfile_path(prefix_name, dir_name);

#ifdef DEBUG
    qDebug()<<"mv_dir_info:"<<file_path<<dir_path<<dir_path_new;
#endif

    QFile file(file_path);
    if (!file.exists())
        return false;

    if (!file.remove()){
        return false;
    }

    QDir dir(dir_path);
    if (!dir.exists())
        return false;

    if (!dir.rename(dir_path, dir_path_new))
        return false;

    if (!dir_name.isEmpty()){
        this->create_dir_info(prefix_name, new_name);
    } else {
        this->create_dir_info(new_name);
    }

    return true;
}
Example #3
0
bool system_menu::create_dir_info(const QString prefix_name, const QString dir_name) {
    QString name;
    QString icon;

    QString file_path;
    QString dir_path;

    if (prefix_name.isEmpty()){
        name = APP_SHORT_NAME;
        icon = APP_SHORT_NAME;
    } else {
        if (dir_name.isEmpty()){
            name = prefix_name;
            icon = "folder";
        } else {
            name = dir_name;
            icon = "folder";
        }
    }

    dir_path = get_dir_path(prefix_name, dir_name);
    file_path = get_dirfile_path(prefix_name, dir_name);

#ifdef DEBUG
    qDebug()<<"[DD] cr_dir_info:"<<file_path<<dir_path;
#endif

    QFile file(file_path);
    if (!file.open(QIODevice::Truncate | QIODevice::WriteOnly | QIODevice::Text))
        return false;

    QTextStream out(&file);
    out << "[Desktop Entry]\nType=Directory\nName=" << name << "\nIcon=" << icon <<"\n";

    file.close();

    QDir dir(dir_path);
    if (!dir.exists()){
        if (!dir.mkdir(dir_path))
            return false;
    }

    return true;
}
Example #4
0
int main(int argc, char *argv[]) {
	::std::string	base_filename;
	if(argc < 2 || strcmp(argv[1], "-") == 0) {
		yyin = stdin;
		base_filename = "-";
	}
	else {
		base_filename = argv[1];
	}
	yydebug = (getenv("BNFDEBUG") != NULL);

	::std::string	base_path = (base_filename ==  "-" ? ::std::string("") : get_dir_path(base_filename));
	auto mod = parse_module_file(base_filename, base_path);
	printf("output module = %p\n", &*mod);

	post_process_module(*mod, base_filename, base_path);

	printf("Crate parsed\n");

	return 0;
}
Example #5
0
void post_process_module(Module& mod, const ::std::string& mod_filename, const ::std::string& mod_dir_path)
{
	::std::cout << "mod = ["<<mod.mod_path()<<"], mod_filename = " << mod_filename << ", mod_dir_path = " << mod_dir_path << ";" << ::std::endl;

	for(auto& item : mod.items())
	{
		Module* opt_submod = dynamic_cast<Module*>(item.get());
		if( !opt_submod )	continue;
		Module& submod = *opt_submod;
		printf("- Module %s\n", submod.name().c_str());

		if( ! submod.is_external() ) {
			// - inline modules can be ignored.. for now
			if( mod_dir_path != "" ) {
				submod.set_paths( mod_filename, mod_dir_path + submod.name() + "/" );
			}
		}
		else
		{
			::std::string	filename;
			::std::string	base_path;
			if( mod_filename == "-" ) {
				fprintf(stderr, "ERROR: Referencing 'mod %s;' from stdin\n", submod.name().c_str());
				exit(1);
			}
			else if( submod.attrs().has("path") ) {
				filename = get_dir_path(mod_filename) + submod.attrs().get_first("path").string();
				base_path = get_dir_path(filename);
			}
			else if( mod_dir_path == "" ) {
				fprintf(stderr, "ERROR: Referencing 'mod %s;' from non-controlling file\n", submod.name().c_str());
				exit(1);
			}
			else {
				filename = mod_dir_path + submod.name() + ".rs";
				base_path = "";
				yyin = fopen( filename.c_str(), "r" );
				if( !yyin ) {
					printf("> '%s' not found\n", filename.c_str());
					base_path = mod_dir_path + submod.name() + "/";
					filename = base_path + "mod.rs";
				}
				else {
					fclose(yyin);
				}
			}

			assert(filename.size() > 0);
			submod = ::std::move( *parse_module_file(filename, base_path) );
			submod.set_paths( filename, base_path );
		}

		auto mp = mod.mod_path();
		mp.push_back(submod.name());
		submod.set_mod_path(::std::move(mp));
	}

	for(auto& item : mod.items())
	{
		Module* opt_submod = dynamic_cast<Module*>(item.get());
		if( !opt_submod )	continue;
		Module& submod = *opt_submod;

		const ::std::string& submod_fname = submod.filename();
		const ::std::string& submod_dir = submod.base_dir();
		post_process_module(submod, submod_fname, submod_dir);
	}
}