1
// $Id: system.hpp 3340 2007-10-27 07:08:51Z grumbel $
3
// Pingus - A free Lemmings clone
4
// Copyright (C) 1999 Ingo Ruhnke <grumbel@gmx.de>
6
// This program is free software; you can redistribute it and/or
7
// modify it under the terms of the GNU General Public License
8
// as published by the Free Software Foundation; either version 2
9
// of the License, or (at your option) any later version.
11
// This program is distributed in the hope that it will be useful,
12
// but WITHOUT ANY WARRANTY; without even the implied warranty of
13
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
// GNU General Public License for more details.
16
// You should have received a copy of the GNU General Public License
17
// along with this program; if not, write to the Free Software
18
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
21
#ifndef HEADER_PINGUS_SYSTEM_HXX
22
#define HEADER_PINGUS_SYSTEM_HXX
31
/** A wrapper class around some system dependend functions (mostly
37
static std::string default_email;
38
static std::string default_username;
41
enum FileType { DE_DIRECTORY, DE_FILE };
48
DirectoryEntry(const std::string&, FileType t = DE_FILE);
52
typedef std::vector<DirectoryEntry> Directory;
53
typedef Directory::iterator DirectoryIter;
56
static Directory opendir(const std::string& pathname, const std::string& pattern = "*");
58
/** Check if a file is avaiblable (no checking for permissens is currently performed)
59
@param filename The name of the file
60
@return True, if the file exist, false otherwise */
61
static bool exist(std::string filename);
63
/** Creates directory if it does not already exist.
64
@param dir The name of the directory */
65
static void create_dir(std::string dir);
67
/** Change into the directory named dir, on error throw an PingusError */
68
static void change_dir (std::string dir);
70
/** Check if all needed directories are available, if not then create
72
static void init_directories();
74
/** Strips directory from filenames
75
@param filename The complete filename */
76
static std::string basename(std::string filename);
78
/** Strips basename from pathnames (see dirname(3))
79
@param filename The complete filename */
80
static std::string dirname(std::string filename);
82
/** Return the extension of the given filename:
84
System::extension ("foobar.jpg") => "jpg"
85
System::extension ("/bla/bla.blub/") => ""
86
System::extension ("/bla/blabl") => ""
88
static std::string extension (std::string filename);
89
static std::string cut_ext (std::string filename);
91
/** Returns the directory where Pingus can store its user specific
92
state and config data (savegames, config files, demos, etc.) */
93
static std::string get_statdir();
95
/** Returns the directory where Pingus can store things that needs
96
to be cached, for example thumbnails */
97
static std::string get_cachedir();
99
/** Returns the directory were Pingus can store its system wide
100
variable game data (highscores, cache images, ...) */
101
static std::string get_vardir();
103
/** Asks different variables to check were the directory for
104
temporary files is located
105
@return The location of the tmp directory */
106
static std::string get_tmpdir();
108
/** Returns the Username how the current user or an empty string */
109
static std::string get_username();
111
/** Returns the EMail of the user or an empty string */
112
static std::string get_email();
114
/** Get the currently country code, in a two letter ISO 639 syntax */
115
static std::string get_language();
117
/** Return the modification time of a file */
118
static uint64_t get_mtime(const std::string& filename);
120
/** Choose the correct translation out of the map, if there is none
121
present, fall back to the default language */
122
static std::string translate(const std::map<std::string, std::string>& strs);
124
static std::string translate(const std::string& str);
126
/** Translate to 'en' */
127
static std::string translate_default(const std::map<std::string, std::string>& strs);
129
/** Removes all .., double slashes and such from a pathname */
130
static std::string realpath(const std::string& pathname);
132
/** Read a file and generate a checksum and return it. The checksum
133
generation is very primitiv and should probably be replaced by CRC
135
static std::string checksum (std::string filename);
138
System (const System&);
139
System& operator= (const System&);