当前位置: 首页>>代码示例>>C++>>正文


C++ File::read_noThrow方法代码示例

本文整理汇总了C++中common::File::read_noThrow方法的典型用法代码示例。如果您正苦于以下问题:C++ File::read_noThrow方法的具体用法?C++ File::read_noThrow怎么用?C++ File::read_noThrow使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在common::File的用法示例。


在下文中一共展示了File::read_noThrow方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: extractAndEncodeWAV

void CompressionTool::extractAndEncodeWAV(const char *outName, Common::File &input, AudioFormat compMode) {
	unsigned int length;
	char fbuf[2048];
	size_t size;

	input.seek(-4, SEEK_CUR);
	length = input.readUint32LE();
	length += 8;
	input.seek(-8, SEEK_CUR);

	/* Copy the WAV data to a temporary file */
	Common::File f(outName, "wb");
	while (length > 0) {
		size = input.read_noThrow(fbuf, length > sizeof(fbuf) ? sizeof(fbuf) : length);
		if (size <= 0)
			break;
		length -= (int)size;
		f.write(fbuf, size);
	}
	f.close();

	/* Convert the WAV temp file to OGG/MP3 */
	encodeAudio(outName, false, -1, tempEncoded, compMode);
}
开发者ID:alexbevi,项目名称:scummvm-tools,代码行数:24,代码来源:compress.cpp

示例2: main

