Beispiel #1
0
void FFMS_Index::CalculateFileSignature(const char *Filename, int64_t *Filesize, uint8_t Digest[20]) {
	FileHandle file(Filename, "rb", FFMS_ERROR_INDEX, FFMS_ERROR_FILE_READ);

#if VERSION_CHECK(LIBAVUTIL_VERSION_INT, >=, 51, 43, 0, 51, 75, 100)
	unknown_size<AVSHA, av_sha_alloc, ffms_free_sha> ctx;
#else
	std::vector<uint8_t> ctxmem(av_sha_size);
	AVSHA *ctx = (AVSHA*)(&ctxmem[0]);
#endif
	av_sha_init(ctx, 160);

	try {
		file.Seek(0, SEEK_END);
		*Filesize = file.Tell();

		file.Seek(0, SEEK_SET);
		std::vector<char> FileBuffer(static_cast<size_t>(std::min<int64_t>(1024*1024, *Filesize)));
		size_t BytesRead = file.Read(&FileBuffer[0], FileBuffer.size());
		av_sha_update(ctx, reinterpret_cast<const uint8_t*>(&FileBuffer[0]), BytesRead);

		if (*Filesize > static_cast<int64_t>(FileBuffer.size())) {
			file.Seek(-(int)FileBuffer.size(), SEEK_END);
			BytesRead = file.Read(&FileBuffer[0], FileBuffer.size());
			av_sha_update(ctx, reinterpret_cast<const uint8_t*>(&FileBuffer[0]), BytesRead);
		}
	}
	catch (...) {
		av_sha_final(ctx, Digest);
		throw;
	}
	av_sha_final(ctx, Digest);
}
Beispiel #2
0
// To speed the process up a bit, and to reduce problematic newlines,
// this goes by entire lines.
char *CC_ParseSpawnEntities (char *ServerLevelName, char *entities)
{
	CFileBuffer FileBuffer(String::Format("maps/ents/%s.ccent", ServerLevelName).CString(), true);
	String finalString;
	char *realEntities;

	if (!FileBuffer.Valid())
		return entities;
	else
		entities = FileBuffer.GetBuffer<char> ();

	realEntities = entities;
	finalString = realEntities;

	/*while ((token = CC_ParseLine(&realEntities)) != NULL)
	{
		if (token == NULL)
			break; // ever happen?

		if (token[0] == '#' && (realEntities = ParsePound(token, realEntities)) != NULL)
			continue;

		// Basically if we reach here, this part makes it into the final compilation.
		finalString += std::string(token) + "\n";

		if (TokenEnd(token))
			break;
	}*/

	return Mem_TagStrDup (finalString.CString(), TAG_LEVEL);
}
Beispiel #3
0
FileBuffer WWWAPIcURLImpl::downloadFile(const std::string &url) {
#if ! SAC_EMSCRIPTEN && ! SAC_WINDOWS
    //check url
    unsigned found = url.find_last_of("/");
    //if url ends with a '/' or there is no '/' at all, it's a bad url
    if (found >= url.size() - 1) {
        LOGE("Invalid URL! " << url);
        return FileBuffer();
    }


    CURL * curl = curl_easy_init();
    if (! curl) {
        LOGE("Could not init curl");
        return FileBuffer();
    }

    FileBuffer fb;

    curl_easy_setopt(curl, CURLOPT_URL, url.c_str());
    curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_data);
    curl_easy_setopt(curl, CURLOPT_WRITEDATA, &fb);
    CURLcode res = curl_easy_perform(curl);
    long HTTPCode;
    curl_easy_getinfo(curl, CURLINFO_HTTP_CODE, &HTTPCode);

    switch (res) {
        case 0:
            if (HTTPCode == 200) {
                LOGI("Successfully downloaded FileBuffer " << url << ". Total size: " << fb.size << "o.");
                return fb;
            } else {
                LOGE("Error with FileBuffer, http_code=" << HTTPCode);
            }
            break;
        case 6:
            LOGE("Could not access url " << url);
            break;
        default:
            LOGE("Unknown error: " << res << " and http_code=" << HTTPCode);
            break;
    }
    curl_easy_cleanup(curl);
#endif
    //return empty file buffer, since we got an error
    return FileBuffer();
}
int main()
{
    printf ("# Program by Shulgin E." "\n\n");
    //setlocale (LC_ALL, "Russian");      // If u want to sort a russian poem

    char FilePath[MAXFILEPATH] = "Bayrone.txt";
    char ReadMode[MAXREADMODE] = "rb";

    FILE* InputFile = FileOpen (FilePath, ReadMode);
    if (InputFile == PTR_ERROR) return -1;

    long long file_len = FileLength (InputFile);
    if (file_len == INT_ERROR) return -1;

    char* buffer = FileBuffer (InputFile, file_len);
    fclose (InputFile);
    if (buffer == PTR_ERROR) return -1;
    //printf ("\n--------------\n" "<%s>" "\n--------------\n", buffer);
    /*const char* bufCopy = (char*) calloc (file_len, sizeof(*buffer));
    memcpy(buffer, bufCopy, sizeof(buffer));
    printf("\n<%s>\n", bufCopy); */

    int nLines = 0;
    nLines = CountLines (buffer, file_len);
    if (nLines == INT_ERROR) return -1;
    //printf ("nLines = %d" "\n", nLines);

    my_string* text = (my_string*) calloc (nLines, sizeof(my_string*));
    Text_Construct (text, buffer, file_len, nLines);
    TextOut (text, nLines);

    int SortType = 1;
    printf ("Available types of sort:" "\n"
            " 1) SortFromBeg" "\n"
            " 2) SortFromEnd" "\n");
    printf ("Input number of preferred sorting: ");
    scanf ("%d", &SortType);
    int sort_check = TextSort (SortType, text, nLines);
    if (sort_check == INT_ERROR) return -1;

    printf ("\n" "Sorted text:" "\n");
    TextOut (text, nLines);

    int Text_check = Text_Destruct (text, nLines);
    if (Text_check == INT_ERROR) return -1;

    int Buf_check = FreeBuffer (buffer);
    if (Buf_check == INT_ERROR) return -1;

    return 1;
}
Beispiel #5
0
bool ZipFileManager::GetFileBuffer(const str_type::string &fileName, FileBuffer &out)
{
	if (!IsLoaded())
		return false;

	str_type::string fixedPath = fileName;
	FixSlashesForUnix(fixedPath);

	zip_file *file = zip_fopen(m_archive, fixedPath.c_str(), 0);

	if (file == NULL)
		return false;

	struct zip_stat stat;
	zip_stat(m_archive, fixedPath.c_str(), 0, &stat);

	out = FileBuffer(new _FileBuffer<unsigned char>(static_cast<unsigned long>(stat.size)));
	zip_fread(file, out->GetAddress(), stat.size);

	zip_fclose(file);
	return true;
}
Beispiel #6
0
bool StdFileManager::GetFileBuffer(const str_type::string &fileName, FileBuffer &out)
{
	#if _MSC_VER >= 1500
		FILE *f = 0;
		_wfopen_s(&f, fileName.c_str(), GS_L("rb"));
	#else
		FILE *f = _wfopen(fileName.c_str(), GS_L("rb"));
	#endif

	if (!f)
	{
		return false;
	}
	
	fseek(f, 0, SEEK_END);
	const std::size_t len = ftell(f);
	fseek(f, 0, SEEK_SET);

	out = FileBuffer(new _FileBuffer<unsigned char>(len));
	fread(out->GetAddress(), len, 1, f);
	fclose(f);
	return true;
}