Пример #1
0
static int sendFile(const char* path, const MABtAddr* address, int port, int maxPacketSize) {
	FILE* file = fopen(path, "rb");
	if(!file) {
		printf("Couldn't open file \"%s\"!\n", path);
		return -__COUNTER__;
	}
	const char* filename = MAX(MAX(path, strrchr(path, '\\')), strrchr(path, '/'));

	Array<u16> unicode_buf(strlen(filename));
	//Big Endian Unicode
	for(uint i=0; i<unicode_buf.size(); i++) {
		unicode_buf[i] = filename[i] << 8;
	}

	if(fseek(file, 0, SEEK_END)) {
		printf("Couldn't scan file \"%s\"!\n", filename);
		return -__COUNTER__;
	}
	int file_len = ftell(file);
	if(fseek(file, 0, SEEK_SET)) {
		printf("Couldn't scan file \"%s\"!\n", filename);
		return -__COUNTER__;
	}

	Array<char> file_buf(file_len);
	int res = fread(file_buf, 1, file_len, file);
	if(res != file_len) {
		DUMPINT(res);
		printf("Couldn't read file \"%s\"!\n", filename);
		return -__COUNTER__;
	}

	return sendObject(*address, file_buf, unicode_buf, port, maxPacketSize);
}
Пример #2
0
std::wstring utf8_to_wstring( const std::string & utf8_string ) {
	int required_size = MultiByteToWideChar( CP_UTF8, 0, utf8_string.c_str(), -1, NULL, 0 );
	if ( required_size <= 0 ) {
		return std::wstring();
	}
	std::vector<wchar_t> unicode_buf( required_size );
	MultiByteToWideChar( CP_UTF8, 0, utf8_string.data(), -1, &unicode_buf[0], required_size );
	return &unicode_buf[0];
}
Пример #3
0
static int sendFile(const char* path, const MABtAddr* address, int port, int maxPacketSize) {
	FILE* file = fopen(path, "rb");
	if(!file) {
		printf("Couldn't open file \"%s\"!\n", path);
		return -__COUNTER__;
	}
	const char* filename = MAX(MAX(path, strrchr(path, '\\')), strrchr(path, '/'));

	Array<u16> unicode_buf(strlen(filename));
	//Big Endian Unicode
	for(uint i=0; i<unicode_buf.size(); i++) {
		unicode_buf[i] = filename[i] << 8;
	}

	if(fseek(file, 0, SEEK_END)) {
		printf("Couldn't scan file \"%s\"!\n", filename);
		return -__COUNTER__;
	}
	int file_len = ftell(file);
	if(fseek(file, 0, SEEK_SET)) {
		printf("Couldn't scan file \"%s\"!\n", filename);
		return -__COUNTER__;
	}

	Array<char> file_buf(file_len);
	int res = fread(file_buf, 1, file_len, file);
	if(res != file_len) {
		DUMPINT(res);
		printf("Couldn't read file \"%s\"!\n", filename);
		return -__COUNTER__;
	}

	if(port < 0) {
		printf("OBEX Object Push port not specified, querying remote device...\n");
		port = findObexPort(address);
		if(port < 0) {
			printf("Query failed (%i). File not sent.\n", port);
			return port;
		} else {
			printf("Port found: %i\n", port);
		}
	}

	return sendObject(*address, file_buf, unicode_buf, port, maxPacketSize);
}