xtd 0.2.0
environment.h
Go to the documentation of this file.
1 #pragma once
7 #include "io/directory.h"
8 #include "argument_exception.h"
9 #include "as.h"
10 #include "compiler.h"
11 #include "core_export.h"
12 #include "cpp_language.h"
13 #include "enum.h"
15 #include "event.h"
16 #include "exit_status.h"
17 #include "guid.h"
18 #include "operating_system.h"
19 #include "platform_id.h"
20 #include "processor.h"
23 #include "static.h"
24 #include "target_type.h"
25 #include "toolkit.h"
26 #include "ustring.h"
27 #include "version.h"
28 #define __XTD_CORE_INTERNAL__
29 #include "internal/__build_type.h"
30 #include "internal/__compiler_id.h"
31 #include "internal/__compiler_version.h"
32 #include "internal/__cpp_language.h"
33 #undef __XTD_CORE_INTERNAL__
34 #include <map>
35 #include <cstdlib>
36 #include <vector>
37 
39 // The following constants are defined in the file xtd_command.cmake.
40 // If the target project is not built with cmake, each constant must be defined by the build tool like this:
41 // | Constant | Value |
42 // | ------------------------------ | ------------------------------------------------ |
43 // | __XTD_INCLUDE_PATH__ | ${XTD_INSTALL_PATH}/include" |
44 // | __XTD_LIB_PATH__ | ${XTD_INSTALL_PATH}/lib" |
45 // | __XTD_CONSOLE_INCLUDE_PATH__ | ${XTD_CONSOLE_INSTALL_PATH}/include" |
46 // | __XTD_CONSOLE_LIB_PATH__ | ${XTD_CONSOLE_INSTALL_PATH}/lib" |
47 // | __XTD_DRAWING_INCLUDE_PATH__ | ${XTD_DRAWING_INSTALL_PATH}/include" |
48 // | __XTD_DRAWING_LIB_PATH__ | ${XTD_DRAWING_INSTALL_PATH}/lib" |
49 // | __XTD_DRAWING_RESOURCES_PATH__ | ${XTD_DRAWING_INSTALL_PATH}/share/xtd/resources" |
50 // | __XTD_FORMS_INCLUDE_PATH__ | ${XTD_FORMS_INSTALL_PATH}/include" |
51 // | __XTD_FORMS_LIB_PATH__ | ${XTD_FORMS_INSTALL_PATH}/lib" |
52 // | __XTD_FORMS_RESOURCES_PATH__ | ${XTD_FORMS_INSTALL_PATH}/share/xtd/resources" |
53 // | __XTD_TUNIT_INCLUDE_PATH__ | ${XTD_TUNIT_INSTALL_PATH}/include" |
54 // | __XTD_TUNIT_LIB_PATH__ | ${XTD_TUNIT_INSTALL_PATH}/lib" |
55 #if !defined(__XTD_INCLUDE_PATH__) || !defined(__XTD_LIB_PATH__) || !defined(__XTD_CONSOLE_INCLUDE_PATH__) || !defined(__XTD_CONSOLE_LIB_PATH__) || !defined(__XTD_DRAWING_INCLUDE_PATH__) || !defined(__XTD_DRAWING_LIB_PATH__) || !defined(__XTD_DRAWING_RESOURCES_PATH__) || !defined(__XTD_FORMS_INCLUDE_PATH__) || !defined(__XTD_FORMS_LIB_PATH__) || !defined(__XTD_FORMS_RESOURCES_PATH__) || !defined(__XTD_TUNIT_INCLUDE_PATH__) || !defined(__XTD_TUNIT_LIB_PATH__)
56 #error "Some variables (like __XTD_INCLUDE_PATH__) are not defined. This is probably because you are not using CMake to generate your project. See the following link for more information: https://gammasoft71.github.io/xtd/docs/documentation/Guides/xtd.cmake/Overview..."
57 #endif
58 
61 namespace xtd {
71  class core_export_ environment final static_ {
72  class signal_catcher;
73  public:
150  enum class special_folder {
152  desktop = 0,
154  programs = 2,
156  my_documents = 5,
158  personal = 5,
160  favorites = 6,
162  startup = 7,
164  recent = 8,
166  send_to = 9,
168  start_menu = 11,
170  my_music = 13,
172  my_videos = 14,
174  desktop_directory = 16,
176  my_computer = 17,
178  network_shortcuts = 19,
180  fonts = 20,
182  templates = 21,
184  common_start_menu = 22,
186  common_programs = 23,
188  common_startup = 24,
190  common_desktop_directory = 25,
192  application_data = 26,
194  printer_shortcuts = 27,
196  local_application_data = 28,
198  internet_cache = 32,
200  cookies = 33,
202  history = 34,
204  common_application_data = 35,
206  windows = 36,
208  system = 37,
210  program_files = 38,
212  my_pictures = 39,
214  user_profile = 40,
216  system_x86 = 41,
218  program_files_x86 = 42,
220  common_program_files = 43,
222  common_program_files_x86 = 44,
224  common_templates = 45,
226  common_documents = 46,
228  common_admin_tools = 47,
230  admin_tools = 48,
232  common_music = 53,
234  common_pictures = 54,
236  common_videos = 55,
238  resources = 56,
240  localized_resources = 57,
242  common_oem_links = 58,
244  cd_burning = 59,
246  home = 64,
248  xtd_install = 1000,
250  xtd_locale = 1001,
252  xtd_reference_guide = 1002,
254  xtd_themes = 1003,
256  xtd_include = 1004,
258  xtd_libraries = 1005,
260  xtd_resources = 1006,
262  xtd_console_include = 1007,
264  xtd_console_libraries = 1008,
266  xtd_drawing_include = 1009,
268  xtd_drawing_libraries = 1010,
270  xtd_drawing_resources = 1011,
272  xtd_forms_include = 1012,
274  xtd_forms_libraries = 1013,
276  xtd_forms_resources = 1014,
278  xtd_tunit_include = 1015,
280  xtd_tunit_libraries = 1016,
281  };
282 
287  none = 0,
289  do_not_verify = 16384,
291  create = 32768
292  };
293 
295  class xtd_library final : public xtd::object {
296  public:
298  xtd_library() = default;
299  xtd_library(const xtd_library&) = default;
300  xtd_library& operator =(const xtd_library&) = default;
302 
304 
308  const xtd::ustring& include_path() const noexcept;
309 
312  const xtd::ustring& library_path() const noexcept;
313 
316  const xtd::ustring& name() const noexcept;
317 
320  const xtd::ustring& resources_path() const noexcept;
321 
324  const xtd::version& version() const noexcept;
326 
328 
330  xtd::ustring to_string() const noexcept override;
332 
333  private:
334  friend class environment;
335  xtd_library(const xtd::ustring& name, const xtd::version& version, const xtd::ustring& include_path, const xtd::ustring& library_path, const xtd::ustring& resources_path);
336  xtd::ustring name_;
337  xtd::version version_;
338  xtd::ustring include_path_;
339  xtd::ustring library_path_;
340  xtd::ustring resources_path_;
341  };
342 
344  using xtd_library_collection = std::vector<xtd_library>;
345 
347 
354  static xtd::ustring command_line() noexcept;
355 
358  static xtd::compiler compiler_version() noexcept {
359  static auto compiler_id = __compiler_id;
360  static auto version = __compiler_version;
361  static auto build_type = __build_type;
362  static xtd::compiler compiler {compiler_id, version, build_type, sizeof(size_t) == 8};
363  return compiler;
364  }
365 
368  static xtd::cpp_language cpp_version() noexcept {
369  static auto cpp_language = __cpp_language;
370  return cpp_language;
371  }
372 
377  static xtd::ustring current_directory();
378 
385  static void current_directory(const xtd::ustring& directory_name);
386 
389  static int32 current_managed_thread_id() noexcept;
390 
393  static intptr current_thread_id() noexcept;
394 
400  static int32 exit_code() noexcept;
406  static void exit_code(int32 value) noexcept;
407 
411  static bool has_shutdown_started();
412 
415  static bool is_64_bit_operating_system() noexcept;
416 
419  static bool is_64_bit_process() noexcept;
420 
424  static std::locale locale() noexcept;
425 
429  static xtd::ustring machine_name();
430 
433  static xtd::ustring new_line() noexcept;
434 
438  template <class char_t, class traits_t>
439  static std::basic_ostream<char_t, traits_t>& new_line(std::basic_ostream<char_t, traits_t>& os) {
440  for (auto c : new_line())
441  os.put(os.widen(c));
442  os.flush();
443  return os;
444  }
445 
448  static xtd::operating_system os_version() noexcept;
449 
452  static uint32 processor_count();
453 
456  static xtd::processor processor_information();
457 
460  static xtd::ustring stack_trace();
461 
465  static xtd::ustring system_directory();
466 
469  static size_t system_page_size();
470 
473  static xtd::target_type target_type() noexcept {
474  return xtd::target_type(as<xtd::target_id>(__XTD_CURRENT_TARGET_ID__));
475  }
476 
479  static std::chrono::milliseconds tick_count();
480 
483  static xtd::toolkit toolkit_version();
484 
485 
488  static bool user_administrator();
489 
492  static xtd::ustring user_domain_name();
493 
499  static bool user_interactive();
500 
503  static xtd::ustring user_name();
504 
507  static xtd::version version() noexcept;
508 
515  static int64 working_set();
516 
519  static const xtd_library_collection& xtd_libraries() noexcept;
521 
523 
531 
536 
538 
541  static void abort();
542 
545  [[noreturn]] static void exit();
549  [[noreturn]] static void exit(int32 exit_code);
552  [[noreturn]] static void exit(xtd::exit_status exit_status);
553 
558  static xtd::ustring expand_environment_variables(const xtd::ustring& name);
559 
575  static xtd::collections::specialized::string_vector get_command_line_args();
576 
583  static xtd::ustring get_environment_variable(const xtd::ustring& variable);
584 
593  static xtd::ustring get_environment_variable(const xtd::ustring& variable, environment_variable_target target);
594 
598  static std::map<std::string, std::string>& get_environment_variables();
599 
606  static std::map<std::string, std::string>& get_environment_variables(environment_variable_target target);
607 
612  static xtd::ustring get_folder_path(environment::special_folder folder);
613 
619  static xtd::ustring get_folder_path(environment::special_folder folder, environment::special_folder_option option);
620 
623  static xtd::collections::specialized::string_vector get_logical_drives();
624 
627  [[noreturn]] static void quick_exit() noexcept;
631  [[noreturn]] static void quick_exit(int32 exit_code) noexcept;
634  [[noreturn]] static void quick_exit(xtd::exit_status exit_status) noexcept;
635 
638  static void raise(xtd::signal signal);
639 
646  static void set_environment_variable(const xtd::ustring& variable, const xtd::ustring& value);
647 
656  static void set_environment_variable(const xtd::ustring& variable, const xtd::ustring& value, environment_variable_target target);
657 
659  static void __signal_catcher_check__();
661 
662  private:
663  static void on_cancel_signal(signal_cancel_event_args& e);
664  static void on_program_exit(const program_exit_event_args& e);
665 
666  inline static constexpr const char* xtd_include_path = __XTD_INCLUDE_PATH__;
667  inline static constexpr const char* xtd_libraries_path = __XTD_LIB_PATH__;
668  inline static constexpr const char* xtd_resources_path = __XTD_RESOURCES_PATH__;
669  inline static constexpr const char* xtd_console_include_path = __XTD_CONSOLE_INCLUDE_PATH__;
670  inline static constexpr const char* xtd_console_libraries_path = __XTD_CONSOLE_LIB_PATH__;
671  inline static constexpr const char* xtd_drawing_include_path = __XTD_DRAWING_INCLUDE_PATH__;
672  inline static constexpr const char* xtd_drawing_libraries_path = __XTD_DRAWING_LIB_PATH__;
673  inline static constexpr const char* xtd_drawing_resources_path = __XTD_DRAWING_RESOURCES_PATH__;
674  inline static constexpr const char* xtd_forms_include_path = __XTD_FORMS_INCLUDE_PATH__;
675  inline static constexpr const char* xtd_forms_libraries_path = __XTD_FORMS_LIB_PATH__;
676  inline static constexpr const char* xtd_forms_resources_path = __XTD_FORMS_RESOURCES_PATH__;
677  inline static constexpr const char* xtd_tunit_include_path = __XTD_TUNIT_INCLUDE_PATH__;
678  inline static constexpr const char* xtd_tunit_libraries_path = __XTD_TUNIT_LIB_PATH__;
679  static signal_catcher signal_catcher_;
680  };
681 }
682 
684 template<> struct xtd::enum_register<xtd::environment::special_folder> {
685  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::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"}};}
686 };
687 
690 };
Provides data for the environment program exit event. This class cannot be inherited.
Definition: program_exit_event_args.h:16
signal
Specifies signals that can interrupt the current process.
Definition: signal.h:18
Contains xtd::diagnostics::stack_trace class.
The file system directory that contains the programs that appear in the Startup folder for all users...
The file system directory that serves as a repository for videos that belong to a user...
Contains xtd::static_object class.
Defines the xtd::startup object that can be used in the main method to safely call the application&#39;s ...
Definition: startup.h:20
A folder for components that are shared across applications. This special folder is valid only for Wi...
Represents a xtd library that contains name, version and paths.
Definition: environment.h:295
Represents information about c++ libraries, such as the version and standard identifier. This class cannot be inherited.
Definition: compiler.h:25
compiler_id
Identifies the compiler, supported by an assembly.
Definition: compiler_id.h:18
Represents information about target type, such as the target identifier. This class cannot be inherit...
Definition: target_type.h:17
Contains xtd::operating_system class.
The file system directory that contains resource data.
build_type
Identifies the build type.
Definition: build_type.h:18
intmax_t intptr
Represent a pointer or a handle.
Definition: types.h:151
The directory that contains the user&#39;s program groups.
special_folder
Definition: environment.h:150
#define static_
This keyword is use to represent a static object. A static object can&#39;t be instantiated (constructors...
Definition: static.h:37
The file system directory that contains the link objects that can exist in the Printers virtual folde...
The path to the folder is verified. If the folder exists, the path is returned. If the folder does no...
A file system directory that contains the link objects that may exist in the My Network Places virtua...
static event< environment, program_exit_event_handler > program_exit
Occurs when the terminates normally (via xtd::environment::exit or returning from the main function)...
Definition: environment.h:534
A virtual folder that contains fonts.
Contains xtd::io::directory class.
Contains xtd::guid class.
The xtd namespace contains all fundamental classes to access Hardware, Os, System, and more.
Definition: system_report.h:17
The file system directory that acts as a staging area for files waiting to be written to a CD...
The directory used to physically store file objects on the desktop. Do not confuse this directory wit...
Contains xtd::as method.
Contains xtd::environment_variable_target enum class.
The file system directory that serves as a repository for image files common to all users...
special_folder_option
Specifies options to use for getting the path to a special folder.
Definition: environment.h:285
Represents text as a sequence of UTF-8 code units.
Definition: ustring.h:46
Represents information about c++ libraries, such as the version and language identifier. This class cannot be inherited.
Definition: cpp_language.h:24
Represents the version number of an assembly, operating system, or the xtd. This class cannot be inhe...
Definition: version.h:95
std::string to_string(const date_time &value, const std::string &fmt, const std::locale &loc)
Convert a specified value into a string with specified format and locale.
Definition: date_time.h:1063
std::vector< std::pair< enum_t, xtd::ustring > > enum_collection
Represents a pair of an enum_t value and a string of an enum of type enum_t.
Definition: enum_collection.h:19
Represents information about an operating system, such as the version and platform identifier...
Definition: operating_system.h:25
The file system directory that serves as a repository for video files common to all users...
The file system directory that contains documents that are common to all users. This special folder i...
Contains xtd::compiler class.
exit_status
Specifies exit status for the xtd::environment::exit method.
Definition: exit_status.h:18
The file system directory that contains home folder.
Contains enum_ and enum_ut_ keywords.
The directory that serves as a common repository for document templates.
The file system directory that contains the programs and folders that appear on the Start menu for al...
The file system directory that is used to store administrative tools for an individual user...
The directory that contains the Start menu items.
Contains xtd::collections::specialized::string_vector typedef.
Contains xtd::cpp_language class.
Contains xtd::exit_status enum class.
Represents an event.
Definition: event.h:21
std::vector< xtd::ustring > string_vector
Represents a collection of strings.
Definition: string_vector.h:25
Contains xtd::toolkit class.
static xtd::target_type target_type() noexcept
Gets an xtd::target_type object that contains the current target identifier.
Definition: environment.h:473
The My Computer folder. The MyComputer constant always yields the empty string ("") because no path i...
The Windows directory or SYSROOT. This corresponds to the windir% or SYSTEMROOT% environment variable...
The file system directory that contains administrative tools for all users of the computer...
Provides data for the environment signal event. This class cannot be inherited.
Definition: signal_cancel_event_args.h:18
std::vector< xtd_library > xtd_library_collection
Represents a xtd libraries collection.
Definition: environment.h:344
Represents a toolkit.
Definition: toolkit.h:19
The path to the folder is returned without verifying whether the path exists. If the folder is locate...
The file system directory that serves as a repository for music files common to all users...
Contains xtd::target_type class.
The file system directory that contains files and folders that appear on the desktop for all users...
Contains xtd::processor class.
Contains xtd::ustring class.
The directory that serves as a common repository for the user&#39;s favorite items.
Contains xtd::version class.
The installation folder of xtd.
The directory that serves as a common repository for Internet cookies.
The program files directory.On a non-x86 system, passing ProgramFiles to the GetFolderPath method ret...
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:368
The directory for components that are shared across applications.To get the x86 common program files ...
Supports all classes in the xtd class hierarchy and provides low-level services to derived classes...
Definition: object.h:32
int_least32_t int32
Represents a 32-bit signed integer.
Definition: types.h:129
Contains xtd::event event.
The directory that contains the Send To menu items.
The directory that corresponds to the user&#39;s Startup program group. The system starts these programs ...
The Program Files folder On an x86 system, passing the ProgramFilesX86 member to the Environment...
The logical Desktop rather than the physical file system location.
Contains xtd::program_exit_event_handler event handler.
The directory that serves as a common repository for application-specific data for the current roamin...
Represents information about a processor, such as the architecture. This class cannot be inherited...
Definition: processor.h:19
The directory that serves as a common repository for application-specific data that is used by all us...
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
Contains xtd::argument_exception exception.
The path to the folder is created if it does not already exist.
The file system directory that contains localized resource data.
static std::basic_ostream< char_t, traits_t > & new_line(std::basic_ostream< char_t, traits_t > &os)
Inserts a new-line character and flushes the stream.
Definition: environment.h:439
The user&#39;s profile folder. Applications should not create files or folders at this level; they should...
The file system directory that contains the templates that are available to all users. This special folder is valid only for Windows NT systems.
int_least64_t int64
Represents a 64-bit signed integer.
Definition: types.h:140
The environment class.
Definition: environment.h:71
uint_least32_t uint32
Represents a 32-bit unsigned integer.
Definition: types.h:239
static event< environment, signal_cancel_event_handler > cancel_signal
Occurs when a signal is sent to the current process.
Definition: environment.h:530
The directory that contains the user&#39;s most recently used documents.
Contains xtd::signal_cancel_event_handler event handler.
This value is recognized in Windows Vista for backward compatibility, but the special folder itself i...
The directory that serves as a common repository for application-specific data that is used by the cu...
Provides the registration struct for enumerations.
Definition: enum_register.h:36
The directory that serves as a common repository for temporary Internet files.
The My Documents folder. This member is equivalent to Personal.
Contains xtd::platform_id enum class.
The directory that serves as a common repository for Internet history items.