// case 3: tail segments, invariants hold, copy, invariants hold
void testNoMergeAfterCopy(CuTest * tc) {

    // main directory
    Directory * dir = _CLNEW RAMDirectory();
    // auxiliary directory
    Directory * aux = _CLNEW RAMDirectory();

    WhitespaceAnalyzer  an;

    setUpDirs(tc, dir, aux);

    IndexWriter4Test * writer = newWriter(dir, &an, false);
    writer->setMaxBufferedDocs(10);
    writer->setMergeFactor(4);

    ValueArray<Directory*> dirs(2);
    dirs[0] = aux;
    dirs[1] = aux;
    writer->addIndexesNoOptimize(dirs);

    assertEquals(1060, writer->docCount());
    assertEquals(1000, writer->getDocCount(0));
    writer->close();
    _CLLDELETE(writer);

    // make sure the index is correct
    verifyNumDocs(tc, dir, 1060);

    dir->close();
    _CLLDELETE(dir);

    aux->close();
    _CLLDELETE(aux);
}
// case 0: add self or exceed maxMergeDocs, expect exception
void testAddSelf(CuTest * tc)  {

    // main directory
    Directory * dir = _CLNEW RAMDirectory();
    // auxiliary directory
    Directory * aux = _CLNEW RAMDirectory();

    IndexWriter4Test * writer = NULL;
    WhitespaceAnalyzer analyzer;

    writer = newWriter(dir, &analyzer, true);
    // add 100 documents
    addDocs(writer, 100);
    assertEquals(100, writer->docCount());
    writer->close();
    _CLLDELETE(writer);

    writer = newWriter(aux, &analyzer, true);
    writer->setUseCompoundFile(false); // use one without a compound file
    writer->setMaxBufferedDocs(1000);
    // add 140 documents in separate files
    addDocs(writer, 40);
    writer->close();
    _CLLDELETE(writer);

    writer = newWriter(aux, &analyzer, true);
    writer->setUseCompoundFile(false); // use one without a compound file
    writer->setMaxBufferedDocs(1000);
    addDocs(writer, 100);
    writer->close();
    _CLLDELETE(writer);

    writer = newWriter(dir, &analyzer, false);
    try {
      // cannot add self
      ValueArray<Directory*> dirs(2);
      dirs[0] = aux;
      dirs[1] = dir;
      writer->addIndexesNoOptimize( dirs );
      assertTrue(false);
    }
    catch (CLuceneError&) {
      assertEquals(100, writer->docCount());
    }
    writer->close();
    _CLLDELETE(writer);

    // make sure the index is correct
    verifyNumDocs(tc, dir, 100);

    dir->close();
    _CLLDELETE(dir);

    aux->close();
    _CLLDELETE(aux);
}
 int64_t IndexReader::getCurrentVersion(const char* directory){
    Directory* dir = FSDirectory::getDirectory(directory);
    int64_t version = getCurrentVersion(dir);
    dir->close();
    _CLDECDELETE(dir);
    return version;
 }
 RAMDirectory::RAMDirectory(const char* dir):
    Directory(),files(true,true)
 {
    Directory* fsdir = FSDirectory::getDirectory(dir,false);
    try{
       _copyFromDir(fsdir,false);
    }_CLFINALLY(fsdir->close();_CLDECDELETE(fsdir););
	~TestConstantScoreRangeQuery()  
    {
        if( m_pSmall )
        {
            m_pSmall->close();
            _CLLDECDELETE( m_pSmall );
        }
    }
/*
  Run above stress test against FSDirectory.
 */
void testFSThreading(CuTest *tc){
  //setup some variables
  char tmpfsdirectory[1024];
  strcpy(tmpfsdirectory,cl_tempDir);
  strcat(tmpfsdirectory,"/threading-index");

  // Second in an FSDirectory:
  Directory* directory = FSDirectory::getDirectory(tmpfsdirectory);
  runThreadingTests(tc,*directory);
  directory->close();
  _CLDECDELETE(directory);
}
Exemple #7
0
boolean FileChooserImpl::chdir(const String& name) {
    Directory* d = Directory::open(name);
    if (d != nil) {
	dir_->close();
	delete dir_;
	dir_ = d;
	clear();
	load();
	return true;
    }
    return false;
}
Exemple #8
0
static List <Buffer> __GetContentAtPath(StringC path, Uint32 flags) {

	Directory dir;
	List <Buffer> list;

	dir.open(path, flags);
	while (dir.next()) {
		list.push_back(dir.getLast());
	}
	dir.close();

	return list;
}
void testRAMDirectory (CuTest *tc) {

    Directory * dir = FSDirectory::getDirectory(indexDir);
    MockRAMDirectory * ramDir = _CLNEW MockRAMDirectory(dir);

    // close the underlaying directory
    dir->close();
    _CLDELETE( dir );

    checkDir(tc, ramDir);

    ramDir->close();
    _CLLDELETE(ramDir);
}
Exemple #10
0
void stupid_remove_directory_recursive(const std::string & dirname)
{
    if (dirname.empty())
    {
        return;
    }

    std::string dir_name(dirname);
    if ('/' != *dir_name.rbegin() && '\\' != *dir_name.rbegin())
    {
        dir_name += g_directory_separator;
    }

    std::list<std::string> sub_folder_list;
    std::list<std::string> folder_list;
    folder_list.push_back(dir_name);
    while (!folder_list.empty())
    {
        const std::string folder_name = folder_list.front();
        folder_list.pop_front();
        Directory dir;
        if (!dir.open(folder_name.c_str()))
        {
            continue;
        }
        while (dir.read())
        {
            if (dir.sub_path_is_directory())
            {
                sub_folder_list.push_front(dir.sub_path_name());
                folder_list.push_back(dir.sub_path_name());
            }
            else
            {
                stupid_chmod_safe(dir.sub_path_name().c_str());
                stupid_unlink_safe(dir.sub_path_name().c_str());
            }
        }
        dir.close();
    }
    for (std::list<std::string>::const_iterator iter = sub_folder_list.begin(); sub_folder_list.end() != iter; ++iter)
    {
        stupid_rmdir_safe(iter->c_str());
    }
    stupid_rmdir_safe(dir_name.c_str());
}
		void ArchetypeEditorManager::load()
		{
			Directory dir;
			const bool success = dir.open(_libraryFolder.c_str());
			AGE_ASSERT(success);
			for (auto it = dir.recursive_begin(); it != dir.recursive_end(); ++it)
			{
				if (Directory::IsFile(*it))
				{
					auto extension = FileUtils::GetExtension(*it);

					if (extension != "raw_archetype")
					{
						continue;
					}
					loadOne(FileUtils::RemoveExtension(FileUtils::GetName(*it)));
				}
			}
			dir.close();
		}
// case 5: tail segments, invariants not hold
void testMoreMerges(CuTest * tc)  {

    // main directory
    Directory * dir = _CLNEW RAMDirectory();
    // auxiliary directory
    Directory * aux = _CLNEW RAMDirectory();
    Directory * aux2 = _CLNEW RAMDirectory();

    WhitespaceAnalyzer  an;

    setUpDirs(tc, dir, aux);

    IndexWriter4Test * writer = newWriter(aux2, &an, true);
    writer->setMaxBufferedDocs(100);
    writer->setMergeFactor(10);

    ValueArray<Directory*> dirs(1);
    dirs[0] = aux;
    writer->addIndexesNoOptimize(dirs);

    assertEquals(30, writer->docCount());
    assertEquals(3, writer->getSegmentCount()); 
    writer->close();
    _CLLDELETE(writer);

    IndexReader * reader = IndexReader::open(aux);
    for (int i = 0; i < 27; i++) {
      reader->deleteDocument(i);
    }
    assertEquals(3, reader->numDocs());
    reader->close();
    _CLLDELETE(reader);

    reader = IndexReader::open(aux2);
    for (int i = 0; i < 8; i++) {
      reader->deleteDocument(i);
    }
    assertEquals(22, reader->numDocs());
    reader->close();
    _CLLDELETE( reader );

    writer = newWriter(dir, &an, false);
    writer->setMaxBufferedDocs(6);
    writer->setMergeFactor(4);

    ValueArray<Directory*> dirs2(2);
    dirs2[0] = aux;
    dirs2[1] = aux2;
    writer->addIndexesNoOptimize(dirs2);

    assertEquals(1025, writer->docCount());
    assertEquals(1000, writer->getDocCount(0));
    writer->close();
    _CLLDELETE( writer );

    // make sure the index is correct
    verifyNumDocs(tc, dir, 1025);

    dir->close();
    _CLLDELETE(dir);

    aux->close();
    _CLLDELETE(aux);

    aux2->close();
    _CLLDELETE(aux2);
}
void testSimpleCase(CuTest *tc) {

    // main directory
    Directory * dir = _CLNEW RAMDirectory();
    // two auxiliary directories
    Directory * aux = _CLNEW RAMDirectory();
    Directory * aux2 = _CLNEW RAMDirectory();

    IndexWriter4Test * writer = NULL;

    WhitespaceAnalyzer analyzer;

    writer = newWriter(dir, &analyzer, true);

    // add 100 documents
    addDocs(writer, 100);
    assertEquals(100, writer->docCount());
    writer->close();
    _CLLDELETE(writer);

    writer = newWriter(aux, &analyzer, true);
    writer->setUseCompoundFile(false); // use one without a compound file
    // add 40 documents in separate files
    addDocs(writer, 40);
    assertEquals(40, writer->docCount());
    writer->close();
    _CLLDELETE(writer);

    writer = newWriter(aux2, &analyzer, true);
    // add 40 documents in compound files
    addDocs2(writer, 50);
    assertEquals(50, writer->docCount());
    writer->close();
    _CLLDELETE(writer);

    // test doc count before segments are merged
    writer = newWriter(dir, &analyzer, false);
    assertEquals(100, writer->docCount());
    {
        ValueArray<Directory*> dirs(2);
        dirs[0] = aux;
        dirs[1] = aux2;
        writer->addIndexesNoOptimize( dirs );
    }
    assertEquals(190, writer->docCount());
    writer->close();
    _CLLDELETE(writer);

    // make sure the old index is correct
    verifyNumDocs(tc, aux, 40);

    // make sure the new index is correct
    verifyNumDocs(tc, dir, 190);

    // now add another set in.
    Directory * aux3 = _CLNEW RAMDirectory();
    writer = newWriter(aux3, &analyzer, true);
    // add 40 documents
    addDocs(writer, 40);
    assertEquals(40, writer->docCount());
    writer->close();
    _CLLDELETE(writer);

    // test doc count before segments are merged/index is optimized
    writer = newWriter(dir, &analyzer, false);
    assertEquals(190, writer->docCount());
    {
        ValueArray<Directory*> dirs(1);
        dirs[0] = aux3;
        writer->addIndexesNoOptimize( dirs );
    }
    assertEquals(230, writer->docCount());
    writer->close();
    _CLLDELETE(writer);

    // make sure the new index is correct
    verifyNumDocs(tc, dir, 230);

    Term t1(_T("content"), _T("aaa"));
    Term t2(_T("content"), _T("bbb"));

    verifyTermDocs(tc, dir, &t1, 180);
    verifyTermDocs(tc, dir, &t2, 50);

    // now optimize it.
    writer = newWriter(dir, &analyzer, false);
    writer->optimize();
    writer->close();
    _CLLDELETE(writer);

    // make sure the new index is correct
    verifyNumDocs(tc, dir, 230);

    verifyTermDocs(tc, dir, &t1, 180);
    verifyTermDocs(tc, dir, &t2, 50);

    // now add a single document
    Directory * aux4 = _CLNEW RAMDirectory();
    writer = newWriter(aux4, &analyzer, true);
    addDocs2(writer, 1);
    writer->close();
    _CLLDELETE(writer);

    writer = newWriter(dir, &analyzer, false);
    assertEquals(230, writer->docCount());

    {
        ValueArray<Directory*> dirs(1);
        dirs[0] = aux4;
        writer->addIndexesNoOptimize( dirs );
    }

    assertEquals(231, writer->docCount());
    writer->close();
    _CLLDELETE(writer);

    verifyNumDocs(tc, dir, 231);

    verifyTermDocs(tc, dir, &t2, 51);

    dir->close();
    _CLLDELETE(dir);
    aux->close();
    _CLLDELETE(aux);
    aux2->close();
    _CLLDELETE(aux2);
    aux3->close();
    _CLLDELETE(aux3);
    aux4->close();
    _CLLDELETE(aux4);
}
	bool AssetsEditorScene::_userUpdateBegin(float time)
	{
		// dirty ! We list files
		static float refreshCounter = 1.0f;
		if (refreshCounter >= 1.0f)
		{
			_cookedPhysicsFiles.clear();
			_cookedPhysicsFullPath.clear();
			_cookedMaterialFiles.clear();
			_cookedMaterialFullPath.clear();
			_cookedMeshFiles.clear();
			_cookedMeshsFullPath.clear();
			_cookedFiles.clear();
			_cookedTextureFiles.clear();
			_cookedTextureFullPath.clear();

			_cookedPhysicsFiles.push_back("NONE");
			_cookedPhysicsFullPath.push_back("NONE");
			_cookedMaterialFiles.push_back("NONE");
			_cookedMaterialFullPath.push_back("NONE");
			_cookedMeshFiles.push_back("NONE");
			_cookedMeshsFullPath.push_back("NONE");
			_cookedTextureFiles.push_back("NONE");
			_cookedTextureFullPath.push_back("NONE");

			const std::string currentDir = Directory::GetCurrentDirectory();
			const std::string absPath = Path::AbsoluteName(currentDir.c_str(), WE::EditorConfiguration::GetCookedDirectory().c_str());
			Directory dir;
			const bool succeed = dir.open(absPath.c_str());
			AGE_ASSERT(succeed && "Impossible to open directory");
			for (auto it = dir.recursive_begin(); it != dir.recursive_end(); ++it)
			{
				if (Directory::IsFile(*it))
				{
					_cookedFiles.push_back(AssetsEditorFileDescriptor(Path::RelativeName(absPath.c_str(), *it), Path::BaseName(*it)));

					auto extension = FileUtils::GetExtension(*it);
					if (extension == "sage")
					{
						_cookedMeshFiles.push_back(_cookedFiles.back().fileName.c_str());
						_cookedMeshsFullPath.push_back(_cookedFiles.back().fullPath.c_str());
					}
					else if (extension == "mage")
					{
						_cookedMaterialFiles.push_back(_cookedFiles.back().fileName.c_str());
						_cookedMaterialFullPath.push_back(_cookedFiles.back().fullPath.c_str());
					}
					else if (extension == "phage")
					{
						_cookedPhysicsFiles.push_back(_cookedFiles.back().fileName.c_str());
						_cookedPhysicsFullPath.push_back(_cookedFiles.back().fullPath.c_str());
					}
					else if (extension == "dds")
					{
						_cookedTextureFiles.push_back(_cookedFiles.back().fileName.c_str());
						_cookedTextureFullPath.push_back(_cookedFiles.back().fullPath.c_str());
					}
				}
			}
			dir.close();
			refreshCounter = 0;
		}
		refreshCounter += time;

		if (_displayWindow == false)
		{
			return true;
		}

		ImGui::Begin("Assets browser");
		{
			{
				ImGui::BeginChild("Raw", ImVec2(0, 0), false);
				_raw.update(
					std::function<bool(FileUtils::Folder*)>([](FileUtils::Folder* folder) {
					bool opened = ImGui::TreeNode((void*)(folder), folder->_path.path().filename().c_str());
					if (opened)
					{
						ImGui::Separator();
					}
					return opened;
				}),
					std::function<bool(FileUtils::Folder*)>([](FileUtils::Folder* folder) {
					ImGui::Separator();
					ImGui::TreePop();
					return true;
				}),
					std::function<void(FileUtils::RawFile*)>([&](FileUtils::RawFile* file) {
					AE::AssetFileManager::PrintClickableRawAssetsFile(file, AE::AssetFileManager::PrintSection::Date | AE::AssetFileManager::PrintSection::Name | AE::AssetFileManager::PrintSection::Type, _selectedRaw);
				}));
				ImGui::EndChild();
			}
			//{
			//	ImGui::BeginChild("Cooked", ImVec2(0, ImGui::GetIO().DisplaySize.y / 2 - 10), false);
			//	//_cook.printImgUi(AE::AssetFile::PrintInfos(AE::AssetFile::Name | AE::AssetFile::Type | AE::AssetFile::Date));
			//	ImGui::EndChild();
			//}
		}
		Singleton<AGE::AE::ConvertorStatusManager>::getInstance()->DisplayTasks();
		ImGui::End();

		if (_selectedRaw != nullptr)
		{
			ImGui::Begin("Selected Raw");
			{
				if (_selectedRaw->dataSet == nullptr)
				{
					auto path = _selectedRaw->getPath();
					path = path.erase(0, _raw._path.path().string().size());
					//_selectedRaw->dataSet->filePath = File(path);
					_selectedRaw->dataSet = std::make_shared<AssetDataSet>(path);

				}
				if (!_selectedRaw->dataSet->isConverting)
				{
					_selectedRaw->selection();
					ImGui::Separator();
					if (ImGui::Button("Cook"))
						_selectedRaw->cook();
				}
				else
				{
					ImGui::TextColored(ImVec4(1, 0, 0, 1), "Currently cooking : %s", _selectedRaw->getFileName().c_str());
				}
			}
			ImGui::End();
		}
		return true;
	}
	void MaterialEditorScene::_selectMaterial()
	{
		const std::string currentDir = Directory::GetCurrentDirectory();
		const std::string absPath = Path::AbsoluteName(currentDir.c_str(), WE::EditorConfiguration::GetCookedDirectory().c_str());
		static std::vector<std::string> materialGettable;
		static std::vector<std::string> materialFullPath;
		static int counter = 0;
		++counter;
		if (counter > 20)
		{
			materialGettable.clear();
			materialFullPath.clear();

			Directory dir;
			const bool succeed = dir.open(absPath.c_str());
			AGE_ASSERT(succeed && "Impossible to open directory");
			for (auto it = dir.recursive_begin(); it != dir.recursive_end(); ++it)
			{
				if (Directory::IsFile(*it) && FileUtils::GetExtension(*it) == "mage")
				{
					materialGettable.push_back(std::string(Path::RelativeName(absPath.c_str(), *it)));
					materialFullPath.push_back(*it);
				}
			}
			dir.close();
			counter = 0;
		}

		static ImGuiTextFilter filter;
		ImGui::Text("Search");
		filter.Draw();

		ImGui::ListBoxHeader("List of existing material", size);
		for (int i = 0; i < materialFullPath.size(); ++i)
		{
			if (filter.PassFilter(materialGettable[i].c_str()))
			{
				if (ImGui::Selectable(materialGettable[i].c_str()))
				{
					_indexMaterial = i;
				}
			}
		}
		ImGui::ListBoxFooter();

		if (_indexMaterial != -1 && ImGui::Button("open a material"))
		{
			_resetEdition();

			std::shared_ptr<MaterialDataSet> material_data_set = std::make_shared<MaterialDataSet>();
			std::ifstream ifs(materialFullPath[_indexMaterial], std::ios::binary);
			cereal::PortableBinaryInputArchive ar(ifs);
			ar(*material_data_set.get());
			_current = *material_data_set;
			if (_current.name == "")
			{
				std::string fileName = std::string(materialGettable[_indexMaterial]);
				_current.name = fileName.substr(0, fileName.find('.'));
			}
			_mode = ModeMaterialEditor::selectSubMaterial;
		}
		if (_indexMaterial == -1)
		{
			ImGui::Text("Please select one material for edition");
		}
	}