mirror of
https://github.com/SFML/SFML.git
synced 2024-11-25 04:41:05 +08:00
Use std::filesystem::path
for paths
This commit is contained in:
parent
ddfb7f6cb0
commit
b68482754b
@ -27,6 +27,8 @@
|
|||||||
|
|
||||||
#import "NSString+stdstring.h"
|
#import "NSString+stdstring.h"
|
||||||
|
|
||||||
|
#include <filesystem>
|
||||||
|
|
||||||
// These define are used for converting the color of the NSPopUpButton
|
// These define are used for converting the color of the NSPopUpButton
|
||||||
#define BLUE @"Blue"
|
#define BLUE @"Blue"
|
||||||
#define GREEN @"Green"
|
#define GREEN @"Green"
|
||||||
@ -39,8 +41,8 @@ struct SFMLmainWindow
|
|||||||
{
|
{
|
||||||
SFMLmainWindow(sf::WindowHandle win) : renderWindow(win), text(font), sprite(logo), background(sf::Color::Blue)
|
SFMLmainWindow(sf::WindowHandle win) : renderWindow(win), text(font), sprite(logo), background(sf::Color::Blue)
|
||||||
{
|
{
|
||||||
std::string resPath = [[[NSBundle mainBundle] resourcePath] tostdstring];
|
std::filesystem::path resPath = [[[NSBundle mainBundle] resourcePath] tostdstring];
|
||||||
if (!logo.loadFromFile(resPath + "/logo.png"))
|
if (!logo.loadFromFile(resPath / "logo.png"))
|
||||||
NSLog(@"Couldn't load the logo image");
|
NSLog(@"Couldn't load the logo image");
|
||||||
|
|
||||||
logo.setSmooth(true);
|
logo.setSmooth(true);
|
||||||
@ -54,7 +56,7 @@ struct SFMLmainWindow
|
|||||||
unsigned int wh = renderWindow.getSize().y;
|
unsigned int wh = renderWindow.getSize().y;
|
||||||
sprite.setPosition(sf::Vector2f(ww, wh) / 2.f);
|
sprite.setPosition(sf::Vector2f(ww, wh) / 2.f);
|
||||||
|
|
||||||
if (!font.loadFromFile(resPath + "/tuffy.ttf"))
|
if (!font.loadFromFile(resPath / "tuffy.ttf"))
|
||||||
NSLog(@"Couldn't load the font");
|
NSLog(@"Couldn't load the font");
|
||||||
|
|
||||||
text.setFillColor(sf::Color::White);
|
text.setFillColor(sf::Color::White);
|
||||||
|
@ -502,10 +502,10 @@ public:
|
|||||||
/// \see download
|
/// \see download
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
[[nodiscard]] Response upload(const std::string& localFile,
|
[[nodiscard]] Response upload(const std::filesystem::path& localFile,
|
||||||
const std::string& remotePath,
|
const std::filesystem::path& remotePath,
|
||||||
TransferMode mode = TransferMode::Binary,
|
TransferMode mode = TransferMode::Binary,
|
||||||
bool append = false);
|
bool append = false);
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Send a command to the FTP server
|
/// \brief Send a command to the FTP server
|
||||||
|
@ -322,31 +322,23 @@ Ftp::Response Ftp::download(const std::filesystem::path& remoteFile, const std::
|
|||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
Ftp::Response Ftp::upload(const std::string& localFile, const std::string& remotePath, TransferMode mode, bool append)
|
Ftp::Response Ftp::upload(const std::filesystem::path& localFile,
|
||||||
|
const std::filesystem::path& remotePath,
|
||||||
|
TransferMode mode,
|
||||||
|
bool append)
|
||||||
{
|
{
|
||||||
// Get the contents of the file to send
|
// Get the contents of the file to send
|
||||||
std::ifstream file(localFile, std::ios_base::binary);
|
std::ifstream file(localFile, std::ios_base::binary);
|
||||||
if (!file)
|
if (!file)
|
||||||
return Response(Response::Status::InvalidFile);
|
return Response(Response::Status::InvalidFile);
|
||||||
|
|
||||||
// Extract the filename from the file path
|
|
||||||
std::string filename = localFile;
|
|
||||||
const std::string::size_type pos = filename.find_last_of("/\\");
|
|
||||||
if (pos != std::string::npos)
|
|
||||||
filename = filename.substr(pos + 1);
|
|
||||||
|
|
||||||
// Make sure the destination path ends with a slash
|
|
||||||
std::string path = remotePath;
|
|
||||||
if (!path.empty() && (path[path.size() - 1] != '\\') && (path[path.size() - 1] != '/'))
|
|
||||||
path += "/";
|
|
||||||
|
|
||||||
// Open a data channel using the given transfer mode
|
// Open a data channel using the given transfer mode
|
||||||
DataChannel data(*this);
|
DataChannel data(*this);
|
||||||
Response response = data.open(mode);
|
Response response = data.open(mode);
|
||||||
if (response.isOk())
|
if (response.isOk())
|
||||||
{
|
{
|
||||||
// Tell the server to start the transfer
|
// Tell the server to start the transfer
|
||||||
response = sendCommand(append ? "APPE" : "STOR", path + filename);
|
response = sendCommand(append ? "APPE" : "STOR", (remotePath / localFile.filename()).string());
|
||||||
if (response.isOk())
|
if (response.isOk())
|
||||||
{
|
{
|
||||||
// Send the file data
|
// Send the file data
|
||||||
|
@ -12,7 +12,7 @@
|
|||||||
|
|
||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
std::string getTemporaryFilePath()
|
std::filesystem::path getTemporaryFilePath()
|
||||||
{
|
{
|
||||||
static int counter = 0;
|
static int counter = 0;
|
||||||
|
|
||||||
@ -24,13 +24,13 @@ std::string getTemporaryFilePath()
|
|||||||
result /= std::filesystem::temp_directory_path();
|
result /= std::filesystem::temp_directory_path();
|
||||||
result /= oss.str();
|
result /= oss.str();
|
||||||
|
|
||||||
return result.string();
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
class TemporaryFile
|
class TemporaryFile
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
std::string m_path;
|
std::filesystem::path m_path;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
// Create a temporary file with a randomly generated path, containing 'contents'.
|
// Create a temporary file with a randomly generated path, containing 'contents'.
|
||||||
@ -56,7 +56,7 @@ public:
|
|||||||
TemporaryFile& operator=(const TemporaryFile&) = delete;
|
TemporaryFile& operator=(const TemporaryFile&) = delete;
|
||||||
|
|
||||||
// Return the randomly generated path.
|
// Return the randomly generated path.
|
||||||
const std::string& getPath() const
|
const std::filesystem::path& getPath() const
|
||||||
{
|
{
|
||||||
return m_path;
|
return m_path;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user