コード例 #1
0
ファイル: mainwindow.cpp プロジェクト: kio2145/vns_kma
void MainWindow::on_actionNew_triggered()
{
    QString filew=QFileDialog::getSaveFileName();
    if(filew.size()<=0)
    {
        QMessageBox::warning(0,"Warning", "УВАГА ВИ ПРАЦЮЕТЕ З ФАЙЛОМ "+openfil());
    }
    else
    {
    QFile file("worckfile");
    QFile filen(filew.replace("\\\"","/"""));
    QTextStream streamm(&filen);
    filen.open(QIODevice::WriteOnly | QIODevice::Text);
    filen.close();
    QTextStream stream(&file);
    if(!file.open(QIODevice::WriteOnly | QIODevice::Text))
    {
        QMessageBox::warning(0,"Warning", " ---");
    }
    else
    {
        stream<<filew.replace("\\\"","/"""); //шаманизм с эскейп последовательностью с форума он пашет
    }
    file.close();
    }
    drawinwindow();
}
コード例 #2
0
//==============================================================================
Error ShaderLoader::parseFileIncludes(ResourceFilename filename, U32 depth)
{
	// first check the depth
	if(depth > MAX_INCLUDE_DEPTH)
	{
		ANKI_LOGE("The include depth is too high. "
				  "Probably circular includance");
		return ErrorCode::USER_DATA;
	}

	// load file in lines
	StringAuto txt(m_alloc);
	StringListAuto lines(m_alloc);

	ResourceFilePtr file;
	ANKI_CHECK(m_manager->getFilesystem().openFile(filename, file));
	ANKI_CHECK(file->readAllText(TempResourceAllocator<char>(m_alloc), txt));
	lines.splitString(txt.toCString(), '\n');
	if(lines.getSize() < 1)
	{
		ANKI_LOGE("File is empty: %s", &filename[0]);
		return ErrorCode::USER_DATA;
	}

	for(const String& line : lines)
	{
		static const CString token = "#include \"";

		if(line.find(token) == 0)
		{
			// - Expect something between the quotes
			// - Expect the last char to be a quote
			if(line.getLength() >= token.getLength() + 2
				&& line[line.getLength() - 1] == '\"')
			{
				StringAuto filen(m_alloc);
				filen.create(line.begin() + token.getLength(), line.end() - 1);

				ANKI_CHECK(parseFileIncludes(filen.toCString(), depth + 1));
			}
			else
			{
				ANKI_LOGE("Malformed #include: %s", &line[0]);
				return ErrorCode::USER_DATA;
			}
		}
		else
		{
			m_sourceLines.pushBackSprintf(m_alloc, "%s", &line[0]);
		}
	}

	return ErrorCode::NONE;
}
コード例 #3
0
ファイル: ListDir.cpp プロジェクト: MarcusSt/s25client
void ListDir(const std::string& path, bool directories, void (*CallBack)(const std::string& filename, void* param), void* param, std::list<std::string> *liste)
{
    // Pfad zum Ordner, wo die Dateien gesucht werden sollen
    std::string rpath = path.substr(0, path.find_last_of('/') + 1);

    // Pfad in Kleinbuchstaben umwandeln
    std::string filen(path);
    std::transform(path.begin(), path.end(), filen.begin(), tolower);

    //LOG.lprintf("%s\n", filen.c_str());
    // Dateiendung merken
    size_t pos = path.find_last_of('.');
    if(pos == std::string::npos)
        return;

    std::string endung = path.substr(pos + 1);

#ifdef _WIN32
    HANDLE hFile;
    WIN32_FIND_DATAA wfd;

    hFile = FindFirstFileA(path.c_str(), &wfd);
    if(hFile != INVALID_HANDLE_VALUE)
    {
        do
        {
            std::string whole_path = rpath + wfd.cFileName;

            bool push = true;
            if(!directories && ( (wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) == FILE_ATTRIBUTE_DIRECTORY) )
                push = false;

            if(push)
            {
                if(CallBack)
                    CallBack(whole_path.c_str(), param);
                if(liste)
                    liste->push_back(whole_path);
            }
        }
        while(FindNextFileA(hFile, &wfd));

        FindClose(hFile);
    }
#else
    DIR* dir_d;
    dirent* dir = NULL;
    if ((dir_d = opendir(rpath.c_str())) != NULL)
    {
        while( (dir = readdir(dir_d)) != NULL)
        {
            struct stat file_stat;
            std::string whole_path = rpath + dir->d_name;

            stat(whole_path.c_str(), &file_stat);

            bool push = true;
            if(!directories && S_ISDIR(file_stat.st_mode))
                push = false;

            if(push)
            {
                std::string ende = dir->d_name;
                size_t pos = ende.find_last_of('.');
                if(pos == std::string::npos)
                    continue;

                ende = ende.substr(pos + 1);

                if(endung != ende)
                    std::transform(ende.begin(), ende.end(), ende.begin(), tolower);

                //LOG.lprintf("%s == %s\n", endung.c_str(), ende.c_str());

                if(endung != ende)
                    continue;

                if(CallBack)
                    CallBack(whole_path, param);
                if(liste)
                    liste->push_back(whole_path);
            }
        }
        closedir(dir_d);
        if(liste)
            liste->sort();
    }
#endif // _WIN32

}
コード例 #4
0
//==============================================================================
void ProgramPrePreprocessor::parseFileForPragmas(
	const PPPString& filename, U32 depth)
{
	// first check the depth
	if(depth > MAX_DEPTH)
	{
		throw ANKI_EXCEPTION("The include depth is too high. "
			"Probably circular includance");
	}

	// load file in lines
	auto alloc = m_shaderSource.getAllocator();
	PPPString txt(alloc);
	PPPStringList lines(alloc);
	File file;
	file.open(filename.toCString(), File::OpenFlag::READ);
	file.readAllText(txt);
	lines = PPPStringList::splitString(txt.toCString(), '\n', alloc);
	if(lines.size() < 1)
	{
		throw ANKI_EXCEPTION("File is empty: %s", &filename[0]);
	}

	for(const PPPString& line : lines)
	{
		PtrSize npos = 0;

		if(line.find("#pragma anki") == 0)
		{
			Bool malformed = true;

			if(parseType(line))
			{
				malformed = false; // All OK
			}
			else if((npos = line.find(commands[6])) == 0)
			{
				// Include

				if(line.getLength() >= std::strlen(commands[6]) + 2)
				{
					PPPString filen(
						line.begin() + std::strlen(commands[6]), 
						line.end() - 1, 
						alloc);

					filen = m_manager->fixResourceFilename(filen.toCString());

					parseFileForPragmas(filen, depth + 1);

					malformed = false; // All OK
				}
			}

			if(malformed)
			{
				throw ANKI_EXCEPTION("Malformed pragma anki: %s", &line[0]);
			}
		}
		else
		{
			m_sourceLines.push_back(line);
		}
	}

	// Sanity checks
	if(m_type == ShaderType::COUNT)
	{
		throw ANKI_EXCEPTION("Shader is missing the type");
	}
}