Added set_environment to OS class

This commit is contained in:
Ignacio Etcheverry 2019-01-29 22:59:38 +01:00
parent d3c51a5dfb
commit 41873ffa88
7 changed files with 19 additions and 0 deletions

View File

@ -266,6 +266,7 @@ public:
virtual bool has_environment(const String &p_var) const = 0;
virtual String get_environment(const String &p_var) const = 0;
virtual bool set_environment(const String &p_var, const String &p_value) const = 0;
virtual String get_name() = 0;
virtual List<String> get_cmdline_args() const { return _cmdline; }

View File

@ -469,6 +469,11 @@ String OS_Unix::get_environment(const String &p_var) const {
return "";
}
bool OS_Unix::set_environment(const String &p_var, const String &p_value) const {
return setenv(p_var.utf8().get_data(), p_var.utf8().get_data(), /* overwrite: */ true) == 0;
}
int OS_Unix::get_processor_count() const {
return sysconf(_SC_NPROCESSORS_CONF);

View File

@ -95,6 +95,7 @@ public:
virtual bool has_environment(const String &p_var) const;
virtual String get_environment(const String &p_var) const;
virtual bool set_environment(const String &p_var, const String &p_value) const;
virtual String get_locale() const;
virtual int get_processor_count() const;

View File

@ -739,6 +739,11 @@ String OSUWP::get_environment(const String &p_var) const {
return "";
};
bool OSUWP::set_environment(const String &p_var, const String &p_value) const {
return false;
}
String OSUWP::get_stdin_string(bool p_block) {
return String();

View File

@ -213,6 +213,7 @@ public:
virtual bool has_environment(const String &p_var) const;
virtual String get_environment(const String &p_var) const;
virtual bool set_environment(const String &p_var, const String &p_value) const;
virtual void set_clipboard(const String &p_text);
virtual String get_clipboard() const;

View File

@ -2604,6 +2604,11 @@ String OS_Windows::get_environment(const String &p_var) const {
return "";
}
bool OS_Windows::set_environment(const String &p_var, const String &p_value) const {
return (bool)SetEnvironmentVariableW(p_var.c_str(), p_value.c_str());
}
String OS_Windows::get_stdin_string(bool p_block) {
if (p_block) {

View File

@ -268,6 +268,7 @@ public:
virtual bool has_environment(const String &p_var) const;
virtual String get_environment(const String &p_var) const;
virtual bool set_environment(const String &p_var, const String &p_value) const;
virtual void set_clipboard(const String &p_text);
virtual String get_clipboard() const;