int main(int argc, char *argv[]) {
	GtkWidget *main_window, *scroll;
	GtkWidget *treeview;
	GtkTreeViewColumn *column;
	GtkCellRenderer *name_renderer, *size_renderer;
	GtkTreeStore *store;
	GtkTreeIter categories[14];
	GValue value = { 0, };
	gint offset;
	uint32 res_counts[14];
	uint32 res_sizes[14];
	int i;

	Common::File in;
	uint32 index_pos;
	uint32 pos, len;

	gtk_init(&argc, &argv);

	if (argc != 2) {
		printf("Usage: %s filename\n", argv[0]);
		return EXIT_FAILURE;
	}

	in.open(argv[1], "rb");
	if (!in.isOpen()) {
		printf("Couldn't open %s for reading\n", argv[1]);
		return EXIT_FAILURE;
	}

	/* Create the main window, scrollable in both directions */

	main_window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
	gtk_window_set_title(GTK_WINDOW(main_window), "CLUster Explorer");
	gtk_window_set_default_size(GTK_WINDOW(main_window), 400, 400);

	g_signal_connect(G_OBJECT(main_window), "destroy", G_CALLBACK(main_window_destroy_cb), NULL);

	scroll = gtk_scrolled_window_new(NULL, NULL);
	gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(scroll), GTK_SHADOW_ETCHED_IN);
	gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scroll), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);

	/* Create the tree view */

	for (i = 0; i < ARRAYSIZE(res_counts); i++) {
		res_counts[i] = 0;
		res_sizes[i] = 0;
	}

	store = gtk_tree_store_new(N_COLUMNS,
		G_TYPE_STRING,
		G_TYPE_STRING,
		G_TYPE_INT,
		G_TYPE_INT,
		G_TYPE_INT);

	gtk_tree_sortable_set_default_sort_func(GTK_TREE_SORTABLE(store), compare_items, NULL, NULL);
	gtk_tree_sortable_set_sort_column_id(GTK_TREE_SORTABLE(store), GTK_TREE_SORTABLE_DEFAULT_SORT_COLUMN_ID, GTK_SORT_ASCENDING);

	index_pos = in.readUint32LE();
	in.seek(index_pos, SEEK_SET);

	for (;;) {
		GtkTreeIter iter;
		byte type;
		gchar *utf8_name;
		gchar name[34];
		gchar *size;

		try {
			pos = in.readUint32LE();
			len = in.readUint32LE();
		} catch (...) {
			break;
		}

		size = make_size(len);

		index_pos = in.pos();

		in.seek(pos, SEEK_SET);

		type = in.readByte();
		in.readByte();				/* compType	*/
		in.readUint32LE();			/* compSize	*/
		in.readUint32LE();			/* decompSize	*/
		in.read_noThrow(name, sizeof(name));

		/*
		 * We need to convert from Latin-1 to UTF-8. Otherwise the text
		 * "CAFÉ" won't be displayed properly.
		 */

		utf8_name = g_convert(name, -1, "UTF-8", "ISO-8859-1", NULL, NULL, NULL);

		if (!res_counts[type]) {
			gtk_tree_store_append(store, &categories[type], NULL);
			gtk_tree_store_set(store, &categories[type],
				NAME_COLUMN, getType(type),
				SIZE_COLUMN, "",
//.........这里部分代码省略.........
开发者ID:CobaltBlues,项目名称:scummvm-tools,代码行数:101,代码来源:sword2_clue.cpp

示例3: loadWAVFromStream

bool loadWAVFromStream(Common::File &stream, int &size, int &rate, byte &flags, uint16 *wavType, int *blockAlign_) {
    const uint32 initialPos = stream.pos();
    byte buf[4+1];

    buf[4] = 0;

    stream.read_noThrow(buf, 4);
    if (memcmp(buf, "RIFF", 4) != 0) {
        warning("getWavInfo: No 'RIFF' header");
        return false;
    }

    uint32 wavLength = stream.readUint32LE();

    stream.read_noThrow(buf, 4);
    if (memcmp(buf, "WAVE", 4) != 0) {
        warning("getWavInfo: No 'WAVE' header");
        return false;
    }

    stream.read_noThrow(buf, 4);
    if (memcmp(buf, "fmt ", 4) != 0) {
        warning("getWavInfo: No 'fmt' header");
        return false;
    }

    uint32 fmtLength = stream.readUint32LE();
    if (fmtLength < 16) {
        // A valid fmt chunk always contains at least 16 bytes
        warning("getWavInfo: 'fmt' header is too short");
        return false;
    }

    // Next comes the "type" field of the fmt header. Some typical
    // values for it:
    // 1  -> uncompressed PCM
    // 17 -> IMA ADPCM compressed WAVE
    // See <http://www.saettler.com/RIFFNEW/RIFFNEW.htm> for a more complete
    // list of common WAVE compression formats...
    uint16 type = stream.readUint16LE();	// == 1 for PCM data
    uint16 numChannels = stream.readUint16LE();	// 1 for mono, 2 for stereo
    uint32 samplesPerSec = stream.readUint32LE();	// in Hz
    uint32 avgBytesPerSec = stream.readUint32LE();	// == SampleRate * NumChannels * BitsPerSample/8

    uint16 blockAlign = stream.readUint16LE();	// == NumChannels * BitsPerSample/8
    uint16 bitsPerSample = stream.readUint16LE();	// 8, 16 ...
    // 8 bit data is unsigned, 16 bit data signed


    if (wavType != 0)
        *wavType = type;

    if (blockAlign_ != 0)
        *blockAlign_ = blockAlign;
#if 0
    printf("WAVE information:\n");
    printf("  total size: %d\n", wavLength);
    printf("  fmt size: %d\n", fmtLength);
    printf("  type: %d\n", type);
    printf("  numChannels: %d\n", numChannels);
    printf("  samplesPerSec: %d\n", samplesPerSec);
    printf("  avgBytesPerSec: %d\n", avgBytesPerSec);
    printf("  blockAlign: %d\n", blockAlign);
    printf("  bitsPerSample: %d\n", bitsPerSample);
#endif

    if (type != 1 && type != 2 && type != 17) {
        warning("getWavInfo: only PCM, MS ADPCM or IMA ADPCM data is supported (type %d)", type);
        return false;
    }

    if (blockAlign != numChannels * bitsPerSample / 8 && type != 2) {
        debug(0, "getWavInfo: blockAlign is invalid");
    }

    if (avgBytesPerSec != samplesPerSec * blockAlign && type != 2) {
        debug(0, "getWavInfo: avgBytesPerSec is invalid");
    }

    // Prepare the return values.
    rate = samplesPerSec;

    flags = 0;
    if (bitsPerSample == 8)		// 8 bit data is unsigned
        flags |= Audio::Mixer::FLAG_UNSIGNED;
    else if (bitsPerSample == 16)	// 16 bit data is signed little endian
        flags |= (Audio::Mixer::FLAG_16BITS | Audio::Mixer::FLAG_LITTLE_ENDIAN);
    else if (bitsPerSample == 4 && type == 17)	// MS IMA ADPCM compressed. We decompress it
        flags |= (Audio::Mixer::FLAG_16BITS | Audio::Mixer::FLAG_LITTLE_ENDIAN);
    else if (bitsPerSample == 4 && type == 2)	// MS ADPCM compressed. We decompress it
        flags |= (Audio::Mixer::FLAG_16BITS | Audio::Mixer::FLAG_LITTLE_ENDIAN);
    else {
        warning("getWavInfo: unsupported bitsPerSample %d", bitsPerSample);
        return false;
    }

    if (numChannels == 2)
        flags |= Audio::Mixer::FLAG_STEREO;
    else if (numChannels != 1) {
        warning("getWavInfo: unsupported number of channels %d", numChannels);
//.........这里部分代码省略.........
开发者ID:vincenthamm,项目名称:scummvm-tools,代码行数:101,代码来源:wave.cpp


注:本文中的common::File::read_noThrow方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。