Skip to content

Commit

Permalink
Added set_environment to OS class
Browse files Browse the repository at this point in the history
  • Loading branch information
neikeq committed Feb 3, 2019
1 parent d3c51a5 commit 41873ff
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 0 deletions.
1 change: 1 addition & 0 deletions core/os/os.h
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,7 @@ class OS {

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; }
Expand Down
5 changes: 5 additions & 0 deletions drivers/unix/os_unix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions drivers/unix/os_unix.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ class OS_Unix : public OS {

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;
Expand Down
5 changes: 5 additions & 0 deletions platform/uwp/os_uwp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
1 change: 1 addition & 0 deletions platform/uwp/os_uwp.h
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@ class OSUWP : public OS {

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;
Expand Down
5 changes: 5 additions & 0 deletions platform/windows/os_windows.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
1 change: 1 addition & 0 deletions platform/windows/os_windows.h
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,7 @@ class OS_Windows : public OS {

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;
Expand Down

0 comments on commit 41873ff

Please sign in to comment.