Пример #1
0
FileList FileList::operator+=(const FileList &list2)
{
	size_t oldsize = files.size();
	files.resize(oldsize + list2.Size());

	for (size_t i = oldsize; i < files.size(); i++)
	{
		files[i] = list2[i-oldsize];
	}

	return *this;
}
Пример #2
0
// used for resolving case-insensative paths to case-sensative ones
// when appropriate IsCaseSensative() = true
bool PlatformNormalize(std::string &normpath, const std::string &path, const std::string root)
{
	if (!FileList::IsCaseSensative()) // windows simply returns identity
	{
		// should only get hit on windows
		if (root[root.length()-1] != '\\')
		{
			normpath = root + "\\" + path;
		}
		else
		{
			normpath = root + path;
		}
		return true;
	}
	// else it's a *nix system - normalize it to / instead of \  -
	FileList curdir;
	normpath = root;
	// break path down into it's componants

	std::vector<std::string> parts;
	Expand(path, '/',  parts);
	bool found;
	for (size_t i = 0; i < parts.size(); i++)
	{
		curdir.GetList(normpath);
		found = false;

		for (size_t j = 0; j < curdir.Size(); j++)
		{
			if (strLower(std::string(curdir[j])) ==
			    strLower(std::string(parts[i])))
			{
				normpath += std::string("/") + curdir[j];
				found = true;
				break;
			}
		}

		if (!found)
			return false; //yikes

		curdir.Clear();
	}

	return true;
}
Пример #3
0
int RunFileBrowser(char *source, char *outname, const char *types[],
		const char *info) {

	int size = 0;
	int index;
	int offset_start, offset_end;
	static int max_entries = 8;
	int scrollModifier = 4;
	int justsavedromdir = 0;
	int scrollMult;

	static int spy;
	int y, i;
	
	// Try to get a saved romdir from a config file
	char* home = getenv("HOME");
	char romcfgfile [128];
	sprintf (romcfgfile, "%s/.fceux/romdir.cfg", home);
	FILE * pFile;
	pFile = fopen (romcfgfile,"r+");
	if (pFile != NULL) {
		fgets (s_LastDir , 128 , pFile);
		fclose (pFile);
	}

	// Create file list
	FileList *list = new FileList(source ? source : s_LastDir, types);
	if (list == NULL)
		return 0;

	
	scrollModifier *= max_entries;

	RESTART:

	spy = 72;

	size = list->Size();

	index = 0;
	offset_start = 0;
	offset_end = size > max_entries ? max_entries : size;

	

	g_dirty = 1;
	while (1) {
		// Parse input
		readkey();
		// TODO - put exit keys

		// Go to previous folder or return ...
		if (parsekey(DINGOO_B)) {
			list->Enter(-1);
			goto RESTART;
		}

		// Enter folder or select rom ...
		if (parsekey(DINGOO_A)) {
			if (list->GetSize(index) == -1) {
				list->Enter(index);
				goto RESTART;
			} else {
				strncpy(outname, list->GetPath(index), 128);
				break;
			}
		}

		if (parsekey(DINGOO_X)) {
			return 0;
		}
		
		if (parsekey(DINGOO_SELECT)) {
			// Save the current romdir in a config file
			char* home = getenv("HOME");
			char romcfgfile [128];
			strncpy(s_LastDir, list->GetCurDir(), 128);
			sprintf (romcfgfile, "%s/.fceux/romdir.cfg", home);
			FILE * pFile;
			pFile = fopen (romcfgfile,"w+");
			fputs (s_LastDir,pFile);
			fclose (pFile);
			justsavedromdir = 1;
		}

		if (size > 0) {
			// Move through file list

			if (parsekey(DINGOO_R, 0)) {
				index = size - 1;
				spy = 72 + 15*(max_entries-1);
				offset_end = size;
				offset_start = offset_end - max_entries;
			}

			if (parsekey(DINGOO_L, 0)) {
				goto RESTART;
			}

			if (parsekey(DINGOO_UP, 1)) {
				if (index > offset_start){
					index--;
					spy -= 15;
				} else if (offset_start > 0) {
					index--;
					offset_start--;
					offset_end--;
				} else {
					index = size - 1;
					offset_end = size;
					offset_start = size <= max_entries ? 0 : offset_end - max_entries;
					spy = 72 + 15*(index - offset_start);
				}
			}

			if (parsekey(DINGOO_DOWN, 1)) {
				if (index < offset_end - 1){
					index++;
					spy += 15;
				} else if (offset_end < size) {
					index++;
					offset_start++;
					offset_end++;
				} else {
					index = 0;
					offset_start = 0;
					offset_end = size <= max_entries ? size : max_entries;
					spy = 72;
				}
			}

			if (parsekey(DINGOO_LEFT, 1)) {
				if (index > offset_start) {
					index = offset_start;

					spy = 72;

				} else if (index - scrollModifier >= 0){
						index -= scrollModifier;
						offset_start -= scrollModifier;
						offset_end = offset_start + max_entries;
				} else
					goto RESTART;
			}

			if (parsekey(DINGOO_RIGHT, 1)) {
				if (index < offset_end-1) {
					index = offset_end-1;

					spy = 72 + 15*(index-offset_start);

				} else if (offset_end + scrollModifier <= size) {
						index += scrollModifier;
						offset_end += scrollModifier;
						offset_start += scrollModifier;
				} else {
					index = size - 1;
					spy = 72 + 15*(max_entries-1);
					offset_end = size;
					offset_start = offset_end - max_entries;
				}
			}
		}

		// Draw stuff
		if (g_dirty) {
			draw_bg(g_bg);
			
			//Draw Top and Bottom Bars
			DrawChar(gui_screen, SP_SELECTOR, 0, 37);
			DrawChar(gui_screen, SP_SELECTOR, 81, 37);
			DrawChar(gui_screen, SP_SELECTOR, 0, 225);
			DrawChar(gui_screen, SP_SELECTOR, 81, 225);
			DrawText(gui_screen, "B - Go Back", 235, 225);
			DrawChar(gui_screen, SP_LOGO, 12, 9);
			
			// Draw selector
			DrawChar(gui_screen, SP_SELECTOR, 4, spy);
			DrawChar(gui_screen, SP_SELECTOR, 81, spy);

			DrawText(gui_screen, "ROM Browser", 8, 37);

			// Draw file list
			for (i = offset_start, y = 72; i < offset_end; i++, y += 15) {
				DrawText(gui_screen, list->GetName(i), 8, y);
			}

			// Draw info
			if (info)
				DrawText(gui_screen, info, 8, 225);
			else {
				if (justsavedromdir == 1){
					DrawText(gui_screen, "ROM dir successfully saved!", 8, 225);
				} else {
					if (list->GetSize(index) == -1)
						DrawText(gui_screen, "SELECT - Save ROM dir", 8, 225);
					else
						DrawText(gui_screen, "SELECT - Save ROM dir", 8, 225);
				}
				justsavedromdir = 0;
			}

			// Draw offset marks
			if (offset_start > 0)
				DrawChar(gui_screen, SP_UPARROW, 157, 57);
			if (offset_end < list->Size())
				DrawChar(gui_screen, SP_DOWNARROW, 157, 197);

			g_dirty = 0;
		}

		SDL_Delay(4);

		// Update real screen
		FCEUGUI_Flip();
		
	}

	if (source == NULL)
		strncpy(s_LastDir, list->GetCurDir(), 128);
	delete list;

	return 1;
}
Пример #4
0
int Book::_Make( const char* dir, int max, ADD_METHOD method ){
/************************************************
定跡の作成
************************************************/
	Shogi* pshogi;
	MOVE move;
	uint64 hash;
	int num = 0;
	FileList flist;
	string fname;
	KIFU_INFO kinfo;

	// ファイルの列挙
	if( 0 == flist.Enumerate( dir, "csa" ) ){
		cerr << "Error!" << '\n';
		return 0;
	}

	pshogi = new Shogi( HIRATE );

	cerr << "Make a book.." << '\n';

	while( flist.Pop( fname ) ){
		if( 0 == pshogi->InputFileCSA( fname.c_str(), &kinfo ) ){
			continue;
		}

		num++;

		// 棋譜の最後かどうか
#if 1
		bool is_last = true;
#endif

		// 定跡登録
		while( pshogi->GetMove( move ) && pshogi->GoBack() ){
			// 勝った側の指し手だけを採用する。 2011/03/13
#if 1
			if( is_last ){
				// 初回は1手だけ戻す。
				// 最後に指した方が勝ったはず。
				is_last = false;
			}
			else{
				// それ以外は2手ずつ戻す。
				if( !( pshogi->GetMove( move ) && pshogi->GoBack() ) ){
					break;
				}
			}
#endif

			// 指定した手数より手前なら登録
			if( pshogi->GetNumber() < max ){
				hash = pshogi->GetHash();
				switch( method ){
				case OVER_WRITE:
					Add( hash, move, OVER_WRITE, 1 );
					break;
				case ADD_NEW:
					Add( hash, move, ADD_NEW, 1, kinfo.start.export_date() );
					break;
				default:
					Add( hash, move, OVER_WRITE, 1 );
					break;
				}
			}
		}

		// 進捗表示
		Progress::Print( num * 100 / flist.Size() );
	}

	// 進捗表示終了
	Progress::Clear();

	cerr << "Number of files : " << num << '\n';

	delete pshogi;

	return 1;
}