Beispiel #1
0
void TexturePacker::recurseDirectory(SpriteArray& sprites, const QString& path)
{
    QStringList filter;
    filter << "png" << "jpg" << "bmp";

    QDir dir(path);
    QFileInfoList infos = dir.entryInfoList();
    for ( auto& info : infos )
    {
        if ( info.isDir() )
        {
            if ( info.fileName() != ".." && info.fileName() != "." )
            {
                recurseDirectory(sprites, info.filePath());
            }
        }
        else if ( filter.contains(info.suffix()) )
        {            
            QImageReader image(info.filePath());

            Sprite sprite;
            sprite.mName = info.filePath();
            sprite.mOriginalSize = image.size();

            sprites.append(sprite);
        }
    }
}
Beispiel #2
0
void TexturePacker::pack()
{
    QString basepath = Project::getActiveProject().getImagePath();

    SpriteArray sprites, usedSprites;
    recurseDirectory(sprites, basepath);

    SpriteAtlas& atlas = Project::getActiveProject().getSpriteAtlas();
    atlas.clear();

    do
    {
        MaxRectsAlgorithm maxrects(2046, 2046);
        maxrects.insert(sprites, usedSprites);

        if ( !usedSprites.isEmpty() )
        {
            SpriteSheet sheet = createSpriteSheet(usedSprites);
            atlas.append(qMove(sheet));

            usedSprites.clear();
        }
    }
    while ( !sprites.isEmpty() );

    atlas.save(Project::getActiveProject().getTileAtlasPath());
}
Beispiel #3
0
void LogViewWindow::cacheFileList()
{
	QString szLogPath;
	g_pApp->getLocalKvircDirectory(szLogPath,KviApplication::Log);
	recurseDirectory(szLogPath);

	setupItemList();
}
Beispiel #4
0
static int checkExists(char *string)
{
	int found = FALSE;

	string = replaceString(string, "msgid \"", "");

	found = recurseDirectory("data/scripts", string);

	if (found == FALSE)
	{
		found = recurseDirectory("src", string);
	}

	if (found == FALSE)
	{
		found = recurseDirectory("data", string);
	}

	return found;
}
Beispiel #5
0
void LogViewWindow::recurseDirectory(const QString & szDir)
{
	QDir dir(szDir);
	QFileInfoList list = dir.entryInfoList();
	for(int i=0; i < list.count(); i++)
	{
		QFileInfo info = list[i];
		if(info.isDir())
		{
			// recursive
			if((info.fileName() != "..") && (info.fileName() != "."))
				recurseDirectory(info.filePath());
		} else if((info.suffix() == "gz") || (info.suffix() == "log"))
		{
			m_logList.append(new LogFile(info.filePath()));
		}
	}
}
Beispiel #6
0
static void recurseDirectory(char *dirName)
{
	DIR *dirp, *dirp2;
	struct dirent *dfile;
	char filename[1024];

	dirp = opendir(dirName);

	if (dirp == NULL)
	{
		printf("%s: Directory does not exist or is not accessable\n", dirName);

		exit(1);
	}

	while ((dfile = readdir(dirp)))
	{
		if (dfile->d_name[0] == '.')
		{
			continue;
		}

		snprintf(filename, sizeof(filename), "%s/%s", dirName, dfile->d_name);

		dirp2 = opendir(filename);

		if (dirp2)
		{
			closedir(dirp2);

			recurseDirectory(filename);
		}

		else
		{
			compressFile(filename, dirp);
		}
	}

	closedir(dirp);
}
Beispiel #7
0
int main(int argc, char *argv[])
{
	int i;
	int32_t length;
	char versionName[5];
	FILE *versionFile;

	if (argc == 3)
	{
		if (strcmpignorecase(argv[1], "-test") == 0)
		{
			testPak(argv[2]);

			exit(0);
		}
	}

	else if (argc < 3)
	{
		printf("Usage   : pak <directory names> <outputname>\n");
		printf("Example : pak data music gfx sound font edgar.pak\n");

		exit(1);
	}

	pak = fopen(argv[argc - 1], "wb");

	totalFiles = 0;

	for (i=1;i<argc-1;i++)
	{
		totalFiles += countFiles(argv[i]);
	}

	totalFiles++;

	printf("Will compress %d files\n", totalFiles);

	printf("Compressing 00%%...\r");

	fileData = malloc(totalFiles * sizeof(FileData));

	if (fileData == NULL)
	{
		printf("Failed to create File Data\n");

		exit(1);
	}

	atexit(cleanup);

	snprintf(versionName, sizeof(versionName), "%0.2f", VERSION);

	versionFile = fopen(versionName, "wb");

	fprintf(versionFile, "%s", versionName);

	fclose(versionFile);

	for (i=1;i<argc-1;i++)
	{
		recurseDirectory(argv[i]);
	}

	compressFile(versionName, NULL);

	remove(versionName);

	length = ftell(pak);

	for (i=0;i<totalFiles;i++)
	{
		if (fileData[i].fileSize == 0)
		{
			break;
		}

		fileData[i].offset = SWAP32(fileData[i].offset);
		fileData[i].compressedSize = SWAP32(fileData[i].compressedSize);
		fileData[i].fileSize = SWAP32(fileData[i].fileSize);

		fwrite(&fileData[i], sizeof(FileData), 1, pak);
	}

	length = SWAP32(length);
	totalFiles = SWAP32(totalFiles);

	fwrite(&length, sizeof(int32_t), 1, pak);
	fwrite(&totalFiles, sizeof(int32_t), 1, pak);

	fclose(pak);

	printf("Compressing 100%%\nCompleted\n");

	return 0;
}
Beispiel #8
0
static int recurseDirectory(char *dirName, char *searchString)
{
	DIR *dirp, *dirp2;
	struct dirent *dfile;
	FILE *infile;
	char filename[MAX_LINE_LENGTH], buffer[MAX_LINE_LENGTH];
	int lineNum;
	unsigned long fileSize;

	dirp = opendir(dirName);

	if (dirp == NULL)
	{
		printf("%s: Directory does not exist or is not accessible\n", dirName);

		exit(1);
	}

	while ((dfile = readdir(dirp)))
	{
		if (dfile->d_name[0] == '.')
		{
			continue;
		}

		snprintf(filename, sizeof(filename), "%s/%s", dirName, dfile->d_name);

		dirp2 = opendir(filename);

		if (dirp2)
		{
			closedir(dirp2);

			if (recurseDirectory(filename, searchString) == TRUE)
			{
				closedir(dirp);

				return TRUE;
			}
		}

		else
		{
			infile = fopen(filename, "rb");

			if (!infile)
			{
				printf("Couldn't open %s for reading!\n", filename);

				closedir(dirp);

				exit(1);
			}

			fseek(infile, 0L, SEEK_END);

			fileSize = ftell(infile);

			if (fileSize == 0)
			{
				printf("%s is an empty file!\n", filename);

				closedir(dirp);

				exit(1);
			}

			fseek(infile, 0L, SEEK_SET);

			lineNum = 1;

			while (fgets(buffer, MAX_LINE_LENGTH, infile) != NULL)
			{
				if (strstr(buffer, searchString) != NULL)
				{
					printf("#: %s:%d\n", filename, lineNum);

					fclose(infile);

					closedir(dirp);

					return TRUE;
				}

				lineNum++;
			}

			fclose(infile);
		}
	}

	closedir(dirp);

	return FALSE;
}
Beispiel #9
0
void FileWatcher::recurseDirectory(const std::string& dir, std::list<std::string>& output, const std::string& wildcard)
{
#ifdef WIN32
	WIN32_FIND_DATAA find = {};
	HANDLE findHandle = FindFirstFileExA((dir + "\\*").c_str(), FindExInfoStandard, &find, FindExSearchNameMatch, NULL, 0);
	if (findHandle == INVALID_HANDLE_VALUE)
		return;

	do
	{
		std::string name = find.cFileName;

		if (find.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
		{
			if (name != "." && name != "..")
				recurseDirectory(dir + '\\' + name, output, wildcard);
		}
		else
		{
			if (wildcmp(wildcard.c_str(), name.c_str()))
			{
				if (dir == ".")
					output.push_back(name);
				else
					output.push_back(dir + '\\' + name);
			}
		}

		if (!FindNextFileA(findHandle, &find))
			break;
	} while (findHandle != INVALID_HANDLE_VALUE);
#else
	DIR* dp;
	if ((dp = opendir(dir.c_str())) == nullptr)
		return;

	dirent* ent;
	while ((ent = readdir(dp)))
	{
		std::string name = ent->d_name;
		if (!(ent->d_type & (DT_DIR | DT_LNK)))
		{
			if (wildcmp(wildcard.c_str(), name.c_str()))
			{
				if (dir == ".")
					output.push_back(name);
				else
					output.push_back(dir + '/' + name);
			}
			continue;
		}

		if (name == "." || name == "..")
			continue;

		std::string path = dir + '/' + name;

		recurseDirectory(path, output, wildcard);
	}

	closedir(dp);
#endif
}