| 1 | /*************************************************************************** |
| 2 | * fheroes2: https://github.com/ihhub/fheroes2 * |
| 3 | * Copyright (C) 2019 - 2025 * |
| 4 | * * |
| 5 | * Free Heroes2 Engine: http://sourceforge.net/projects/fheroes2 * |
| 6 | * Copyright (C) 2013 by Andrey Afletdinov <[email protected]> * |
| 7 | * * |
| 8 | * This program is free software; you can redistribute it and/or modify * |
| 9 | * it under the terms of the GNU General Public License as published by * |
| 10 | * the Free Software Foundation; either version 2 of the License, or * |
| 11 | * (at your option) any later version. * |
| 12 | * * |
| 13 | * This program is distributed in the hope that it will be useful, * |
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * |
| 16 | * GNU General Public License for more details. * |
| 17 | * * |
| 18 | * You should have received a copy of the GNU General Public License * |
| 19 | * along with this program; if not, write to the * |
| 20 | * Free Software Foundation, Inc., * |
| 21 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * |
| 22 | ***************************************************************************/ |
| 23 | |
| 24 | #pragma once |
| 25 | |
| 26 | #include <ctime> |
| 27 | #include <filesystem> |
| 28 | #include <string> |
| 29 | #include <string_view> |
| 30 | #include <vector> |
| 31 | |
| 32 | namespace System |
| 33 | { |
| 34 | bool isHandheldDevice(); |
| 35 | |
| 36 | // Returns true if the target platform supports touch input, otherwise returns false. |
| 37 | bool isTouchInputAvailable(); |
| 38 | |
| 39 | bool isVirtualKeyboardSupported(); |
| 40 | |
| 41 | // Returns true if target platform supports shell-level globbing (Unix-like platforms with POSIX-compatible shells). |
| 42 | // Otherwise returns false, which means that app need to resolve wildcard patterns itself (for example, on Windows). |
| 43 | bool isShellLevelGlobbingSupported(); |
| 44 | |
| 45 | bool MakeDirectory( const std::string_view path ); |
| 46 | bool Unlink( const std::string_view path ); |
| 47 | |
| 48 | std::string concatPath( const std::string_view left, const std::string_view right ); |
| 49 | |
| 50 | void appendOSSpecificDirectories( std::vector<std::string> & directories ); |
| 51 | |
| 52 | // Returns the path to the app settings directory (usually some user-specific directory). An empty string can be returned, |
| 53 | // which should be considered as the current directory. |
| 54 | std::string GetConfigDirectory( const std::string_view appName ); |
| 55 | |
| 56 | // Returns the path to the app data directory (usually some user-specific directory). An empty string can be returned, |
| 57 | // which should be considered as the current directory. |
| 58 | std::string GetDataDirectory( const std::string_view appName ); |
| 59 | |
| 60 | std::string GetParentDirectory( std::string_view path ); |
| 61 | std::string GetFileName( std::string_view path ); |
| 62 | std::string GetStem( const std::string_view path ); |
| 63 | |
| 64 | bool IsFile( const std::string_view path ); |
| 65 | bool IsDirectory( const std::string_view path ); |
| 66 | |
| 67 | bool GetCaseInsensitivePath( const std::string_view path, std::string & correctedPath ); |
| 68 | |
| 69 | // Resolves the wildcard pattern 'glob' and appends matching paths to 'fileNames'. Supported wildcards are '?' and '*'. |
| 70 | // These wildcards are resolved only if they are in the last element of the path. For example, they will be resolved |
| 71 | // in the case of the 'foo/b*r?' pattern, but they will be ignored (used as is) in the case of '*/bar' pattern. If there |
| 72 | // are no files matching the pattern, it will be appended to the 'fileNames' as is. |
| 73 | void globFiles( const std::string_view glob, std::vector<std::string> & fileNames ); |
| 74 | |
| 75 | // Converts the given string from local encoding to UTF-8 encoding (used by SDL). It is used mainly on Windows, because on |
| 76 | // Windows this app works with ANSI code page (CP_ACP). On all other systems, it is currently assumed that UTF-8 encoding |
| 77 | // is used, and the original string is simply returned unchanged. |
| 78 | std::string encLocalToUTF8( const std::string_view str ); |
| 79 | |
| 80 | // Converts the given string from UTF-8 encoding (used by SDL) to local encoding. It is used mainly on Windows, because on |
| 81 | // Windows this app works with ANSI code page (CP_ACP). On all other systems, it is currently assumed that UTF-8 encoding |
| 82 | // is used, and the original string is simply returned unchanged. |
| 83 | std::string encUTF8ToLocal( const std::string_view str ); |
| 84 | |
| 85 | // Performs a safe conversion of an std::filesystem::path instance to a string. See the implementation for details. |
| 86 | std::string fsPathToString( const std::filesystem::path & path ); |
| 87 | |
| 88 | tm GetTM( const time_t time ); |
| 89 | } |