void ViewController::reloadGameListView(IGameListView* view, bool reloadTheme)
{
	for(auto it = mGameListViews.begin(); it != mGameListViews.end(); it++)
	{
		if(it->second.get() == view)
		{
			bool isCurrent = (mCurrentView == it->second);
			SystemData* system = it->first;
			FileData* cursor = view->getCursor();
			mGameListViews.erase(it);

			if(reloadTheme)
				system->loadTheme();

			std::shared_ptr<IGameListView> newView = getGameListView(system);

			// to counter having come from a placeholder
			if (!cursor->isPlaceHolder()) {
				newView->setCursor(cursor);
			}

			if(isCurrent)
				mCurrentView = newView;

			break;
		}
	}
	// Redisplay the current view
	if (mCurrentView)
		mCurrentView->onShow();

}
Example #2
0
int
main(int, char **)
{
    FileData table;

    QTextStream stream(stdin);

    while (true)
    {
        QString path = stream.readLine(); 
        if (path.isNull()) break;

        QFileInfo pathfi(path);

        FileData::Data data;
        data.isdir_ = pathfi.isDir();
        path = pathfi.absoluteFilePath();

        bool flag;
        table.insert(path, data, flag);
    }

    table.print();

    return(0);
}
FileData *luax_getfiledata(lua_State *L, int idx)
{
	FileData *data = nullptr;
	File *file = nullptr;

	if (lua_isstring(L, idx) || luax_istype(L, idx, FILESYSTEM_FILE_ID))
	{
		file = luax_getfile(L, idx);
		file->retain();
	}
	else if (luax_istype(L, idx, FILESYSTEM_FILE_DATA_ID))
	{
		data = luax_checkfiledata(L, idx);
		data->retain();
	}

	if (!data && !file)
	{
		luaL_argerror(L, idx, "filename, File, or FileData expected");
		return nullptr; // Never reached.
	}

	if (file)
	{
		luax_catchexcept(L,
			[&]() { data = file->read(); },
			[&](bool) { file->release(); }
		);
	}

	return data;
}
Example #4
0
Shader* create_shader_from_filename(const std::string& filename) {
	std::vector<ShaderStage*> shader_list;
	{
		FileData file = load_file(filename + ".vert");
		shader_list.push_back(new ShaderStage(compile_shader(GL_VERTEX_SHADER, filename.c_str(), file.data())));
	}
	{
		FileData file = load_file(filename + ".frag");
		shader_list.push_back(new ShaderStage(compile_shader(GL_FRAGMENT_SHADER, filename.c_str(), file.data())));
	}

	for(ShaderStage* s : shader_list) {
		if(s->resource == 0) {
			std::for_each(shader_list.begin(), shader_list.end(), free_shaderstage);
			return nullptr;
		}
	}

	GLuint resource = link_program(filename.c_str(), shader_list);
	std::for_each(shader_list.begin(), shader_list.end(), free_shaderstage);

	if(resource == 0) return nullptr;

	Shader* shader = new Shader();
	shader->resource = resource;

	init_shader(shader);

	return shader;
}
void BasicGameListView::setCursor(FileData* cursor)
{
	if (cursor->isPlaceHolder())
		return;
	if(!mList.setCursor(cursor))
	{
		populateList(cursor->getParent()->getChildrenListToDisplay());
		mList.setCursor(cursor);

		// update our cursor stack in case our cursor just got set to some folder we weren't in before
		if(mCursorStack.empty() || mCursorStack.top() != cursor->getParent())
		{
			std::stack<FileData*> tmp;
			FileData* ptr = cursor->getParent();
			while(ptr && ptr != mRoot)
			{
				tmp.push(ptr);
				ptr = ptr->getParent();
			}
			
			// flip the stack and put it in mCursorStack
			mCursorStack = std::stack<FileData*>();
			while(!tmp.empty())
			{
				mCursorStack.push(tmp.top());
				tmp.pop();
			}
		}
	}
}
Example #6
0
/**
 * Remove old files from the list of monitored files.
 * Normally these files are deleted from the list when they are processed.
 * However if a file was detected by function "CanProcessFile" once but wasn't 
 * processed later (for example if the user deleted it), it will stay in the list,
 * until we remove it here.
 */
