/**
 * Preprocess a shader.
 * @param OutPreprocessedShader - Upon return contains the preprocessed source code.
 * @param ShaderOutput - ShaderOutput to which errors can be added.
 * @param ShaderInput - The shader compiler input.
 * @param AdditionalDefines - Additional defines with which to preprocess the shader.
 * @returns true if the shader is preprocessed without error.
 */
bool PreprocessShaderFile(FString& OutPreprocessedShader, TArray<FShaderCompilerError>& OutShaderErrors, const FString& InShaderFile)
{
	FString McppOptions;
	FString McppOutput, McppErrors;
	ANSICHAR* McppOutAnsi = nullptr;
	ANSICHAR* McppErrAnsi = nullptr;
	bool bSuccess = false;

	// MCPP is not threadsafe.
	static FCriticalSection McppCriticalSection;
	FScopeLock McppLock(&McppCriticalSection);

	FSimpleMcppFileLoader FileLoader(InShaderFile);

	int32 Result = mcpp_run(
		TCHAR_TO_ANSI(*McppOptions),
		TCHAR_TO_ANSI(*FileLoader.GetInputShaderFilename()),
		&McppOutAnsi,
		&McppErrAnsi,
		FileLoader.GetMcppInterface()
		);

	McppOutput = McppOutAnsi;
	McppErrors = McppErrAnsi;

	if (ParseMcppErrors(OutShaderErrors, McppErrors, false))
	{
		// exchange strings
		FMemory::Memswap( &OutPreprocessedShader, &McppOutput, sizeof(FString) );
		bSuccess = true;
	}

	return bSuccess;
}
void TestFString()
{
	FString s1("s1");
	FText t1 = FText::FromString(s1);
	s1 = t1.ToString();

	// 转化成FString
	s1 = FString::SanitizeFloat(0.1f);
	s1 = FString::FromInt(1);
	s1 = true ? TEXT("true") : TEXT("false");
	s1 = FVector::ZeroVector.ToString();
	s1 = FVector2D::ZeroVector.ToString();
	s1 = FLinearColor::Red.ToString();
	s1 = ((UObject*)(NULL))->GetFullName();

	// 转化为基础类型
	bool b1 = FString(TEXT("true")).ToBool();
	b1 = FCString::ToBool(*FString(TEXT("true")));
	float f1 = FCString::Atof(*FString(TEXT("0.1f")));
	int i1 = FCString::Atoi(*FString(TEXT("1")));

	if (s1.Equals(TEXT("1111"), ESearchCase::IgnoreCase))
	{
		Debug(TEXT("11111"));
	}

	s1 = FString(ANSI_TO_TCHAR("s1"));
	s1 = FString(ANSI_TO_TCHAR(TCHAR_TO_ANSI(TEXT("s1"))));
	Debug(TCHAR_TO_ANSI(*s1));
}
Example #3
0
bool UNdiMediaFinder::Initialize()
{
	Shutdown();

	if (!FNdi::IsInitialized())
	{
		return false;
	}

	FString ExtraAddressesString = FString::Join(ExtraAddresses, TEXT(","));
	FString GroupsString = FString::Join(GroupFilters, TEXT(","));

	NDIlib_find_create_t FindCreate;
	{
		FindCreate.show_local_sources = ShowLocalSources;
		FindCreate.p_extra_ips = TCHAR_TO_ANSI(*ExtraAddressesString);
		FindCreate.p_groups = TCHAR_TO_ANSI(*GroupsString);
	}

	FindInstance = FNdi::Lib->NDIlib_find_create_v2(&FindCreate);

	if (FindInstance == nullptr)
	{
		UE_LOG(LogNdiMedia, Warning, TEXT("Failed to create NDI Find instance"));
		return false;
	}

	return true;
}
Example #4
0
void FWebSocket::Connect(){
#if !PLATFORM_HTML5
	struct lws_client_connect_info ConnectInfo = {
			Context, TCHAR_TO_ANSI(*StrInetAddress), InetPort, false, "/", TCHAR_TO_ANSI(*StrInetAddress), TCHAR_TO_ANSI(*StrInetAddress), Protocols[1].name, -1, this
	};
	Wsi = lws_client_connect_via_info(&ConnectInfo);
	check(Wsi);

#else // PLATFORM_HTML5

	SockFd = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP);
	if (SockFd == -1) {
		UE_LOG(LogHTML5Networking, Error, TEXT("Socket creationg failed "));
	}
	else
	{
		UE_LOG(LogHTML5Networking, Warning, TEXT(" Socked %d created "), SockFd);
	}

	fcntl(SockFd, F_SETFL, O_NONBLOCK);

