const char *SoundDriver_Win32::Start(const char * const *parm) { WAVEFORMATEX wfex; wfex.wFormatTag = WAVE_FORMAT_PCM; wfex.nChannels = 2; wfex.wBitsPerSample = 16; wfex.nSamplesPerSec = GetDriverParamInt(parm, "hz", 44100); wfex.nBlockAlign = (wfex.nChannels * wfex.wBitsPerSample) / 8; wfex.nAvgBytesPerSec = wfex.nSamplesPerSec * wfex.nBlockAlign; /* Limit buffer size to prevent overflows. */ _bufsize = GetDriverParamInt(parm, "bufsize", (GB(GetVersion(), 0, 8) > 5) ? 8192 : 4096); _bufsize = min(_bufsize, UINT16_MAX); try { if (NULL == (_event = CreateEvent(NULL, FALSE, FALSE, NULL))) throw "Failed to create event"; if (waveOutOpen(&_waveout, WAVE_MAPPER, &wfex, (DWORD_PTR)_event, 0, CALLBACK_EVENT) != MMSYSERR_NOERROR) throw "waveOutOpen failed"; MxInitialize(wfex.nSamplesPerSec); PrepareHeader(&_wave_hdr[0]); PrepareHeader(&_wave_hdr[1]); if (NULL == (_thread = CreateThread(NULL, 8192, SoundThread, 0, 0, &_threadId))) throw "Failed to create thread"; } catch (const char *error) { this->Stop(); return error; } return NULL; }
string PrepareMeteo( const map<time_t, vector<entity::Measurement>>& measure_sets, const vector<string>& metrics) { vector<string> rows; rows.push_back(PrepareHeader(metrics)); for (auto& ms_entry : measure_sets) { vector<string> row_parts; auto measure_set = ms_entry.second; row_parts.push_back(to_string(ms_entry.first)); for (auto& metrics_item : metrics) { bool inserted = false; for (auto& meteo_element : measure_set) { if (meteo_element.code == metrics_item) { if (meteo_element.is_numeric) row_parts.push_back(to_string(meteo_element.value_number)); else row_parts.push_back(meteo_element.value_text); inserted = true; break; } } if (!inserted) row_parts.push_back(constant::csv_missing_value); } rows.push_back(join(row_parts, constant::csv_delimiter)); } return join(rows, constant::csv_new_line); }
bool BaseWordForm::Init() { __WCtrl = WordCtrl::GetInstance(); Construct(GetResourceID()); //AddOrientationEventListener(*this); // context menu must be first // because when is created // show menu button in footer PrepareContextMenu(); PrepareHeader(); PrepareFooter(); return true; }
void FontGen::Go() { // Starts genereting the font stuff PrepareFont(); PrepareBitmap(); PrepareHeader(); DrawFont(); if (!cppFormat) { SaveTarga(); SaveFontdef(); } else { SaveCpp(); } }
//----------------------------------------------------------------------------------------- // //----------------------------------------------------------------------------------------- bool tGPXFileExport::ExportFile( const QString& filepath, bool useExtents, tOrientedRect orientedExtents ) { tFile file( filepath ); if ( !file.open( QIODevice::WriteOnly | QFile::Text ) ) { return false; } QString headerString; PrepareHeader(headerString); file.write(headerString.toAscii()); ExportWaypoints(file, useExtents, orientedExtents); ExportRoutes(file, useExtents, orientedExtents); ExportTracks(file, useExtents, orientedExtents); QString footerString = "</gpx>\n"; file.write(footerString.toAscii()); file.close(); return true; }
bool FileVEILOperationsImpl::EncryptSignStream(std::shared_ptr<IDataReader> inputData, std::shared_ptr<IDataWriter> outputData, std::shared_ptr<ICmsHeader> Header, CompressionType comp, TS_ALG_ID algorithm, TS_ALG_ID hashAlgorithm, bool SignHeader, bool bindData, CMSFileFormatIds DataFormat, bool randomIvec, SymmetricPaddingType paddingType, int blockSize) { TSDECLARE_FUNCTIONExt(true); std::shared_ptr<ICmsHeaderBase> header2; std::shared_ptr<ICmsHeader> header7; std::shared_ptr<IKeyGenCallback> callback; int64_t fileSize = 0; if (Header == NULL) { LogError("The CKM Header is missing."); return TSRETURN_ERROR(("Bad Header"), false); } if (!Header->DuplicateHeader(header2)) { LogError("The specified CKM Header is incomplete or invalid."); return TSRETURN_ERROR(("Bad Header"), false); } if (!(header7 = std::dynamic_pointer_cast<ICmsHeader>(header2))) { LogError("The specified CKM Header is incomplete or invalid."); return TSRETURN_ERROR(("Bad Header"), false); } // // Now get the length of the source file // if (inputData->AllowsRandomAccess()) fileSize = inputData->DataLength(); else fileSize = -1; if (!PrepareHeader(header7, comp, algorithm, hashAlgorithm, SignHeader, bindData, DataFormat, randomIvec, paddingType, blockSize, fileSize)) { LogError("The specified CKM Header could not be prepared for key generation."); return TSRETURN_ERROR(("Bad Header"), false); } // CkmDevOnly << "Header after prepare" << endl << indent << TSHeaderToString(header7) << endl << outdent; #ifdef HAVE_BSTR // TODO: Implement Linux mime support here - libmagic { tscrypto::tsCryptoData tmp; CryptoUtf16 tmpBstr(inputData->DataName()); LPWSTR mime = NULL; if (inputData->PeekData(4096, tmp)) { if (FindMimeFromData(NULL, tmpBstr.c_str(), tmp.rawData(), (DWORD)tmp.size(), NULL, 3 /*FMFD_ENABLEMIMESNIFFING | FMFD_URLASFILENAME*/, &mime, 0) >= 0) { if (mime != NULL && mime[0] != 0) { header7->SetMimeType(CryptoUtf16(mime).toUtf8()); } } } } #endif // HAVE_BSTR std::shared_ptr<ICryptoHelper> helper; if (!m_session && header7->NeedsSession()) { if (!!m_sessionCallback) { if (!(m_sessionCallback->GetSessionForHeader(true, header2, 0, m_session))) { LogError("No session."); return TSRETURN_ERROR(("Returns ~~"), false); } } } if (!m_session) { LogError("Unable to retrieve the cryptographic helper object from the CKM Runtime."); return TSRETURN_ERROR(("Returns ~~"), false); } else { if (!(helper = CreateCryptoHelper(m_session))) { LogError("Unable to generate the working key and encrypted data - Unable to create the helper."); return TSRETURN_ERROR(("Unable to generate the working key and encrypted data."), false); } } helper->SetOperationStatusCallback(m_status); helper->SetTaskInformation(m_currentTask, m_taskCount); if (!!m_keyGenCallback) helper->SetKeyGenCallback(m_keyGenCallback); if (!header7->SetDataName(inputData->DataName().c_str())) { LOG(DebugInfo1, "WARNING: Unable to save the original file name. Continuing to process the file.\n"); } if (!helper->EncryptStream(comp, algorithm, hashAlgorithm, header2, true, tscrypto::tsCryptoData(), inputData, outputData, SignHeader, bindData, DataFormat, randomIvec, paddingType, blockSize)) { LogError("Unable to encrypt the data."); return TSRETURN_ERROR(("Unable to encrypt the data."), false); } return TSRETURN(("OK"), true); }
void CatalogImages::Impl::ProcessFiles(const String& dir, bool subdirs, const std::vector<bool>& scan_types, const String& title, const String& description, int img_size, bool folder_scan, int jpeg_compr) { dir_stack_.clear(); cur_dir_ = 0; root_dir_ = 0; ScanDir(dir, subdirs); if (root_dir_ == 0) return; if (parentWnd_) ::PostMessage(parentWnd_, MESSAGE, files_.size(), DIR_SCAN_DONE); //TODO: save header record with catalog info //no of images, types scanned, directory structure, etc... std::vector<uint8> header; PrepareHeader(header, dir, title, description, root_dir_.get(), folder_scan); uint64 header_offset= dbImages_.Append(header); tags_.clear(); failed_.clear(); // now write images ProcessFiles(img_size, jpeg_compr); // write special record with statistics //TODO: std::vector<uint8> stats; stats.reserve(200); MemPointer p; // p.SetResizeCallback(boost::bind(&vector<uint8>::resize, &stats, _1)); p.SetResizeCallback(boost::bind(&ResizeBuffer, &stats, _1, &p)); p.SetByteOrder(false); // little endian p.PutUInt32('tats'); // stat p.PutUInt32(static_cast<uint32>(tags_.size())); for (TagMap::const_iterator it= tags_.begin(); it != tags_.end(); ++it) { p.WriteWString(it->first); const size_t count= it->second.size(); p.PutUInt32(static_cast<uint32>(count)); for (size_t i= 0; i < count; ++i) p.PutUInt64(it->second[i]); } p.PutUInt32(0); p.PutUInt32(0); p.PutUInt32(0); p.PutUInt32(0); uint64 stats_offset_= dbImages_.Append(stats); if (parentWnd_) ::PostMessage(parentWnd_, MESSAGE, 0, IMG_PROC_DONE); // update total amount of images in the catalog header_.img_count_ = static_cast<uint32>(counter_); header_.statistics_record_offset_ = stats_offset_; header_.Write(header); dbImages_.Update(header_offset, header); }