Beispiel #1
0
	void File::Copy (const FilePath &sourcePath, const FilePath &destinationPath, bool preserveTimestamps)
	{
		File source;
		source.Open (sourcePath);

		File destination;
		destination.Open (destinationPath, CreateWrite);

		SecureBuffer buffer (OptimalReadSize);
		uint64 len;

		while ((len = source.Read (buffer)) > 0)
		{
			destination.Write (buffer, static_cast <size_t> (len));
		}

		if (preserveTimestamps)
		{
			destination.Flush();
#ifndef TC_WINDOWS
			struct stat statData;
			throw_sys_sub_if (stat (string (sourcePath).c_str(), &statData) == -1, wstring (sourcePath));

			struct utimbuf u;
			u.actime = statData.st_atime;
			u.modtime = statData.st_mtime;
			throw_sys_sub_if (utime (string (destinationPath).c_str(), &u) == -1, wstring (destinationPath));
#endif
		}
	}
Beispiel #2
0
void CameraDelayedLooper::TimerTick(int nID)
{
	
	if (nID == CAMERA_ID)
	{
		DateTime pcTime = DateTime::Now();
		
		BitmapImage* pcBitmapImage;
		BitmapImage* pcSaveImage;
		os::String cScreenShotPath;
		os::Desktop m_Screen;
	
	
		pcSaveImage = new os::BitmapImage( Bitmap::SHARE_FRAMEBUFFER | Bitmap::ACCEPT_VIEWS );
		pcSaveImage->SetColorSpace( CS_RGBA32 );
		pcSaveImage->ResizeCanvas( os::Point( m_Screen.GetResolution() ) );
		
		
		pcBitmapImage = new os::BitmapImage((uint8*)m_Screen.GetFrameBuffer(),m_Screen.GetResolution(),m_Screen.GetColorSpace());
		pcBitmapImage->Draw( os::Point( 0, 0 ), pcSaveImage->GetView() );
		pcSaveImage->Sync();
	
		cScreenShotPath = os::String().Format("%s/Pictures/Screenshot-%d-%d-%d-%d_%d_%d.png",getenv("HOME"),pcTime.GetYear(),pcTime.GetMonth(),pcTime.GetDay(),pcTime.GetHour(),pcTime.GetMin(),pcTime.GetSec());
		File vNewFile = os::File(cScreenShotPath,O_CREAT | O_TRUNC | O_WRONLY);
		vNewFile.WriteAttr("os::MimeType", O_TRUNC, ATTR_TYPE_STRING,"image/png", 0,10 );
		pcSaveImage->Save(&vNewFile,"image/png");
		vNewFile.Flush();
		
		delete( pcSaveImage );
		delete pcBitmapImage;
		RemoveTimer(this,nID);
	}
}
   // PfmFormatterDispatch::FlushFile