#endif

	// Windows XP does not have support for inet_pton
#if PLATFORM_WINDOWS && _WIN32_WINNT <= 0x0502
	memset(&RemoteAddr, 0, sizeof(RemoteAddr));
	int32 SizeOfRemoteAddr = sizeof(RemoteAddr);

	// Force ServerAddress into non-const array. API doesn't modify contents but old API still requires non-const string
	if (WSAStringToAddress(StrInetAddress.GetCharArray().GetData(), AF_INET, NULL, (sockaddr*)&RemoteAddr, &SizeOfRemoteAddr) != 0)
	{
		UE_LOG(LogHTML5Networking, Warning, TEXT("WSAStringToAddress failed "));
		return;
	}

	RemoteAddr.sin_family = AF_INET;
	RemoteAddr.sin_port = htons(InetPort);
#else
	memset(&RemoteAddr, 0, sizeof(RemoteAddr));
	RemoteAddr.sin_family = AF_INET;
	RemoteAddr.sin_port = htons(InetPort);

	if (inet_pton(AF_INET, TCHAR_TO_ANSI(*StrInetAddress), &RemoteAddr.sin_addr) != 1)
	{
		UE_LOG(LogHTML5Networking, Warning, TEXT("inet_pton failed "));
		return;
	}
#endif

#if PLATFORM_HTML5
	int Ret = connect(SockFd, (struct sockaddr *)&RemoteAddr, sizeof(RemoteAddr));
	UE_LOG(LogHTML5Networking, Warning, TEXT(" Connect socket returned %d"), Ret);
#endif

	IsDestroyed = false; 
}
void FLinuxPlatformProcess::LaunchURL(const TCHAR* URL, const TCHAR* Parms, FString* Error)
{
	// @todo This ignores params and error; mostly a stub
	pid_t pid = fork();
	UE_LOG(LogHAL, Verbose, TEXT("FLinuxPlatformProcess::LaunchURL: '%s'"), TCHAR_TO_ANSI(URL));
	if (pid == 0)
	{
		exit(execl("/usr/bin/xdg-open", "xdg-open", TCHAR_TO_ANSI(URL), (char *)0));
	}
}
	void Process()
	{
		UE_LOG(LogMapPakDownloader, Warning, TEXT("Starting Download for %s"), *FileName);

		emscripten_async_wget2(
			TCHAR_TO_ANSI(*(Url + FString(TEXT("?rand=")) + FGuid::NewGuid().ToString())),
			TCHAR_TO_ANSI(*FileName),
			TCHAR_TO_ANSI(TEXT("GET")),
			TCHAR_TO_ANSI(TEXT("")),
			this,
			&FEmscriptenHttpFileRequest::OnLoad,
			&FEmscriptenHttpFileRequest::OnError,
			&FEmscriptenHttpFileRequest::OnProgress
			);
	}
/** 
 * Write out the steam app id to the steam_appid.txt file before initializing the API
 * @param SteamAppId id assigned to the application by Steam
 */
