void SearchFromIntialNode(int column, int row, Board* board, DictionaryTrie* Trie, ThreadsafeStack<char*>* words)
{
	TrieCursor dictionaryCursor(Trie);
	BoardCursor boardCursor(board);

	boardCursor.StartFrom(column, row);
	if (dictionaryCursor.hasChild(*boardCursor.GetLetter()))
	{
		dictionaryCursor.goToChild(*boardCursor.GetLetter());
		RecursiveTreeWalk(&boardCursor, &dictionaryCursor, words);
	}
}
void ResourcePackerScreen::PackResources()
{
	Logger::Debug("Input: %s Output: %s Exclude: %s", inputGfxDirectory.c_str(), outputGfxDirectory.c_str(), excludeDirectory.c_str());
	
	isGfxModified = false;

	String path, lastDir;
	FileSystem::SplitPath(inputGfxDirectory, path, lastDir);
	std::transform(lastDir.begin(), lastDir.end(), lastDir.begin(), ::tolower);
	gfxDirName = lastDir;


	String processDirectoryPath = excludeDirectory + String("/") + GetProcessFolderName() + String("/");
	if (FileSystem::Instance()->CreateDirectory(processDirectoryPath, true) == FileSystem::DIRECTORY_CANT_CREATE)
	{
		//Logger::Error("Can't create directory: %s", processDirectoryPath.c_str());
	}


	if (IsMD5ChangedDir(excludeDirectory + String("/") + GetProcessFolderName(), outputGfxDirectory, gfxDirName + ".md5", true))
	{
		if (Core::Instance()->IsConsoleMode())
			printf("[Gfx not available or changed - performing full repack]\n");
		isGfxModified = true;
	
		// Remove whole output directory
		bool result = FileSystem::Instance()->DeleteDirectory(outputGfxDirectory);
		if (result)
		{
			Logger::Debug("Removed output directory: %s", outputGfxDirectory.c_str());
		}
		if (!result && Core::Instance()->IsConsoleMode())
		{
			printf("[ERROR: Can't delete directory %s]\n", outputGfxDirectory.c_str());
		}
	}

	RecursiveTreeWalk(inputGfxDirectory, outputGfxDirectory);

	// Put latest md5 after convertation
	IsMD5ChangedDir(excludeDirectory + String("/") + GetProcessFolderName(), outputGfxDirectory, gfxDirName + ".md5", true);
}
示例#3
0
void UIFileTree::SetPath(const String & fullpath, const String & extensionsString)
{
	originalExtensionsString = extensionsString;
	Split(extensionsString, ";", extensions);
	
	SafeRelease(treeHead);
	
	String path, dirname;
	FileSystem::SplitPath(fullpath, path, dirname);

	treeHead = new UITreeItemInfo(this);
	treeHead->Set(0, dirname, fullpath, true);
	
	
	RecursiveTreeWalk(fullpath, treeHead);
	
	
	UIList::SetDelegate(this);
	RefreshList();
}
void RecursiveTreeWalk(BoardCursor* boardCursor, TrieCursor* dictCursor, ThreadsafeStack<char*>* words)
{
	Direction allDirections[8] = { Right, Left, Up, Down, UpRight, UpLeft, DownRight, DownLeft };
	for(int i = 0; i < 8; i++)
	{
		Direction direction = allDirections[i];
		bool moved = boardCursor->Move(direction);
		if (moved)
		{
			char* boardLetter = boardCursor->GetLetter();
			if (dictCursor->hasChild(*boardLetter))
			{
				dictCursor->goToChild(*boardLetter);
				dictCursor->LockNode();
				if (dictCursor->isWord() && !dictCursor->getWordUsed())
				{
					char* word = boardCursor->GetWord();
#if defined(_DEBUG)
					writeLogLineFormatted("Adding found word %s", word);
#endif

					dictCursor->setWordUsed();
					words->Lock();
					words->push(word);
					words->Unlock();
					//delete[] word;
				}
				dictCursor->UnlockNode();

				RecursiveTreeWalk(boardCursor, dictCursor, words);
				dictCursor->goToParent();
			}
			delete[] boardLetter;
			boardCursor->Pop();
		}
	}	
}
void ResourcePackerScreen::RecursiveTreeWalk(const String & inputPath, const String & outputPath)
{
	uint64 packTime = SystemTimer::Instance()->AbsoluteMS();

	FileList * fileList = new FileList(inputPath);

	/* New $process folder structure */
	
	String dataSourceRelativePath = inputPath;
	StringReplace(dataSourceRelativePath, excludeDirectory, std::string(""));
	// printf("%s\n", dataSourceRelativePath.c_str());

	String processDirectoryPath = excludeDirectory + String("/") + GetProcessFolderName() + String("/") + dataSourceRelativePath;
	if (FileSystem::Instance()->CreateDirectory(processDirectoryPath, true) == FileSystem::DIRECTORY_CANT_CREATE)
	{
		//Logger::Error("Can't create directory: %s", processDirectoryPath.c_str());
	}

	if(clearProcessDirectory)
	{
		FileSystem::Instance()->DeleteDirectoryFiles(processDirectoryPath, false);
	}

	//String outputPath = outputPath;
	if (FileSystem::Instance()->CreateDirectory(outputPath) == FileSystem::DIRECTORY_CANT_CREATE)
	{
		//Logger::Error("Can't create directory: %s", outputPath.c_str());
	}
	
	CommandLineParser::Instance()->ClearFlags();
	std::list<DefinitionFile *> definitionFileList;

	// Find flags and setup them
	for (int fi = 0; fi < fileList->GetCount(); ++fi)
	{
		if (!fileList->IsDirectory(fi))
		{
			if (fileList->GetFilename(fi) == "flags.txt")
			{
				String fullname = inputPath + String("/") + fileList->GetFilename(fi);
				ProcessFlags(fullname);
				break;
			}
		}
	}
	
	bool modified = isGfxModified;
	// Process all psd / png files

	if (IsMD5ChangedDir(processDirectoryPath, inputPath, "dir.md5", false))
	{
		modified = true;
		//if (Core::Instance()->IsConsoleMode())
		//	printf("[Directory changed - rebuild: %s]\n", inputGfxDirectory.c_str());
	}

	if (modified)
	{
		FileSystem::Instance()->DeleteDirectoryFiles(outputPath, false);
		
		for (int fi = 0; fi < fileList->GetCount(); ++fi)
		{
			if (!fileList->IsDirectory(fi))
			{
				String fullname = inputPath + String("/") + fileList->GetFilename(fi);
				if (FileSystem::GetExtension(fullname) == ".psd")
				{
					DefinitionFile * defFile = ProcessPSD(processDirectoryPath, fullname, fileList->GetFilename(fi));
					definitionFileList.push_back(defFile);
				}
				else if(isLightmapsPacking && FileSystem::GetExtension(fullname) == ".png")
				{
					DefinitionFile * defFile = new DefinitionFile();
					defFile->LoadPNG(fullname, processDirectoryPath);
					definitionFileList.push_back(defFile);
				}
				else if (FileSystem::GetExtension(fullname) == ".pngdef")
				{
					DefinitionFile * defFile = new DefinitionFile();
					if (defFile->LoadPNGDef(fullname, processDirectoryPath))
					{
						definitionFileList.push_back(defFile);
					}
					else 
					{
						SafeDelete(defFile);
					}
				}
			}
		}

		// 
		if (definitionFileList.size() > 0 && modified)
		{
			TexturePacker packer;
			String outputPathWithSlash = outputPath + String("/");
				
			if(isLightmapsPacking)
			{
				packer.UseOnlySquareTextures();
				packer.SetMaxTextureSize(2048);
			}

			if (CommandLineParser::Instance()->IsFlagSet("--split"))
			{
				packer.PackToTexturesSeparate(excludeDirectory.c_str(), outputPathWithSlash.c_str(), definitionFileList);
			}
			else
			{
				packer.PackToTextures(excludeDirectory.c_str(), outputPathWithSlash.c_str(), definitionFileList);
			}
		}
	}	

	packTime = SystemTimer::Instance()->AbsoluteMS() - packTime;

	if (Core::Instance()->IsConsoleMode())
	{
		if (CommandLineParser::Instance()->IsExtendedOutput())
		{
			printf("[%d files packed with flags: %s]\n", (int)definitionFileList.size(), currentFlags.c_str());
		}
	
		String result = "[unchanged]";
		if (modified)
			result = "[REPACKED]";

		printf("[%s - %.2lf secs] - %s\n", inputPath.c_str(), (float64)packTime / 1000.0f, result.c_str());
	}

	
	for (std::list<DefinitionFile*>::iterator it = definitionFileList.begin(); it != definitionFileList.end(); ++it)
	{
		DefinitionFile * file = *it;
		SafeDelete(file);
	}
	definitionFileList.clear();
	
	for (int fi = 0; fi < fileList->GetCount(); ++fi)
	{
		if (fileList->IsDirectory(fi))
		{
			String filename = fileList->GetFilename(fi);
			if ((filename != ".") && (filename != "..") && (filename != "$process") && (filename != ".svn"))
			{
				if ((filename.size() > 0) && (filename[0] != '.'))
					RecursiveTreeWalk(inputPath + String("/") + fileList->GetFilename(fi),
									  outputPath + String("/") + fileList->GetFilename(fi));
			}
		}
	}
	
	SafeRelease(fileList);
}