bool MemoryMatrix::loadAsBin(const char* filename) { ifstream memfile(filename, ios::out|ios::binary); if (memfile.is_open()) { memfile.seekg(0, ios::end); size_t size = memfile.tellg(); if (size >= 8) { char* memblock = new char[size]; memfile.seekg(0, ios::beg); memfile.read(memblock, size); unsigned char r[4] = {memblock[0], memblock[1], memblock[2], memblock[3]}; unsigned char c[4] = {memblock[4], memblock[5], memblock[6], memblock[7]}; unsigned int rows = *(unsigned int*) &r; unsigned int cols = *(unsigned int*) &c; resize(rows, cols); unsigned int k = 8; for (unsigned int i = 0; i < rows; i += 1) { for (unsigned int j = 0; j < cols; j += 1) { _data[i][j] = memblock[k] == 0 ? 0 : 1; k++; } } delete [] memblock; memfile.close(); return true; } } return false; }
corona::Image* load_image_from_packfile(const char* filename) { VFILE* vf = vopen(filename); if (!vf) { err("loadimage: couldn't load image %s; couldnt find a file or a vfile", filename); } int l = filesize(vf); std::auto_ptr<char> buffer(new char[l]); vread(buffer.get(), l, vf); vclose(vf); std::auto_ptr<corona::File> memfile(corona::CreateMemoryFile(buffer.get(), l)); return corona::OpenImage(memfile.get(), corona::FF_AUTODETECT, corona::PF_DONTCARE); }
int CHttpCurl::Post(LPCTSTR szUrl, LPBYTE pBuffer, int nSize, int nConnectTime, int nSendtime, std::string &strRead) { int nRetCode = CURLE_FAILED_INIT; int nStatusCode = 0; std::string strURL = CW2A(szUrl); struct curl_slist *headers = NULL; CWriteCurlMemFile memfile(strRead); CURL *pCurl = curl_easy_init(); if (pCurl == NULL) goto Exit0; char* cpszHeader = "Content-Type: application/octet-stream"; headers = curl_slist_append (headers, cpszHeader); headers = curl_slist_append (headers, ("User-Agent: Mozilla/4.0")); nRetCode = curl_easy_setopt(pCurl, CURLOPT_URL, strURL.c_str()); if (nRetCode != CURLE_OK) goto Exit0; nRetCode = curl_easy_setopt(pCurl, CURLOPT_POST, TRUE); if (nRetCode != CURLE_OK) goto Exit0; nRetCode = curl_easy_setopt(pCurl, CURLOPT_POSTFIELDS, pBuffer); if (nRetCode != CURLE_OK) goto Exit0; nRetCode = curl_easy_setopt(pCurl, CURLOPT_POSTFIELDSIZE, nSize); if (nRetCode != CURLE_OK) goto Exit0; nRetCode = curl_easy_setopt(pCurl, CURLOPT_HTTPHEADER, headers); if (nRetCode != CURLE_OK) goto Exit0; nRetCode = curl_easy_setopt(pCurl, CURLOPT_TIMEOUT, nSendtime); if (nRetCode != CURLE_OK) goto Exit0; nRetCode = curl_easy_setopt(pCurl, CURLOPT_CONNECTTIMEOUT, nConnectTime); if (nRetCode != CURLE_OK) goto Exit0; nRetCode = curl_easy_setopt(pCurl, CURLOPT_WRITEFUNCTION, CWriteCurlMemFile::WriteCallBack); if (nRetCode != CURLE_OK) goto Exit0; nRetCode = curl_easy_setopt(pCurl, CURLOPT_WRITEDATA, &memfile); if (nRetCode != CURLE_OK) goto Exit0; nRetCode = curl_easy_perform(pCurl); if (nRetCode != CURLE_OK) goto Exit0; curl_easy_getinfo(pCurl, CURLINFO_RESPONSE_CODE, &nStatusCode); if (nStatusCode != 200) nRetCode = nStatusCode; Exit0: if (headers) curl_slist_free_all(headers); if (pCurl) curl_easy_cleanup(pCurl); return nRetCode; }