xtd 0.2.0
Loading...
Searching...
No Matches
environment.h
Go to the documentation of this file.
1
4#pragma once
7#include "io/directory.h"
8#include "io/path.h"
10#include "as.h"
12#include "compiler.h"
13#include "core_export.h"
14#include "cpp_language.h"
15#include "enum.h"
17#include "event.h"
18#include "exit_status.h"
19#include "guid.h"
20#include "operating_system.h"
21#include "platform_id.h"
22#include "processor.h"
25#include "static.h"
26#include "target_id.h"
27#include "target_type.h"
28#include "toolkit.h"
29#include "string.h"
30#include "version.h"
31#define __XTD_CORE_INTERNAL__
36#undef __XTD_CORE_INTERNAL__
37#include <map>
38#include <cstdlib>
39#include <vector>
40
42// The following constant is defined in the file xtd_command.cmake.
43// If the target project is not built with cmake, the following constant must be defined by the build tool like this if the cmake_install_prefix is not modified; otherwise the cmake_install_prefix value:
44// | Constant | Windows Value | macOS | linux |
45// | ----------------- | ---------------------------- |--------------|--------------|
46// | __XTD_ROOT_PATH__ | "C:\Program Files (x86)\xtd" | "/usr/local" | "/usr/local" |
47// Remarks : If __XTD_ROOT_PATH__ is empty the environment variable XTD_ROOT_PATH is used. And if the environment variable XTD_ROOT_PATH is empty too the directory componant of __FILE__ macro is used.
48
49#if !defined(__XTD_ROOT_PATH__)
50# define __XTD_ROOT_PATH__ ""
51#endif
53
55namespace xtd {
67 class signal_catcher;
68 public:
144 enum class special_folder {
146 desktop = 0,
148 programs = 2,
150 my_documents = 5,
152 personal = 5,
154 favorites = 6,
156 startup = 7,
158 recent = 8,
160 send_to = 9,
162 start_menu = 11,
164 my_music = 13,
166 my_videos = 14,
168 desktop_directory = 16,
170 my_computer = 17,
172 network_shortcuts = 19,
174 fonts = 20,
176 templates = 21,
178 common_start_menu = 22,
180 common_programs = 23,
182 common_startup = 24,
184 common_desktop_directory = 25,
186 application_data = 26,
188 printer_shortcuts = 27,
190 local_application_data = 28,
192 internet_cache = 32,
194 cookies = 33,
196 history = 34,
198 common_application_data = 35,
200 windows = 36,
202 system = 37,
204 program_files = 38,
206 my_pictures = 39,
208 user_profile = 40,
210 system_x86 = 41,
212 program_files_x86 = 42,
214 common_program_files = 43,
216 common_program_files_x86 = 44,
218 common_templates = 45,
220 common_documents = 46,
222 common_admin_tools = 47,
224 admin_tools = 48,
226 common_music = 53,
228 common_pictures = 54,
230 common_videos = 55,
232 resources = 56,
234 localized_resources = 57,
236 common_oem_links = 58,
238 cd_burning = 59,
240 home = 64,
242 application_resources = 999,
244 xtd_install = 1000,
246 xtd_locale = 1001,
248 xtd_reference_guide = 1002,
250 xtd_themes = 1003,
252 xtd_include = 1004,
254 xtd_libraries = 1005,
256 xtd_resources = 1006,
258 xtd_console_include = 1007,
260 xtd_console_libraries = 1008,
262 xtd_drawing_include = 1009,
264 xtd_drawing_libraries = 1010,
266 xtd_drawing_resources = 1011,
268 xtd_forms_include = 1012,
270 xtd_forms_libraries = 1013,
272 xtd_forms_resources = 1014,
274 xtd_tunit_include = 1015,
276 xtd_tunit_libraries = 1016,
277 };
278
283 none = 0,
285 do_not_verify = 16384,
287 create = 32768
288 };
289
291 class xtd_library final : public xtd::object {
292 public:
294 xtd_library() = default;
295 xtd_library(const xtd_library&) = default;
296 xtd_library& operator =(const xtd_library&) = default;
298
300
304 const xtd::string& include_path() const noexcept;
305
308 const xtd::string& library_path() const noexcept;
309
312 const xtd::string& name() const noexcept;
313
316 const xtd::string& resources_path() const noexcept;
317
320 const xtd::version& version() const noexcept;
322
324
326 xtd::string to_string() const noexcept override;
328
329 private:
330 friend class environment;
331 xtd_library(const xtd::string& name, const xtd::version& version, const xtd::string& include_path, const xtd::string& library_path, const xtd::string& resources_path);
332 xtd::string name_;
333 xtd::version version_;
334 xtd::string include_path_;
335 xtd::string library_path_;
336 xtd::string resources_path_;
337 };
338
341
343
350 static xtd::string command_line() noexcept;
351
354 static xtd::compiler compiler_version() noexcept {
355 static auto compiler_id = __compiler_id;
356 static auto version = __compiler_version;
357 static auto build_type = __build_type;
358 static xtd::compiler compiler {compiler_id, version, build_type, sizeof(size_t) == 8};
359 return compiler;
360 }
361
364 static xtd::cpp_language cpp_version() noexcept {
365 static auto cpp_language = __cpp_language;
366 return cpp_language;
367 }
368
374
381 static void current_directory(const xtd::string& directory_name);
382
386
389 static intptr current_thread_id() noexcept;
390
396 static int32 exit_code() noexcept;
402 static void exit_code(int32 value) noexcept;
403
407 static bool has_shutdown_started();
408
411 static bool is_64_bit_operating_system() noexcept;
412
415 static bool is_64_bit_process() noexcept;
416
420 static std::locale locale() noexcept;
421
425 static xtd::string machine_name();
426
429 static xtd::string new_line() noexcept;
430
434 template <typename char_t, class traits_t>
435 static std::basic_ostream<char_t, traits_t>& new_line(std::basic_ostream<char_t, traits_t>& os) {
436 for (auto c : new_line())
437 os.put(os.widen(c));
438 return os;
439 }
440
444
447 static uint32 processor_count();
448
451 static xtd::processor processor_information();
452
455 static xtd::string stack_trace();
456
460 static xtd::string system_directory();
461
464 static size_t system_page_size();
465
468 static xtd::target_type target_type() noexcept {
469 return xtd::target_type(as<xtd::target_id>(__XTD_CURRENT_TARGET_ID__));
470 }
471
474 static std::chrono::milliseconds tick_count();
475
479
480
483 static bool user_administrator();
484
488
494 static bool user_interactive();
495
499
502 static xtd::version version() noexcept;
503
510 static int64 working_set();
511
514 static const xtd_library_collection& xtd_libraries() noexcept;
516
518
526
531
533
536 static void abort();
537
540 [[noreturn]] static void exit();
544 [[noreturn]] static void exit(int32 exit_code);
547 [[noreturn]] static void exit(xtd::exit_status exit_status);
548
553 static xtd::string expand_environment_variables(const xtd::string& name);
554
570 static xtd::collections::specialized::string_collection get_command_line_args();
571
578 static xtd::string get_environment_variable(const xtd::string& variable);
579
588 static xtd::string get_environment_variable(const xtd::string& variable, environment_variable_target target);
589
593 static std::map<std::string, std::string>& get_environment_variables();
594
601 static std::map<std::string, std::string>& get_environment_variables(environment_variable_target target);
602
607 static xtd::string get_folder_path(environment::special_folder folder);
608
614 static xtd::string get_folder_path(environment::special_folder folder, environment::special_folder_option option);
615
618 static xtd::collections::specialized::string_collection get_logical_drives();
619
622 [[noreturn]] static void quick_exit() noexcept;
626 [[noreturn]] static void quick_exit(int32 exit_code) noexcept;
629 [[noreturn]] static void quick_exit(xtd::exit_status exit_status) noexcept;
630
633 static void raise(xtd::signal signal);
634
641 static void set_environment_variable(const xtd::string& variable, const xtd::string& value);
642
651 static void set_environment_variable(const xtd::string& variable, const xtd::string& value, environment_variable_target target);
653
655 static void __signal_catcher_check__();
657
658 private:
659 static void on_cancel_signal(signal_cancel_event_args& e);
660 static void on_program_exit(const program_exit_event_args& e);
661
662 inline static bool is_gui_application() noexcept {return target_type().is_guid_application();}
663 inline static const string xtd_root_path() {return xtd::io::path::get_full_path(string::is_empty(__XTD_ROOT_PATH__) ? (string::is_empty(get_environment_variable("XTD_ROOT_PATH")) ? io::path::get_full_path(io::path::combine(io::path::get_directory_name(__FILE__), "..", "..")) : get_environment_variable("XTD_ROOT_PATH")) : __XTD_ROOT_PATH__);}
664 static signal_catcher signal_catcher_;
665 };
666}
667
670 explicit operator auto() const noexcept {return xtd::enum_collection<xtd::environment::special_folder> {{xtd::environment::special_folder::desktop, "desktop"}, {xtd::environment::special_folder::programs, "programs"}, {xtd::environment::special_folder::my_documents, "my_documents"}, {xtd::environment::special_folder::favorites, "favorites"}, {xtd::environment::special_folder::startup, "startup"}, {xtd::environment::special_folder::recent, "recent"}, {xtd::environment::special_folder::send_to, "send_to"}, {xtd::environment::special_folder::start_menu, "start_menu"}, {xtd::environment::special_folder::my_music, "my_music"}, {xtd::environment::special_folder::my_videos, "my_videos"}, {xtd::environment::special_folder::desktop_directory, "desktop_directory"}, {xtd::environment::special_folder::my_computer, "my_computer"}, {xtd::environment::special_folder::network_shortcuts, "network_shortcuts"}, {xtd::environment::special_folder::fonts, "fonts"}, {xtd::environment::special_folder::templates, "templates"}, {xtd::environment::special_folder::common_start_menu, "common_start_menu"}, {xtd::environment::special_folder::common_programs, "common_programs"}, {xtd::environment::special_folder::common_startup, "common_startup"}, {xtd::environment::special_folder::common_desktop_directory, "common_desktop_directory"}, {xtd::environment::special_folder::application_data, "application_data"}, {xtd::environment::special_folder::printer_shortcuts, "printer_shortcuts"}, {xtd::environment::special_folder::local_application_data, "local_application_data"}, {xtd::environment::special_folder::internet_cache, "internet_cache"}, {xtd::environment::special_folder::cookies, "cookies"}, {xtd::environment::special_folder::history, "history"}, {xtd::environment::special_folder::common_application_data, "common_application_data"}, {xtd::environment::special_folder::windows, "windows"}, {xtd::environment::special_folder::system, "system"}, {xtd::environment::special_folder::program_files, "program_files"}, {xtd::environment::special_folder::my_pictures, "my_pictures"}, {xtd::environment::special_folder::user_profile, "user_profile"}, {xtd::environment::special_folder::system_x86, "system_x86"}, {xtd::environment::special_folder::program_files_x86, "program_files_x86"}, {xtd::environment::special_folder::common_program_files, "common_program_files"}, {xtd::environment::special_folder::common_program_files_x86, "common_program_files_x86"}, {xtd::environment::special_folder::common_templates, "common_templates"}, {xtd::environment::special_folder::common_documents, "common_documents"}, {xtd::environment::special_folder::common_admin_tools, "common_admin_tools"}, {xtd::environment::special_folder::admin_tools, "admin_tools"}, {xtd::environment::special_folder::common_music, "common_music"}, {xtd::environment::special_folder::common_pictures, "common_pictures"}, {xtd::environment::special_folder::common_videos, "common_videos"}, {xtd::environment::special_folder::resources, "resources"}, {xtd::environment::special_folder::localized_resources, "localized_resources"}, {xtd::environment::special_folder::common_oem_links, "common_oem_links"}, {xtd::environment::special_folder::cd_burning, "cd_burning"}, {xtd::environment::special_folder::home, "home"}, {xtd::environment::special_folder::application_resources, "application_resources"}, {xtd::environment::special_folder::xtd_install, "xtd_install"}, {xtd::environment::special_folder::xtd_locale, "xtd_locale"}, {xtd::environment::special_folder::xtd_reference_guide, "xtd_reference_guide"}, {xtd::environment::special_folder::xtd_themes, "xtd_themes"}, {xtd::environment::special_folder::xtd_include, "xtd_include"}, {xtd::environment::special_folder::xtd_libraries, "xtd_libraries"}, {xtd::environment::special_folder::xtd_resources, "xtd_resources"}, {xtd::environment::special_folder::xtd_console_include, "xtd_console_include"}, {xtd::environment::special_folder::xtd_console_libraries, "xtd_console_libraries"}, {xtd::environment::special_folder::xtd_drawing_include, "xtd_drawing_include"}, {xtd::environment::special_folder::xtd_drawing_libraries, "xtd_drawing_libraries"}, {xtd::environment::special_folder::xtd_drawing_resources, "xtd_drawing_resources"}, {xtd::environment::special_folder::xtd_forms_include, "xtd_forms_include"}, {xtd::environment::special_folder::xtd_forms_libraries, "xtd_forms_libraries"}, {xtd::environment::special_folder::xtd_forms_resources, "xtd_forms_resources"}, {xtd::environment::special_folder::xtd_tunit_include, "xtd_tunit_include"}, {xtd::environment::special_folder::xtd_tunit_libraries, "xtd_tunit_libraries"}};}
671};
672
675};
Contains __build_type definition.
Contains __compiler_id definition.
Contains __compiler_version definition.
Contains __cpp_language definition.
Contains xtd::argument_exception exception.
Contains xtd::as method.
Contains availability versions.
Represents text as a sequence of character units.
Definition basic_string.h:79
Represents information about c++ libraries, such as the version and standard identifier....
Definition compiler.h:27
Represents information about c++ libraries, such as the version and language identifier....
Definition cpp_language.h:26
Represents a xtd library that contains name, version and paths.
Definition environment.h:291
const xtd::string & include_path() const noexcept
Gets The inlcude path of the library.
The environment class.
Definition environment.h:66
static std::chrono::milliseconds tick_count()
Gets the number of milliseconds elapsed since the system started.
special_folder
Specifies enumerated constants used to retrieve directory paths to system special folders.
Definition environment.h:144
@ common_startup
The file system directory that contains the programs that appear in the Startup folder for all users....
@ xtd_locale
The xtd locale folder.
@ printer_shortcuts
The file system directory that contains the link objects that can exist in the Printers virtual folde...
@ windows
The Windows directory or SYSROOT. This corresponds to the windir% or SYSTEMROOT% environment variable...
@ home
The file system directory that contains home folder.
@ xtd_drawing_libraries
The xtd::drawing libraries folder.
@ local_application_data
The directory that serves as a common repository for application-specific data that is used by the cu...
@ my_computer
The My Computer folder. The MyComputer constant always yields the empty string ("") because no path i...
@ user_profile
The user's profile folder. Applications should not create files or folders at this level; they should...
@ xtd_console_libraries
The xtd::console libraries folder.
@ common_application_data
The directory that serves as a common repository for application-specific data that is used by all us...
@ xtd_forms_resources
The xtd::forms resources folder.
@ xtd_forms_libraries
The xtd::forms libraries folder.
@ xtd_reference_guide
The xtd reference guide folder.
@ localized_resources
The file system directory that contains localized resource data.
@ common_program_files
The directory for components that are shared across applications.To get the x86 common program files ...
@ program_files
The program files directory.On a non-x86 system, passing ProgramFiles to the GetFolderPath method ret...
@ history
The directory that serves as a common repository for Internet history items.
@ xtd_console_include
The xtd::console include folder.
@ xtd_resources
The xtd resources folder.
@ common_videos
The file system directory that serves as a repository for video files common to all users.
@ common_admin_tools
The file system directory that contains administrative tools for all users of the computer.
@ programs
The directory that contains the user's program groups.
@ system
The System directory.
@ resources
The file system directory that contains resource data.
@ cookies
The directory that serves as a common repository for Internet cookies.
@ admin_tools
The file system directory that is used to store administrative tools for an individual user....
@ xtd_tunit_libraries
The xtd::tunit libraries folder.
@ common_desktop_directory
The file system directory that contains files and folders that appear on the desktop for all users....
@ common_start_menu
The file system directory that contains the programs and folders that appear on the Start menu for al...
@ xtd_drawing_include
The xtd::drawing include folder.
@ common_pictures
The file system directory that serves as a repository for image files common to all users.
@ my_music
The My Music folder.
@ desktop_directory
The directory used to physically store file objects on the desktop. Do not confuse this directory wit...
@ common_programs
A folder for components that are shared across applications. This special folder is valid only for Wi...
@ xtd_tunit_include
The xtd::tunit include folder.
@ xtd_include
The xtd inlude folder.
@ recent
The directory that contains the user's most recently used documents.
@ common_music
The file system directory that serves as a repository for music files common to all users.
@ my_pictures
The My Pictures folder.
@ fonts
A virtual folder that contains fonts.
@ xtd_install
The installation folder of xtd.
@ system_x86
The Windows System folder.
@ start_menu
The directory that contains the Start menu items.
@ my_documents
The My Documents folder. This member is equivalent to Personal.
@ xtd_forms_include
The xtd::forms include folder.
@ common_program_files_x86
The Program Files folder.
@ favorites
The directory that serves as a common repository for the user's favorite items.
@ desktop
The logical Desktop rather than the physical file system location.
@ network_shortcuts
A file system directory that contains the link objects that may exist in the My Network Places virtua...
@ internet_cache
The directory that serves as a common repository for temporary Internet files.
@ common_templates
The file system directory that contains the templates that are available to all users....
@ application_resources
The application resources folder.
@ send_to
The directory that contains the Send To menu items.
@ xtd_drawing_resources
The xtd::drawing resources folder.
@ application_data
The directory that serves as a common repository for application-specific data for the current roamin...
@ program_files_x86
The Program Files folder On an x86 system, passing the ProgramFilesX86 member to the Environment....
@ cd_burning
The file system directory that acts as a staging area for files waiting to be written to a CD.
@ startup
The directory that corresponds to the user's Startup program group. The system starts these programs ...
@ xtd_themes
The xtd themes folder.
@ common_oem_links
This value is recognized in Windows Vista for backward compatibility, but the special folder itself i...
@ my_videos
The file system directory that serves as a repository for videos that belong to a user.
@ common_documents
The file system directory that contains documents that are common to all users. This special folder i...
@ xtd_libraries
The xtd libraries folder.
@ templates
The directory that serves as a common repository for document templates.
static bool user_administrator()
Gets a value indicating whether the current user is an administrator.
static void current_directory(const xtd::string &directory_name)
Sets the fully qualified path of the current working directory.
static xtd::cpp_language cpp_version() noexcept
Gets an xtd::cpp_language object that contains the current c++ standard identifier and version number...
Definition environment.h:364
static int32 current_managed_thread_id() noexcept
Gets a unique identifier for the current managed thread.
static xtd::operating_system os_version() noexcept
Gets an xtd::operating_system object that contains the current platform identifier and version number...
static xtd::string user_name()
Gets the user name of the person who is currently logged on to the operating system.
special_folder_option
Specifies options to use for getting the path to a special folder.
Definition environment.h:281
@ none
The path to the folder is verified. If the folder exists, the path is returned. If the folder does no...
@ create
The path to the folder is created if it does not already exist.
@ do_not_verify
The path to the folder is returned without verifying whether the path exists. If the folder is locate...
static xtd::version version() noexcept
Gets a version consisting of the major, minor, build, and revision numbers of the xtd framework.
std::vector< xtd_library > xtd_library_collection
Represents a xtd libraries collection.
Definition environment.h:340
static xtd::string user_domain_name()
Gets the network domain name associated with the current user.
static xtd::string current_directory()
Gets the fully qualified path of the current working directory.
static bool user_interactive()
Gets a value indicating whether the current process is running in user interactive mode.
static xtd::toolkit toolkit_version()
Gets the current toolkit version.
Represents an event.
Definition event.h:21
static xtd::string get_full_path(const xtd::string &path)
Returns the absolute path for the specified path string.
Supports all classes in the xtd class hierarchy and provides low-level services to derived classes....
Definition object.h:42
Represents information about an operating system, such as the version and platform identifier....
Definition operating_system.h:25
Represents information about a processor, such as the architecture. This class cannot be inherited.
Definition processor.h:19
Provides data for the environment program exit event. This class cannot be inherited.
Definition program_exit_event_args.h:16
Provides data for the environment signal event. This class cannot be inherited.
Definition signal_cancel_event_args.h:18
Defines the xtd::startup object that can be used in the main method to safely call the application's ...
Definition startup.h:23
Represents information about target type, such as the target identifier. This class cannot be inherit...
Definition target_type.h:17
bool is_guid_application() const noexcept
Gets target id is gui application.
Represents a toolkit.
Definition toolkit.h:19
Represents the version number of an assembly, operating system, or the xtd. This class cannot be inhe...
Definition version.h:114
Contains xtd::compiler class.
Contains core_export_ keyword.
Contains xtd::cpp_language class.
Contains enum_ and enum_ut_ keywords.
Contains xtd::event event.
Contains xtd::exit_status enum class.
xtd::delegate< void(const program_exit_event_args &)> program_exit_event_handler
Represents the method that will handle the program exit events of a xtd::environment.
Definition program_exit_event_handler.h:17
xtd::delegate< void(signal_cancel_event_args &)> signal_cancel_event_handler
Represents the method that will handle the signal events of a xtd::environment.
Definition signal_cancel_event_handler.h:17
#define static_
This keyword is use to represent a static object. A static object can't be instantiated (constructors...
Definition static.h:37
#define core_export_
Define shared library export.
Definition core_export.h:13
int32_t int32
Represents a 32-bit signed integer.
Definition int32.h:23
int64_t int64
Represents a 64-bit signed integer.
Definition int64.h:23
uint32_t uint32
Represents a 32-bit unsigned integer.
Definition uint32.h:23
intmax_t intptr
Represent a pointer or a handle.
Definition intptr.h:23
signal
Specifies signals that can interrupt the current process.
Definition signal.h:18
exit_status
Specifies exit status for the xtd::environment::exit method.
Definition exit_status.h:18
environment_variable_target
Specifies the location where an environment variable is stored or retrieved in a set or get operation...
Definition environment_variable_target.h:15
build_type
Identifies the build type.
Definition build_type.h:20
std::vector< xtd::collections::generic::key_value_pair< enum_t, xtd::string > > enum_collection
Represents a pair of an enum_t value and a string of an enum of type enum_t.
Definition enum_collection.h:22
compiler_id
Identifies the compiler, supported by an assembly.
Definition compiler_id.h:20
@ none
No modifier key.
@ home
The HOME key.
@ c
The C key.
The xtd namespace contains all fundamental classes to access Hardware, Os, System,...
Definition xtd_about_box.h:10
Contains xtd::operating_system class.
Contains xtd::platform_id enum class.
Contains xtd::processor class.
Contains xtd::program_exit_event_handler event handler.
Contains xtd::signal_cancel_event_handler event handler.
Contains xtd::static_object class.
Contains xtd::string alias.
Contains xtd::collections::specialized::string_collection typedef.
Provides the registration struct for enumerations.
Definition enum_register.h:38
Contains xtd::target_id enum class.
Contains xtd::target_type class.
Contains xtd::version class.
Contains xtd::diagnostics::stack_trace class.
Contains xtd::environment_variable_target enum class.
Contains xtd::guid class.
Contains xtd::io::directory class.
Contains xtd::io::path class.
Contains xtd::forms::native::toolkit API.