Example #1
0
 params_t ReadParams(const ::std::string& path, char delimiter = ',')
 {
     params_t params;
     IFile* fp = detail::IFileSystem::New();
     if( fp != NULL )
     {
         if( fp->Open(path.c_str(), IFile::OpenRead) )
         {
             const ::std::string dataset = fp->ReadAll();
             ::std::string::size_type prev = 0;
             ::std::string::size_type pos = 0;
             while( pos = dataset.find(delimiter, prev), pos != ::std::string::npos )
             {
                 const ::std::string data = dataset.substr(prev, pos - prev);
                 AppendParams(params, data);
                 ++pos;
                 prev = pos;
             }
             AppendParams(params, dataset.substr(prev));
         }
         else
         {
             fprintf(stderr, "Unable to open file \"%s\".\n", path.c_str());
             fflush(stderr);
         }
         detail::IFileSystem::Free(fp);
     }
     IUTEST_CHECK_(!params.empty());
     return params;
 }
Example #2
0
	IFile* CFileSystem::OpenFile( const string_t& relativePath, uint mode ) {
		string_t				fullPath;
		assignMap_t::iterator	it;
		IFile*					file;

#if PLATFORM == PLATFORM_WIN32
		file = new CFile;
		m_files.push_back(file);
#elif defined(PLATFORM_LINUX)
#else
#endif

		// first try open file by OS path
		if ( file->Open( relativePath, mode ) )
			return file;

		// try open file from assign map
		for ( it = m_assigns.begin(); it != m_assigns.end(); ++it ) {
			fullPath = it->second.c_str();
			fullPath += relativePath;
			if ( file->Open( fullPath.c_str(), mode ) ) {
				return file;
			} 
		}

		SafeDelete(file);

		for ( size_t i = 0; i < m_archives.size(); i++ ) {
			if ( m_archives[i]->FindFile( relativePath ) ) {
				file = m_archives[i]->NewFileObject();
				if ( file->Open( relativePath ) ) {
					return file;
				} else {
					SafeDelete(file);
				}
			}
		}

		return NULL;
	}
Example #3
0
	/*
	check that files inside enumeratoed archives can be read correctly
	*/
	TEST_FIXTURE( VFSTestFixture, ZipArchiveContentTests ) {
		_vfs->Mount( ( Resources::Instance().RootDir() + L"../../../tests/content/test.zip" ).c_str() );

		IFile *file = _vfs->GetFile( L"content/test.lua" );
		IFileReader *reader = nullptr;
		CHECK_EQUAL( MGDF_OK, file->Open( &reader ) );
		CHECK( reader != nullptr );

		std::vector<std::string> list;
		ReadLines( reader, list );

		//see if the file has as many lines as we expect
		CHECK_EQUAL( 20, list.size() );
		//check to see the first and last lines are as expected
		CHECK_EQUAL( "class 'ConsoleStorageListener'(MGDF.StorageListener)", list[0] );
		CHECK_EQUAL( "end", list[19] );
	}
Example #4
0
	/**
	check that files in the standard file can be read from the vfs correctly
	*/
	TEST_FIXTURE( VFSTestFixture, FileSystemContentTests ) {
		_vfs->Mount( ( Resources::Instance().RootDir() + L"../../../tests/content" ).c_str() );

		IFile *file = _vfs->GetFile( L"console.json" );
		IFileReader *reader = nullptr;
		CHECK_EQUAL( MGDF_OK, file->Open( &reader ) );
		CHECK( reader != nullptr );

		std::vector<std::string> list;
		ReadLines( reader, list );

		//see if the file has as many lines as we expect
		CHECK_EQUAL( 17, list.size() );
		//check to see the first and last lines are as expected
		CHECK_EQUAL( "{", list[0] );
		CHECK_EQUAL( "}", list[16] );
	}