static void WriteSteamAppIdToDisk(int32 SteamAppId)
{
	if (SteamAppId > 0)
	{
		// Turn off sandbox temporarily to make sure file is where it's always expected
		FScopeSandboxContext ScopedSandbox(false);

		// Access the physical file writer directly so that we still write next to the executable in CotF builds.
		FString SteamAppIdFilename = GetSteamAppIdFilename();
		IFileHandle* Handle = IPlatformFile::GetPlatformPhysical().OpenWrite(*SteamAppIdFilename, false, false);
		if (!Handle)
		{
			UE_LOG_ONLINE(Fatal, TEXT("Failed to create file: %s"), *SteamAppIdFilename);
		}
		else
		{
			FString AppId = FString::Printf(TEXT("%d"), SteamAppId);

			FBufferArchive Archive;
			Archive.Serialize((void*)TCHAR_TO_ANSI(*AppId), AppId.Len());

			Handle->Write(Archive.GetData(), Archive.Num());
			delete Handle;
			Handle = nullptr;
		}
	}
}
void SDistributionCurveEditor::KeyTimeCommitted(const FText& CommentText, ETextCommit::Type CommitInfo)
{
	if (CommitInfo == ETextCommit::OnEnter)
	{
		FCurveEditorSelectedKey& SelKey = SharedData->SelectedKeys[0];
		FCurveEdEntry& Entry = SharedData->EdSetup->Tabs[SharedData->EdSetup->ActiveTab].Curves[SelKey.CurveIndex];
		FCurveEdInterface* EdInterface = UInterpCurveEdSetup::GetCurveEdInterfacePointer(Entry);
		
		if (SharedData->NotifyObject)
		{
			// Make a list of all curves we are going to remove keys from.
			TArray<UObject*> CurvesAboutToChange;
			if(Entry.CurveObject)
			{
				CurvesAboutToChange.AddUnique(Entry.CurveObject);
				// Notify a containing tool that keys are about to be removed
				SharedData->NotifyObject->PreEditCurve(CurvesAboutToChange);
			}
		}

		// Set then set using EdInterface.
		EdInterface->SetKeyIn(SelKey.KeyIndex, atof(TCHAR_TO_ANSI( *CommentText.ToString() )));

		if (SharedData->NotifyObject)
		{
			SharedData->NotifyObject->PostEditCurve();
		}

		Viewport->RefreshViewport();
	}

	CloseEntryPopup();
}
bool FCodeLiteSourceCodeAccessor::OpenSolution()
{

	FString Filename = FPaths::GetBaseFilename(GetSolutionPath()) + ".workspace";
	FString Directory = FPaths::GetPath(GetSolutionPath());
	FString Solution = "\"" + Directory + "/" + Filename + "\"";
	FString CodeLitePath;
	if(!CanRunCodeLite(CodeLitePath))
	{
		UE_LOG(LogCodeLiteAccessor, Warning, TEXT("FCodeLiteSourceCodeAccessor::OpenSolution: Cannot find CodeLite binary"));
		return false;
	}

	UE_LOG(LogCodeLiteAccessor, Warning, TEXT("FCodeLiteSourceCodeAccessor::OpenSolution: %s %s"), *CodeLitePath, *Solution);
	
#ifdef USE_DBUS

	//
	// TODO Somehow codelite is not opening the workspace using GetWorkspace()->Open(...)
	//
	DBusMessage* message = nullptr;
	DBusMessageIter args;
		
	// Create new message.
	message = dbus_message_new_signal ("/org/codelite/command", "org.codelite.command", "OpenWorkSpace");

	char* fileName = TCHAR_TO_ANSI(*Solution);

	// Add parameters to the message.
	dbus_message_iter_init_append(message, &args);
	if(!dbus_message_iter_append_basic(&args, DBUS_TYPE_STRING, &fileName)) {
		UE_LOG(LogCodeLiteAccessor, Warning, TEXT("Sdbus_message_iter_append_basic failed."));
		return false;
	}
	
	// Send the message.
	dbus_connection_send(DBusConnection, message, nullptr);
	if(dbus_error_is_set(&DBusError))
	{
		UE_LOG(LogCodeLiteAccessor, Warning, TEXT("dbus_connection_send failed: %s"), DBusError.message);
		return false;
	}
	// Free the message resources.
	dbus_message_unref(message);
	
	return true;

#else

	FProcHandle Proc = FPlatformProcess::CreateProc(*CodeLitePath, *Solution, true, false, false, nullptr, 0, nullptr, nullptr);
	if(Proc.IsValid())
	{
		FPlatformProcess::CloseProc(Proc);
		return true;
	}
	return false;

#endif

}
void UIpConnection::InitLocalConnection(UNetDriver* InDriver, class FSocket* InSocket, const FURL& InURL, EConnectionState InState, int32 InMaxPacket, int32 InPacketOverhead)
{
	InitBase(InDriver, InSocket, InURL, InState, 
		// Use the default packet size/overhead unless overridden by a child class
		(InMaxPacket == 0 || InMaxPacket > MAX_PACKET_SIZE) ? MAX_PACKET_SIZE : InMaxPacket,
		InPacketOverhead == 0 ? UDP_HEADER_SIZE : InPacketOverhead);

	// Figure out IP address from the host URL
	bool bIsValid = false;
	// Get numerical address directly.
	RemoteAddr = InDriver->GetSocketSubsystem()->CreateInternetAddr();
	RemoteAddr->SetIp(*InURL.Host, bIsValid);
	RemoteAddr->SetPort(InURL.Port);

	// Try to resolve it if it failed
	if (bIsValid == false)
	{
		// Create thread to resolve the address.
		ResolveInfo = InDriver->GetSocketSubsystem()->GetHostByName(TCHAR_TO_ANSI(*InURL.Host));
		if (ResolveInfo == NULL)
		{
			Close();
			UE_LOG(LogNet, Verbose, TEXT("IpConnection::InitConnection: Unable to resolve %s"), *InURL.Host);
		}
	}

	// Initialize our send bunch
	InitSendBuffer();
}
Example #11
0
bool FLinuxPlatformProcess::IsApplicationRunning( const TCHAR* ProcName )
{
	FString Commandline = TEXT("pidof '");
	Commandline += ProcName;
	Commandline += TEXT("'  > /dev/null");
	return !system(TCHAR_TO_ANSI(*Commandline));
}
Example #12
0
/**
 * Decodes a Base64 string into a FString
 *
 * @param Source the stringified data to convert
 * @param Dest the out buffer that will be filled with the decoded data
 */