void Scanner::DropOldFiles()
{
	time_t tCurrent = time(NULL);

	int i = 0;
	for (FileList::iterator it = m_FileList.begin(); it != m_FileList.end(); )
    {
        FileData* pFileData = *it;
		if ((tCurrent - pFileData->GetLastChange() >= 
			(g_pOptions->GetNzbDirInterval() + g_pOptions->GetNzbDirFileAge()) * 2) ||
			// can occur if the system clock was adjusted
			tCurrent < pFileData->GetLastChange())
		{
			debug("Removing file %s from scan file list", pFileData->GetFilename());

			delete pFileData;
			m_FileList.erase(it);
			it = m_FileList.begin() + i;
		}
		else
		{
			it++;
			i++;
		}
	}
}
Example #7
0
BOOL perlRegex::include(FileData &file) const
{
    boost::xpressive::wsmatch results;
    if (boost::xpressive::regex_search(file.getFileName().begin(), file.getFileName().end(), results, regex))
        return true;
    return false;
};
bool UIImage::initWithContentsOfFile(const string &strPath, eImageFormat imageType)
{
	bool bRet = false;
	
	FileData data;
    unsigned long nSize  = 0;
    unsigned char* pBuffer = data.getFileData(strPath.c_str(), "rb", &nSize);

    if (pBuffer)
    {
	    switch (imageType)
	    {
	    case kCCImageFormatPNG:
		    // use libpng load image
		    bRet = loadPngFromStream(pBuffer, nSize);
		    break;
	    case kCCImageFormatJPG:
		    bRet = loadJpgFromStream(pBuffer, nSize);
		    break;
	    default:
		    // unsupported image type
		    bRet = false;
		    break;
	    }
    }

	return bRet;
}
void GridGameListView::remove(FileData *game, bool deleteFile)
{
	if (deleteFile)
		Utils::FileSystem::removeFile(game->getPath());  // actually delete the file on the filesystem
	FileData* parent = game->getParent();
	if (getCursor() == game)                     // Select next element in list, or prev if none
	{
		std::vector<FileData*> siblings = parent->getChildrenListToDisplay();
		auto gameIter = std::find(siblings.cbegin(), siblings.cend(), game);
		int gamePos = (int)std::distance(siblings.cbegin(), gameIter);
		if (gameIter != siblings.cend())
		{
			if ((gamePos + 1) < (int)siblings.size())
			{
				setCursor(siblings.at(gamePos + 1));
			} else if ((gamePos - 1) > 0) {
				setCursor(siblings.at(gamePos - 1));
			}
		}
	}
	mGrid.remove(game);
	if(mGrid.size() == 0)
	{
		addPlaceholder();
	}
	delete game;                                 // remove before repopulating (removes from parent)
	onFileChanged(parent, FILE_REMOVED);           // update the view, with game removed
}
Example #10
0
int w_newFileData(lua_State *L)
{
	// Single argument: treat as filepath or File.
	if (lua_gettop(L) == 1)
	{
		// We don't use luax_getfiledata because we want to use an ioError.
		if (lua_isstring(L, 1))
			luax_convobj(L, 1, "filesystem", "newFile");

		// Get FileData from the File.
		if (luax_istype(L, 1, FILESYSTEM_FILE_ID))
		{
			File *file = luax_checkfile(L, 1);

			FileData *data = 0;
			try
			{
				data = file->read();
			}
			catch (love::Exception &e)
			{
				return luax_ioError(L, "%s", e.what());
			}
			luax_pushtype(L, FILESYSTEM_FILE_DATA_ID, data);
			data->release();
			return 1;
		}
		else
			return luaL_argerror(L, 1, "filename or File expected");
	}

	size_t length = 0;
	const char *str = luaL_checklstring(L, 1, &length);
	const char *filename = luaL_checkstring(L, 2);
	const char *decstr = lua_isstring(L, 3) ? lua_tostring(L, 3) : 0;

	FileData::Decoder decoder = FileData::FILE;

	if (decstr && !FileData::getConstant(decstr, decoder))
		return luaL_error(L, "Invalid FileData decoder: %s", decstr);

	FileData *t = 0;

	switch (decoder)
	{
	case FileData::FILE:
		t = instance()->newFileData((void *)str, (int)length, filename);
		break;
	case FileData::BASE64:
		t = instance()->newFileData(str, filename);
		break;
	default:
		return luaL_error(L, "Invalid FileData decoder: %s", decstr);
	}

	luax_pushtype(L, FILESYSTEM_FILE_DATA_ID, t);
	t->release();
	return 1;
}
void ISimpleGameListView::onFileChanged(FileData* file, FileChangeType change)
{
	// we could be tricky here to be efficient;
	// but this shouldn't happen very often so we'll just always repopulate
	FileData* cursor = getCursor();
	populateList(cursor->getParent()->getChildren());
	setCursor(cursor);
}
Example #12
0
BOOL RvFindRegex::include(FileData &file, const std::wstring& regex, const std::wstring& pathRoot) const
{
    if (pathRoot.size())
    {
        if (!boost::algorithm::istarts_with(file.getFileName(), pathRoot))
            return false;
    }
    return fpattern_matchn(regex.c_str() , file.getFileName().c_str() + (std::find(file.getFileName().rbegin(), file.getFileName().rend(), L'\\').base() - file.getFileName().begin()));
}
Example #13
0
BOOL NRvFindRegex::include(FileData &file, const std::wstring& regex, const std::wstring& pathRoot) const
{
    if (!boost::algorithm::iequals(pathRoot,
        boost::make_iterator_range(file.getFileName().begin(),
        std::find(file.getFileName().rbegin(), file.getFileName().rend(), L'\\').base())
        ))
        return false;
    return fpattern_matchn(regex.c_str(), file.getFileName().c_str() + (file.getFileName().end() - (std::find(file.getFileName().rbegin(), file.getFileName().rend(), L'\\').base() + 1)) );
}
bool ISimpleGameListView::input(InputConfig* config, Input input)
{
	if(input.value != 0)
	{
		if(config->isMappedTo("a", input))
		{
			FileData* cursor = getCursor();
			if(cursor->getType() == GAME)
			{
				Sound::getFromTheme(getTheme(), getName(), "launch")->play();
				launch(cursor);
			}else{
				// it's a folder
				if(cursor->getChildren().size() > 0)
				{
					mCursorStack.push(cursor);
					populateList(cursor->getChildren());
				}
			}
				
			return true;
		}else if(config->isMappedTo("b", input))
		{
			if(mCursorStack.size())
			{
				populateList(mCursorStack.top()->getParent()->getChildren());
				setCursor(mCursorStack.top());
				mCursorStack.pop();
				Sound::getFromTheme(getTheme(), getName(), "back")->play();
			}else{
				onFocusLost();
				ViewController::get()->goToSystemView(getCursor()->getSystem());
			}

			return true;
		}else if(config->isMappedTo("right", input) || config->isMappedTo("righttop", input))
		{
			if(Settings::getInstance()->getBool("QuickSystemSelect"))
			{
				onFocusLost();
				ViewController::get()->goToNextGameList();
				return true;
			}
		}else if(config->isMappedTo("left", input) || config->isMappedTo("lefttop", input))
		{
			if(Settings::getInstance()->getBool("QuickSystemSelect"))
			{
				onFocusLost();
				ViewController::get()->goToPrevGameList();
				return true;
			}
		}
	}

	return IGameListView::input(config, input);
}
Example #15
0
/**
 * Only files which were not changed during last g_pOptions->GetNzbDirFileAge() seconds
 * can be processed. That prevents the processing of files, which are currently being
 * copied into nzb-directory (eg. being downloaded in web-browser).
 */
