//-------------------------------------------------------------- //-------------------------------------------------------------- bool FileSystem::ReadFile(StorageLocation in_storageLocation, const std::string& in_directory, std::string& out_contents) const { Core::FileStreamUPtr fileStream = CreateFileStream(in_storageLocation, in_directory, Core::FileMode::k_read); if (fileStream == nullptr) { return false; } fileStream->GetAll(out_contents); return true; }
//-------------------------------------------------------------- //-------------------------------------------------------------- bool FileSystem::WriteFile(StorageLocation in_storageLocation, const std::string& in_directory, const std::string& in_contents) const { Core::FileStreamUPtr fileStream = CreateFileStream(in_storageLocation, in_directory, Core::FileMode::k_writeBinary); if (fileStream.get() == nullptr) { return false; } fileStream->Write(in_contents); return true; }
//-------------------------------------------------------------- //-------------------------------------------------------------- u32 FileSystem::GetFileSize(StorageLocation in_storageLocation, const std::string& in_filepath) const { //open the file FileStreamUPtr file = CreateFileStream(in_storageLocation, in_filepath, FileMode::k_readBinary); if (file != nullptr) { //get the length of the file file->SeekG(0, SeekDir::k_end); s32 dwLength = file->TellG(); return dwLength; } return 0; }
bool OBS::StartRecording(bool force) { if (!bRunning || bRecording) return true; int networkMode = AppConfig->GetInt(TEXT("Publish"), TEXT("Mode"), 2); bool saveToFile = AppConfig->GetInt(L"Publish", L"SaveToFile") != 0; bWriteToFile = force || networkMode == 1 || saveToFile; // Don't request a keyframe while everything is starting up for the first time if(!bStartingUp) videoEncoder->RequestKeyframe(); String strOutputFile; if (bWriteToFile) strOutputFile = GetOutputFilename(); bool success = true; if(!bTestStream && bWriteToFile && strOutputFile.IsValid()) { fileStream = CreateFileStream(strOutputFile); if(!fileStream) { Log(TEXT("Warning - OBSCapture::Start: Unable to create the file stream. Check the file path in Broadcast Settings.")); OBSMessageBox(hwndMain, Str("Capture.Start.FileStream.Warning"), Str("Capture.Start.FileStream.WarningCaption"), MB_OK | MB_ICONWARNING); bRecording = false; success = false; bRecordingReplayBuffer = false; } else { bRecording = true; ReportStartRecordingTrigger(); lastOutputFile = strOutputFile; } ConfigureStreamButtons(); } return success; }
//-------------------------------------------------------------- //-------------------------------------------------------------- u32 FileSystem::GetFileChecksumCRC32(StorageLocation in_storageLocation, const std::string& in_filePath) const { u32 output = 0; //open the file FileStreamUPtr file = CreateFileStream(in_storageLocation, in_filePath, FileMode::k_readBinary); if (file != nullptr) { //get the length of the file file->SeekG(0, SeekDir::k_end); s32 length = file->TellG(); file->SeekG(0, SeekDir::k_beginning); //read contents of file s8* contents = new s8[length]; file->Read(contents, length); //get the hash output = HashCRC32::GenerateHashCode(contents, length); CS_SAFEDELETE_ARRAY(contents); } return output; }
/** * Constructor * @param archive The name of the .chm archive. Remember that archive must * be local file accesible via fopen, fread functions! * @param filename The Name of the file to be extracted from archive * @param simulate if true than class should simulate .HHP-File based on #SYSTEM * if false than class does nothing if it doesnt find .hhp */ wxChmInputStream::wxChmInputStream(const wxString& archive, const wxString& filename, bool simulate) : wxInputStream() { m_pos = 0; m_size = 0; m_content = NULL; m_contentStream = NULL; m_lasterror = wxSTREAM_NO_ERROR; m_chm = new wxChmTools (wxFileName(archive)); m_file = NULL; m_fileName = wxString(filename).MakeLower(); m_simulateHHP = simulate; if ( !m_chm->Contains(m_fileName) ) { // if the file could not be located, but was *.hhp, than we create // the content of the hhp-file on the fly and store it for reading // by the application if ( m_fileName.Find(_T(".hhp")) != wxNOT_FOUND && m_simulateHHP ) { // now we open an hhp-file CreateHHPStream(); } else { wxLogError(_("Could not locate file '%s'."), filename.c_str()); m_lasterror = wxSTREAM_READ_ERROR; return; } } else { // file found CreateFileStream(m_fileName); } }
//-------------------------------------------------------------- //-------------------------------------------------------------- std::string FileSystem::GetFileChecksumMD5(StorageLocation in_storageLocation, const std::string& in_filePath) const { FileStreamUPtr file = CreateFileStream(in_storageLocation, in_filePath, FileMode::k_readBinary); return file->GetMD5Checksum(); }
//-------------------------------------------------------------- //-------------------------------------------------------------- std::string FileSystem::GetFileChecksumSHA1(StorageLocation in_storageLocation, const std::string& in_filePath) const { FileStreamUPtr file = CreateFileStream(in_storageLocation, in_filePath, FileMode::k_readBinary); return file->GetSHA1Checksum(CSHA1::REPORT_TYPE::REPORT_HEX_SHORT); }
/** * Help Browser tries to read the contents of the * file by interpreting a .hhp file in the Archiv. * For .chm doesnt include such a file, we need * to rebuild the information based on stored * system-files. */ void wxChmInputStream::CreateHHPStream() { wxFileName file; bool topic = false; bool hhc = false; bool hhk = false; wxInputStream *i; wxMemoryOutputStream *out; const char *tmp; // Try to open the #SYSTEM-File and create the HHP File out of it // see http://bonedaddy.net/pabs3/chmspec/0.1.2/Internal.html#SYSTEM if ( ! m_chm->Contains(_T("/#SYSTEM")) ) { #ifdef DEBUG wxLogDebug(_("Archive doesnt contain #SYSTEM file")); #endif return; } else { file = wxFileName(_T("/#SYSTEM")); } if ( CreateFileStream(_T("/#SYSTEM")) ) { // New stream for writing a memory area to simulate the // .hhp-file out = new wxMemoryOutputStream(); tmp = "[OPTIONS]\r\n"; out->Write((const void *) tmp, strlen(tmp)); wxUint16 code; wxUint16 len; void *buf; // use the actual stream for reading i = m_contentStream; /* Now read the contents, and try to get the needed information */ // First 4 Bytes are Version information, skip i->SeekI(4); while (!i->Eof()) { // Read #SYSTEM-Code and length i->Read(&code, 2); code = wxUINT16_SWAP_ON_BE( code ) ; i->Read(&len, 2); len = wxUINT16_SWAP_ON_BE( len ) ; // data buf = malloc(len); i->Read(buf, len); switch (code) { case 0: // CONTENTS_FILE tmp = "Contents file="; hhc=true; break; case 1: // INDEX_FILE tmp = "Index file="; hhk = true; break; case 2: // DEFAULT_TOPIC tmp = "Default Topic="; topic = true; break; case 3: // TITLE tmp = "Title="; break; // case 6: // COMPILED_FILE // tmp = "Compiled File="; // break; case 7: // COMPILED_FILE tmp = "Binary Index=YES\r\n"; out->Write( (const void *) tmp, strlen(tmp)); tmp = NULL; break; case 4: // STRUCT SYSTEM INFO tmp = NULL ; if ( len >= 28 ) { char *structptr = (char*) buf ; // LCID at position 0 wxUint32 dummy = *((wxUint32 *)(structptr+0)) ; wxUint32 lcid = wxUINT32_SWAP_ON_BE( dummy ) ; wxString msg ; msg.Printf(_T("Language=0x%X\r\n"),lcid) ; out->Write(msg.c_str() , msg.Length() ) ; } break ; default: tmp=NULL; } if (tmp) { out->Write((const void *) tmp, strlen(tmp)); out->Write(buf, strlen((char*)buf)); out->Write("\r\n", 2); } free(buf); buf=NULL; } // Free the old data which wont be used any more delete m_contentStream; if (m_content) free (m_content); // Now add entries which are missing if ( !hhc && m_chm->Contains(_T("*.hhc")) ) { tmp = "Contents File=*.hhc\r\n"; out->Write((const void *) tmp, strlen(tmp)); } if ( !hhk && m_chm->Contains(_T("*.hhk")) ) { tmp = "Index File=*.hhk\r\n"; out->Write((const void *) tmp, strlen(tmp)); } // Now copy the Data from the memory out->SeekO(0, wxFromEnd); m_size = out->TellO(); out->SeekO(0, wxFromStart); m_content = (char *) malloc (m_size+1); out->CopyTo(m_content, m_size); m_content[m_size]='\0'; m_size++; m_contentStream = new wxMemoryInputStream(m_content, m_size); delete out; } }