35 #include <sys/types.h>
40 #include <OgrePlatform.h>
41 #include <OgreFileSystem.h>
53 std::wstring MSW_Utf8ToWchar(
const char* path)
55 if( path ==
nullptr || path[0] == 0 )
57 RoR::Log(
"[RoR] Internal error: MSW_Utf8ToWchar() received empty input");
58 return std::wstring();
61 int size_needed = MultiByteToWideChar(CP_UTF8, 0, &path[0], -1, NULL, 0);
62 std::wstring out_wstr( size_needed, 0 );
63 int raw_result = MultiByteToWideChar(CP_UTF8, 0, &path[0], -1, &out_wstr[0], size_needed);
66 RoR::LogFormat(
"[RoR] Internal error: MSW_Utf8ToWchar() could not convert UTF-8 to UTF-16; MultiByteToWideChar() returned %d", raw_result);
67 return std::wstring();
72 DWORD MSW_GetFileAttrs(
const char* path)
74 if (path ==
nullptr || path[0] == 0)
76 return INVALID_FILE_ATTRIBUTES;
79 std::wstring wpath = MSW_Utf8ToWchar(path);
82 return GetFileAttributesW(wpath.c_str());
85 std::string MSW_WcharToUtf8(
const wchar_t* wstr)
87 if( wstr ==
nullptr || wstr[0] == 0 )
89 RoR::Log(
"[RoR] Internal error: MSW_WcharToUtf8() received empty input");
93 const int dst_size = WideCharToMultiByte(CP_UTF8, 0, &wstr[0], -1,
nullptr, 0,
nullptr,
nullptr);
94 std::string dst(dst_size, 0);
95 int raw_result = WideCharToMultiByte(CP_UTF8, 0, &wstr[0], -1, &dst[0], dst_size,
nullptr,
nullptr);
98 RoR::LogFormat(
"[RoR] Internal error: MSW_WcharToUtf8() could not convert UTF-16 to UTF-8; WideCharToMultiByte() returned %d", raw_result);
106 DWORD file_attrs = MSW_GetFileAttrs(path);
107 return (file_attrs != INVALID_FILE_ATTRIBUTES && ! (file_attrs & FILE_ATTRIBUTE_DIRECTORY));
112 DWORD file_attrs = MSW_GetFileAttrs(path);
113 return (file_attrs != INVALID_FILE_ATTRIBUTES && (file_attrs & FILE_ATTRIBUTE_DIRECTORY));
120 std::wstring wpath = MSW_Utf8ToWchar(path);
121 CreateDirectoryW(wpath.c_str(),
nullptr);
127 std::wstring out_wstr(MAX_PATH, 0);
128 HRESULT hres = SHGetFolderPathW(
nullptr, CSIDL_PERSONAL,
nullptr, SHGFP_TYPE_CURRENT, &out_wstr[0]);
131 RoR::LogFormat(
"[RoR] Internal error: GetUserHomeDirectory() failed; SHGetFolderPathW() returned %ld",
static_cast<long>(hres));
132 return std::string();
135 return MSW_WcharToUtf8(out_wstr.c_str());
140 const int BUF_SIZE = 500;
141 std::wstring out_wstr(BUF_SIZE, 0);
142 DWORD res = GetModuleFileNameW(
nullptr, &out_wstr[0], BUF_SIZE);
145 RoR::LogFormat(
"[RoR] Internal error: GetExecutablePath() failed; GetModuleFileNameW() returned %d",
static_cast<int>(res));
146 return std::string();
149 return MSW_WcharToUtf8(out_wstr.c_str());
154 ::ShellExecute(0, 0, url.c_str(), 0, 0 , SW_SHOW );
166 return (stat(path, &st) == 0);
172 return (stat(path, &st) == 0);
177 mkdir(path, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH);
182 return getenv(
"HOME");
187 const int BUF_SIZE = 500;
188 std::string buf_str(BUF_SIZE, 0);
190 if (readlink(
"/proc/self/exe", &buf_str[0], BUF_SIZE-1) == -1)
192 RoR::LogFormat(
"[RoR] Internal error: GetExecutablePath() failed; readlink() sets errno to %d",
static_cast<int>(errno));
193 return std::string();
196 return std::move(buf_str);
201 std::string buf =
"xdg-open " + url;
202 ::system(buf.c_str());
211 const char* start = src_buff;
212 size_t count = strlen(src_buff);
216 if (count == 0) {
return std::string(); }
217 if (start[count - 1] !=
PATH_SLASH) {
break; }
223 if (count == 0) {
return std::string(); }
230 if (count == 0) {
return std::string(); }
231 if (start[count - 1] !=
PATH_SLASH) {
break; }
235 return std::string(start, count);
240 Ogre::FileSystemArchiveFactory factory;
241 Ogre::Archive* fs_archive = factory.createInstance(path,
true);
242 std::time_t time = fs_archive->getModifiedTime(path);
243 factory.destroyInstance(fs_archive);