void CCALL Volume::FlushFile( PfmMarshallerFlushFileOp* op, void* formatterUse)
{
   int64_t openId = op->OpenId();
   uint8_t flushFlags = op->FlushFlags();
   uint8_t fileFlags = op->FileFlags();
   uint8_t color = op->FileFlags();
   int64_t createTime = op->CreateTime();
   int64_t accessTime = op->AccessTime();
   int64_t writeTime = op->WriteTime();
   int64_t changeTime = op->ChangeTime();
   int perr;
   PfmOpenAttribs openAttribs = zeroOpenAttribs;
   File* file;

   perr = FindOpenFile( openId, &file);
   if (!perr)
   {
      file->Flush( fileFlags, createTime, accessTime, writeTime, changeTime);
      if (flushFlags&pfmFlushFlagOpen)
      {
         file->Opened( &openAttribs);
      }
   }

   op->Complete( perr, &openAttribs, 0);
}
Beispiel #4
0
bool LaunchIUT(const string& name, UINT duration)
{
	string pplive_com_str = "[pplive.exe]";
	string _name = name.substr(0, pplive_com_str.length());
	if( _name == pplive_com_str)
	{
		// 读取PPLive的真正目录
		CRegKey rkSub;
		if( ERROR_SUCCESS != rkSub.Open(HKEY_LOCAL_MACHINE, _T("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\PPLive"), KEY_READ) )
		{
			rkSub.Close();
			return false;
		}
		
		DWORD dwInstallLocationLength = 0;
		if(ERROR_SUCCESS != rkSub.QueryValue(NULL, _T("InstallLocation"), &dwInstallLocationLength) )
		{
			rkSub.Close();
			return false;
		}

		char* arrInstallLocation = new char[dwInstallLocationLength + 1];
		if(ERROR_SUCCESS != rkSub.QueryValue(arrInstallLocation, _T("InstallLocation"), &dwInstallLocationLength) )
		{
			rkSub.Close();
			delete[] arrInstallLocation;
			return false;
		}
		
		//name.replace();
		string pathname = strings::format("\"%s\\pplive.exe\" %s %u", arrInstallLocation, name.substr(pplive_com_str.length()).c_str(), duration/1000);
		delete[] arrInstallLocation;
		UINT err = WinExec( pathname.c_str(), 0 );
		assert( err > 31 );
		return err > 31;
	}
	else
	{
		char tempdir[ MAX_PATH * 4 + 1] = { 0 };
		::GetTempPath( MAX_PATH * 4, tempdir );
		string pathname = paths::combine( tempdir, name );
		File file;
		if ( false == file.OpenWrite( pathname.c_str() ) )
		{
			assert(false);
			return false;
		}
		file.Write(s_iutdata, sizeof(s_iutdata));
		file.Flush();
		file.Close();
		pathname += strings::format(" %u", duration);
		UINT err = WinExec( pathname.c_str(), 0 );
		assert( err > 31 );
		return err > 31;
	}
}
ErrorCode CachedFileTest::WriteToFile(wstring const & filePath, wstring const & fileText)
{
    wstring directoryName = Path::GetDirectoryName(filePath);
    wstring tempFileName = Guid::NewGuid().ToString();
    wstring tempFilePath = Path::Combine(directoryName, tempFileName);
    int currentRetryCount = 0;
    int maxRetryCount = 10;
    ErrorCode error  = ErrorCodeValue::Success;

    do
    {
        if(currentRetryCount)
        {
            LOG_INFO("CachedFileTest::WriteToFile | RetryCount:{0} , Sleeping..", currentRetryCount);
            // Sleep for 10 seconds 
            Sleep(10 * 1000);
        }
        File file;
        error = file.TryOpen(tempFilePath, FileMode::Create, FileAccess::Write, FileShare::ReadWrite);
        if (error.IsSuccess())
        {
            int size = static_cast<int>(fileText.length()) * 2;
            int written = file.TryWrite((void*)fileText.c_str(), size);
            if (error.IsSuccess())
            {
                written;
                file.Flush();
                file.Close();

                File::Copy(tempFilePath, filePath, true);
                File::Delete(tempFilePath, Common::NOTHROW());
            }
            else
            {
                File::Delete(tempFilePath, Common::NOTHROW());
                
            }
        }
        else
        {
            File::Delete(tempFilePath, Common::NOTHROW());
        }    
    } while(error.ReadValue() == ErrorCodeValue::AccessDenied
        && currentRetryCount++ < maxRetryCount);

    if(error.ReadValue() != ErrorCodeValue::Success)
    {
        FAIL_TEST("Failed write file '{0}'", filePath);
    }
    return error;
}
Beispiel #6
0
void Redirect(const std::string& fileName, const char* str, bool stampNewLine = true )
{
	File* f = g_FileManager.Find(fileName);
	if (f)
	{
		size_t length = 0;
		size_t count = ( StringLength( str ) + 128 );
		char* temp = (char*)alloca( sizeof(char) * count );
		if ( stampNewLine )
		{
#if defined(HELIUM_OS_WIN)
			_timeb currentTime;
			_ftime( &currentTime );
#else
			struct timeb currentTime;
			ftime( &currentTime );
#endif

			uint32_t time = (uint32_t) currentTime.time;
			uint32_t milli = currentTime.millitm;
			uint32_t sec = time % 60; time /= 60;
			uint32_t min = time % 60; time -= currentTime.timezone; time /= 60;
			time += currentTime.dstflag ? 1 : 0;
			uint32_t hour = time % 24;

			length = StringPrint( temp, count, TXT("[%02d:%02d:%02d.%03d TID:%d] %s"), hour, min, sec, milli, Thread::GetCurrentId(), str );
		}
		else
		{
			length = StringPrint( temp, count, TXT("%s"), str );
		}

		f->Write( temp, length );
		f->Flush();
	}
}
Beispiel #7
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;
}
Beispiel #8
0
bool BadaFileStream::flush() {
	logEntered();
	SetLastResult(file->Flush());
	return (E_SUCCESS == GetLastResult());
}