SuperTuxKart
Loading...
Searching...
No Matches
file_utils.hpp
1// SuperTuxKart - a fun racing game with go-kart
2// Copyright (C) 2019 SuperTuxKart-Team
3//
4// This program is free software; you can redistribute it and/or
5// modify it under the terms of the GNU General Public License
6// as published by the Free Software Foundation; either version 3
7// of the License, or (at your option) any later version.
8//
9// This program is distributed in the hope that it will be useful,
10// but WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12// GNU General Public License for more details.
13//
14// You should have received a copy of the GNU General Public License
15// along with this program; if not, write to the Free Software
16// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17
18#ifndef HEADER_FILE_UTILS_HPP
19#define HEADER_FILE_UTILS_HPP
20
21#include <stdio.h>
22#include <string>
23#include <sys/stat.h>
24#include "irrString.h"
25
26namespace FileUtils
27{
28 namespace Private
29 {
30 std::string getShortPath(const std::string& u8_path);
31 std::string getShortPathW(const irr::core::stringw& w_path);
32 std::string getShortPathWriting(const std::string& u8_path);
33 }
34 // ------------------------------------------------------------------------
35 FILE* fopenU8Path(const std::string& u8_path, const char* mode);
36 // ------------------------------------------------------------------------
37 int statU8Path(const std::string& u8_path, struct stat *buf);
38 // ------------------------------------------------------------------------
39 int renameU8Path(const std::string& u8_path_old,
40 const std::string& u8_path_new);
41 // ------------------------------------------------------------------------
42 /* Return a path which can be opened for writing in all systems, as long as
43 * u8_path is unicode encoded. */
44 inline std::string getPortableWritingPath(const std::string& u8_path)
45 {
46#if defined(WIN32)
47 return Private::getShortPathWriting(u8_path);
48#else
49 return u8_path;
50#endif
51 }
52 // ------------------------------------------------------------------------
53 /* Return a path which can be opened in all systems, as long as u8_path
54 * is unicode encoded. */
55 inline std::string getPortableReadingPath(const std::string& u8_path)
56 {
57#if defined(WIN32)
58 return Private::getShortPath(u8_path);
59#else
60 return u8_path;
61#endif
62 }
63} // namespace FileUtils
64
65#endif