bool FBase64::Decode(const FString& Source, FString& Dest)
{
	uint32 Length = Source.Len();
	// Size must be a multiple of 4
	if (Length % 4)
	{
		return false;
	}
	// Each 4 uint8 chunk of characters is 3 bytes of data
	uint32 ExpectedLength = Length / 4 * 3;
	TArray<ANSICHAR> TempDest;
	TempDest.AddZeroed(ExpectedLength);
	uint8* Buffer = (uint8*)TempDest.GetData();
	uint32 PadCount = 0;

	bool bWasSuccessful = Decode(TCHAR_TO_ANSI(*Source), Length, Buffer, PadCount);
	if (bWasSuccessful)
	{
		if (PadCount > 0)
		{
			Buffer[ExpectedLength - PadCount] = 0;
		}
		else
		{
			TempDest.Add('\0');
		}
		Dest = ANSI_TO_TCHAR(TempDest.GetData());
	}
	return bWasSuccessful;
}
int32 FInternationalization::GetCultureIndex(const FString& Name)
{
#if UE_ENABLE_ICU
	static const int32 MaximumNameLength = 64;
	const int32 NameLength = Name.Len();
	check(NameLength < MaximumNameLength);
	char CanonicalName[MaximumNameLength];

	UErrorCode ICUStatus = U_ZERO_ERROR;
	uloc_canonicalize(TCHAR_TO_ANSI( *Name ), CanonicalName, MaximumNameLength, &ICUStatus);
#endif	

	const int32 CultureCount = AllCultures.Num();
	int32 i;
	for (i = 0; i < CultureCount; ++i)
	{
#if UE_ENABLE_ICU
		if( AllCultures[i]->GetName() == CanonicalName )
#else
		if( AllCultures[i]->GetName() == Name )
#endif
		{
			break;
		}
	}
	if(i >= CultureCount)
	{
		i = -1;
	}
	return i;
}
Example #14
0
void FLinuxPlatformProcess::LaunchFileInDefaultExternalApplication( const TCHAR* FileName, const TCHAR* Parms, ELaunchVerb::Type Verb )
{
	// TODO This ignores parms and verb
	pid_t pid = fork();
	if (pid == 0)
	{
		exit(execl("/usr/bin/xdg-open", "xdg-open", TCHAR_TO_ANSI(FileName), (char *)0));
	}
}
Example #15
0
EAppReturnType::Type FHTML5Misc::MessageBoxExt(EAppMsgType::Type MsgType, const TCHAR* Text, const TCHAR* Caption)
{

#if PLATFORM_HTML5_BROWSER 

	ANSICHAR* AText = TCHAR_TO_ANSI(Text);
	ANSICHAR* ACaption = TCHAR_TO_ANSI(Caption);
	return static_cast<EAppReturnType::Type>(UE_MessageBox(MsgType,AText,ACaption));

#endif 

#if PLATFORM_HTML5_WIN32

	return FGenericPlatformMisc::MessageBoxExt(MsgType, Text, Caption); 

#endif 

}
Example #16
0
bool USQLiteDatabase::CanOpenDatabase(FString DatabaseFilename)
{
	sqlite3* db;
	if (sqlite3_open(TCHAR_TO_ANSI(*DatabaseFilename), &db) == SQLITE_OK)
	{
		sqlite3_close(db);
		return true;
	}
	return false;
}
bool FCodeLiteSourceCodeAccessor::OpenFileAtLine(const FString& FullPath, int32 LineNumber, int32 ColumnNumber)
{
	FString CodeLitePath;
	if(!CanRunCodeLite(CodeLitePath))
	{
		UE_LOG(LogCodeLiteAccessor,Warning, TEXT("FCodeLiteSourceCodeAccessor::OpenFileAtLine: Cannot find CodeLite binary"));
		return false;
	}
	
#ifdef USE_DBUS	
	
	DBusMessage* message = nullptr;
	DBusMessageIter args;
	
	// Create new message.
	message = dbus_message_new_signal ("/org/codelite/command", "org.codelite.command", "OpenFileAtLine");

	char* fileName = TCHAR_TO_ANSI(*FullPath);

	// Add parameters to the message.
	dbus_message_iter_init_append(message, &args);
	if (!dbus_message_iter_append_basic(&args, DBUS_TYPE_STRING, &fileName)) {
		printf("FCodeLiteSourceCodeAccessor::OpenFileAtLine: dbus_message_iter_append_basic failed.\n");
	}
	if (!dbus_message_iter_append_basic(&args, DBUS_TYPE_INT32, &LineNumber)) {
		printf("FCodeLiteSourceCodeAccessor::OpenFileAtLine: dbus_message_iter_append_basic failed.\n");
	}
	
	// Send the message.
	dbus_connection_send(DBusConnection, message, nullptr);
	if(dbus_error_is_set(&DBusError))
	{
		printf("dbus_connection_send failed (%s)\n", DBusError.message);
		return false;
	}
	dbus_connection_flush(DBusConnection);
	
	// Free the message resources.
	dbus_message_unref (message);
	
#else

	const FString Path = FString::Printf(TEXT("\"%s --line=%d\""), *FullPath, LineNumber);

	if(FPlatformProcess::CreateProc(*CodeLitePath, *Path, true, true, false, nullptr, 0, nullptr, nullptr).IsValid())
	{
		UE_LOG(LogCodeLiteAccessor, Warning, TEXT("FCodeLiteSourceCodeAccessor::OpenSolution: Cannot find CodeLite binary"));
	}
	
#endif

	UE_LOG(LogCodeLiteAccessor, Warning, TEXT("CodeLiteSourceCodeAccessor::OpenFileAtLine: %s %d"), *FullPath, LineNumber);

	return true;
}
/**
 * Preprocess a shader.
 * @param OutPreprocessedShader - Upon return contains the preprocessed source code.
 * @param ShaderOutput - ShaderOutput to which errors can be added.
 * @param ShaderInput - The shader compiler input.
 * @param AdditionalDefines - Additional defines with which to preprocess the shader.
 * @returns true if the shader is preprocessed without error.
 */