bool Scanner::CanProcessFile(const char* szFullFilename, bool bCheckStat)
{
	const char* szExtension = strrchr(szFullFilename, '.');
	if (!szExtension ||
		!strcasecmp(szExtension, ".queued") ||
		!strcasecmp(szExtension, ".error") ||
		!strcasecmp(szExtension, ".processed"))
	{
		return false;
	}

	if (!bCheckStat)
	{
		return true;
	}

	long long lSize = Util::FileSize(szFullFilename);
	time_t tCurrent = time(NULL);
	bool bCanProcess = false;
	bool bInList = false;

	for (FileList::iterator it = m_FileList.begin(); it != m_FileList.end(); it++)
    {
        FileData* pFileData = *it;
		if (!strcmp(pFileData->GetFilename(), szFullFilename))
		{
			bInList = true;
			if (pFileData->GetSize() == lSize &&
				tCurrent - pFileData->GetLastChange() >= g_pOptions->GetNzbDirFileAge())
			{
				bCanProcess = true;
				delete pFileData;
				m_FileList.erase(it);
			}
			else
			{
				pFileData->SetSize(lSize);
				if (pFileData->GetSize() != lSize)
				{
					pFileData->SetLastChange(tCurrent);
				}
			}
			break;
		}
	}

	if (!bInList)
	{
		FileData* pFileData = new FileData(szFullFilename);
		pFileData->SetSize(lSize);
		pFileData->SetLastChange(tCurrent);
		m_FileList.push_back(pFileData);
	}

	return bCanProcess;
}
Example #16
0
int main() {
    FileData<char> cd;
    FileData<string> strd;
    FileData<int> id;
    fstream f;
    char c;
    string str;
    int n;
    cout<<"Enter a character, a string, a number in that order\n";
    cin>>c>>str>>n;
    f.open("sample.txt",fstream::in|fstream::out);
    cd.setData(&f,c);
    cd.setData(&f,'\n');

    strd.setData(&f,str);
    cd.setData(&f,'\n');

    id.setData(&f,n);
    cd.setData(&f,'\n');

    cout<<"retriving data from the file:\n";
    f>>c;
    cout<<c<<endl;

    f>>str;
    cout<<str<<endl;

    f>>n;
    cout<<n<<endl;
    return 0;

}
void GridGameListView::updateInfoPanel()
{
	FileData* file = (mGrid.size() == 0 || mGrid.isScrolling()) ? NULL : mGrid.getSelected();

	bool fadingOut;
	if(file == NULL)
	{
		//mDescription.setText("");
		fadingOut = true;
	}else{
		mDescription.setText(file->metadata.get("desc"));
		mDescContainer.reset();

		mRating.setValue(file->metadata.get("rating"));
		mReleaseDate.setValue(file->metadata.get("releasedate"));
		mDeveloper.setValue(file->metadata.get("developer"));
		mPublisher.setValue(file->metadata.get("publisher"));
		mGenre.setValue(file->metadata.get("genre"));
		mPlayers.setValue(file->metadata.get("players"));
		mName.setValue(file->metadata.get("name"));

		if(file->getType() == GAME)
		{
			mLastPlayed.setValue(file->metadata.get("lastplayed"));
			mPlayCount.setValue(file->metadata.get("playcount"));
		}

		fadingOut = false;
	}

	std::vector<GuiComponent*> comps = getMDValues();
	comps.push_back(&mDescription);
	comps.push_back(&mName);
	std::vector<TextComponent*> labels = getMDLabels();
	comps.insert(comps.cend(), labels.cbegin(), labels.cend());

	for(auto it = comps.cbegin(); it != comps.cend(); it++)
	{
		GuiComponent* comp = *it;
		// an animation is playing
		//   then animate if reverse != fadingOut
		// an animation is not playing
		//   then animate if opacity != our target opacity
		if((comp->isAnimationPlaying(0) && comp->isAnimationReversed(0) != fadingOut) ||
		   (!comp->isAnimationPlaying(0) && comp->getOpacity() != (fadingOut ? 0 : 255)))
		{
			auto func = [comp](float t)
			{
				comp->setOpacity((unsigned char)(Math::lerp(0.0f, 1.0f, t)*255));
			};
			comp->setAnimation(new LambdaAnimation(func, 150), 0, nullptr, fadingOut);
		}
	}
}
GuiGamelistOptions::~GuiGamelistOptions()
{
	// save and apply sort
	SystemData* system = getGamelist()->getCursor()->getSystem();
	FileData* root = system->getRootFolder();
	system->sortId = mListSort->getSelectedId(); // this will break if mListSort isn't in the same order as FileSorts:typesArr
	root->sort(*mListSort->getSelected()); // will also recursively sort children

	// notify that the root folder was sorted
	getGamelist()->onFileChanged(root, FILE_SORTED);
}
Example #19
0
void GuiGameList::onInput(InputManager::InputButton button, bool keyDown)
{
	if(button == InputManager::BUTTON1 && mFolder->getFileCount() > 0)
	{
		if(!keyDown)
		{
			FileData* file = mList->getSelectedObject();
			if(file->isFolder())
			{
				//set current directory to this or something
				mFolderStack.push(mFolder);
				mFolder = (FolderData*)file;
				updateList();
			}else{
				mSystem->launchGame((GameData*)file);
			}
		}
	}

	if(button == InputManager::BUTTON2 && keyDown && mFolderStack.size())
	{
		mFolder = mFolderStack.top();
		mFolderStack.pop();
		updateList();
	}

	if(button == InputManager::RIGHT && keyDown)
	{
		setSystemId(mSystemId + 1);
	}
	if(button == InputManager::LEFT && keyDown)
	{
		setSystemId(mSystemId - 1);
	}

	if(button == InputManager::MENU && keyDown)
	{
		new GuiMenu(this);
	}

	if(mDetailed)
	{
		if(!keyDown && (button == InputManager::UP || button == InputManager::DOWN))
		{
			if(mList->getSelectedObject() && !mList->getSelectedObject()->isFolder())
			{
				mScreenshot->setImage(((GameData*)mList->getSelectedObject())->getImagePath());
			}else{
				mScreenshot->setImage("");
			}
		}
	}
}
void GuiGamelistOptions::openMetaDataEd()
{
	// open metadata editor
	FileData* file = getGamelist()->getCursor();
	ScraperSearchParams p;
	p.game = file;
	p.system = file->getSystem();
	mWindow->pushGui(new GuiMetaDataEd(mWindow, &file->metadata, file->metadata.getMDD(), p, file->getPath().filename().string(), 
		std::bind(&IGameListView::onFileChanged, getGamelist(), file, FILE_METADATA_CHANGED), [this, file] { 
			getGamelist()->remove(file);
	}));
}
Example #21
0
void DataModelTest::parseFile()
{
    const QString path = QFINDTESTDATA("/data/massif.out.kate");
    QFile file(path);
    QVERIFY(file.open(QIODevice::ReadOnly));

    Parser parser;
    QScopedPointer<FileData> scopedData(parser.parse(&file));
    FileData* data = scopedData.data();
    QVERIFY(data);

    {
        TotalCostModel* model = new TotalCostModel(this);
        new ModelTest(model, this);
        model->setSource(data);
        QVERIFY(model->rowCount() == data->snapshots().size());
        for ( int r = 0; r < model->rowCount(); ++r ) {
            for ( int c = 0; c < model->columnCount(); ++c ) {
                qDebug() << r << c << model->data(model->index(r, c));
            }
        }
        // remove data
        model->setSource(0);
    }

    {
        DetailedCostModel* model = new DetailedCostModel(this);
        new ModelTest(model, this);
        model->setSource(data);
        for ( int r = 0; r < model->rowCount(); ++r ) {
            for ( int c = 0; c < model->columnCount(); ++c ) {
                qDebug() << r << c << model->data(model->index(r, c));
            }
            if ( r ) {
                // we want that the snapshots are ordered properly
                QVERIFY(model->data(model->index(r, 0)).toDouble() > model->data(model->index(r - 1, 0)).toDouble());
            }
        }
        // remove data
        model->setSource(0);
    }

    {
        DataTreeModel* model = new DataTreeModel(this);
        new ModelTest(model, this);
        model->setSource(data);
        QVERIFY(model->rowCount() == data->snapshots().size());
        // remove data
        model->setSource(0);
    }

}
void GuiFastSelect::updateGameListSort()
{
	const FileData::SortType& sort = FileSorts::SortTypes.at(mSortId);

	SystemData* system = mGameList->getCursor()->getSystem();
	FileData* root = system->getRootFolder();

	system->sortId = mSortId; // update system sort setting

	root->sort(sort); // will also recursively sort children

	// notify that the root folder was sorted
	mGameList->onFileChanged(root, FILE_SORTED);
}
void GuiGamelistOptions::openMetaDataEd()
{
	// open metadata editor
	FileData* file = getGamelist()->getCursor();
	ScraperSearchParams p;
	p.game = file;
	p.system = file->getSystem();
	mWindow->pushGui(new GuiMetaDataEd(mWindow, &file->metadata, file->metadata.getMDD(), p, file->getPath().filename().string(), 
		std::bind(&IGameListView::onFileChanged, getGamelist(), file, FILE_METADATA_CHANGED), [this, file] { 
			boost::filesystem::remove(file->getPath()); //actually delete the file on the filesystem
			file->getParent()->removeChild(file); //unlink it so list repopulations triggered from onFileChanged won't see it
			getGamelist()->onFileChanged(file, FILE_REMOVED); //tell the view
			delete file; //free it
	}));
}
// this updates all collection files related to the argument file
void CollectionSystemManager::updateCollectionSystems(FileData* file)
{
	// collection files use the full path as key, to avoid clashes
	std::string key = file->getFullPath();
	// find games in collection systems
	for(auto sysIt = SystemData::sSystemVector.begin(); sysIt != SystemData::sSystemVector.end(); sysIt++)
	{
		if ((*sysIt)->isCollection()) {
			const std::unordered_map<std::string, FileData*>& children = (*sysIt)->getRootFolder()->getChildrenByFilename();
			bool found = children.find(key) != children.end();
			FileData* rootFolder = (*sysIt)->getRootFolder();
			FileFilterIndex* fileIndex = (*sysIt)->getIndex();
			std::string name = (*sysIt)->getName();
			if (found) {
				// if we found it, we need to update it
				FileData* collectionEntry = children.at(key);
				// remove from index, so we can re-index metadata after refreshing
				fileIndex->removeFromIndex(collectionEntry);
				collectionEntry->refreshMetadata();
				if (name == "favorites" && file->metadata.get("favorite") == "false") {
					// need to check if still marked as favorite, if not remove
					ViewController::get()->getGameListView((*sysIt)).get()->remove(collectionEntry, false);
					ViewController::get()->onFileChanged((*sysIt)->getRootFolder(), FILE_REMOVED);
				}
				else
				{
					// re-index with new metadata
					fileIndex->addToIndex(collectionEntry);
					ViewController::get()->onFileChanged(collectionEntry, FILE_METADATA_CHANGED);
				}
			}
			else
			{
				// we didn't find it here - we need to check if we should add it
				if (name == "recent" && file->metadata.get("playcount") > "0" ||
					name == "favorites" && file->metadata.get("favorite") == "true") {
					CollectionFileData* newGame = new CollectionFileData(file, (*sysIt));
					rootFolder->addChild(newGame);
					fileIndex->addToIndex(newGame);
					ViewController::get()->onFileChanged(file, FILE_METADATA_CHANGED);
					ViewController::get()->getGameListView((*sysIt))->onFileChanged(newGame, FILE_METADATA_CHANGED);
				}
			}
			rootFolder->sort(getSortType(mCollectionSystemDecls[name].defaultSort));
			ViewController::get()->onFileChanged(rootFolder, FILE_SORTED);
		}
	}
}
Example #25
0
BOOL sha1EList::include(FileData &file) const
{
    std::wstring calcHash = file.SHA1();
    if (calcHash[0] == L'!')
        return true;
    return std::binary_search(values.begin(),values.end(),calcHash);
}
void BasicGameListView::setCursor(const FileData& cursor)
{
	if(!mList.setCursor(cursor))
	{
		LOG(LogWarning) << "Tried to setCursor to non-present filedata (" << cursor.getFileID() << " for system " << cursor.getSystemID() << ")";
	}
}
Example #27
0
void FileCtrl::UpdateItem(const wxListItem &item)
{
    FileData *fd = (FileData*)GetItemData(item);
    wxCHECK_RET(fd, wxT("invalid filedata"));

    fd->ReadData();

    SetItemText(item, fd->GetFileName());
    SetItemImage(item, fd->GetImageId());

    if (GetWindowStyleFlag() & wxLC_REPORT)
    {
        for (int i = 1; i < FileData::FileList_Max; i++)
            SetItem( item.m_itemId, i, fd->GetEntry((FileData::fileListFieldType)i) );
    }
}
Example #28
0
Resource FileResourceLoader::get(const ResourceId &id)
{
	if (id.getType() & "File")
	{
		fs::path p((m_basePath / id.getName()).native_directory_string());

		if (fs::exists(p))
		{
			FileData *pData = new FileData(this);
			pData->setId(id);
			pData->setPath(p);
			return FileResource(pData);
		}
	}
	return Resource();
}
void CollectionSystemManager::loadAutoCollectionSystems()
{
	for(std::map<std::string, CollectionSystemDecl>::iterator it = mCollectionSystemDecls.begin() ; it != mCollectionSystemDecls.end() ; it++ )
	{
		CollectionSystemDecl sysDecl = it->second;
		if (!sysDecl.isCustom && !findCollectionSystem(sysDecl.name))
		{
			SystemData* newSys = new SystemData(sysDecl.name, sysDecl.longName, mCollectionEnvData, sysDecl.themeFolder, true);

			FileData* rootFolder = newSys->getRootFolder();
			FileFilterIndex* index = newSys->getIndex();
			for(auto sysIt = SystemData::sSystemVector.begin(); sysIt != SystemData::sSystemVector.end(); sysIt++)
			{
				if ((*sysIt)->isGameSystem()) {
					std::vector<FileData*> files = (*sysIt)->getRootFolder()->getFilesRecursive(GAME);
					for(auto gameIt = files.begin(); gameIt != files.end(); gameIt++)
					{
						bool include = includeFileInAutoCollections((*gameIt));
						switch(sysDecl.type) {
							case AUTO_LAST_PLAYED:
								include = include && (*gameIt)->metadata.get("playcount") > "0";
								break;
							case AUTO_FAVORITES:
								// we may still want to add files we don't want in auto collections in "favorites"
								include = (*gameIt)->metadata.get("favorite") == "true";
								break;
						}

						if (include) {
							CollectionFileData* newGame = new CollectionFileData(*gameIt, newSys);
							rootFolder->addChild(newGame);
							index->addToIndex(newGame);
						}
					}
				}
			}
			rootFolder->sort(getSortType(sysDecl.defaultSort));
			mAutoCollectionSystems.push_back(newSys);

			CollectionSystemData newCollectionData;
			newCollectionData.system = newSys;
			newCollectionData.decl = sysDecl;
			newCollectionData.isEnabled = false;
			mAllCollectionSystems[sysDecl.name] = newCollectionData;
		}
	}
}
Example #30
0
void FileCtrl::OnListEndLabelEdit( wxListEvent &event )
{
    FileData *fd = (FileData*)event.m_item.m_data;
    wxASSERT( fd );

    if ((event.GetLabel().empty()) ||
            (event.GetLabel() == _(".")) ||
            (event.GetLabel() == _("..")) ||
            (event.GetLabel().First( wxFILE_SEP_PATH ) != wxNOT_FOUND))
    {
        wxMessageDialog dialog(this, _("Illegal directory name."), _("Error"), wxOK | wxICON_ERROR );
        dialog.ShowModal();
        event.Veto();
        return;
    }

    wxString new_name( wxPathOnly( fd->GetFilePath() ) );
    new_name += wxFILE_SEP_PATH;
    new_name += event.GetLabel();

    wxLogNull log;

    if (wxFileExists(new_name))
    {
        wxMessageDialog dialog(this, _("File name exists already."), _("Error"), wxOK | wxICON_ERROR );
        dialog.ShowModal();
        event.Veto();
    }

    if (wxRenameFile(fd->GetFilePath(),new_name))
    {
        fd->SetNewName( new_name, event.GetLabel() );

        ignoreChanges = true;
        SetItemState( event.GetItem(), wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED );
        ignoreChanges = false;

        UpdateItem( event.GetItem() );
        EnsureVisible( event.GetItem() );
    }
    else
    {
        wxMessageDialog dialog(this, _("Operation not permitted."), _("Error"), wxOK | wxICON_ERROR );
        dialog.ShowModal();
        event.Veto();
    }
}