本文整理汇总了C++中gd::String::ToLocale方法的典型用法代码示例。如果您正苦于以下问题:C++ String::ToLocale方法的具体用法?C++ String::ToLocale怎么用?C++ String::ToLocale使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类gd::String
的用法示例。
在下文中一共展示了String::ToLocale方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: LoadFromFile
bool ProjectFileWriter::LoadFromFile(gd::Project & project, const gd::String & filename)
{
//Load the XML document structure
TiXmlDocument doc;
if ( !doc.LoadFile(filename.ToLocale().c_str()) )
{
gd::String errorTinyXmlDesc = doc.ErrorDesc();
gd::String error = _( "Error while loading :" ) + "\n" + errorTinyXmlDesc + "\n\n" +_("Make sure the file exists and that you have the right to open the file.");
gd::LogError( error );
return false;
}
#if defined(GD_IDE_ONLY)
project.SetProjectFile(filename);
project.SetDirty(false);
#endif
TiXmlHandle hdl( &doc );
gd::SerializerElement rootElement;
ConvertANSIXMLFile(hdl, doc, filename);
//Load the root element
TiXmlElement * rootXmlElement = hdl.FirstChildElement("project").ToElement();
//Compatibility with GD <= 3.3
if (!rootXmlElement) rootXmlElement = hdl.FirstChildElement("Project").ToElement();
if (!rootXmlElement) rootXmlElement = hdl.FirstChildElement("Game").ToElement();
//End of compatibility code
gd::Serializer::FromXML(rootElement, rootXmlElement);
//Unsplit the project
#if defined(GD_IDE_ONLY) && !defined(GD_NO_WX_GUI)
wxString projectPath = wxFileName::FileName(filename).GetPath();
gd::Splitter splitter;
splitter.Unsplit(rootElement, [&projectPath](gd::String path, gd::String name) {
TiXmlDocument doc;
gd::SerializerElement rootElement;
gd::String filename = projectPath + path + "-" + MakeFileNameSafe(name);
if (!doc.LoadFile(filename.ToLocale().c_str()))
{
gd::String errorTinyXmlDesc = doc.ErrorDesc();
gd::String error = _( "Error while loading :" ) + "\n" + errorTinyXmlDesc + "\n\n" +_("Make sure the file exists and that you have the right to open the file.");
gd::LogError(error);
return rootElement;
}
TiXmlHandle hdl( &doc );
gd::Serializer::FromXML(rootElement, hdl.FirstChildElement().ToElement());
return rootElement;
});
#endif
//Unserialize the whole project
project.UnserializeFrom(rootElement);
return true;
}
示例2: ShowTextInput
/**
* Show a dialog so as to get a text from user
*/
bool GD_EXTENSION_API ShowTextInput( RuntimeScene & scene, gd::Variable & variable, const gd::String & message, const gd::String & title )
{
sf::Clock timeSpent;
gd::String result;
//Display the box
#if defined(WINDOWS)
CInputBox ibox(NULL);
if (ibox.DoModal(title.ToWide().c_str(), message.ToWide().c_str()))
result = gd::String::FromWide(ibox.Text);
#endif
#if defined(LINUX) || defined(MACOS)
std::string strResult;
nw::TextInput dialog(title.ToLocale(), message.ToLocale(), strResult);
dialog.wait_until_closed();
result = gd::String::FromLocale(strResult); //Convert from locale
#endif
scene.GetTimeManager().NotifyPauseWasMade(timeSpent.getElapsedTime().asMicroseconds());//Don't take the time spent in this function in account.
//Update the variable
variable.SetString(result);
return true;
}
示例3: SaveToFile
bool ProjectFileWriter::SaveToFile(const gd::Project & project, const gd::String & filename, bool forceSingleFile)
{
//Serialize the whole project
gd::SerializerElement rootElement;
project.SerializeTo(rootElement);
#if defined(GD_IDE_ONLY) && !defined(GD_NO_WX_GUI)
if (project.IsFolderProject() && !forceSingleFile) //Optionally split the project
{
wxString projectPath = wxFileName::FileName(filename).GetPath();
gd::Splitter splitter;
auto splitElements = splitter.Split(rootElement, {
"/layouts/layout",
"/externalEvents/externalEvents",
"/externalLayouts/externalLayout",
});
for (auto & element : splitElements)
{
//Create a partial XML document
TiXmlDocument doc;
doc.LinkEndChild(new TiXmlDeclaration("1.0", "UTF-8", ""));
TiXmlElement * root = new TiXmlElement("projectPartial");
doc.LinkEndChild(root);
gd::Serializer::ToXML(element.element, root);
//And write the element in it
gd::String filename = projectPath + element.path + "-" + MakeFileNameSafe(element.name);
gd::RecursiveMkDir::MkDir(wxFileName::FileName(filename).GetPath());
if (!doc.SaveFile(filename.ToLocale().c_str()))
{
gd::LogError( _( "Unable to save file ") + filename + _("!\nCheck that the drive has enough free space, is not write-protected and that you have read/write permissions." ) );
return false;
}
}
}
#endif
//Create the main XML document
TiXmlDocument doc;
doc.LinkEndChild(new TiXmlDeclaration( "1.0", "UTF-8", "" ));
TiXmlElement * root = new TiXmlElement( "project" );
doc.LinkEndChild(root);
gd::Serializer::ToXML(rootElement, root);
//Write XML to file
if ( !doc.SaveFile( filename.ToLocale().c_str() ) )
{
gd::LogError( _( "Unable to save file ") + filename + _("!\nCheck that the drive has enough free space, is not write-protected and that you have read/write permissions." ) );
return false;
}
return true;
}
示例4: ShowMessageBox
/**
* Display a simple message box.
*/
void GD_EXTENSION_API ShowMessageBox( RuntimeScene & scene, const gd::String & message, const gd::String & title )
{
sf::Clock timeSpent;
//Display the box
#if defined(WINDOWS)
MessageBoxW(NULL, message.ToWide().c_str(), title.ToWide().c_str(), MB_ICONINFORMATION);
#endif
#if defined(LINUX) || defined(MACOS)
nw::MsgBox msgBox(title.ToLocale(), message.ToLocale());
msgBox.wait_until_closed();
#endif
scene.GetTimeManager().NotifyPauseWasMade(timeSpent.getElapsedTime().asMicroseconds());//Don't take the time spent in this function in account.
}
示例5: SendData
void AnalyticsSender::SendData(gd::String collection, SerializerElement & data)
{
#if !defined(GD_NO_WX_GUI)
//Check if we are allowed to send these data.
bool sendInfo;
wxConfigBase::Get()->Read("/Startup/SendInfo", &sendInfo, true);
if (!sendInfo) return;
data.SetAttribute("gdVersion", VersionWrapper::FullString());
data.SetAttribute("os", gd::String(wxGetOsDescription()));
data.SetAttribute("lang",
gd::String(wxLocale::GetLanguageCanonicalName(LocaleManager::Get()->GetLanguage())));
if (wxConfig::Get())
data.SetAttribute("openingCount", wxConfig::Get()->ReadDouble("Startup/OpeningCount", 0));
// Create request
std::cout << "Sending analytics data..."; std::cout.flush();
sf::Http Http;
Http.setHost("http://api.keen.io");
sf::Http::Request request;
request.setMethod(sf::Http::Request::Post);
request.setField("Content-Type", "application/json");
request.setUri("/3.0/projects/"+projectId.ToLocale()+"/events/"+collection.ToLocale()+"?api_key="+writeKey.ToLocale());
request.setBody(Serializer::ToJSON(data).ToSfString());
// Send the request
sf::Http::Response response = Http.sendRequest(request, sf::seconds(2));
std::cout << "done (" << response.getStatus() << ")" << std::endl;
#endif
}
示例6: ReadFile
gd::String NativeFileSystem::ReadFile(const gd::String & file)
{
std::ifstream t(file.ToLocale().c_str());
std::stringstream buffer;
buffer << t.rdbuf();
return gd::String::FromUTF8(buffer.str());
}
示例7: LoadPlainText
gd::String ResourcesLoader::LoadPlainText( const gd::String & filename )
{
gd::String text;
if (resFile.ContainsFile(filename))
{
char* buffer = resFile.GetFile(filename);
if (!buffer) {
cout << "Failed to read a file from resource file: " << filename << endl;
} else {
text = gd::String::FromUTF8(std::string(buffer));
}
}
else
{
ifstream file(filename.ToLocale().c_str(), ios::in);
if(!file.fail())
{
string ligne;
while(getline(file, ligne))
text += gd::String::FromUTF8(ligne)+"\n";
file.close();
}
else
cout << "Failed to read a file: " << filename << endl;
}
return text;
}
示例8: DownloadFile
void GD_API DownloadFile( const gd::String & host, const gd::String & uri, const gd::String & outputfilename )
{
// Separate the host and the port number
auto hostInfo = host.Split(U':');
if(hostInfo.size() < 2)
return; //Invalid address (there should be two elements: "http" and "//the.domain.com")
// Create Http
sf::Http http;
http.setHost(hostInfo[0].ToUTF8() + ":" + hostInfo[1].ToUTF8(), hostInfo.size() > 2 ? hostInfo[2].To<unsigned short>() : 0);
// Create request
sf::Http::Request Request;
Request.setMethod(sf::Http::Request::Get);
Request.setUri(uri.ToUTF8());
// Send request & Get response
sf::Http::Response datas = http.sendRequest(Request);
ofstream ofile(outputfilename.ToLocale().c_str(), ios_base::binary);
if ( ofile.is_open() )
{
ofile.write(datas.getBody().c_str(),datas.getBody().size());
ofile.close();
return;
}
cout << "Downloading file : Unable to open output file " << outputfilename;
return;
}
示例9: FileExists
bool GD_API FileExists( const gd::String & file )
{
TiXmlDocument doc;
if ( !doc.LoadFile(file.ToLocale().c_str()) && doc.ErrorId() == 2)
return false;
return true ;
}
示例10: WriteToFile
bool NativeFileSystem::WriteToFile(const gd::String & filename, const gd::String & content)
{
std::ofstream file( filename.ToLocale().c_str() );
if ( file.is_open() ) {
file << content.ToUTF8();
file.close();
return true;
}
return false;
}
示例11: Run
void HttpServer::Run(gd::String indexDirectory)
{
//Some options ( Last option must be NULL )
std::string indexDirectoryLocale = indexDirectory.ToLocale();
const char *options[] = {"listening_ports", "2828", "document_root", indexDirectoryLocale.c_str(), NULL};
//Setup callbacks, i.e. nothing to do :)
struct mg_callbacks callbacks;
memset(&callbacks, 0, sizeof(callbacks));
ctx = mg_start(&callbacks, NULL, options);
}
示例12: CaptureScreen
void GD_EXTENSION_API CaptureScreen( RuntimeScene & scene, const gd::String & destFileName, const gd::String & destImageName )
{
if ( !scene.renderWindow ) return;
sf::Image capture = scene.renderWindow->capture();
if ( !destFileName.empty() ) capture.saveToFile(destFileName.ToLocale());
if ( !destImageName.empty() && scene.GetImageManager()->HasLoadedSFMLTexture(destImageName) )
{
std::shared_ptr<SFMLTextureWrapper> sfmlTexture = scene.GetImageManager()->GetSFMLTexture(destImageName);
sfmlTexture->image = capture;
sfmlTexture->texture.loadFromImage(sfmlTexture->image); //Do not forget to update the associated texture
}
}
示例13: ShowYesNoMsgBox
/**
* Show a message box with Yes/No buttons
*/
void GD_EXTENSION_API ShowYesNoMsgBox( RuntimeScene & scene, gd::Variable & variable, const gd::String & message, const gd::String & title )
{
sf::Clock timeSpent;
gd::String result;
//Display the box
#if defined(WINDOWS)
if( MessageBoxW(NULL, message.ToWide().c_str(), title.ToWide().c_str(), MB_ICONQUESTION | MB_YESNO) == IDYES)
result = "yes";
else
result = "no";
#endif
#if defined(LINUX) || defined(MACOS)
nw::YesNoMsgBox dialog(title.ToLocale(), message.ToLocale(), result.Raw());
dialog.wait_until_closed();
#endif
scene.GetTimeManager().NotifyPauseWasMade(timeSpent.getElapsedTime().asMicroseconds());//Don't take the time spent in this function in account.
//Update the variable
variable.SetString(result); //Can only be "yes" or "no", no need to encode in UTF8
}
示例14: OpenLibrary
std::shared_ptr<gd::Platform> PlatformLoader::LoadPlatformInManager(gd::String fullpath)
{
std::cout << "Loading platform " << fullpath << "..." << std::endl;
Handle platformHdl = OpenLibrary(fullpath.ToLocale().c_str()); //Use the system locale for filepath
if (platformHdl == NULL)
{
gd::String error = DynamicLibraryLastError();
cout << "Loading of "<< fullpath <<" failed." << endl;
cout << "Error returned : \"" << error << "\"" << endl;
#if defined(GD_IDE_ONLY) && !defined(GD_NO_WX_GUI)
wxString userMsg = _("Platform ") + fullpath +
_(" could not be loaded.\nContact the developer for more information.\n\nDetailed log:\n") + error;
wxMessageBox(userMsg, _("Platform not compatible"), wxOK | wxICON_EXCLAMATION);
#endif
}
else
{
CreatePlatformFunPtr createFunPtr = (CreatePlatformFunPtr)GetSymbol(platformHdl, "CreateGDPlatform");
DestroyPlatformFunPtr destroyFunPtr = (DestroyPlatformFunPtr)GetSymbol(platformHdl, "DestroyGDPlatform");
if ( createFunPtr == NULL || destroyFunPtr == NULL )
{
cout << "Loading of "<< fullpath <<" failed (no valid create/destroy functions)." << endl;
CloseLibrary(platformHdl);
#if defined(GD_IDE_ONLY) && !defined(GD_NO_WX_GUI)
wxString userMsg = _("Platform ")+ fullpath +
_(" could not be loaded.\nContact the developer for more information.\n\nDetailed log:\nNo valid create/destroy functions." );
wxMessageBox(userMsg, _("Platform not compatible"), wxOK | wxICON_EXCLAMATION);
#endif
}
else
{
#if defined(GD_IDE_ONLY) && !defined(GD_NO_WX_GUI)
gd::LocaleManager::Get()->AddCatalog(wxFileName(fullpath).GetName()); //In editor, load catalog associated with extension, if any.
#endif
std::shared_ptr<gd::Platform> platform(createFunPtr(), destroyFunPtr);
std::cout << "Loading of " << fullpath << " done." << std::endl;
gd::PlatformManager::Get()->AddPlatform(platform);
std::cout << "Registration in platform manager of " << fullpath << " done." << std::endl;
return platform;
}
}
return std::shared_ptr<gd::Platform>();
}
示例15: OpenSFMLTextureFromFile
void GD_EXTENSION_API OpenSFMLTextureFromFile( RuntimeScene & scene, const gd::String & fileName, const gd::String & imageName )
{
//Get or create the texture in memory
std::shared_ptr<SFMLTextureWrapper> newTexture;
if ( !scene.GetImageManager()->HasLoadedSFMLTexture(imageName) )
newTexture = std::shared_ptr<SFMLTextureWrapper>(new SFMLTextureWrapper);
else
newTexture = scene.GetImageManager()->GetSFMLTexture(imageName);
//Open the SFML image and the SFML texture
newTexture->image.loadFromFile(fileName.ToLocale());
newTexture->texture.loadFromImage(newTexture->image); //Do not forget to update the associated texture
scene.GetImageManager()->SetSFMLTextureAsPermanentlyLoaded(imageName, newTexture);
}