bool SimpleCache::GetFileForIndex(int index, ByteBuffer & data) {

	String filePath;
	BuildPathForFileInCache(index, filePath);

	if (!File::IsFileExist(filePath)) {
		return false;
	}

	AppLog("Reading data from cached file at %S", filePath.GetPointer());

	File cachedFile;
	cachedFile.Construct(filePath, L"r+");
	if (IsFailed(GetLastResult())) {
		AppLog("Error opening destination file in cache");
		return false;
	}

	FileAttributes fAttributes;
	File::GetAttributes(filePath, fAttributes);

	data.Construct(fAttributes.GetFileSize());
	cachedFile.Read(data);
	AppLog("Read cache: %d bytes", data.GetCapacity());
	if (IsFailed(GetLastResult())) {
		AppLog("Error reading from cached file");
		return false;
	}

	return true;

}
KDint xmBadaTruncate ( const KDchar* path, off_t length )
{
	File     file;
	result   r;

	r = file.Construct ( path, "wb" );

	if ( IsFailed ( r ) )
	{
		goto failed;
	}

	r = file.Truncate ( (KDint) length );

	if ( IsFailed ( r ) )
	{
		goto failed;
	}

	return 0;

failed :

	xmBadaSetError ( r );

	return -1;
}
Beispiel #3
0
void
ShareMenu::OnAppControlCompleted(const Osp::Base::String& appControlId, const Osp::Base::String& operationId, const Osp::Base::Collection::IList* pResultList)
{
	Osp::Base::String* pBTResult = null;
	if(appControlId.Equals(APPCONTROL_PROVIDER_BLUETOOTH)
			&& operationId.Equals(APPCONTROL_OPERATION_PICK))
	{
		pBTResult = (Osp::Base::String*)pResultList->GetAt(0);
		if(pBTResult->Equals(String(APPCONTROL_RESULT_SUCCEEDED)))
		{
			BluetoothDevice* pBTDevice = BluetoothDevice::GetInstanceFromAppControlResultN(*pResultList);

			if(pBTDevice)
			{

				if(!__pBTOppClient)
					__pBTOppClient = new BluetoothOppClient();

				result res = E_SUCCESS;
				String filePath(__shareContent);

				if(__isLink == true)
				{

					filePath = L"/Home/";
					filePath.Append(Application::GetInstance()->GetAppName());
					filePath.Append(".txt");

					File tempFile;
					tempFile.Construct(filePath, L"w+", true);
					tempFile.Write(__shareContent);

				}

				__pBTOppClient->Construct(*this);
				res = __pBTOppClient->PushFile(*pBTDevice, filePath);
				if(res != E_SUCCESS)
				{
					AppLog("PushFile FAILED");
				}
			}
			else
			{
				AppLog("No Device from BT AppControl");
			}
		}
		else if(pBTResult->Equals(String(APPCONTROL_RESULT_FAILED)))
		{
			AppLog("Bluetooth list failed.");
		}
	}
}
void ActionsManager::build(void)
{
	Osp::Base::String filePath(L"/Home/dataPremiersSecours.txt");
	File file;
	file.Construct(filePath, L"r");

	Osp::Base::String readLine;

	while(file.Read(readLine) == E_SUCCESS)
	{
		addAction(readLine);
	}



}
Beispiel #5
0
ArrayListT<Trip *> * IRailAPI::testRoutePlanner(){
	result r = E_SUCCESS;
	String fileName(L"/Home/2.xml");
	File *file = new File();
	FileAttributes sourcefilemeta;
	File::GetAttributes(fileName, sourcefilemeta);
	int filesize = sourcefilemeta.GetFileSize();
	ByteBuffer buffer;
	buffer.Construct(filesize);
	//AppLog("Read buffer size %d", buffer.GetLimit());
	r = file->Construct(fileName, L"r"); //for write: w or w+
	r = file->Read(buffer); //to write: file->Write *beware of the permission w instead of r
	delete file; //closes the file, there is no default close method for files, its gets closed when its scope is closed
	buffer.SetPosition(0);
	ArrayListT<Trip *> * test = createTripList(&buffer);
	//AppLog("completed trips");
	return test;
}
Beispiel #6
0
BadaFileStream *BadaFileStream::makeFromPath(const String &path, bool writeMode) {
	File *ioFile = new File();

	String filePath = path;
	if (writeMode && (path[0] != '.' && path[0] != '/')) {
		filePath.Insert(PATH_HOME_X, 0);
	}

	AppLog("Open file %S", filePath.GetPointer());

	result r = ioFile->Construct(filePath, writeMode ? L"w" : L"r", writeMode);
	if (r == E_SUCCESS) {
		return new BadaFileStream(ioFile, writeMode);
	}

	AppLog("Failed to open file");
	delete ioFile;
	return 0;
}
Beispiel #7
0
result
MyCardManager::ReadNameCardFromFile(Tizen::Base::String& name, Tizen::Base::String& number, Tizen::Base::String& address)
{
	File file;
	String buffer;
	int length;
	result r = E_SUCCESS;

	r = file.Construct(App::GetInstance()->GetAppRootPath() + NFC_BUMP_MY_CARD_INFO_PATH, "r", false);
	TryReturn(r == E_SUCCESS, r, "Failed to open the file.");

	r = file.Seek(FILESEEKPOSITION_BEGIN, 0);
	TryReturn(r == E_SUCCESS, r, "Failed to repositions the file pointer.");

	//read user's name from data file
	r = file.Read(buffer);
	TryReturn(r == E_SUCCESS, r, "Failed to read my name from file.");

	length = buffer.GetLength();
	buffer.SubString(0, length - 1, name);
	buffer.Clear();

	//read user's phone number from data file
	r = file.Read(buffer);
	TryReturn(r == E_SUCCESS, r, "Failed to read my phone number from file.");

	length = buffer.GetLength();
	buffer.SubString(0, length - 1, number);
	buffer.Clear();

	//read user's e-mail address from data file
	r = file.Read(buffer);
	TryReturn(r == E_SUCCESS, r, "Failed to read my e-mail address from file.");

	length = buffer.GetLength();
	buffer.SubString(0, length - 1, address);

	return r;
}
bool SimpleCache::StoreFile(ByteBuffer & data, int position) {

	String filePath;
	BuildPathForFileInCache(position, filePath);

	AppLog("Storing data object in file at %S", filePath.GetPointer());

	File cachedFile;
	cachedFile.Construct(filePath, L"w+");
	if (IsFailed(GetLastResult())) {
		AppLog("Error opening destination file in cache");
		return false;
	}

	cachedFile.Write(data);
	if (IsFailed(GetLastResult())) {
		AppLog("Error writing data to destination file in cache");
		return false;
	}

	return true;

}
Beispiel #9
0
result
MyCardManager::WriteNameCardToFile(const Tizen::Base::String& name, const Tizen::Base::String& number,
		const Tizen::Base::String& address)
{
	File file;
	result r = E_SUCCESS;

	r = file.Construct(App::GetInstance()->GetAppRootPath() + NFC_BUMP_MY_CARD_INFO_PATH, "w", false);
	TryReturn(r == E_SUCCESS, r, "Failed to open the file.");

	r = file.Seek(FILESEEKPOSITION_BEGIN, 0);
	TryReturn(r == E_SUCCESS, r, "Failed to repositions the file pointer.");

	r = file.Write(name + "\n");
	TryReturn(r == E_SUCCESS, r, "Failed to write my name to file.");

	r = file.Write(number + "\n");
	TryReturn(r == E_SUCCESS, r, "Failed to write my phone number to file.");

	r = file.Write(address + "\n");
	TryReturn(r == E_SUCCESS, r, "Failed to write my e-mail address to file.");

	return r;
}
Beispiel #10
0
result
CategoryItemForm::ReadCustomListItems()
{
	result r = E_SUCCESS;
	String dirName(L"/Home/catalog/"+dir);
	Directory* pDir;
	DirEnumerator* pDirEnum;

	pDir = new Directory; // allocate Directory instance

	// Open directory
	r = pDir->Construct(dirName);

	// Read all directory entries
	pDirEnum = pDir->ReadN();

	String contentType;
	int i = 0;
	while(pDirEnum->MoveNext() == E_SUCCESS) {
		DirEntry dirEntry = pDirEnum->GetCurrentDirEntry();
		if(dirEntry.IsNomalFile()) {
			//AppLog("%S", dirEntry.GetName().GetPointer());
			if(!dirEntry.GetName().Equals("category.info", false)) {

				String fileName(dirName+"/"+dirEntry.GetName());

				String title, desc;
				String iTempStr, iTempStr2;

				File file;
				result r = file.Construct(fileName, L"r");
				if( IsFailed(r) )
				{
						AppLog("File::Consturct() is failed by %s", GetErrorMessage(r));
				}

				FileAttributes fileAttrs;
				file.GetAttributes(fileName, fileAttrs);
				long long size = fileAttrs.GetFileSize();


				ByteBuffer readBuffer;
				readBuffer.Construct((int)size + 1);

				r = file.Read(readBuffer);
				if( IsFailed(r) )
				{
						AppLog("File::Read() is failed by %s", GetErrorMessage(r));
				}

				char* data = new char[readBuffer.GetLimit()+1];
				readBuffer.SetPosition(0);
				readBuffer.GetArray((byte*)data, 0, readBuffer.GetLimit());
				data[readBuffer.GetLimit()] ='\0';
				//String str = String(data);

				String str;
				r = StringUtil::Utf8ToString(data, str);
				delete data;
				if(IsFailed(r)) {
					AppLog("File read error. File : %S", fileName.GetPointer());
					continue;
				}

				file.Seek(FILESEEKPOSITION_BEGIN, 0);
				file.Read(title);

				r = TextPic::GetTranslated(title);
				if (IsFailed(r)) {
					continue;
				}

				int linecount = 0;
				while(file.Read(iTempStr) != E_END_OF_FILE) {
					linecount++;
					iTempStr2.Append(iTempStr);
				}

				anciilist.Add(*(new String(iTempStr2)));
				titlelist.Add(*(new String(title)));
				filelist.Add(*(new String(fileName)));

				ItemListForm::AddListItem(*CategoryList, title, iTempStr2, i++, linecount);
				file.Flush();
			}
		}
	}

	delete pDirEnum;
	delete pDir;

	return r;
}