bool PreprocessShader(
	FString& OutPreprocessedShader,
	FShaderCompilerOutput& ShaderOutput,
	const FShaderCompilerInput& ShaderInput,
	const FShaderCompilerDefinitions& AdditionalDefines
	)
{
	FString McppOptions;
	FString McppOutput, McppErrors;
	ANSICHAR* McppOutAnsi = NULL;
	ANSICHAR* McppErrAnsi = NULL;
	bool bSuccess = false;

	// MCPP is not threadsafe.
	static FCriticalSection McppCriticalSection;
	FScopeLock McppLock(&McppCriticalSection);

	FMcppFileLoader FileLoader(ShaderInput);

	AddMcppDefines(McppOptions, ShaderInput.Environment.GetDefinitions());
	AddMcppDefines(McppOptions, AdditionalDefines.GetDefinitionMap());

	int32 Result = mcpp_run(
		TCHAR_TO_ANSI(*McppOptions),
		TCHAR_TO_ANSI(*FileLoader.GetInputShaderFilename()),
		&McppOutAnsi,
		&McppErrAnsi,
		FileLoader.GetMcppInterface()
		);

	McppOutput = McppOutAnsi;
	McppErrors = McppErrAnsi;

	if (ParseMcppErrors(ShaderOutput, McppErrors))
	{
		// exchange strings
		FMemory::Memswap( &OutPreprocessedShader, &McppOutput, sizeof(FString) );
		bSuccess = true;
	}

	return bSuccess;
}
Example #19
0
void UHTTPAdmin::Init()
{
	// Don't garbage collect me
	SetFlags(RF_MarkAsRootSet);

	CombinedAuth = User + TEXT(":") + Password;

	if (Port == 0)
	{
		Port = 8080;
	}

	// Start Mongoose with all requests being handeled by 'StaticMGHandler'
	MGServer = mg_create_server(this, StaticMGHandler);
	
	// Set the port
	FString PortStr = FString::FromInt(Port);
	mg_set_option(MGServer, "listening_port", TCHAR_TO_ANSI(*PortStr));

	// Set the document root
	FString DocumentRoot = FPaths::GamePluginsDir() / TEXT("HTTPAdmin") / TEXT("HTML");
	mg_set_option(MGServer, "document_root", TCHAR_TO_ANSI(*DocumentRoot));

	// Set access log file
	//FString AccessLog = FPaths::GamePluginsDir() / TEXT("HTTPAdmin") / TEXT("accessLog.txt");
	//mg_set_option(MGServer, "access_log_file", TCHAR_TO_ANSI(*AccessLog));

	// http://www.askapache.com/online-tools/htpasswd-generator/
	// Set the auth password file
	// DEFAULT: admin  admin
	FString AuthFile = FPaths::GamePluginsDir() / TEXT("HTTPAdmin") / TEXT(".htpasswd");
	mg_set_option(MGServer, "global_auth_file", TCHAR_TO_ANSI(*AuthFile));

	// Set the auth domain
	FString AuthDomain = TEXT("HTTPAdmin");
	mg_set_option(MGServer, "auth_domain", TCHAR_TO_ANSI(*AuthDomain));
	

	UE_LOG(HTTPAdmin, Log, TEXT("=================="));
	UE_LOG(HTTPAdmin, Log, TEXT("HTTPAdmin Started on port: %i"), Port);
	UE_LOG(HTTPAdmin, Log, TEXT("=================="));
}
Example #20
0
void FArtemis::WritePipe(FString msg)
{
	pipe = CreateFile(TEXT("\\\\.\\pipe\\artemis"), GENERIC_WRITE, 0, nullptr, OPEN_EXISTING, FILE_FLAG_OVERLAPPED, nullptr);
	if (pipe == nullptr || pipe == INVALID_HANDLE_VALUE)
	{
		return;
	}

	uint32 BytesWritten = 0;
	WriteFile(pipe, TCHAR_TO_ANSI(*msg), msg.Len(), (::DWORD*)&BytesWritten, nullptr);
}
void* FLinuxPlatformProcess::GetDllHandle( const TCHAR* Filename )
{
	check( Filename );
	FString AbsolutePath = FPaths::ConvertRelativePathToFull(Filename);
	void *Handle = dlopen( TCHAR_TO_ANSI(*AbsolutePath), RTLD_LAZY | RTLD_LOCAL );
	if (!Handle)
	{
		UE_LOG(LogLinux, Warning, TEXT("dlopen failed: %s"), ANSI_TO_TCHAR(dlerror()) );
	}
	return Handle;
}
Example #22
0
FString FCulture::FICUCultureImplementation::GetCanonicalName(const FString& Name)
{
	static const int32 MaximumNameLength = 64;
	const int32 NameLength = Name.Len();
	check(NameLength < MaximumNameLength);
	char CanonicalName[MaximumNameLength];

	UErrorCode ICUStatus = U_ZERO_ERROR;
	uloc_canonicalize(TCHAR_TO_ANSI( *Name ), CanonicalName, MaximumNameLength, &ICUStatus);
	return CanonicalName;
}
void FIOSPlatformMisc::GetEnvironmentVariable(const TCHAR* VariableName, TCHAR* Result, int32 ResultLength)
{
	ANSICHAR *AnsiResult = getenv(TCHAR_TO_ANSI(VariableName));
	if (AnsiResult)
	{
		wcsncpy(Result, ANSI_TO_TCHAR(AnsiResult), ResultLength);
	}
	else
	{
		*Result = 0;
	}
}
Example #24
0
void APing::ClientPing(const FString& host = "127.0.0.1", const int port = 8888)
{
	UE_LOG(RakNet_Ping, Log, TEXT("APing::ClientPing"));

	client = RakNet::RakPeerInterface::GetInstance();
	RakNet::SocketDescriptor socketDescriptor(0, 0);
	client->Startup(1, &socketDescriptor, 1);
	client->Ping(TCHAR_TO_ANSI(*host), port, false);

	//waitReceivedData = true;

}
uint32 SerialThread::Run()
{
	FPlatformProcess::Sleep(0.03);
	while (StopTaskCounter.GetValue() == 0 && SP->IsOpened())
	{
		int nBytesRead = SP->ReadData(incomingData1, 1);
		if (nBytesRead > 0)
		{
			if (len1 > 180 || incomingData1[0] == '\n')//strcmp(incomingData1, "\r") == 0 || strcmp(incomingData1, "\n") == 0 || strcmp(incomingData1, "\t") == 0 || len1 > 180)
			{
				if (strlen(outData1) > 0)
				{
					std::string test(outData1);
					FString Fout(test.c_str());
					TheBP->GetData(Fout);
					len1 = 0;
					memset(outData1, 0, sizeof outData1);
				}
			}
			else
			{
				//bool flag = false;

				//if (len1 == 0)
				//{
				//	flag = (incomingData1[0] == 's');//(strcmp(incomingData1, "s") == 0);
				//}
				//else if (len1 == 1)
				//{
				//	flag = (incomingData1[0] == 't');// (strcmp(incomingData1, "t") == 0);
				//}
				//else if (len1 == 2)
				//{
				//	flag = (incomingData1[0] == 'e');// (strcmp(incomingData1, "e") == 0);
				//}
				//else
				//	flag = true;

				//if (flag)
				//{
					outData1[len1] = incomingData1[0];
					len1++;
				//}
			
			}
		}

		FString writeData = TheBP->SendData();
		strcpy_s(writeBuffer1, TCHAR_TO_ANSI(*writeData));
		SP->SendData(writeBuffer1, strlen(writeBuffer1));
	}
	return 0;
}
Example #26
0
void RecordingFile::writeString(const std::string& str)
{
    try {    
        if (log_file_handle_) {
            FString line_f = FString(str.c_str());
            log_file_handle_->Write((const uint8*)TCHAR_TO_ANSI(*line_f), line_f.Len());
        }
        else
            UAirBlueprintLib::LogMessageString("Attempt to write to recording log file when file was not opened", "", LogDebugLevel::Failure);
    }
    catch(std::exception& ex) {
        UAirBlueprintLib::LogMessageString(std::string("file write to recording file failed "), ex.what(), LogDebugLevel::Failure);        
    }
}
Example #27
0
/// <summary> Writes a full line at the end of the file created for this session </summary>
/// <param name="line"> The text line to append at the end of the file </param>
void UMovementTracker::WriteToCurrentFile(FString line)
{
	if (WritePosition && DirectoryExists)
	{
		IPlatformFile& PlatformFile = FPlatformFileManager::Get().GetPlatformFile();
		IFileHandle* handle = PlatformFile.OpenWrite(*FileName, true);
		if (handle)
		{
			handle->Write((const uint8 *)TCHAR_TO_ANSI(*line), line.Len());
			handle->Write((const uint8 *)"\n", 1);
			delete handle;
		}
	}
}
SteamControllerInterface::SteamControllerInterface( const TSharedRef< FGenericApplicationMessageHandler >& InMessageHandler )
	: MessageHandler( InMessageHandler )
{
	if(SteamController() != NULL)
	{
		FString vdfPath = FPaths::ConvertRelativePathToFull(FPaths::Combine(*FPaths::GeneratedConfigDir(), TEXT("controller.vdf")));
		bool bInited = SteamController()->Init(TCHAR_TO_ANSI(*vdfPath));
		UE_LOG(LogSteamController, Log, TEXT("SteamController %s initialized with vdf file '%s'."), bInited ? TEXT("could not be") : TEXT("has been"), *vdfPath);

		// [RCL] 2014-05-05 FIXME: disable when could not init?
		if (bInited)
		{
			FMemory::MemZero(ControllerStates);
		}
	}
	else
	{
		UE_LOG(LogSteamController, Log, TEXT("SteamController is not available"));
	}

	InitialButtonRepeatDelay = 0.2f;
	ButtonRepeatDelay = 0.1f;

	Buttons[0] = EControllerButtons::FaceButtonBottom;
	Buttons[1] = EControllerButtons::FaceButtonRight;
	Buttons[2] = EControllerButtons::FaceButtonLeft;
	Buttons[3] = EControllerButtons::FaceButtonTop;
	Buttons[4] = EControllerButtons::LeftShoulder;
	Buttons[5] = EControllerButtons::RightShoulder;
	Buttons[6] = EControllerButtons::SpecialRight;
	Buttons[7] = EControllerButtons::SpecialLeft;
	Buttons[8] = EControllerButtons::LeftThumb;
	Buttons[9] = EControllerButtons::RightThumb;
	Buttons[10] = EControllerButtons::LeftTriggerThreshold;
	Buttons[11] = EControllerButtons::RightTriggerThreshold;
	Buttons[12] = EControllerButtons::Touch0;
	Buttons[13] = EControllerButtons::Touch1;
	Buttons[14] = EControllerButtons::Touch2;
	Buttons[15] = EControllerButtons::Touch3;
	Buttons[16] = EControllerButtons::LeftStickUp;
	Buttons[17] = EControllerButtons::LeftStickDown;
	Buttons[18] = EControllerButtons::LeftStickLeft;
	Buttons[19] = EControllerButtons::LeftStickRight;
	Buttons[20] = EControllerButtons::RightStickUp;
	Buttons[21] = EControllerButtons::RightStickDown;
	Buttons[22] = EControllerButtons::RightStickLeft;
	Buttons[23] = EControllerButtons::RightStickRight;
	Buttons[24] = EControllerButtons::BackLeft;
	Buttons[25] = EControllerButtons::BackRight;
}
Example #29
0
void FSlateOpenGLShader::CompileShader( const FString& Filename, GLenum ShaderType )
{
	// Create a new shader ID.
	ShaderID = glCreateShader( ShaderType );
	GLint CompileStatus = GL_FALSE;

	check( ShaderID );

	// Load the file to a string
	FString Source;
	bool bFileFound = FFileHelper::LoadFileToString( Source, *Filename );
	check(bFileFound);
	
	// Allocate a buffer big enough to store the string in ascii format
	ANSICHAR* Chars[2] = {0};
	// pass the #define along to the shader
#if PLATFORM_USES_ES2
	Chars[0] = (ANSICHAR*)"#define PLATFORM_USES_ES2 1\n\n#define PLATFORM_LINUX 0\n";
#elif PLATFORM_LINUX
	#if LINUX_USE_OPENGL_3_2
	Chars[0] = (ANSICHAR*)"#version 150\n\n#define PLATFORM_USES_ES2 0\n\n#define PLATFORM_LINUX 1\n";
	#else
	Chars[0] = (ANSICHAR*)"#version 120\n\n#define PLATFORM_USES_ES2 0\n\n#define PLATFORM_LINUX 1\n";
	#endif // LINUX_USE_OPENGL_3_2
#else
	Chars[0] = (ANSICHAR*)"#version 120\n\n#define PLATFORM_USES_ES2 0\n\n#define PLATFORM_LINUX 0\n";
#endif
	Chars[1] = new ANSICHAR[Source.Len()+1];
	FCStringAnsi::Strcpy(Chars[1], Source.Len() + 1, TCHAR_TO_ANSI(*Source));

	// give opengl the source code for the shader
	glShaderSource( ShaderID, 2, (const ANSICHAR**)Chars, NULL );
	delete[] Chars[1];

	// Compile the shader and check for success
	glCompileShader( ShaderID );

	glGetShaderiv( ShaderID, GL_COMPILE_STATUS, &CompileStatus );
	if( CompileStatus == GL_FALSE )
	{
		// The shader did not compile.  Display why it failed.
		FString Log = GetGLSLShaderLog( ShaderID );

		checkf(false, TEXT("Failed to compile shader: %s\n%s"), *Filename, *Log );

		// Delete the shader since it failed.
		glDeleteShader( ShaderID );
		ShaderID = 0;
	}
}
Example #30
0
FLibvlcMedia* FVlcMediaSource::OpenUrl(const FString& Url)
{
	Close();

	Media = FVlc::MediaNewLocation(VlcInstance, TCHAR_TO_ANSI(*Url));

	if (Media == nullptr)
	{
		UE_LOG(LogVlcMedia, Warning, TEXT("Failed to open media %s: %s"), *Url, ANSI_TO_TCHAR(FVlc::Errmsg()));
	}

	CurrentUrl = Url;

	return Media;
}